diff options
author | Richard Ipsum <richard.ipsum@codethink.co.uk> | 2015-08-26 13:48:10 +0000 |
---|---|---|
committer | Richard Ipsum <richard.ipsum@codethink.co.uk> | 2015-08-26 14:38:11 +0000 |
commit | f74e7e428325be1cb018898a52d0aed4aec7a549 (patch) | |
tree | 9205f7de320c291b1285053674fe67b7ec38bbd4 /baserockimport/exts/python.to_lorry | |
parent | 5957c58e8113439e3ef36ff646eb52695085046d (diff) | |
download | import-f74e7e428325be1cb018898a52d0aed4aec7a549.tar.gz |
Add zip support to python.to_lorry ext
Change-Id: I04ed11272c7ddfb22829c71607772b86f216d457
Diffstat (limited to 'baserockimport/exts/python.to_lorry')
-rwxr-xr-x | baserockimport/exts/python.to_lorry | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/baserockimport/exts/python.to_lorry b/baserockimport/exts/python.to_lorry index 30f38e7..2a0cebb 100755 --- a/baserockimport/exts/python.to_lorry +++ b/baserockimport/exts/python.to_lorry @@ -37,15 +37,12 @@ from importer_python_common import * from utils import warn, error import utils -def filter_urls(urls): - allowed_extensions = ['tar.gz', 'tgz', 'tar.Z', 'tar.bz2', 'tbz2', - 'tar.lzma', 'tar.xz', 'tlz', 'txz', 'tar'] +def filter_urls(urls, extensions): + def match(url): + return ('.'.join(url['url'].split('.')[-2:]) in extensions + or url['url'].split('.')[-1] in extensions) - def allowed_extension(url): - return ('.'.join(url['url'].split('.')[-2:]) in allowed_extensions - or url['url'].split('.')[-1:] in allowed_extensions) - - return filter(allowed_extension, urls) + return filter(match, urls) def get_releases(client, package_name): try: @@ -55,7 +52,7 @@ def get_releases(client, package_name): return releases -def generate_tarball_lorry(lorry_prefix, client, package_name, version=None): +def generate_archive_lorry(lorry_prefix, client, package_name, version=None): releases = get_releases(client, package_name) if len(releases) == 0: @@ -79,12 +76,20 @@ def generate_tarball_lorry(lorry_prefix, client, package_name, version=None): except Exception as e: error("Couldn't fetch release urls:", e) - tarball_urls = filter_urls(urls) + tar_extensions = ('tar.gz', 'tgz', 'tar.Z', 'tar.bz2', 'tbz2', + 'tar.lzma', 'tar.xz', 'tlz', 'txz', 'tar') + tarball_urls = filter_urls(urls, tar_extensions) + zip_urls = filter_urls(urls, ('zip',)) + archive_type = None if len(tarball_urls) > 0: urls = tarball_urls + archive_type = 'tarball' + elif len(zip_urls) > 0: + urls = zip_urls + archive_type = 'zip' elif len(urls) > 0: - warn("None of these urls look like tarballs:") + warn("None of these urls look like archives:") for url in urls: warn("\t%s" % url['url']) error("Cannot proceed") @@ -94,7 +99,8 @@ def generate_tarball_lorry(lorry_prefix, client, package_name, version=None): url = urls[0]['url'] # TODO: shouldn't be hardcoding ext name here - return utils.str_tarball_lorry('python', lorry_prefix, package_name, url) + return utils.str_archive_lorry(archive_type, + 'python', lorry_prefix, package_name, url) class PythonLorryExtension(ImportExtension): @@ -133,7 +139,7 @@ class PythonLorryExtension(ImportExtension): logging.debug('Treating %s as %s' % (package_name, new_proj_name)) package_name = new_proj_name - print(generate_tarball_lorry(lorry_prefix, client, + print(generate_archive_lorry(lorry_prefix, client, package_name, version)) if __name__ == '__main__': |