From: Magnus Hagander Date: Wed, 4 Mar 2009 13:19:34 +0000 (+0100) Subject: Add wrapper for os.system() that throws exception when it gets X-Git-Url: http://git.postgresql.org/gitweb/static/benefitdownload/file?a=commitdiff_plain;h=f637a85b49ad186ec6e8528dd10553159e33aed2;p=pggit.git Add wrapper for os.system() that throws exception when it gets nonzero exitcode, and use said wrapper for all calls when syncing. --- diff --git a/reposync.py b/reposync.py index 246b5b9..ecac74b 100755 --- a/reposync.py +++ b/reposync.py @@ -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)