summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Ipsum <richard.ipsum@codethink.co.uk>2015-01-08 11:30:48 +0000
committerRichard Ipsum <richard.ipsum@codethink.co.uk>2015-01-12 11:57:46 +0000
commit0553ce72422eb55ba6389037df3290b30142dd60 (patch)
tree56196721552b514766599a86350d41ea0aa99a38
parent86dab9e0377370d6ee57b905051d3a5331ce9478 (diff)
downloadimport-0553ce72422eb55ba6389037df3290b30142dd60.tar.gz
Read lorry prefix from yaml file
This adds PythonLorryExtension class to python.to_lorry to run the extension in a more conventional way. Previously the PythonExtension class was used to execute any of the extensions (it would call the extensions main() function). We move away from this so the extension can access useful methods, such as local_data_path(), that are provided by the ImportExtension class. This also removes use of pkg_resources.parse_requirement which is redundant. This also removes the unused import of select.
-rwxr-xr-xbaserockimport/exts/python.to_lorry69
1 files changed, 39 insertions, 30 deletions
diff --git a/baserockimport/exts/python.to_lorry b/baserockimport/exts/python.to_lorry
index accc9dc..06ee31d 100755
--- a/baserockimport/exts/python.to_lorry
+++ b/baserockimport/exts/python.to_lorry
@@ -28,7 +28,7 @@ import shutil
import tempfile
import xmlrpclib
import logging
-import select
+import yaml
import pkg_resources
@@ -109,9 +109,8 @@ def get_compression(url):
return None
# Assumption: url passed to this function must have a 'standard' tar extension
-def make_tarball_lorry(package_name, url):
- # TODO: this prefix probably shouldn't be hardcoded here either
- name = 'python-packages/%s' % package_name.lower()
+def make_tarball_lorry(lorry_prefix, package_name, url):
+ name = '%s/%s' % (lorry_prefix, package_name.lower())
lorry = {'type': 'tarball', 'url': url}
compression = get_compression(url)
@@ -138,7 +137,7 @@ def get_releases(client, requirement):
return releases
-def generate_tarball_lorry(client, requirement):
+def generate_tarball_lorry(lorry_prefix, client, requirement):
releases = get_releases(client, requirement)
if len(releases) == 0:
@@ -178,43 +177,53 @@ def generate_tarball_lorry(client, requirement):
url = urls[0]['url']
- return make_tarball_lorry(requirement.project_name, url)
+ return make_tarball_lorry(lorry_prefix, requirement.project_name, url)
-def str_repo_lorry(package_name, repo_type, url):
- # TODO: this prefix probably shouldn't be hardcoded here
- name = 'python-packages/%s' % package_name.lower()
+def str_repo_lorry(lorry_prefix, package_name, repo_type, url):
+ name = '%s/%s' % (lorry_prefix, package_name.lower())
return json.dumps({name: {'type': repo_type, 'url': url}},
indent=4, sort_keys=True)
-def main():
- if len(sys.argv) != 2:
- # TODO explain the format of python requirements
- # warn the user that they probably want to quote their arg
- # > < will be interpreted as redirection by the shell
- print('usage: %s requirement' % sys.argv[0], file=sys.stderr)
- sys.exit(1)
+class PythonLorryExtension(ImportExtension):
- client = xmlrpclib.ServerProxy(PYPI_URL)
+ def __init__(self):
+ super(PythonLorryExtension, self).__init__()
- req = pkg_resources.parse_requirements(sys.argv[1]).next()
+ def run(self):
+ if len(sys.argv) != 2:
+ # TODO explain the format of python requirements
+ # warn the user that they probably want to quote their arg
+ # > < will be interpreted as redirection by the shell
+ print('usage: %s requirement' % sys.argv[0], file=sys.stderr)
+ sys.exit(1)
- new_proj_name = name_or_closest(client, req.project_name)
+ client = xmlrpclib.ServerProxy(PYPI_URL)
- if new_proj_name == None:
- error("Couldn't find any project with name '%s'" % req.project_name)
+ req = pkg_resources.parse_requirements(sys.argv[1]).next()
- logging.debug('Treating %s as %s' % (req.project_name, new_proj_name))
- req.project_name = new_proj_name
+ with open(self.local_data_path('python.yaml')) as f:
+ lorry_prefix = yaml.load(f)['lorry-prefix']
- metadata = fetch_package_metadata(req.project_name)
- info = metadata['info']
+ new_proj_name = name_or_closest(client, req.project_name)
- repo_type = (find_repo_type(info['home_page'])
- if 'home_page' in info else None)
+ if new_proj_name == None:
+ error("Couldn't find any project with name '%s'" % req.project_name)
- print(str_repo_lorry(req.project_name, repo_type, info['home_page'])
- if repo_type else generate_tarball_lorry(client, req))
+ logging.debug('Treating %s as %s' % (req.project_name, new_proj_name))
+ req.project_name = new_proj_name
+
+ metadata = fetch_package_metadata(req.project_name)
+ info = metadata['info']
+
+ repo_type = (find_repo_type(info['home_page'])
+ if 'home_page' in info else None)
+
+ if repo_type:
+ print(str_repo_lorry(lorry_prefix, req.project_name,
+ repo_type, info['home_page']))
+ else:
+ print(generate_tarball_lorry(lorry_prefix, client, req))
if __name__ == '__main__':
- PythonExtension().run()
+ PythonLorryExtension().run()