diff options
author | Nirbheek Chauhan <nirbheek.chauhan@gmail.com> | 2008-07-08 21:56:34 +0530 |
---|---|---|
committer | Nirbheek Chauhan <nirbheek.chauhan@gmail.com> | 2008-07-08 21:56:34 +0530 |
commit | 09df2c8899061f6a2a413227f22c09f50ac0b1c3 (patch) | |
tree | 98784efd4bd797563efe6955b1bb3b0875ca87e6 | |
parent | And it works! =) (diff) | |
download | autotua-09df2c8899061f6a2a413227f22c09f50ac0b1c3.tar.gz autotua-09df2c8899061f6a2a413227f22c09f50ac0b1c3.tar.bz2 autotua-09df2c8899061f6a2a413227f22c09f50ac0b1c3.zip |
Fix major logic problems in autotua.sync which led to *no* syncing happening in most cases. (Found by armin76)
- Use names for the return values of is_repo() (I should've implemented Ford_Prefect's suggestion earlier)
- Renovate git cloning/fetching; inspired from git.eclass (Thanks for git.eclass dberkholz!)
- Fix detection of repository for bzr
- rm -rf properly when {git,bzr}-export-ing
- Add a few comments explaining what's going on
-rw-r--r-- | slave/autotua/sync/__init__.py | 66 |
1 files changed, 44 insertions, 22 deletions
diff --git a/slave/autotua/sync/__init__.py b/slave/autotua/sync/__init__.py index 7f9a954..2067839 100644 --- a/slave/autotua/sync/__init__.py +++ b/slave/autotua/sync/__init__.py @@ -10,6 +10,14 @@ import os, subprocess, shutil import os.path as osp from .. import const +# init == sync (example: rsync) +ONLY_SYNC = 1 +# init and sync are different (eg: git) +INIT_SYNC = 2 +# sync == rmtree && init (eg: bzr-export, git with destdir not a repo) +RMTREE_INIT = 3 + + class Syncer(object): """ Sync stuff @@ -26,6 +34,8 @@ class Syncer(object): @scheme uri: string @param rev: SCM Revision to export. Default is latest + this variable is only taken into account in + the following cases: bzr-export, git-export @scheme rev: string @param scheme: The URI scheme @@ -39,23 +49,31 @@ class Syncer(object): """ Broad classification of repos into three types based on their behaviour 1. Same commands for init & sync (eg: rsync) - - return 1 (init) + - return ONLY_SYNC 2. Different init & sync commands (eg: git) - Detect if self.destdir is a repo - * Return 2 if it is (sync), 3 if not (rmtree && init) + * Return INIT_SYNC if it is, RMTREE_INIT if not (rmtree && init) 3. No concept of sync (eg: bzr-export) - Delete self.destdir before 'sync' - * return 3 (rmtree && init) + * return RMTREE_INIT (rmtree && init) """ - if self.scheme in ['rsync']: - return 1 + if self.scheme in ['rsync', 'rsync-nc']: + return ONLY_SYNC elif self.scheme in ['git', 'bzr']: - result = subprocess.Popen('cd %s; git-rev-parse' % self.destdir, shell=True) - if result != 0: - return 3 - return 2 + is_repo_cmd = None + if self.scheme == 'git': + is_repo_cmd = 'git-rev-parse' + elif self.scheme == 'bzr': + is_repo_cmd = 'bzr info' + else: + raise 'Unknown scm: "%s"' % self.scheme + result = subprocess.Popen('cd "%s"; %s' % (self.destdir, is_repo_cmd), shell=True) + returncode = result.wait() + if returncode < 0: + return RMTREE_INIT + return INIT_SYNC elif self.scheme in ['git-export', 'bzr-export']: - return 3 + return RMTREE_INIT def sync(self): """ @@ -66,12 +84,14 @@ class Syncer(object): # FIXME: Custom exceptions raise '"%s" exists and is not a directory' % self.destdir result = self._is_repo() - if result == '1': + if result == ONLY_SYNC: self.command.run('init') - elif result == '2': + elif result == INIT_SYNC: self.command.run('sync') - elif result == '3': - raise 'destdir: \"%s\" exists and is not a %s tree' % self.destdir, self.scheme + elif result == RMTREE_INIT: + self.command.run('init') + else: + raise 'Erm. I did not expect this. DIE DIE DIE.' else: if not osp.exists(osp.dirname(self.destdir)): # Create parents @@ -95,23 +115,25 @@ class Command(object): self.destdir = destdir def _get_args(self, action='init'): - if self.scheme == 'bzr': + if self.scheme == 'bzr': # Sync to latest revision if action == 'init': return 'bzr branch "%s" "%s"' % (self.uri, self.destdir) elif action == 'sync': return 'bzr pull --overwrite "%s" -d "%s"' % (self.uri, self.destdir) elif self.scheme == 'bzr-export': return 'bzr export -r"%s" "%s" "%s"' % (self.rev, self.destdir, self.uri) - elif self.scheme == 'git': + elif self.scheme == 'git': # Sync to latest HEAD + cmd = 'export GIT_DIR="%s" URI="%s";' % (self.destdir, self.uri) if action == 'init': - return 'git clone "%s" "%s"' % (self.uri, self.destdir) + return cmd+'git clone --bare "$URI" "$GIT_DIR";git config remote.origin.url "$URI"' if action == 'sync': - return 'cd "%s"; git reset --hard HEAD; git pull "%s"' % (self.destdir, self.uri) - elif self.scheme == 'git-export': - return 'git-archive --prefix="%s/" --remote="%s" "%s" | tar x -C "%s"' % (osp.basename(self.destdir), self.uri, self.rev, osp.dirname(self.destdir)) - elif self.scheme == 'rsync': + return cmd+'git config remote.origin.url "$URI";git fetch -f -u origin HEAD:HEAD' + elif self.scheme == 'git-export': # export self.rev + return 'git-archive --prefix="%s/" --remote="%s" "%s" | tar x -C "%s"' % \ + (osp.basename(self.destdir), self.uri, self.rev, osp.dirname(self.destdir)) + elif self.scheme == 'rsync': # rsync, delete return 'rsync -a --delete-after "%s" "%s"' % (self.uri, self.destdir) - elif self.scheme == 'rsync-nc': + elif self.scheme == 'rsync-nc': # rsync, no-clobber return 'rsync -a "%s" "%s"' % (self.uri, self.destdir) else: raise "Unknown scheme: %s" % self.scheme |