From 81bf9eff259bddefe63ee8b4b70430a7306967c7 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 13 Jan 2011 16:21:01 -0800 Subject: uhd: moved fix-co-years and added path option --- fix-copyright-years | 66 ++++++++++++++++++++++++++++++++++++++++++++++++ host/fix-copyright-years | 63 --------------------------------------------- 2 files changed, 66 insertions(+), 63 deletions(-) create mode 100755 fix-copyright-years delete mode 100755 host/fix-copyright-years diff --git a/fix-copyright-years b/fix-copyright-years new file mode 100755 index 000000000..c6ee16a21 --- /dev/null +++ b/fix-copyright-years @@ -0,0 +1,66 @@ +#!/usr/bin/env python + +import re +import sys +import datetime +import subprocess +import multiprocessing + +co_line_matcher = re.compile('^.*Copyright (.*) Ettus Research LLC$') + +def command(*args): return subprocess.Popen(args, stdout=subprocess.PIPE).communicate()[0] + +def get_co_line(lines): + for i, line in enumerate(lines[:5]): + if co_line_matcher.match(line): return line, i + return None, None + +def fix_co_years(files): + for file in files: + print file + lines = open(file).readlines() + line, num = get_co_line(lines) + if line is None: continue + + #extract the years from the git history + log_years = map( + lambda l: int(l.split()[-2]), + filter( + lambda l: l.startswith('Date'), + command('git', 'log', file).splitlines(), + ), + ) + log_years = min(log_years), max(log_years) + + #extract years from co string + try: + co_years_str = co_line_matcher.match(line).groups()[0] + co_years = map(int, co_years_str.split('-')) + co_years = min(co_years), max(co_years) + except Exception, e: + print ' format error on line %d: "%s"'%(num, line), e + continue + + if log_years != co_years: + print ' log years: %s != copyright years: %s'%(log_years, co_years) + year_now = datetime.datetime.now().year + all_years = min(log_years), max(list(log_years)+[year_now]) #add the current year + all_years_str = '%s-%s'%all_years + if all_years[0] == all_years[1]: all_years_str = str(all_years[0]) + 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__": + if len(sys.argv) < 2: print "Usage: %s path/"%sys.argv[0]; exit() + + #get recursive list of files in the repo + files = command('git', 'ls-tree', '--name-only', 'HEAD', '-r', sys.argv[1]).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) diff --git a/host/fix-copyright-years b/host/fix-copyright-years deleted file mode 100755 index f5a3d5822..000000000 --- a/host/fix-copyright-years +++ /dev/null @@ -1,63 +0,0 @@ -#!/usr/bin/env python - -import re -import datetime -import subprocess -import multiprocessing - -co_line_matcher = re.compile('^.*Copyright (.*) Ettus Research LLC$') - -def command(*args): return subprocess.Popen(args, stdout=subprocess.PIPE).communicate()[0] - -def get_co_line(lines): - for i, line in enumerate(lines[:5]): - if co_line_matcher.match(line): return line, i - return None, None - -def fix_co_years(files): - for file in files: - print file - lines = open(file).readlines() - line, num = get_co_line(lines) - if line is None: continue - - #extract the years from the git history - log_years = map( - lambda l: int(l.split()[-2]), - filter( - lambda l: l.startswith('Date'), - command('git', 'log', file).splitlines(), - ), - ) - log_years = min(log_years), max(log_years) - - #extract years from co string - try: - co_years_str = co_line_matcher.match(line).groups()[0] - co_years = map(int, co_years_str.split('-')) - co_years = min(co_years), max(co_years) - except Exception, e: - print ' format error on line %d: "%s"'%(num, line), e - continue - - if log_years != co_years: - print ' log years: %s != copyright years: %s'%(log_years, co_years) - year_now = datetime.datetime.now().year - all_years = min(log_years), max(list(log_years)+[year_now]) #add the current year - all_years_str = '%s-%s'%all_years - if all_years[0] == all_years[1]: all_years_str = str(all_years[0]) - 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) -- cgit v1.2.3