changeset 2:54b30e8f6f82

* add a simulate mode * remove hello test * remove broken invokation from main fucntion
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 16 Jul 2010 14:47:13 -0700
parents 6cf716c40bb6
children 4d38d14cf1d4
files gut/main.py
diffstat 1 files changed, 21 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/gut/main.py	Fri Jul 16 14:28:21 2010 -0700
+++ b/gut/main.py	Fri Jul 16 14:47:13 2010 -0700
@@ -31,16 +31,26 @@
         print stderr
     return dict(stdout=stdout, stderr=stderr, code=code)
 
+def fake_call(command, **kw):
+    if isinstance(command, basestring):
+        print command
+    else:
+        print ' '.join(command)
+
 class gut(object):
     """
     a workflow for git
     """
 
-    def __init__(self, remote=None):
-        self.remote = remote 
-
-    def hello(self, name='world'):
-        print 'hello %s' % name
+    def __init__(self, remote=None, simulate=False):
+        """
+        - remote: name of the remote repository in .git/config
+        - simulate: print what calls will be used but don't run them
+        """
+        self.remote = remote
+        self.simulate = simulate
+        if simulate:
+            globals()['call'] = fake_call
 
     def update(self):
         """update the master and the branch you're on"""
@@ -57,11 +67,13 @@
 
     def patch(self, output=None):
         """generate a patch for review"""
+        diff = call(['git', 'diff', 'master'], pipe=True, output=False)
+        log = call(['git', 'log', 'master..'], pipe=True, output=False)
+        if self.simulate:
+            return
         if not output:
             output = self.branch() + '.diff'
-        diff = call(['git', 'diff', 'master'], pipe=True, output=False)
         diff = diff['stdout']
-        log = call(['git', 'log', 'master..'], pipe=True, output=False)
         log = log['stdout']
         f = file(output) # write the output to a patch file
         return log
@@ -69,13 +81,14 @@
     def branch(self):
         """print what branch you're on"""
         output = call(['git', 'branch'], output=False)
+        if self.simulate:
+            return
         for line in output['stdout'].splitlines():
             if line.startswith('*'):
                 return line[1:].strip()
 
 def main(args=sys.argv[1:]):
     parser = CommandParser(gut)
-    options, args = parser.parse_args(args)
     parser.invoke(args)
 
 if __name__ == '__main__':