Commits

Bryan O'Sullivan  committed 906d902

Making progress on autogenerated example output.

  • Participants
  • Parent commits 379a802

Comments (0)

Files changed (5)

File en/00book.tex

 \usepackage{fullpage}
 \usepackage{graphics}
 \usepackage{newcent}
+\usepackage{fancyvrb}
 \usepackage{hyperref}
 
 \include{99defs}

File en/99defs.tex

+\newcommand{\tildefile}[1]{\texttt{\~/#1}}
 \newcommand{\filename}[1]{\texttt{#1}}
 \newcommand{\hgext}[1]{\texttt{#1}}
 \newcommand{\hgcmd}[1]{``\texttt{hg #1}''}
 \newcommand{\hgcmdargs}[2]{``\texttt{hg #1 #2}''}
 
+\DefineVerbatimEnvironment{codesample}{Verbatim}{frame=single,gobble=2,numbers=left}
+
 %%% Local Variables: 
 %%% mode: latex
 %%% TeX-master: "00book"

File en/examples/mq.qinit-help

+# name: help
+hg help qinit

File en/examples/run-example

+#!/usr/bin/python
+
+import cStringIO
+import os
+import pty
+import re
+import sys
+
+class example:
+    def __init__(self, name):
+        self.name = name
+
+    def parse(self):
+        fp = open(self.name)
+        cfp = cStringIO.StringIO()
+        for line in fp:
+            cfp.write(line)
+            if not line.rstrip().endswith('\\'):
+                yield cfp.getvalue()
+                cfp.seek(0)
+                cfp.truncate()
+        
+    name_re = re.compile('#\s*name:\s*(.*)$')
+    
+    def status(self, s):
+        sys.stdout.write(s)
+        if not s.endswith('\n'):
+            sys.stdout.flush()
+
+    def run(self):
+        ofp = None
+        self.status('running %s ' % os.path.basename(self.name))
+        for hunk in self.parse():
+            m = self.name_re.match(hunk)
+            if m:
+                self.status('.')
+                out = m.group(1)
+                assert os.sep not in out
+                if out:
+                    ofp = open('%s.%s.out' % (self.name, out), 'w')
+                else:
+                    ofp = None
+            elif ofp: ofp.write(hunk)
+        self.status('\n')
+
+def main(path='.'):
+    args = sys.argv[1:]
+    if args:
+        for a in args:
+            example(a).run()
+        return
+    for name in os.listdir(path):
+        if name == 'run-example' or name.startswith('.'): continue
+        if name.endswith('.out') or name.endswith('~'): continue
+        example(os.path.join(path, name)).run()
+
+if __name__ == '__main__':
+    main()
 
 The patch management problem arises in many situations.  Probably the
 most visible is that a user of an open source software project will
-contribute a bugfix or new feature to the project's maintainers in the
+contribute a bug fix or new feature to the project's maintainers in the
 form of a patch.
 
 Distributors of operating systems that include open source software
 patch will contain only one bug fix (the patch might modify several
 files, but it's doing ``only one thing''), and you may have a number
 of such patches for different bugs you need fixed and local changes
-you require.  In this situation, if you submit a bugfix patch to the
+you require.  In this situation, if you submit a bug fix patch to the
 upstream maintainers of a package and they include your fix in a
 subsequent release, you can simply drop that single patch when you're
 updating to the newer release.
 modifications those patches make.
 
 Quilt knows nothing about revision control tools, so it works equally
-well on top of an unpacked tarball or a Suversion repository.
+well on top of an unpacked tarball or a Subversion repository.
 
 \subsection{From patchwork quilt to Mercurial Queues}
 \label{sec:mq:quilt-mq}
 \section{Getting started with Mercurial Queues}
 \label{sec:mq:start}
 
-Because MQ is implemented as an extension, you have to explicitly
-enable it in order to use it.  (You don't need to download anything;
-MQ ships with the standard Mercurial distribution.)  To enable it,
-edit your \filename{~/.hgrc} file, and add the following lines:
+Because MQ is implemented as an extension, you must explicitly enable
+before you can use it.  (You don't need to download anything; MQ ships
+with the standard Mercurial distribution.)  To enable MQ, edit your
+\tildefile{.hgrc} file, and add the following lines:
 
-\begin{verbatim}
-[extensions]
-hgext.mq =
-\end{verbatim}
+\begin{codesample}
+  [extensions]
+  hgext.mq =
+\end{codesample}
+
+Once the extension is enabled, it will make a number of new commands
+available.  
+
 
 %%% Local Variables: 
 %%% mode: latex