Mercurial > hg > fetch
changeset 28:5ecb6507931b
fix vcs fetchers to almost follow a pattern
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Mon, 14 Nov 2011 22:12:49 -0800 |
parents | 423b67ff4512 |
children | 1c963875e6cd |
files | fetch.py |
diffstat | 1 files changed, 32 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/fetch.py Mon Nov 14 21:32:54 2011 -0800 +++ b/fetch.py Mon Nov 14 22:12:49 2011 -0800 @@ -83,8 +83,7 @@ type = 'tar' def __call__(self, dest): - if self.clobber: - shutil.rmtree(dest) + self.clobber() if os.path.exists(dest): assert os.path.isdir(dest), "Destination must be a directory" else: @@ -121,9 +120,12 @@ """ Fetcher.__init__(self, url) self.export = export + self.prog = self.type # name of app program + self.vcs_dir = '.' + self.type # subdirectory for version control def __call__(self, dest): + self.clobber(dest) if self.subpath or self.export: # can only export with a subpath self.export(dest, subpath=self.subpath) @@ -131,6 +133,7 @@ if os.path.exists(dest): assert os.path.isdir(dest) + else: self.clone(dest) def export(self, dest): @@ -172,8 +175,11 @@ updates a checkout """ raise NotImplementedError("Abstract base class") - + def versioned(self, directory): + return os.path.exists(os.path.join(directory, self.vcs_dir)) + + if which('hg'): class HgFetcher(VCSFetcher): @@ -181,23 +187,24 @@ type = 'hg' def __init__(self, url, export=True): - VCSFetcher.__init__(self, url, export=True) + VCSFetcher.__init__(self, url, export=export) self.hg = which('hg') assert self.hg, "'hg' command not found" - def __call__(self, dest): + def clone(self, dest): if os.path.exists(dest): - assert os.path.isdir(dest) and os.path.exists(os.path.join(dest, '.hg')) - call([self.hg, 'pull', self.url], cwd=dest) - call([self.hg, 'update'], cwd=dest) - else: - if not os.path.exists(dest): - os.mkdirs(dest) - call([self.hg, 'clone', self.url, dest]) + assert os.path.isdir(dest) + call([self.hg, 'clone', self.url, dest]) + + def update(self, dest): + assert os.path.versioned(dest) + assert os.path.exists(dest) + call([self.hg, 'pull', self.url], cwd=dest) + call([self.hg, 'update', '-C'], cwd=dest) + fetchers.append(HgFetcher) - if which('git'): class GitFetcher(Fetcher): @@ -205,19 +212,20 @@ type = 'git' def __init__(self, url, export=True): - VCSFetcher.__init__(self, url, export=True) + VCSFetcher.__init__(self, url, export=export) self.git = which('git') + assert self.git, "'git' command not found" - def __call__(self, dest): - if os.path.exists(dest): - assert os.path.isdir(dest) and os.path.exists(os.path.join(dest, '.git')) - call([self.git, 'pull', self.url], cwd=dest) - call([self.hg, 'update'], cwd=dest) - else: - if not os.path.exists(dest): - os.mkdirs(dest) - call([self.hg, 'clone', self.url, dest]) - + def update(self, dest): + assert os.path.isdir(dest) + assert os.path.versioned(dest) + call([self.git, 'pull', self.url], cwd=dest) + call([self.git, 'update'], cwd=dest) + + def clone(self, dest): + if not os.path.exists(dest): + os.makedirs(dest) + call([self.git, 'clone', self.url, dest]) fetchers.append(GitFetcher)