Functions | Variables
bump_copyright Namespace Reference

Functions

def has_hidden_dirs (dirpath)
 
def get_the_paths (root_dir)
 
def do_the_subs (path_collection, search, replace)
 

Variables

string search_string = r'Copyright \(c\) 2003-20\d\d'
 
string replace_string = r'Copyright (c) 2003-2020'
 
string d = "."
 
 path_collection = get_the_paths(d)
 

Detailed Description

Walk the directory tree and replace the '20XX' copyright dates in lines with
'Copyright 2003-20XX' with '2016'. Usage:

    ./bump_copyright.py          # use "." as the start directory
    ./bump_copyright.py dirname  # use dirname as the start directory

Function Documentation

def bump_copyright.do_the_subs (   path_collection,
  search,
  replace 
)
Look for the copyright string and sub the date

Definition at line 50 of file bump_copyright.py.

50 def do_the_subs(path_collection, search, replace):
51  """
52  Look for the copyright string and sub the date
53  """
54  for path in path_collection:
55  with open(path, 'r+') as p:
56  contents = p.read()
57  pattern = re.compile(search)
58  contents = pattern.sub(replace, contents)
59  p.seek(0)
60  p.truncate()
61  p.write(contents)
62 
63 
int open(const char *, int)
Opens a file descriptor.
def bump_copyright.get_the_paths (   root_dir)
Get all the files NOT in hidden directories

Definition at line 34 of file bump_copyright.py.

34 def get_the_paths(root_dir):
35  """
36  Get all the files NOT in hidden directories
37  """
38  path_collection = []
39  for dirpath, dirnames, filenames in os.walk(root_dir):
40  use_dir = not has_hidden_dirs(dirpath)
41  if use_dir:
42  for filename in filenames:
43  # Don't try to replace the strings in this script
44  if not re.search(sys.argv[0].split("/")[-1], filename):
45  fullpath = os.path.join(dirpath, filename)
46  path_collection.append(fullpath)
47  return path_collection
48 
49 
void split(std::string const &s, char c, OutIter dest)
Definition: split.h:35
def bump_copyright.has_hidden_dirs (   dirpath)
Check if the directory path has any directories leading with a '.' (accept
the current working directory as okay).

Definition at line 20 of file bump_copyright.py.

20 def has_hidden_dirs(dirpath):
21  """
22  Check if the directory path has any directories leading with a '.' (accept
23  the current working directory as okay).
24  """
25  dirs = dirpath.split("/")
26  for dir in dirs:
27  # match - anchor a "." at the beginning, then 1 or more of any char
28  m = re.match(r'^\.(.+)', dir)
29  if m:
30  return True
31  return False
32 
33 

Variable Documentation

bump_copyright.d = "."

Definition at line 70 of file bump_copyright.py.

bump_copyright.path_collection = get_the_paths(d)

Definition at line 74 of file bump_copyright.py.

string bump_copyright.replace_string = r'Copyright (c) 2003-2020'

Definition at line 17 of file bump_copyright.py.

string bump_copyright.search_string = r'Copyright \(c\) 2003-20\d\d'

Definition at line 16 of file bump_copyright.py.