diff options
author | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2014-09-01 15:02:07 +0100 |
---|---|---|
committer | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2014-09-01 15:02:07 +0100 |
commit | eed799b04e95558f46191fa7d4bdfaee3eb743b6 (patch) | |
tree | 456b871c0c8d4b8bd64e2ee456b823ca8f8d2454 | |
parent | a1156c6cd761dd38f5e18df6505db236f95184e2 (diff) | |
download | morph-eed799b04e95558f46191fa7d4bdfaee3eb743b6.tar.gz |
import: add logging support (also hoe url)
-rwxr-xr-x | import/rubygem.to_lorry | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/import/rubygem.to_lorry b/import/rubygem.to_lorry index 4fba9d53..f75fec14 100755 --- a/import/rubygem.to_lorry +++ b/import/rubygem.to_lorry @@ -21,6 +21,7 @@ import requests import requests_cache +import logging import json import os import sys @@ -36,6 +37,7 @@ known_source_uris = { 'diff-lcs': 'https://github.com/halostatue/diff-lcs', 'sigar': 'https://github.com/hyperic/sigar', 'highline': 'https://github.com/JEG2/highline', + 'hoe': 'https://github.com/seattlerb/hoe', 'erubis': 'https://github.com/kwatch/erubis', 'coveralls': 'https://github.com/lemurheavy/coveralls-ruby', # URI is listed as https://github.com/net-ssh/net-sftp-gateway in the @@ -98,6 +100,7 @@ class RubyGemLorryGenerator(object): source_code_uri = gem_info['source_code_uri'] if gem_name in known_source_uris: + logging.debug('Found %s in known_source_uris', gem_name) known_uri = known_source_uris[gem_name] if source_code_uri is not None and known_uri != source_code_uri: sys.stderr.write( @@ -105,14 +108,16 @@ class RubyGemLorryGenerator(object): (gem_name, known_uri, source_code_uri)) return known_uri - if source_code_uri is not None: + if source_code_uri is not None and len(source_code_uri) > 0: + logging.debug('Got source_code_uri %s', source_code_uri) if source_code_uri.endswith('/tree'): source_code_uri = source_code_uri[:-len('/tree')] return source_code_uri homepage_uri = gem_info['homepage_uri'] - if homepage_uri is not None: + if homepage_uri is not None and len(homepage_uri) > 0: + logging.debug('Got homepage_uri %s', source_code_uri) netloc = urlparse.urlsplit(homepage_uri)[1] if netloc == 'github.com': return homepage_uri @@ -141,6 +146,7 @@ class RubyGemLorryGenerator(object): gem_info = rubygems_client.get_gem_info(gem_name) gem_source_url = self.find_upstream_repo_for_gem(gem_name, gem_info) + logging.info('Got URL <%s> for %s', gem_source_url, gem_name) project_name = self.project_name_from_repo(gem_source_url) @@ -158,6 +164,15 @@ class RubyGemLorryGenerator(object): return lorry +def setup_logging(): + stream = os.environ.get('BASEROCK_IMPORT_LOG', None) + level = os.environ.get('BASEROCK_IMPORT_LOG_LEVEL', 'info') + + level_id = logging._levelNames.get(level.upper(), logging.INFO) + if stream is not None: + logging.basicConfig(stream=open(stream, 'a'), level=level_id) + + def write_lorry(stream, lorry): json.dump(lorry, stream, indent=4) @@ -168,6 +183,8 @@ def main(): 'Please call me with the name of a RubyGem as an argument.\n') sys.exit(1) + setup_logging() + gem_name = sys.argv[1] lorry_generator = RubyGemLorryGenerator() |