Add wrapper for os.system() that throws exception when it gets
authorMagnus Hagander <magnus@hagander.net>
Wed, 4 Mar 2009 13:19:34 +0000 (14:19 +0100)
committerMagnus Hagander <magnus@hagander.net>
Wed, 4 Mar 2009 13:19:34 +0000 (14:19 +0100)
nonzero exitcode, and use said wrapper for all calls when syncing.

reposync.py

index 246b5b919f80a4977605520309bf81ec742fc9a6..ecac74b49e031e1a4388c789904a59b1c6d776a3 100755 (executable)
@@ -79,11 +79,19 @@ class SyncMethod(object):
        def finalize(self):
                savedir = os.getcwd()
                os.chdir(self.repopath)
-               os.system("git update-server-info")
+               self.system("git update-server-info")
                os.chdir(savedir)
                if os.environ.has_key('GIT_DIR'):
                        del os.environ['GIT_DIR']
 
+       def system(self, cmd):
+               # Version of os.system() that raises an exception if the command
+               # fails to run or returns with bad exit code.
+               r = os.system(cmd)
+               if r != 0:
+                       raise Exception("Failed to execute \"%s\": %s" % (cmd, r))
+               return 0
+
                
 class SyncMethodCvs(SyncMethod):
 # Synchronize using "git cvsimport", which deals with remove CVS repositories
@@ -103,7 +111,7 @@ class SyncMethodCvs(SyncMethod):
 
        def normalsync(self):
                # Not initial sync, so just do a sync
-               os.system("git cvsimport -v -d %s -r master -C %s -i -k %s" % (
+               self.system("git cvsimport -v -d %s -r master -C %s -i -k %s" % (
                        # CVS url
                        self.remoteurl,
                        # New repo
@@ -125,7 +133,7 @@ class SyncMethodRsyncCvs(SyncMethod):
                rsyncpath = "%s/rsyncsrc/%s" % (self.conf.get("paths", "githome"), self.name)
 
                # First, rsync the cvs repository
-               os.system("rsync -azCH --delete %s %s" % (
+               self.system("rsync -azCH --delete %s %s" % (
                        self.remoteurl,
                        rsyncpath
                ))
@@ -135,7 +143,7 @@ class SyncMethodRsyncCvs(SyncMethod):
                os.chdir("%s/sw/fromcvs" % self.conf.get("paths", "githome"))
                
                # Perform Magic!
-               os.system("ruby togit.rb %s %s %s" % (
+               self.system("ruby togit.rb %s %s %s" % (
                        rsyncpath,
                        self.remotemodule,
                        self.repopath,
@@ -143,7 +151,7 @@ class SyncMethodRsyncCvs(SyncMethod):
                
                # Repack changes
                os.chdir(self.repopath)
-               os.system("git repack -f -d")
+               self.system("git repack -f -d")
                
                # Restore working dir
                os.chdir(savedir)               
@@ -152,7 +160,7 @@ class SyncMethodRsyncCvs(SyncMethod):
 class SyncMethodGit(SyncMethod):
 # Sync with a remote git repository.
        def initialsync(self):
-               os.system("git clone --no-checkout --bare %s %s" % (
+               self.system("git clone --no-checkout --bare %s %s" % (
                        self.remoteurl,
                        self.repopath
                ))
@@ -161,7 +169,7 @@ class SyncMethodGit(SyncMethod):
                savedir = os.getcwd()
                os.chdir(self.repopath)
                del os.environ['GIT_DIR']
-               os.system("git fetch %s" % self.remoteurl)
+               self.system("git fetch %s" % self.remoteurl)
                os.chdir(savedir)