summaryrefslogtreecommitdiff
path: root/dtools
diff options
context:
space:
mode:
authorJohnathan Corgan2010-06-24 16:44:51 -0700
committerJohnathan Corgan2010-06-24 16:44:51 -0700
commitc7593e94007f9e4b5de8c5db62ad09e8a99b2635 (patch)
tree31314b65760504fd38d6c029a57d5d2c8c453ff8 /dtools
parent36389a6f6c5c84599757a140c83e59372f0350c9 (diff)
parent5cc3614abac37d9adc1923dbf9211bc67e73a167 (diff)
downloadgnuradio-c7593e94007f9e4b5de8c5db62ad09e8a99b2635.tar.gz
gnuradio-c7593e94007f9e4b5de8c5db62ad09e8a99b2635.tar.bz2
gnuradio-c7593e94007f9e4b5de8c5db62ad09e8a99b2635.zip
Merge branch 'master' into next
* master: added python script to fix copyright years based on git log grc: expanded nports ability to have multiple port duplicators per side
Diffstat (limited to 'dtools')
-rwxr-xr-xdtools/bin/fix-copyright-years65
1 files changed, 65 insertions, 0 deletions
diff --git a/dtools/bin/fix-copyright-years b/dtools/bin/fix-copyright-years
new file mode 100755
index 000000000..bb0f3009d
--- /dev/null
+++ b/dtools/bin/fix-copyright-years
@@ -0,0 +1,65 @@
+#!/usr/bin/env python
+
+import re
+import datetime
+import subprocess
+import multiprocessing
+
+def command(*args): return subprocess.Popen(args, stdout=subprocess.PIPE).communicate()[0]
+
+def is_gnuradio_co_source(lines):
+ for line in lines[:20]:
+ if 'GNU Radio is free software' in line: return True
+ return False
+
+def get_gnuradio_co_line(lines):
+ for i, line in enumerate(lines[:5]):
+ if 'Copyright' in line and 'Free Software Foundation' in line: return line, i
+ return None
+
+def fix_co_years(files):
+ for file in files:
+ print file
+ lines = open(file).readlines()
+ if not is_gnuradio_co_source(lines): continue
+
+ #extract the years from the git history
+ years = set(map(
+ lambda l: int(l.split()[-2]),
+ filter(
+ lambda l: l.startswith('Date'),
+ command('git', 'log', file).splitlines(),
+ ),
+ ))
+
+ #extract line and line number for co line
+ try: line, num = get_gnuradio_co_line(lines)
+ except: continue
+
+ #extract years from co string
+ try:
+ co_years_str = re.match('^.*Copyright (.*) Free Software Foundation.*$', line).groups()[0]
+ co_years = set(map(int, co_years_str.split(',')))
+ except: print ' format error on line %d: "%s"'%(num, line); continue
+
+ #update the years if missing any
+ all_years = co_years.union(years)
+ if all_years != co_years:
+ print ' missing years: %s'%(', '.join(map(str, sorted(all_years - co_years))))
+ all_years.add(datetime.datetime.now().year) #add the current year
+ all_years_str = ', '.join(map(str, sorted(all_years)))
+ new_text = ''.join(lines[:num] + [line.replace(co_years_str, all_years_str)] + lines[num+1:])
+ open(file, 'w').write(new_text)
+
+if __name__ == "__main__":
+ #get recursive list of files in the repo
+ files = command('git', 'ls-tree', '--name-only', 'HEAD', '-r').splitlines()
+
+ #start n+1 processes to handle the files
+ num_procs = multiprocessing.cpu_count()
+ procs = [multiprocessing.Process(
+ target=lambda *files: fix_co_years(files),
+ args=files[num::num_procs],
+ ) for num in range(num_procs)]
+ map(multiprocessing.Process.start, procs)
+ map(multiprocessing.Process.join, procs)