Mercurial > hg > fetch
diff fetch.py @ 29:1c963875e6cd
add a test for manifest and fix resulting bugs
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Tue, 15 Nov 2011 10:13:47 -0800 |
parents | 5ecb6507931b |
children | 60e0e932570e |
line wrap: on
line diff
--- a/fetch.py Mon Nov 14 22:12:49 2011 -0800 +++ b/fetch.py Tue Nov 15 10:13:47 2011 -0800 @@ -60,7 +60,7 @@ class FileFetcher(Fetcher): """fetch a single file""" # Note: subpath and clobber for single files are ignored - + type = 'file' @classmethod @@ -130,7 +130,7 @@ # can only export with a subpath self.export(dest, subpath=self.subpath) return - + if os.path.exists(dest): assert os.path.isdir(dest) else: @@ -179,7 +179,7 @@ def versioned(self, directory): return os.path.exists(os.path.join(directory, self.vcs_dir)) - + if which('hg'): class HgFetcher(VCSFetcher): @@ -195,7 +195,7 @@ if os.path.exists(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) @@ -232,7 +232,7 @@ __all__ += [i.__name__ for i in fetchers] class Fetch(object): - + def __init__(self, fetchers=fetchers[:], relative_to=None, strict=True): self.fetchers = fetchers self.relative_to = relative_to @@ -256,7 +256,8 @@ # ensure all the required fetchers are available types = set([i['type'] for i in items]) assert not [i for i in types - if [True for fetcher in fetchers if fetcher.match(i)]] + if not [True for fetcher in fetchers + if fetcher.match(i)]] for item in items: @@ -274,18 +275,21 @@ def read_manifests(*manifests): """ read some manifests and return the items - + Format: %s """ % format_string - # sanity check - assert not [i for i in manifests if not os.path.exists(i)] - retval = [] for manifest in manifests: - for line in file(i).readlines(): + if isinstance(manifest, basestring): + assert os.path.exists(manifest), "manifest '%s' not found" % manifest + f = file(manifest) + else: + f = manifest + + for line in f.readlines(): line = line.strip() if line.startswith('#') or not line: continue @@ -316,7 +320,7 @@ return description + '\n' else: return '' - + parser = optparse.OptionParser(usage=usage, description=__doc__, formatter=PlainDescriptionFormatter()) parser.add_option('-o', '--output', help="output relative to this location vs. the manifest location") @@ -345,6 +349,9 @@ parser.print_help() parser.exit() + # sanity check + assert not [i for i in args if not os.path.exists(i)] + items = read_manifests(*args) fetch = Fetch(fetchers, strict=options.strict) @@ -352,5 +359,5 @@ fetch.fetch(*items) if __name__ == '__main__': - main() + main()