summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Ipsum <richard.ipsum@codethink.co.uk>2014-10-08 11:49:03 +0100
committerRichard Ipsum <richard.ipsum@codethink.co.uk>2014-11-04 12:40:53 +0000
commit027b60b8b2076af0414cfe09eb55f6c23a81e73e (patch)
treeb5d33d33b06ef04bebe9272e380ee55e4d126341
parent155ee640ba80205b689aa0d119c9af8afeeb2f47 (diff)
downloadimport-027b60b8b2076af0414cfe09eb55f6c23a81e73e.tar.gz
Get user to choose in the case of multiple releases
-rwxr-xr-ximport/pip.to_lorry78
1 files changed, 58 insertions, 20 deletions
diff --git a/import/pip.to_lorry b/import/pip.to_lorry
index 7483b6b..67dca8b 100755
--- a/import/pip.to_lorry
+++ b/import/pip.to_lorry
@@ -24,34 +24,72 @@ import requests
import json
import sys
+import xmlrpclib
+
+PYPI_URL = 'http://pypi.python.org/pypi'
+
def fetch_package_metadata(package_name):
- return requests.get('http://pypi.python.org/pypi/%s/json'
- % package_name).json()
+ return requests.get('%s/%s/json'
+ % (PYPI_URL, package_name)).json()
def is_repo(url):
- vcss = [('git', 'clone'), ('hg', 'clone'),
- ('svn', 'checkout'), ('bzr', 'branch')]
+ vcss = [('git', 'clone'), ('hg', 'clone'),
+ ('svn', 'checkout'), ('bzr', 'branch')]
+
+ for (vcs, vcs_command) in vcss:
+ p = subprocess.Popen([vcs, vcs_command, url], stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+
+ if p.returncode == 0:
+ return True
+
+ return False
- for (vcs, vcs_command) in vcss:
- p = subprocess.Popen([vcs, vcs_command, url], stdout=subprocess.PIPE,
- stderr=subprocess.PIPE)
+def make_lorry(name, url):
+ return '''{
+ "%s-tarball": {
+ "type": "tarball",
+ "url": "%s"
+ }
+}''' % (name, url)
- if p.returncode == 0:
- return True
+def generate_lorry_from_tarball(package_name):
+ client = xmlrpclib.ServerProxy(PYPI_URL)
+ releases = client.package_releases(package_name)
+ print('releases: ', releases)
- return False
+ for n, release in enumerate(releases):
+ print('%s: %s (%s)' % (n, client.release_data(package_name,
+ release)['name'], release))
+
+ s = raw_input('--> ')
+ choice = int(s) if s.isdigit() else None
+ choice = choice if choice < len(releases) else None
+
+ if choice == None:
+ print("Invalid choice, exiting", file=sys.stderr)
+ sys.exit(1)
+
+ release = releases[choice]
+ print('Will use ', choice)
if len(sys.argv) != 2:
- print('usage: %s python_package' % sys.argv[0], file=sys.stderr)
- sys.exit(1)
+ print('usage: %s python_package' % sys.argv[0], file=sys.stderr)
+ sys.exit(1)
-info = fetch_package_metadata('numpy')['info']
+package_name = sys.argv[1]
+metadata = fetch_package_metadata(package_name)
+info = metadata['info']
if 'home_page' in info:
- # TODO: detect if git repo, if so then great lorry from here
- if is_repo(info['home_page']):
- # lorry this thing
- print('not implemented yet: lorry from ', info['home_page'])
- else:
- # tarball time
- print("not a repo, it's tarball time!")
+ # TODO: detect if git repo, if so then great lorry from here
+ if is_repo(info['home_page']):
+ # lorry this thing
+ print('not implemented yet: lorry from ', info['home_page'])
+ else:
+ # tarball time
+ print("not a repo, it's tarball time!")
+
+ # urls or releases???
+
+ generate_lorry_from_tarball(package_name) \ No newline at end of file