mirror of
git://git.yoctoproject.org/layerindex-web.git
synced 2025-07-19 20:59:01 +02:00
Fix import script for Django 1.8 & Python 3
Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
This commit is contained in:
parent
f268a3cfdb
commit
78406e520a
|
@ -1,8 +1,8 @@
|
|||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Import a layer into the database
|
||||
#
|
||||
# Copyright (C) 2013 Intel Corporation
|
||||
# Copyright (C) 2016 Intel Corporation
|
||||
# Author: Paul Eggleton <paul.eggleton@linux.intel.com>
|
||||
#
|
||||
# Licensed under the MIT license, see COPYING.MIT for details
|
||||
|
@ -20,6 +20,9 @@ import utils
|
|||
import logging
|
||||
import subprocess
|
||||
|
||||
class DryRunRollbackException(Exception):
|
||||
pass
|
||||
|
||||
logger = utils.logger_create('LayerIndexImport')
|
||||
|
||||
link_re = re.compile(r'\[(http.*) +link\]')
|
||||
|
@ -138,12 +141,12 @@ def maintainers_extract(maintfn):
|
|||
|
||||
|
||||
def get_github_layerinfo(layer_url, username = None, password = None):
|
||||
import httplib
|
||||
import http.client
|
||||
import json
|
||||
from layerindex.models import LayerMaintainer
|
||||
|
||||
def github_api_call(path):
|
||||
conn = httplib.HTTPSConnection('api.github.com')
|
||||
conn = http.client.HTTPSConnection('api.github.com')
|
||||
headers = {"User-Agent": "test_github.py"}
|
||||
if username:
|
||||
import base64
|
||||
|
@ -161,18 +164,18 @@ def get_github_layerinfo(layer_url, username = None, password = None):
|
|||
layer_url = layer_url[:-4]
|
||||
resp = github_api_call('/repos/%s' % layer_url.split('github.com/')[-1].rstrip('/'))
|
||||
if resp.status in [200, 302]:
|
||||
data = resp.read()
|
||||
data = resp.read().decode('utf-8')
|
||||
json_data = json.loads(data)
|
||||
#headers = dict((key, value) for key, value in resp.getheaders())
|
||||
#print(headers)
|
||||
owner_resp = github_api_call(json_data['owner']['url'].split('api.github.com')[-1])
|
||||
if resp.status in [200, 302]:
|
||||
owner_data = owner_resp.read()
|
||||
owner_data = owner_resp.read().decode('utf-8')
|
||||
owner_json_data = json.loads(owner_data)
|
||||
else:
|
||||
logger.error('HTTP status %s reading owner info from github API: %s' % (resp.status, resp.read()))
|
||||
logger.error('HTTP status %s reading owner info from github API: %s' % (resp.status, resp.read().decode('utf-8')))
|
||||
else:
|
||||
logger.error('HTTP status %s reading repo info from github API: %s' % (resp.status, resp.read()))
|
||||
logger.error('HTTP status %s reading repo info from github API: %s' % (resp.status, resp.read().decode('utf-8')))
|
||||
|
||||
return (json_data, owner_json_data)
|
||||
|
||||
|
@ -212,7 +215,7 @@ def main():
|
|||
if options.subdir:
|
||||
layer_name = options.subdir
|
||||
else:
|
||||
layer_name = filter(None, layer_url.split('/'))[-1]
|
||||
layer_name = [x for x in layer_url.split('/') if x][-1]
|
||||
if layer_name.endswith('.git'):
|
||||
layer_name = layer_name[:-4]
|
||||
|
||||
|
@ -244,9 +247,8 @@ def main():
|
|||
|
||||
master_branch = utils.get_branch('master')
|
||||
core_layer = None
|
||||
transaction.enter_transaction_management()
|
||||
transaction.managed(True)
|
||||
try:
|
||||
with transaction.atomic():
|
||||
# Fetch layer
|
||||
logger.info('Fetching repository %s' % layer_url)
|
||||
|
||||
|
@ -398,14 +400,9 @@ def main():
|
|||
layer.save()
|
||||
|
||||
if options.dryrun:
|
||||
transaction.rollback()
|
||||
else:
|
||||
transaction.commit()
|
||||
except:
|
||||
transaction.rollback()
|
||||
raise
|
||||
finally:
|
||||
transaction.leave_transaction_management()
|
||||
raise DryRunRollbackException()
|
||||
except DryRunRollbackException:
|
||||
pass
|
||||
|
||||
sys.exit(0)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user