diff options
author | Richard Ipsum <richard.ipsum@codethink.co.uk> | 2014-10-07 18:29:43 +0100 |
---|---|---|
committer | Richard Ipsum <richard.ipsum@codethink.co.uk> | 2014-11-04 12:40:53 +0000 |
commit | 155ee640ba80205b689aa0d119c9af8afeeb2f47 (patch) | |
tree | d9e47823d9d87b7588866a8d9908ab6d985d025b | |
parent | 8393fcaa5a57cf9481584fd544dfcdee7f8725c7 (diff) | |
download | import-155ee640ba80205b689aa0d119c9af8afeeb2f47.tar.gz |
Add stuff for finding whether a url is a repo
-rwxr-xr-x | import/pip.to_lorry | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/import/pip.to_lorry b/import/pip.to_lorry index 49ec3be..7483b6b 100755 --- a/import/pip.to_lorry +++ b/import/pip.to_lorry @@ -19,10 +19,39 @@ from __future__ import print_function +import subprocess import requests +import json +import sys -def get_package_json(package_name): +def fetch_package_metadata(package_name): return requests.get('http://pypi.python.org/pypi/%s/json' % package_name).json() -print(get_package_json('numpy'))
\ No newline at end of file +def is_repo(url): + 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 + +if len(sys.argv) != 2: + print('usage: %s python_package' % sys.argv[0], file=sys.stderr) + sys.exit(1) + +info = fetch_package_metadata('numpy')['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!") |