Begin porting to python3 (osc branch)

This commit is contained in:
Stephan Kulow
2018-04-26 13:28:25 +02:00
parent 3ca5e488e7
commit 9b4b0ed15a
10 changed files with 68 additions and 46 deletions

View File

@@ -55,7 +55,7 @@ class CommandLineInterface(ReviewBot.CommandLineInterface):
elif i.startswith('openSUSE'):
project[i] = openSUSEUpdate(j)
else:
raise "Unknown openQA", i
raise Exception("Unknown openQA", i)
return project, target, api
def postoptparse(self):

View File

@@ -1,5 +1,11 @@
import re
import urllib2
try:
from urllib.error import HTTPError
except ImportError:
#python 2.x
from urllib2 import HTTPError
import warnings
from xml.etree import cElementTree as ET
@@ -155,7 +161,7 @@ class AcceptCommand(object):
clean_list = set(pkglist) - set(self.api.cnocleanup_packages)
for package in clean_list:
print "[cleanup] deleted %s/%s" % (project, package)
print("[cleanup] deleted %s/%s" % (project, package))
delete_package(self.api.apiurl, project, package, force=True, msg="autocleanup")
# wipe Test-DVD binaries and breaks kiwi build
@@ -178,7 +184,7 @@ class AcceptCommand(object):
url = self.api.makeurl(['build', project], query)
try:
http_POST(url)
except urllib2.HTTPError as err:
except HTTPError as err:
# failed to wipe isos but we can just continue
pass
@@ -202,7 +208,7 @@ class AcceptCommand(object):
for req in rqlist:
oldspecs = self.api.get_filelist_for_package(pkgname=req['packages'][0], project=self.api.project, extension='spec')
print 'Accepting request %d: %s' % (req['id'], ','.join(req['packages']))
print('Accepting request %d: %s' % (req['id'], ','.join(req['packages'])))
if req['type'] == 'delete':
# Remove devel project/package tag before accepting the request
self.remove_obsoleted_develtag(self.api.project, req['packages'][0])
@@ -227,10 +233,10 @@ class AcceptCommand(object):
for spec in removedspecs:
# Deleting all the packages that no longer have a .spec file
url = self.api.makeurl(['source', project, spec[:-5]])
print "Deleting package %s from project %s" % (spec[:-5], project)
print("Deleting package %s from project %s" % (spec[:-5], project))
try:
http_DELETE(url)
except urllib2.HTTPError as err:
except HTTPError as err:
if err.code == 404:
# the package link was not yet created, which was likely a mistake from earlier
pass
@@ -252,7 +258,7 @@ class AcceptCommand(object):
continue
# Check if the target package already exists, if it does not, we get a HTTP error 404 to catch
if not self.api.item_exists(project, package):
print "Creating new package %s linked to %s" % (package, pkgname)
print("Creating new package %s linked to %s" % (package, pkgname))
# new package does not exist. Let's link it with new metadata
newmeta = re.sub(r'(<package.*name=.){}'.format(pkgname),
r'\1{}'.format(package),
@@ -318,7 +324,7 @@ class AcceptCommand(object):
rebuild_result = self.api.check_pkgs(rebuild_result)
result = set(rebuild_result) ^ set(fact_result)
print sorted(result)
print(sorted(result))
for package in result:
self.api.rebuild_pkg(package, self.api.project, arch, None)

View File

@@ -1,5 +1,12 @@
from __future__ import print_function
import json
import urllib2
try:
from urllib.error import HTTPError
except ImportError:
#python 2.x
from urllib2 import HTTPError
from colorama import Fore
@@ -24,43 +31,43 @@ class AdiCommand:
info = self.api.project_status(project, True)
if len(info['selected_requests']):
if len(info['building_repositories']):
print query_project, Fore.MAGENTA + 'building'
print(query_project + " " + Fore.MAGENTA + 'building')
return
if len(info['untracked_requests']):
print query_project, Fore.YELLOW + 'untracked:', ', '.join(['{}[{}]'.format(
Fore.CYAN + req['package'] + Fore.RESET, req['number']) for req in info['untracked_requests']])
print(query_project + " " + Fore.YELLOW + 'untracked: ' + ', '.join(['{}[{}]'.format(
Fore.CYAN + req['package'] + Fore.RESET + " " + req['number']) for req in info['untracked_requests']]))
return
if len(info['obsolete_requests']):
print query_project, Fore.YELLOW + 'obsolete:', ', '.join(['{}[{}]'.format(
Fore.CYAN + req['package'] + Fore.RESET, req['number']) for req in info['obsolete_requests']])
print(query_project + " " + Fore.YELLOW + 'obsolete: ' + ', '.join(['{}[{}]'.format(
Fore.CYAN + req['package'] + Fore.RESET, req['number']) for req in info['obsolete_requests']]))
return
if len(info['broken_packages']):
print query_project, Fore.RED + 'broken:', ', '.join([
Fore.CYAN + p['package'] + Fore.RESET for p in info['broken_packages']])
print(query_project + " " + Fore.RED + 'broken: ' + ', '.join([
Fore.CYAN + p['package'] + Fore.RESET for p in info['broken_packages']]))
return
for review in info['missing_reviews']:
print query_project, Fore.WHITE + 'review:', '{} for {}[{}]'.format(
print(query_project + " " + Fore.WHITE + 'review: ' + '{} for {}[{}]'.format(
Fore.YELLOW + review['by'] + Fore.RESET,
Fore.CYAN + review['package'] + Fore.RESET,
review['request'])
review['request']))
return
if self.api.is_user_member_of(self.api.user, self.api.cstaging_group):
print query_project, Fore.GREEN + 'ready'
print(query_project + " " + Fore.GREEN + 'ready')
packages = []
for req in info['selected_requests']:
print ' - {} [{}]'.format(Fore.CYAN + req['package'] + Fore.RESET, req['number'])
print(' - {} [{}]'.format(Fore.CYAN + req['package'] + Fore.RESET, req['number']))
self.api.rm_from_prj(project, request_id=req['number'], msg='ready to accept')
packages.append(req['package'])
self.api.accept_status_comment(project, packages)
try:
delete_project(self.api.apiurl, project, force=True)
except urllib2.HTTPError as e:
except HTTPError as e:
print(e)
pass
else:
print query_project, Fore.GREEN + 'ready:', ', '.join(['{}[{}]'.format(
Fore.CYAN + req['package'] + Fore.RESET, req['number']) for req in info['selected_requests']])
print(query_project, Fore.GREEN + 'ready:', ', '.join(['{}[{}]'.format(
Fore.CYAN + req['package'] + Fore.RESET, req['number']) for req in info['selected_requests']]))
def check_adi_projects(self):
for p in self.api.get_adi_projects():
@@ -132,7 +139,7 @@ class AdiCommand:
requests = set()
if move:
items = RequestFinder.find_staged_sr(packages, self.api).items()
print items
print(items)
for request, request_project in items:
staging_project = request_project['staging']
self.api.rm_from_prj(staging_project, request_id=request)

View File

@@ -1,6 +1,5 @@
import json
class CheckCommand(object):
def __init__(self, api):
self.api = api
@@ -134,6 +133,6 @@ class CheckCommand(object):
# newline to split multiple prjs at once
print('')
else:
print '\n'.join(self._check_project(project))
print('\n'.join(self._check_project(project)))
return True

View File

@@ -3,7 +3,6 @@ from osclib.core import package_binary_list
from osclib.core import target_archs
import yaml
class CheckDuplicateBinariesCommand(object):
def __init__(self, api):
self.api = api
@@ -45,4 +44,3 @@ class CheckDuplicateBinariesCommand(object):
self.api.save_file_content(*args)
else:
print(current)

View File

@@ -4,7 +4,11 @@ from osc.core import makeurl
from osc.core import http_GET
from osclib.core import fileinfo_ext_all
import urllib2
try:
from urllib.error import HTTPError
except ImportError:
#python 2.x
from urllib2 import HTTPError
class CleanupRings(object):
def __init__(self, api):
@@ -40,31 +44,31 @@ class CleanupRings(object):
links = si.findall('linked')
pkg = si.get('package')
if links is None or len(links) == 0:
print '# {} not a link'.format(pkg)
print('# {} not a link'.format(pkg))
else:
linked = links[0]
dprj = linked.get('project')
dpkg = linked.get('package')
if dprj != self.api.project:
if not dprj.startswith(self.api.crings):
print "#{} not linking to base {} but {}".format(pkg, self.api.project, dprj)
print("#{} not linking to base {} but {}".format(pkg, self.api.project, dprj))
self.links[dpkg] = pkg
# multi spec package must link to ring
elif len(links) > 1:
mainpkg = links[1].get('package')
mainprj = links[1].get('project')
if mainprj != self.api.project:
print '# FIXME: {} links to {}'.format(pkg, mainprj)
print('# FIXME: {} links to {}'.format(pkg, mainprj))
else:
destring = None
if mainpkg in self.api.ring_packages:
destring = self.api.ring_packages[mainpkg]
if not destring:
print '# {} links to {} but is not in a ring'.format(pkg, mainpkg)
print "osc linkpac {}/{} {}/{}".format(mainprj, mainpkg, prj, mainpkg)
print('# {} links to {} but is not in a ring'.format(pkg, mainpkg))
print("osc linkpac {}/{} {}/{}".format(mainprj, mainpkg, prj, mainpkg))
else:
if pkg != 'glibc.i686': # FIXME: ugly exception
print "osc linkpac -f {}/{} {}/{}".format(destring, mainpkg, prj, pkg)
print("osc linkpac -f {}/{} {}/{}".format(destring, mainpkg, prj, pkg))
self.links[mainpkg] = pkg
@@ -123,7 +127,7 @@ class CleanupRings(object):
try:
url = makeurl(self.api.apiurl, ['build', project, 'images', arch, dvd, '_buildinfo'])
root = ET.parse(http_GET(url)).getroot()
except urllib2.HTTPError as e:
except HTTPError as e:
if e.code == 404:
continue
raise
@@ -132,7 +136,7 @@ class CleanupRings(object):
continue
b = bdep.attrib['name']
if b not in self.bin2src:
print "{} not found in bin2src".format(b)
print("{} not found in bin2src".format(b))
continue
b = self.bin2src[b]
self.pkgdeps[b] = 'MYdvd{}'.format(self.api.rings.index(project))

View File

@@ -4,7 +4,12 @@ from dateutil.parser import parse as date_parse
import re
from xml.etree import cElementTree as ET
from lxml import etree as ETL
from urllib2 import HTTPError
try:
from urllib.error import HTTPError
except ImportError:
#python 2.x
from urllib2 import HTTPError
from osc.core import get_binarylist
from osc.core import get_dependson

View File

@@ -94,7 +94,7 @@ if __name__ == '__main__':
fh = open(fn, 'rb')
cpio = Cpio(fh.read())
for i in cpio:
print i
print(i)
ofh = open(i.name, 'wb')
ofh.write(i.header())
ofh.close()

View File

@@ -1,4 +1,10 @@
import urllib2
try:
from urllib.parse import quote
from urllib.error import HTTPError
except ImportError:
#python 2.x
from urllib2 import HTTPError, quote
from xml.etree import cElementTree as ET
from osc import oscerr
@@ -42,7 +48,7 @@ class RequestFinder(object):
url = makeurl(self.api.apiurl, ['request', str(request_id)])
try:
f = http_GET(url)
except urllib2.HTTPError:
except HTTPError:
return None
root = ET.parse(f).getroot()
@@ -66,7 +72,7 @@ class RequestFinder(object):
"""
query = 'types=submit,delete&states=new,review&project={}&view=collection&package={}'
query = query.format(self.api.project, urllib2.quote(package))
query = query.format(self.api.project, quote(package))
url = makeurl(self.api.apiurl, ['request'], query)
f = http_GET(url)

View File

@@ -26,9 +26,7 @@ from xml.etree import cElementTree as ET
import sys
import cmdln
import logging
import urllib2
import osc.core
import yaml
import os
import ToolBase
@@ -229,4 +227,3 @@ class CommandLineInterface(ToolBase.CommandLineInterface):
if __name__ == "__main__":
app = CommandLineInterface()
sys.exit(app.main())