Skip to content

Instantly share code, notes, and snippets.

@stephenmcd
Created January 21, 2012 02:16
Show Gist options
  • Save stephenmcd/1650811 to your computer and use it in GitHub Desktop.
Save stephenmcd/1650811 to your computer and use it in GitHub Desktop.
Convert 3-clause BSD licenses to 2-clause in a directory of projects, commit and push to BitBucket and GitHub
#!/usr/bin/env python
import os
cwd = os.path.abspath(os.getcwd())
for project in os.listdir("."):
path = os.path.join(cwd, project)
if not os.path.isdir(path):
continue
os.chdir(path)
try:
with open("LICENSE", "r") as f:
license = f.read()
except:
continue
skip = False
lines = []
for line in license.split("\n"):
if line.strip().startswith("3"):
skip = True
elif skip and line.startswith("THIS"):
skip = False
if not skip:
lines.append(line)
with open("LICENSE", "w") as f:
f.writelines("\n".join(lines))
os.system('hg commit -m "Changed LICENSE from 3-clause to 2-clause BSD."')
os.system('hg push && hg push github')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment