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
|
# Import a layer into the database
|
||||||
#
|
#
|
||||||
# Copyright (C) 2013 Intel Corporation
|
# Copyright (C) 2016 Intel Corporation
|
||||||
# Author: Paul Eggleton <paul.eggleton@linux.intel.com>
|
# Author: Paul Eggleton <paul.eggleton@linux.intel.com>
|
||||||
#
|
#
|
||||||
# Licensed under the MIT license, see COPYING.MIT for details
|
# Licensed under the MIT license, see COPYING.MIT for details
|
||||||
|
@ -20,6 +20,9 @@ import utils
|
||||||
import logging
|
import logging
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
class DryRunRollbackException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
logger = utils.logger_create('LayerIndexImport')
|
logger = utils.logger_create('LayerIndexImport')
|
||||||
|
|
||||||
link_re = re.compile(r'\[(http.*) +link\]')
|
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):
|
def get_github_layerinfo(layer_url, username = None, password = None):
|
||||||
import httplib
|
import http.client
|
||||||
import json
|
import json
|
||||||
from layerindex.models import LayerMaintainer
|
from layerindex.models import LayerMaintainer
|
||||||
|
|
||||||
def github_api_call(path):
|
def github_api_call(path):
|
||||||
conn = httplib.HTTPSConnection('api.github.com')
|
conn = http.client.HTTPSConnection('api.github.com')
|
||||||
headers = {"User-Agent": "test_github.py"}
|
headers = {"User-Agent": "test_github.py"}
|
||||||
if username:
|
if username:
|
||||||
import base64
|
import base64
|
||||||
|
@ -161,18 +164,18 @@ def get_github_layerinfo(layer_url, username = None, password = None):
|
||||||
layer_url = layer_url[:-4]
|
layer_url = layer_url[:-4]
|
||||||
resp = github_api_call('/repos/%s' % layer_url.split('github.com/')[-1].rstrip('/'))
|
resp = github_api_call('/repos/%s' % layer_url.split('github.com/')[-1].rstrip('/'))
|
||||||
if resp.status in [200, 302]:
|
if resp.status in [200, 302]:
|
||||||
data = resp.read()
|
data = resp.read().decode('utf-8')
|
||||||
json_data = json.loads(data)
|
json_data = json.loads(data)
|
||||||
#headers = dict((key, value) for key, value in resp.getheaders())
|
#headers = dict((key, value) for key, value in resp.getheaders())
|
||||||
#print(headers)
|
#print(headers)
|
||||||
owner_resp = github_api_call(json_data['owner']['url'].split('api.github.com')[-1])
|
owner_resp = github_api_call(json_data['owner']['url'].split('api.github.com')[-1])
|
||||||
if resp.status in [200, 302]:
|
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)
|
owner_json_data = json.loads(owner_data)
|
||||||
else:
|
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:
|
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)
|
return (json_data, owner_json_data)
|
||||||
|
|
||||||
|
@ -212,7 +215,7 @@ def main():
|
||||||
if options.subdir:
|
if options.subdir:
|
||||||
layer_name = options.subdir
|
layer_name = options.subdir
|
||||||
else:
|
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'):
|
if layer_name.endswith('.git'):
|
||||||
layer_name = layer_name[:-4]
|
layer_name = layer_name[:-4]
|
||||||
|
|
||||||
|
@ -244,9 +247,8 @@ def main():
|
||||||
|
|
||||||
master_branch = utils.get_branch('master')
|
master_branch = utils.get_branch('master')
|
||||||
core_layer = None
|
core_layer = None
|
||||||
transaction.enter_transaction_management()
|
|
||||||
transaction.managed(True)
|
|
||||||
try:
|
try:
|
||||||
|
with transaction.atomic():
|
||||||
# Fetch layer
|
# Fetch layer
|
||||||
logger.info('Fetching repository %s' % layer_url)
|
logger.info('Fetching repository %s' % layer_url)
|
||||||
|
|
||||||
|
@ -398,14 +400,9 @@ def main():
|
||||||
layer.save()
|
layer.save()
|
||||||
|
|
||||||
if options.dryrun:
|
if options.dryrun:
|
||||||
transaction.rollback()
|
raise DryRunRollbackException()
|
||||||
else:
|
except DryRunRollbackException:
|
||||||
transaction.commit()
|
pass
|
||||||
except:
|
|
||||||
transaction.rollback()
|
|
||||||
raise
|
|
||||||
finally:
|
|
||||||
transaction.leave_transaction_management()
|
|
||||||
|
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user