- return contents.replace(COPYRIGHT_TAG, copyright_string)
-
-def update_file(filename, verbose=True):
- if verbose == True:
- print "updating", filename
- contents = file(filename, 'r').read()
-
- p = Pipe([['bzr', 'log', '-n0', filename],
- ['grep', '^ *timestamp: '],
- ['tail', '-n1'],
- ['sed', 's/^ *//;'],
- ['cut', '-b', '16-19']])
- if p.status != 0:
- assert p.statuses[0] == 3, p.statuses
- return # bzr doesn't version that file
- assert p.status == 0, p.statuses
- orig_year = int(p.stdout.strip())
-
- p = Pipe([['bzr', 'log', '-n0', filename],
- ['grep', '^ *author: \|^ *committer: '],
- ['cut', '-d:', '-f2'],
- ['sed', 's/^ *//;s/ *$//'],
- ['sort'],
- ['uniq']])
- assert p.status == 0, p.statuses
- authors = p.stdout.rstrip().split('\n')
- authors = _replace_aliases(authors, with_email=True,
- aliases=ALIASES+COPYRIGHT_ALIASES)
-
- contents = _update_copyright(contents, orig_year, authors)
- f = file(filename, 'w')
- f.write(contents)
+ return contents.replace(COPY_RIGHT_TAG, copyright_string)
+
+def ignored_file(filename, ignored_paths=None, ignored_files=None,
+ check_disk=True, check_vcs=True):
+ """
+ >>> ignored_paths = ['./a/', './b/']
+ >>> ignored_files = ['x', 'y']
+ >>> ignored_file('./a/z', ignored_paths, ignored_files, False, False)
+ True
+ >>> ignored_file('./ab/z', ignored_paths, ignored_files, False, False)
+ False
+ >>> ignored_file('./ab/x', ignored_paths, ignored_files, False, False)
+ True
+ >>> ignored_file('./ab/xy', ignored_paths, ignored_files, False, False)
+ False
+ >>> ignored_file('./z', ignored_paths, ignored_files, False, False)
+ False
+ """
+ if ignored_paths == None:
+ ignored_paths = IGNORED_PATHS
+ if ignored_files == None:
+ ignored_files = IGNORED_FILES
+ if check_disk == True and os.path.isfile(filename) == False:
+ return True
+ for path in ignored_paths:
+ if filename.startswith(path):
+ return True
+ if os.path.basename(filename) in ignored_files:
+ return True
+ if check_vcs == True and is_versioned(filename) == False:
+ return True
+ return False
+
+def _set_contents(filename, contents, original_contents=None, dry_run=False,
+ verbose=0):
+ if original_contents == None and os.path.isfile(filename):
+ f = open(filename, 'r')
+ original_contents = f.read()
+ f.close()
+ if verbose > 0:
+ print "checking %s ... " % filename,
+ if contents != original_contents:
+ if verbose > 0:
+ if original_contents == None:
+ print "[creating]"
+ else:
+ print "[updating]"
+ if verbose > 1 and original_contents != None:
+ print '\n'.join(
+ difflib.unified_diff(
+ original_contents.splitlines(), contents.splitlines(),
+ fromfile=os.path.normpath(os.path.join('a', filename)),
+ tofile=os.path.normpath(os.path.join('b', filename)),
+ n=3, lineterm=''))
+ if dry_run == False:
+ f = file(filename, 'w')
+ f.write(contents)
+ f.close()
+ elif verbose > 0:
+ print "[no change]"
+
+# Update commands
+
+def update_authors(authors_fn=authors_list, dry_run=False, verbose=0):
+ new_contents = '%s was written by:\n%s\n' % (
+ PROJECT_INFO['project'],
+ '\n'.join(authors_fn())
+ )
+ _set_contents('AUTHORS', new_contents, dry_run=dry_run, verbose=verbose)
+
+def update_file(filename, original_year_fn=original_year, authors_fn=authors,
+ dry_run=False, verbose=0):
+ f = file(filename, 'r')
+ contents = f.read()