2 """Script to locate email addresses in the CVS logs."""
3 __version__ = '$Revision: 1.1.1.1 $'
13 class Acknowledgements(UserDict.UserDict):
14 def add(self, email, name, path):
16 d.setdefault(email, {})[path] = name
19 def open_cvs_log(info, paths=None):
20 cvsroot = info.get_cvsroot()
21 cmd = "cvs -q -d%s log " % cvsroot
23 cmd += " ".join(paths)
24 return os.popen(cmd, "r")
27 email_rx = re.compile("<([a-z][-a-z0-9._]*@[-a-z0-9.]+)>", re.IGNORECASE)
29 def find_acks(f, acks):
32 MAGIC_WORDS = ('van', 'von')
37 if line.startswith("Working file: "):
38 filename = line.split(None, 2)[2].strip()
41 m = email_rx.search(line)
43 words = prev.split() + line[:m.start()].split()
46 and (words[-1][0].isupper() or words[-1] in MAGIC_WORDS):
47 L.insert(0, words.pop())
49 email = m.group(1).lower()
50 acks.add(email, name, filename)
54 def load_cvs_log_acks(acks, args):
55 repolist = cvsinfo.get_repository_list(args or [""])
56 for info, paths in repolist:
57 print >>sys.stderr, "Repository:", info.get_cvsroot()
58 f = open_cvs_log(info, paths)
63 def load_tex_source_acks(acks, args):
65 path = path or os.curdir
66 if os.path.isfile(path):
67 read_acks_from_tex_file(acks, path)
69 read_acks_from_tex_dir(acks, path)
72 def read_acks_from_tex_file(acks, path):
78 if line.startswith(r"\sectionauthor{"):
79 line = line[len(r"\sectionauthor"):]
80 name, line = extract_tex_group(line)
81 email, line = extract_tex_group(line)
82 acks.add(email, name, path)
85 def read_acks_from_tex_dir(acks, path):
89 for n in os.listdir(p):
90 n = os.path.join(p, n)
93 elif os.path.normpath(n).endswith(".tex"):
94 read_acks_from_tex_file(acks, n)
97 def extract_tex_group(s):
99 for i in range(len(s)):
105 return s[1:i], s[i+1:]
108 def print_acks(acks):
110 for email, D in acks.items():
118 for file, name in L[1:]:
123 print prefname, "<%s>:" % email
130 print " %s (as %s)" % (file, name)
133 def print_ack_names(acks):
135 for email, D in acks.items():
139 for file, name in L[1:]:
140 prefname = prefname or name
141 names.append(prefname or email)
145 return cmp((s1.split()[-1], s1),
146 (s2.split()[-1], s2))
154 acks = Acknowledgements()
155 load_cvs_log_acks(acks, args)
156 load_tex_source_acks(acks, args)
157 print_ack_names(acks)
160 if __name__ == "__main__":