# HG changeset patch # User Dongsheng Song # Date 1236843640 -28800 # Node ID 2180358c32c40319a1ed24064a729ade0f09e0a0 # Parent 1ef7708b3b7fcae20c0061233ee989e38a2a615b Move some files to contrib diff -r 1ef7708b3b7f -r 2180358c32c4 contrib/hg-interdiff --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/contrib/hg-interdiff Thu Mar 12 15:40:40 2009 +0800 @@ -0,0 +1,45 @@ +#!/usr/bin/env python +# +# Adapter for using interdiff with mercurial's extdiff extension. +# +# Copyright 2006 Bryan O'Sullivan +# +# This software may be used and distributed according to the terms of +# the GNU General Public License, incorporated herein by reference. + +import os, sys + +def walk(base): + # yield all non-directories below the base path. + for root, dirs, files in os.walk(base): + for f in files: + path = os.path.join(root, f) + yield path[len(base)+1:], path + else: + if os.path.isfile(base): + yield '', base + +# create list of unique file names under both directories. +files = dict(walk(sys.argv[1])) +files.update(walk(sys.argv[2])) +files = files.keys() +files.sort() + +def name(base, f): + if f: + path = os.path.join(base, f) + else: + path = base + # interdiff requires two files; use /dev/null if one is missing. + if os.path.exists(path): + return path + return '/dev/null' + +ret = 0 + +for f in files: + if os.system('interdiff "%s" "%s"' % (name(sys.argv[1], f), + name(sys.argv[2], f))): + ret = 1 + +sys.exit(ret) diff -r 1ef7708b3b7f -r 2180358c32c4 contrib/hg-replay --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/contrib/hg-replay Thu Mar 12 15:40:40 2009 +0800 @@ -0,0 +1,107 @@ +#!/usr/bin/env python +# +# Adapter for using interdiff with mercurial's extdiff extension. +# +# Copyright 2006 Bryan O'Sullivan +# +# This software may be used and distributed according to the terms of +# the GNU General Public License, incorporated herein by reference. + +import os +import shutil +import sys +import tempfile + +if len(sys.argv) < 4: + print >> sys.stderr, ('usage: %s srcrepo destrepo cset-to-omit [...]' % + os.path.basename(sys.argv[0])) + sys.exit(1) + +srcrepo, destrepo = sys.argv[1], sys.argv[2] +omit = sys.argv[3:] + +changemap = {} +revs = [] + +parent = None + +sys.stdout.write('gathering history...') +sys.stdout.flush() + +for line in os.popen("hg --cwd %r log -r0:tip --template '{rev}:{node} {parents}\n'" % srcrepo): + changes = line.split() + cset = changes[0].split(':')[1] + rev = len(revs) + changemap[cset] = rev + if len(changes) >= 2: + p1 = int(changes[1].split(':', 1)[0]) + if len(changes) == 3: + p2 = int(changes[2].split(':', 1)[0]) + else: + p2 = None + if len(changes) == 1: + p1 = parent + revs.append((cset, p1, p2)) + parent = rev + +sys.stdout.write(' %d revs\n' % len(revs)) + +def findrev(r): + try: + i = int(r) + if str(i) == r: + rev = i + if rev < 0: + rev += len(revs) + if rev < 0 or rev > len(revs): + print >> sys.stderr, 'bad changeset: %r' % r + sys.exit(1) + cset = revs[rev][0] + except ValueError: + cset = r + matches = [changemap[c] for c in changemap if c.startswith(cset)] + if len(matches) != 1: + print >> sys.stderr, 'bad changeset: %r' % r + sys.exit(1) + rev = matches[0] + return rev + +def run(cmd): + print cmd + ret = os.system(cmd) + if ret: + print >> sys.stderr, 'failure:', cmd + sys.exit(1) + +omit = map(findrev, omit) +omit.sort() +newrevs = revs[:omit[0]] +tip = len(newrevs) - 1 +run('hg clone -q -r%s %r %r' % (tip, srcrepo, destrepo)) + +os.environ['HGMERGE'] = 'true' + +patchdir = tempfile.mkdtemp(prefix='replay.') +try: + run('hg --cwd %r export --git -o %r%s%%R %d:tip' % + (srcrepo, patchdir, os.sep, omit[0]+1)) + for rev in xrange(omit[0], len(revs)): + if rev in omit: + print 'omit', rev + newrevs.append((None, revs[rev][1], None)) + continue + _, p1, p2 = revs[rev] + np1 = newrevs[p1][1] + if tip != np1: + run('hg --cwd %r update -q -C %s' % (destrepo, np1)) + np2 = None + if p2: + np2 = newrevs[p2][1] + run('hg --cwd %r merge -q %s' % (destrepo, np2)) + print >> sys.stderr, 'XXX - cannot handle merges properly yet' + run('hg --cwd %r import -q -f %r%s%d' % (destrepo, patchdir, os.sep, rev)) + tip = len(newrevs) - 1 + newrevs.append((None, tip, np2)) +finally: + print 'cleaning up ...' + #shutil.rmtree(patchdir) diff -r 1ef7708b3b7f -r 2180358c32c4 contrib/latex-to-docbook --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/contrib/latex-to-docbook Thu Mar 12 15:40:40 2009 +0800 @@ -0,0 +1,198 @@ +#!/usr/bin/python +# +# This is the most horrible of hacks. Pretend you're not looking. + +import cStringIO as StringIO +import re, sys + +sections = { + 'chapter': 'chapter', + 'section': 'sect1', + 'subsection': 'sect2', + 'subsubsection': 'sect3', + } + +envs = { + 'codesample2': 'programlisting', + 'codesample4': 'programlisting', + 'enumerate': 'orderedlist', + 'figure': 'informalfigure', + 'itemize': 'itemizedlist', + 'note': 'note', + 'quote': 'blockquote', + } + +def process(ifp, ofp): + print >> ofp, '\n' + stack = [] + para = True + inlist = 0 + for line in ifp: + if line.startswith('%%% Local Variables:'): + break + line = (line.rstrip() + .replace('~', ' ') + .replace('&', '&') + .replace('---', '&emdash;') + .replace('\_', '_') + .replace('\{', '{') + .replace('\}', '}') + .replace('\$', '$') + .replace('\%', '%') + .replace('\#', '#') + .replace('<', '<') + .replace('>', '>') + .replace('``', '') + .replace("''", '') + .replace('\\', '\\')) + line = re.sub(r'\s*\\(?:centering|small)\b\s*', '', line) + line = re.sub(r'\\(?:hgrc\\|hgrc)\b', + r' /.hgrc', line) + line = re.sub(r'\\item\[(?P[^]]+)\]', r'\item \g:', line) + line = re.sub(r'\\bug{(?P\d+)}', + r'issue \g', line) + line = re.sub(r'\\cite{([^}]+)}', r'\1', line) + line = re.sub(r'\\hggopt{(?P[^}]+)}', + r'', line) + line = re.sub(r'\\hgxopt{(?P[^}]+)}{(?P[^}]+)}{(?P[^}]+)}', + r'', line) + line = re.sub(r'\\hgxcmd{(?P[^}]+)}{(?P[^}]+)}', + r'\g', line) + line = re.sub(r'\\hgext{(?P[^}]+)}', + r'\g', line) + line = re.sub(r'\\hgopt{(?P[^}]+)}{(?P[^}]+)}', + r'', + line) + line = re.sub(r'\\cmdopt{(?P[^}]+)}{(?P[^}]+)}', + r'', + line) + line = re.sub(r'\\hgcmd{(?P[^}]+)}', + r'hg \g', line) + line = re.sub(r'\\caption{(?P[^}]+?)}', + r'\g', line) + line = re.sub(r'\\grafix{(?P[^}]+)}', + r'XXX add text', line) + line = re.sub(r'\\envar{(?P[^}]+)}', + r'\g', line) + line = re.sub(r'\\rcsection{(?P[^}]+)}', + r'\g', line) + line = re.sub(r'\\rcitem{(?P[^}]+)}{(?P[^}]+)}', + r'\g', line) + line = re.sub(r'\\dirname{(?P[^}]+?)}', + r'\g', line) + line = re.sub(r'\\filename{(?P[^}]+?)}', + r'\g', line) + line = re.sub(r'\\tildefile{(?P[^}]+)}', + r'~/\g', line) + line = re.sub(r'\\sfilename{(?P[^}]+)}', + r'\g', line) + line = re.sub(r'\\sdirname{(?P[^}]+)}', + r'\g', line) + line = re.sub(r'\\interaction{(?P[^}]+)}', + r'', line) + line = re.sub(r'\\excode{(?P[^}]+)}', + r'', line) + line = re.sub(r'\\pymod{(?P[^}]+)}', + r'\g', line) + line = re.sub(r'\\pymodclass{(?P[^}]+)}{(?P[^}]+)}', + r'\g', line) + line = re.sub(r'\\url{(?P[^}]+)}', + r'\g', line) + line = re.sub(r'\\href{(?P[^}]+)}{(?P[^}]+)}', + r'\g', line) + line = re.sub(r'\\command{(?P[^}]+)}', + r'\g', line) + line = re.sub(r'\\option{(?P[^}]+)}', + r'', line) + line = re.sub(r'\\ref{(?P[^}]+)}', r'', line) + line = re.sub(r'\\emph{(?P[^}]+)}', + r'\g', line) + line = re.sub(r'\\texttt{(?P[^}]+)}', + r'\g', line) + line = re.sub(r'\\textbf{(?P[^}]+)}', + r'\g', line) + line = re.sub(r'\\hook{(?P[^}]+)}', + r'\g', line) + line = re.sub(r'\\tplfilter{(?P[^}]+)}', + r'\g', line) + line = re.sub(r'\\tplkword{(?P[^}]+)}', + r'\g', line) + line = re.sub(r'\\tplkwfilt{(?P[^}]+)}{(?P[^}]+)}', + r'\g', line) + line = re.sub(r'\\[vV]erb(.)(?P[^\1]+?)\1', + r'\g', line) + line = re.sub(r'\\package{(?P[^}]+)}', + r'\g', line) + line = re.sub(r'\\hgcmdargs{(?P[^}]+)}{(?P[^}]+)}', + r'hg \g \g', + line) + line = re.sub(r'\\cmdargs{(?P[^}]+)}{(?P[^}]+)}', + r'\g \g', + line) + m = re.match(r'\\(chapter|section|subsection|subsubsection){(.*)}', line) + if m: + kind, content = m.groups() + sec = sections[kind] + while stack and stack[-1] >= sec: + close = stack.pop() + print >> ofp, '' % close + stack.append(sec) + print >> ofp, '<%s>\n%s' % (sec, content) + else: + m = re.match(r'\s*\\(begin|end){(?P[^}]+)}', line) + if m: + if not para: + print >> ofp, '' + if inlist: + ofp.write('') + para = True + state, env = m.groups() + env = envs[env] + if state == 'begin': + ofp.write('<') + if env in ('itemizedlist', 'orderedlist'): + inlist = 1 + else: + ofp.write('> ofp, env + '>' + else: + if line.startswith('\\item '): + if inlist > 1: + print >> ofp, '' + print >> ofp, '' + else: + inlist = 2 + para = True + line = line[6:] + if line and para: + if inlist: + ofp.write('') + ofp.write('') + para = False + if not line and not para: + print >> ofp, '' + if inlist: + ofp.write('') + para = True + print >> ofp, line + while stack: + print >> ofp, '' % stack.pop() + ofp.write('\n'.join(['\n'])) + + +if __name__ == '__main__': + for name in sys.argv[1:]: + if not name.endswith('.tex'): + continue + newname = name[:-3] + 'xml' + ofp = StringIO.StringIO() + process(open(name), ofp) + s = ofp.getvalue() + s = re.sub('\n+', '', s, re.M) + open(newname, 'w').write(s) diff -r 1ef7708b3b7f -r 2180358c32c4 contrib/sillybench.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/contrib/sillybench.py Thu Mar 12 15:40:40 2009 +0800 @@ -0,0 +1,177 @@ +#!/usr/bin/python +# +# Silly benchmarking program, to give a vague idea of how fast a few +# tools are on a handful of common operations. +# +# Use a fairly big and real source tarball to test with: Firefox +# 2.0.0.3 (37622 files, 5374 directories, 343MB unpacked onto +# 4KB-blocksize ext3). + +import csv +import os +import shutil +import sys +import tempfile +import time +import urllib2 + +url = 'ftp://ftp.mozilla.org/pub/mozilla.org/firefox/releases/2.0.0.3/source/firefox-2.0.0.3-source.tar.bz2' + +class CommandFailure(Exception): + pass + +class rcs(object): + def __init__(self): + self.logfp = open(self.__class__.__name__ + '.csv', 'w') + self.csv = csv.writer(self.logfp) + + def download(self): + name = url[url.rfind('/')+1:] + path = os.path.join(os.environ['HOME'], name) + if not os.path.isfile(path): + ofp = open(path + '.part', 'wb') + try: + ifp = urllib2.urlopen(url) + nbytes = ifp.info()['content-length'] + sys.stdout.write('%s: %s bytes ' % (name, nbytes)) + sys.stdout.flush() + while True: + data = ifp.read(131072) + if not data: break + sys.stdout.write('.') + sys.stdout.flush() + ofp.write(data) + del ofp + os.rename(path + '.part', path) + except: + if os.path.exists(path + '.part'): + os.unlink(path + '.part') + if os.path.exists(path): + os.unlink(path) + raise + return path + + def run(self, args, mustsucceed=True): + ret = os.spawnvp(os.P_WAIT, args[0], args) + if ret < 0: + msg = 'killed by signal %d' % (-ret) + if ret > 0: + msg = 'exited with status %d' % (ret) + if ret: + if mustsucceed: + raise CommandFailure('%s: %s' % (msg, ' '.join(args))) + print >> sys.stderr, 'WARNING: %s: %s' % (msg, ' '.join(args)) + + def time(self, *args, **kwargs): + start = time.time() + self.run(*args, **kwargs) + end = time.time() + return end - start + + def logtime(self, name, elapsed, rest=[]): + self.log('time:' + name, '%.3f' % elapsed, rest) + + def log(self, name, value, rest=[]): + item = (name, value, repr(rest)) + print ' '.join(item) + self.csv.writerow(item) + self.logfp.flush() + + def unpack(self): + tarball = self.download() + t = self.time(['tar', '-C', self.wdir, '-jxf', tarball]) + self.logtime('internal:untar', t) + for name in os.listdir(os.path.join(self.wdir, 'mozilla')): + os.rename(os.path.join(self.wdir, 'mozilla', name), + os.path.join(self.wdir, name)) + + def cleanup(self): + pass + + def add(self, paths): + pass + + def commit(self, msg, paths): + pass + + def status(self, path): + pass + + def remove(self, path): + pass + + +class subversion(rcs): + def __init__(self, root): + rcs.__init__(self) + self.repo = os.path.join(root, 'repo') + self.wdir = os.path.join(root, 'wc') + create = self.time(['svnadmin', 'create', '--fs-type=fsfs', self.repo]) + self.logtime('svn:create', create) + co = self.time(['svn', 'co', 'file://' + self.repo, self.wdir]) + self.logtime('svn:co', co) + self.logtime('init', create + co) + os.chdir(self.wdir) + + def dropmeta(self, names): + return [n for n in names if os.path.basename(n) != '.svn'] + + def add(self, paths): + t = self.time(['svn', 'add', '-q'] + paths) + self.logtime('add %r' % paths, t) + + def commit(self, msg, paths=[]): + if paths: + t = self.time(['svn', 'ci', '-q', '-m', msg] + paths) + else: + t = self.time(['svn', 'ci', '-q', '-m', msg]) + self.logtime('commit %r' % paths, t) + + +class mercurial(rcs): + def __init__(self, root): + rcs.__init__(self) + self.repo = os.path.join(root, 'repo') + self.wdir = self.repo + init = self.time(['hg', 'init', self.repo]) + self.logtime('init', init) + os.chdir(self.wdir) + + def dropmeta(self, names): + return [n for n in names if os.path.basename(n) != '.hg'] + + def add(self, paths): + t = self.time(['hg', 'add', '-q'] + paths) + self.logtime('add %r' % paths, t) + + def commit(self, msg, paths=[]): + if paths: + t = self.time(['hg', 'ci', '-q', '-m', msg] + paths) + else: + t = self.time(['hg', 'ci', '-q', '-m', msg]) + self.logtime('commit %r' % paths, t) + +def benchmark(cls): + oldcwd = os.getcwd() + root = tempfile.mkdtemp(prefix='sillybench.') + try: + print 'root', root + inst = cls(root) + inst.unpack() + names = inst.dropmeta(os.listdir('.')) + dirs = [n for n in names if os.path.isdir(n)] + nondirs = [n for n in names if not os.path.isdir(n)] + dirs.sort(key=hash) + names.sort(key=hash) + for d in dirs[:len(dirs)/2]: + inst.add([d]) + inst.commit('Add %r' % d, [d]) + inst.add(dirs[len(dirs)/2:] + names) + inst.commit('Add remaining dirs and files') + finally: + print >> sys.stderr, '[cleaning up...]' + shutil.rmtree(root) + os.chdir(oldcwd) + +benchmark(mercurial) +#benchmark(subversion) diff -r 1ef7708b3b7f -r 2180358c32c4 examples/hg-interdiff --- a/examples/hg-interdiff Thu Mar 12 15:35:19 2009 +0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -#!/usr/bin/env python -# -# Adapter for using interdiff with mercurial's extdiff extension. -# -# Copyright 2006 Bryan O'Sullivan -# -# This software may be used and distributed according to the terms of -# the GNU General Public License, incorporated herein by reference. - -import os, sys - -def walk(base): - # yield all non-directories below the base path. - for root, dirs, files in os.walk(base): - for f in files: - path = os.path.join(root, f) - yield path[len(base)+1:], path - else: - if os.path.isfile(base): - yield '', base - -# create list of unique file names under both directories. -files = dict(walk(sys.argv[1])) -files.update(walk(sys.argv[2])) -files = files.keys() -files.sort() - -def name(base, f): - if f: - path = os.path.join(base, f) - else: - path = base - # interdiff requires two files; use /dev/null if one is missing. - if os.path.exists(path): - return path - return '/dev/null' - -ret = 0 - -for f in files: - if os.system('interdiff "%s" "%s"' % (name(sys.argv[1], f), - name(sys.argv[2], f))): - ret = 1 - -sys.exit(ret) diff -r 1ef7708b3b7f -r 2180358c32c4 examples/hg-replay --- a/examples/hg-replay Thu Mar 12 15:35:19 2009 +0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,107 +0,0 @@ -#!/usr/bin/env python -# -# Adapter for using interdiff with mercurial's extdiff extension. -# -# Copyright 2006 Bryan O'Sullivan -# -# This software may be used and distributed according to the terms of -# the GNU General Public License, incorporated herein by reference. - -import os -import shutil -import sys -import tempfile - -if len(sys.argv) < 4: - print >> sys.stderr, ('usage: %s srcrepo destrepo cset-to-omit [...]' % - os.path.basename(sys.argv[0])) - sys.exit(1) - -srcrepo, destrepo = sys.argv[1], sys.argv[2] -omit = sys.argv[3:] - -changemap = {} -revs = [] - -parent = None - -sys.stdout.write('gathering history...') -sys.stdout.flush() - -for line in os.popen("hg --cwd %r log -r0:tip --template '{rev}:{node} {parents}\n'" % srcrepo): - changes = line.split() - cset = changes[0].split(':')[1] - rev = len(revs) - changemap[cset] = rev - if len(changes) >= 2: - p1 = int(changes[1].split(':', 1)[0]) - if len(changes) == 3: - p2 = int(changes[2].split(':', 1)[0]) - else: - p2 = None - if len(changes) == 1: - p1 = parent - revs.append((cset, p1, p2)) - parent = rev - -sys.stdout.write(' %d revs\n' % len(revs)) - -def findrev(r): - try: - i = int(r) - if str(i) == r: - rev = i - if rev < 0: - rev += len(revs) - if rev < 0 or rev > len(revs): - print >> sys.stderr, 'bad changeset: %r' % r - sys.exit(1) - cset = revs[rev][0] - except ValueError: - cset = r - matches = [changemap[c] for c in changemap if c.startswith(cset)] - if len(matches) != 1: - print >> sys.stderr, 'bad changeset: %r' % r - sys.exit(1) - rev = matches[0] - return rev - -def run(cmd): - print cmd - ret = os.system(cmd) - if ret: - print >> sys.stderr, 'failure:', cmd - sys.exit(1) - -omit = map(findrev, omit) -omit.sort() -newrevs = revs[:omit[0]] -tip = len(newrevs) - 1 -run('hg clone -q -r%s %r %r' % (tip, srcrepo, destrepo)) - -os.environ['HGMERGE'] = 'true' - -patchdir = tempfile.mkdtemp(prefix='replay.') -try: - run('hg --cwd %r export --git -o %r%s%%R %d:tip' % - (srcrepo, patchdir, os.sep, omit[0]+1)) - for rev in xrange(omit[0], len(revs)): - if rev in omit: - print 'omit', rev - newrevs.append((None, revs[rev][1], None)) - continue - _, p1, p2 = revs[rev] - np1 = newrevs[p1][1] - if tip != np1: - run('hg --cwd %r update -q -C %s' % (destrepo, np1)) - np2 = None - if p2: - np2 = newrevs[p2][1] - run('hg --cwd %r merge -q %s' % (destrepo, np2)) - print >> sys.stderr, 'XXX - cannot handle merges properly yet' - run('hg --cwd %r import -q -f %r%s%d' % (destrepo, patchdir, os.sep, rev)) - tip = len(newrevs) - 1 - newrevs.append((None, tip, np2)) -finally: - print 'cleaning up ...' - #shutil.rmtree(patchdir) diff -r 1ef7708b3b7f -r 2180358c32c4 sillybench/sillybench.py --- a/sillybench/sillybench.py Thu Mar 12 15:35:19 2009 +0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,177 +0,0 @@ -#!/usr/bin/python -# -# Silly benchmarking program, to give a vague idea of how fast a few -# tools are on a handful of common operations. -# -# Use a fairly big and real source tarball to test with: Firefox -# 2.0.0.3 (37622 files, 5374 directories, 343MB unpacked onto -# 4KB-blocksize ext3). - -import csv -import os -import shutil -import sys -import tempfile -import time -import urllib2 - -url = 'ftp://ftp.mozilla.org/pub/mozilla.org/firefox/releases/2.0.0.3/source/firefox-2.0.0.3-source.tar.bz2' - -class CommandFailure(Exception): - pass - -class rcs(object): - def __init__(self): - self.logfp = open(self.__class__.__name__ + '.csv', 'w') - self.csv = csv.writer(self.logfp) - - def download(self): - name = url[url.rfind('/')+1:] - path = os.path.join(os.environ['HOME'], name) - if not os.path.isfile(path): - ofp = open(path + '.part', 'wb') - try: - ifp = urllib2.urlopen(url) - nbytes = ifp.info()['content-length'] - sys.stdout.write('%s: %s bytes ' % (name, nbytes)) - sys.stdout.flush() - while True: - data = ifp.read(131072) - if not data: break - sys.stdout.write('.') - sys.stdout.flush() - ofp.write(data) - del ofp - os.rename(path + '.part', path) - except: - if os.path.exists(path + '.part'): - os.unlink(path + '.part') - if os.path.exists(path): - os.unlink(path) - raise - return path - - def run(self, args, mustsucceed=True): - ret = os.spawnvp(os.P_WAIT, args[0], args) - if ret < 0: - msg = 'killed by signal %d' % (-ret) - if ret > 0: - msg = 'exited with status %d' % (ret) - if ret: - if mustsucceed: - raise CommandFailure('%s: %s' % (msg, ' '.join(args))) - print >> sys.stderr, 'WARNING: %s: %s' % (msg, ' '.join(args)) - - def time(self, *args, **kwargs): - start = time.time() - self.run(*args, **kwargs) - end = time.time() - return end - start - - def logtime(self, name, elapsed, rest=[]): - self.log('time:' + name, '%.3f' % elapsed, rest) - - def log(self, name, value, rest=[]): - item = (name, value, repr(rest)) - print ' '.join(item) - self.csv.writerow(item) - self.logfp.flush() - - def unpack(self): - tarball = self.download() - t = self.time(['tar', '-C', self.wdir, '-jxf', tarball]) - self.logtime('internal:untar', t) - for name in os.listdir(os.path.join(self.wdir, 'mozilla')): - os.rename(os.path.join(self.wdir, 'mozilla', name), - os.path.join(self.wdir, name)) - - def cleanup(self): - pass - - def add(self, paths): - pass - - def commit(self, msg, paths): - pass - - def status(self, path): - pass - - def remove(self, path): - pass - - -class subversion(rcs): - def __init__(self, root): - rcs.__init__(self) - self.repo = os.path.join(root, 'repo') - self.wdir = os.path.join(root, 'wc') - create = self.time(['svnadmin', 'create', '--fs-type=fsfs', self.repo]) - self.logtime('svn:create', create) - co = self.time(['svn', 'co', 'file://' + self.repo, self.wdir]) - self.logtime('svn:co', co) - self.logtime('init', create + co) - os.chdir(self.wdir) - - def dropmeta(self, names): - return [n for n in names if os.path.basename(n) != '.svn'] - - def add(self, paths): - t = self.time(['svn', 'add', '-q'] + paths) - self.logtime('add %r' % paths, t) - - def commit(self, msg, paths=[]): - if paths: - t = self.time(['svn', 'ci', '-q', '-m', msg] + paths) - else: - t = self.time(['svn', 'ci', '-q', '-m', msg]) - self.logtime('commit %r' % paths, t) - - -class mercurial(rcs): - def __init__(self, root): - rcs.__init__(self) - self.repo = os.path.join(root, 'repo') - self.wdir = self.repo - init = self.time(['hg', 'init', self.repo]) - self.logtime('init', init) - os.chdir(self.wdir) - - def dropmeta(self, names): - return [n for n in names if os.path.basename(n) != '.hg'] - - def add(self, paths): - t = self.time(['hg', 'add', '-q'] + paths) - self.logtime('add %r' % paths, t) - - def commit(self, msg, paths=[]): - if paths: - t = self.time(['hg', 'ci', '-q', '-m', msg] + paths) - else: - t = self.time(['hg', 'ci', '-q', '-m', msg]) - self.logtime('commit %r' % paths, t) - -def benchmark(cls): - oldcwd = os.getcwd() - root = tempfile.mkdtemp(prefix='sillybench.') - try: - print 'root', root - inst = cls(root) - inst.unpack() - names = inst.dropmeta(os.listdir('.')) - dirs = [n for n in names if os.path.isdir(n)] - nondirs = [n for n in names if not os.path.isdir(n)] - dirs.sort(key=hash) - names.sort(key=hash) - for d in dirs[:len(dirs)/2]: - inst.add([d]) - inst.commit('Add %r' % d, [d]) - inst.add(dirs[len(dirs)/2:] + names) - inst.commit('Add remaining dirs and files') - finally: - print >> sys.stderr, '[cleaning up...]' - shutil.rmtree(root) - os.chdir(oldcwd) - -benchmark(mercurial) -#benchmark(subversion) diff -r 1ef7708b3b7f -r 2180358c32c4 tools/latex-to-docbook --- a/tools/latex-to-docbook Thu Mar 12 15:35:19 2009 +0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,198 +0,0 @@ -#!/usr/bin/python -# -# This is the most horrible of hacks. Pretend you're not looking. - -import cStringIO as StringIO -import re, sys - -sections = { - 'chapter': 'chapter', - 'section': 'sect1', - 'subsection': 'sect2', - 'subsubsection': 'sect3', - } - -envs = { - 'codesample2': 'programlisting', - 'codesample4': 'programlisting', - 'enumerate': 'orderedlist', - 'figure': 'informalfigure', - 'itemize': 'itemizedlist', - 'note': 'note', - 'quote': 'blockquote', - } - -def process(ifp, ofp): - print >> ofp, '\n' - stack = [] - para = True - inlist = 0 - for line in ifp: - if line.startswith('%%% Local Variables:'): - break - line = (line.rstrip() - .replace('~', ' ') - .replace('&', '&') - .replace('---', '&emdash;') - .replace('\_', '_') - .replace('\{', '{') - .replace('\}', '}') - .replace('\$', '$') - .replace('\%', '%') - .replace('\#', '#') - .replace('<', '<') - .replace('>', '>') - .replace('``', '') - .replace("''", '') - .replace('\\', '\\')) - line = re.sub(r'\s*\\(?:centering|small)\b\s*', '', line) - line = re.sub(r'\\(?:hgrc\\|hgrc)\b', - r' /.hgrc', line) - line = re.sub(r'\\item\[(?P[^]]+)\]', r'\item \g:', line) - line = re.sub(r'\\bug{(?P\d+)}', - r'issue \g', line) - line = re.sub(r'\\cite{([^}]+)}', r'\1', line) - line = re.sub(r'\\hggopt{(?P[^}]+)}', - r'', line) - line = re.sub(r'\\hgxopt{(?P[^}]+)}{(?P[^}]+)}{(?P[^}]+)}', - r'', line) - line = re.sub(r'\\hgxcmd{(?P[^}]+)}{(?P[^}]+)}', - r'\g', line) - line = re.sub(r'\\hgext{(?P[^}]+)}', - r'\g', line) - line = re.sub(r'\\hgopt{(?P[^}]+)}{(?P[^}]+)}', - r'', - line) - line = re.sub(r'\\cmdopt{(?P[^}]+)}{(?P[^}]+)}', - r'', - line) - line = re.sub(r'\\hgcmd{(?P[^}]+)}', - r'hg \g', line) - line = re.sub(r'\\caption{(?P[^}]+?)}', - r'\g', line) - line = re.sub(r'\\grafix{(?P[^}]+)}', - r'XXX add text', line) - line = re.sub(r'\\envar{(?P[^}]+)}', - r'\g', line) - line = re.sub(r'\\rcsection{(?P[^}]+)}', - r'\g', line) - line = re.sub(r'\\rcitem{(?P[^}]+)}{(?P[^}]+)}', - r'\g', line) - line = re.sub(r'\\dirname{(?P[^}]+?)}', - r'\g', line) - line = re.sub(r'\\filename{(?P[^}]+?)}', - r'\g', line) - line = re.sub(r'\\tildefile{(?P[^}]+)}', - r'~/\g', line) - line = re.sub(r'\\sfilename{(?P[^}]+)}', - r'\g', line) - line = re.sub(r'\\sdirname{(?P[^}]+)}', - r'\g', line) - line = re.sub(r'\\interaction{(?P[^}]+)}', - r'', line) - line = re.sub(r'\\excode{(?P[^}]+)}', - r'', line) - line = re.sub(r'\\pymod{(?P[^}]+)}', - r'\g', line) - line = re.sub(r'\\pymodclass{(?P[^}]+)}{(?P[^}]+)}', - r'\g', line) - line = re.sub(r'\\url{(?P[^}]+)}', - r'\g', line) - line = re.sub(r'\\href{(?P[^}]+)}{(?P[^}]+)}', - r'\g', line) - line = re.sub(r'\\command{(?P[^}]+)}', - r'\g', line) - line = re.sub(r'\\option{(?P[^}]+)}', - r'', line) - line = re.sub(r'\\ref{(?P[^}]+)}', r'', line) - line = re.sub(r'\\emph{(?P[^}]+)}', - r'\g', line) - line = re.sub(r'\\texttt{(?P[^}]+)}', - r'\g', line) - line = re.sub(r'\\textbf{(?P[^}]+)}', - r'\g', line) - line = re.sub(r'\\hook{(?P[^}]+)}', - r'\g', line) - line = re.sub(r'\\tplfilter{(?P[^}]+)}', - r'\g', line) - line = re.sub(r'\\tplkword{(?P[^}]+)}', - r'\g', line) - line = re.sub(r'\\tplkwfilt{(?P[^}]+)}{(?P[^}]+)}', - r'\g', line) - line = re.sub(r'\\[vV]erb(.)(?P[^\1]+?)\1', - r'\g', line) - line = re.sub(r'\\package{(?P[^}]+)}', - r'\g', line) - line = re.sub(r'\\hgcmdargs{(?P[^}]+)}{(?P[^}]+)}', - r'hg \g \g', - line) - line = re.sub(r'\\cmdargs{(?P[^}]+)}{(?P[^}]+)}', - r'\g \g', - line) - m = re.match(r'\\(chapter|section|subsection|subsubsection){(.*)}', line) - if m: - kind, content = m.groups() - sec = sections[kind] - while stack and stack[-1] >= sec: - close = stack.pop() - print >> ofp, '' % close - stack.append(sec) - print >> ofp, '<%s>\n%s' % (sec, content) - else: - m = re.match(r'\s*\\(begin|end){(?P[^}]+)}', line) - if m: - if not para: - print >> ofp, '' - if inlist: - ofp.write('') - para = True - state, env = m.groups() - env = envs[env] - if state == 'begin': - ofp.write('<') - if env in ('itemizedlist', 'orderedlist'): - inlist = 1 - else: - ofp.write('> ofp, env + '>' - else: - if line.startswith('\\item '): - if inlist > 1: - print >> ofp, '' - print >> ofp, '' - else: - inlist = 2 - para = True - line = line[6:] - if line and para: - if inlist: - ofp.write('') - ofp.write('') - para = False - if not line and not para: - print >> ofp, '' - if inlist: - ofp.write('') - para = True - print >> ofp, line - while stack: - print >> ofp, '' % stack.pop() - ofp.write('\n'.join(['\n'])) - - -if __name__ == '__main__': - for name in sys.argv[1:]: - if not name.endswith('.tex'): - continue - newname = name[:-3] + 'xml' - ofp = StringIO.StringIO() - process(open(name), ofp) - s = ofp.getvalue() - s = re.sub('\n+', '', s, re.M) - open(newname, 'w').write(s)