Merge pull request #1793 from coolo/more_python3
Port pkglistgen (and some more)
This commit is contained in:
commit
c12bcd0620
@ -1,5 +1,7 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
from pprint import pprint
|
||||
import os, sys, re
|
||||
import logging
|
||||
|
@ -1,5 +1,7 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
from xml.etree import cElementTree as ET
|
||||
import cmdln
|
||||
import datetime
|
||||
@ -11,13 +13,13 @@ import time
|
||||
|
||||
try:
|
||||
from urllib.error import HTTPError
|
||||
from urllib.parse import quote_plus
|
||||
except ImportError:
|
||||
# python 2.x
|
||||
from urllib2 import HTTPError
|
||||
|
||||
from urllib import quote_plus
|
||||
import osc.conf
|
||||
import osc.core
|
||||
from urllib import quote_plus
|
||||
|
||||
from osclib.memoize import memoize
|
||||
|
||||
@ -55,7 +57,7 @@ class ToolBase(object):
|
||||
return http_GET(url)
|
||||
except HTTPError as e:
|
||||
if 500 <= e.code <= 599:
|
||||
print 'Retrying {}'.format(url)
|
||||
print('Retrying {}'.format(url))
|
||||
time.sleep(1)
|
||||
return self.retried_GET(url)
|
||||
logging.error('%s: %s', e, url)
|
||||
|
@ -20,6 +20,8 @@
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
from ConfigParser import ConfigParser
|
||||
from xdg.BaseDirectory import load_first_config
|
||||
from lxml import etree as ET
|
||||
@ -204,7 +206,7 @@ class CommandLineInterface(ToolBase.CommandLineInterface):
|
||||
continue
|
||||
person = self.tool.resolve_person(o.name)
|
||||
if person.email.endswith('@suse.com'):
|
||||
print p, o.name
|
||||
print(p, o.name)
|
||||
else:
|
||||
logger.debug('%s skipped', o.name)
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
#!/usr/bin/python2
|
||||
# check if all packages in a repo are newer than all other repos
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import sys
|
||||
import os
|
||||
import re
|
||||
|
@ -1,5 +1,7 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
from pprint import pprint
|
||||
import os
|
||||
import sys
|
||||
@ -158,7 +160,7 @@ class DepTool(cmdln.Cmdln):
|
||||
return False
|
||||
|
||||
for s in trans.newsolvables():
|
||||
print ','.join(packages), s.name
|
||||
print(','.join(packages), s.name)
|
||||
if opts.explain and s.name in opts.explain:
|
||||
reason, rule = solver.describe_decision(s)
|
||||
ruleinfo = None
|
||||
@ -310,7 +312,7 @@ class DepTool(cmdln.Cmdln):
|
||||
if kindid == solv.SOLVABLE_PROVIDES and r == s:
|
||||
continue
|
||||
if not kindprinted:
|
||||
print kind
|
||||
print(kind)
|
||||
kindprinted = True
|
||||
print(' {}: {}-{}@{}'.format(p, r.name, r.evr, r.arch))
|
||||
|
||||
@ -338,7 +340,7 @@ class DepTool(cmdln.Cmdln):
|
||||
continue
|
||||
for r in sel.solvables():
|
||||
if not kindprinted:
|
||||
print kind
|
||||
print(kind)
|
||||
kindprinted = True
|
||||
print(' {}-{}@{}'.format(r.name, r.evr, r.arch))
|
||||
|
||||
|
@ -10,7 +10,6 @@ from collections import namedtuple
|
||||
import sys
|
||||
import cmdln
|
||||
import logging
|
||||
import urllib2
|
||||
import filecmp
|
||||
from osc.core import checkout_package
|
||||
from osc.core import http_GET, http_PUT
|
||||
@ -40,7 +39,12 @@ import subprocess
|
||||
import re
|
||||
import yaml
|
||||
import requests
|
||||
import urlparse
|
||||
try:
|
||||
from urllib.parse import urljoin, urlparse
|
||||
except ImportError:
|
||||
# python 2.x
|
||||
from urlparse import urljoin, urlparse
|
||||
|
||||
import gzip
|
||||
import tempfile
|
||||
import traceback
|
||||
@ -990,7 +994,7 @@ class CommandLineInterface(ToolBase.CommandLineInterface):
|
||||
|
||||
repo = pool.add_repo(''.join(random.choice(string.letters) for _ in range(5)))
|
||||
path_prefix = 'suse/' if name and repo_style == 'build' else ''
|
||||
url = urlparse.urljoin(baseurl, path_prefix + 'repodata/repomd.xml')
|
||||
url = urljoin(baseurl, path_prefix + 'repodata/repomd.xml')
|
||||
repomd = requests.get(url)
|
||||
ns = {'r': 'http://linux.duke.edu/metadata/repo'}
|
||||
root = ET.fromstring(repomd.content)
|
||||
@ -1017,7 +1021,7 @@ class CommandLineInterface(ToolBase.CommandLineInterface):
|
||||
f.flush()
|
||||
os.lseek(f.fileno(), 0, os.SEEK_SET)
|
||||
repo.add_repomdxml(f, 0)
|
||||
url = urlparse.urljoin(baseurl, path_prefix + location)
|
||||
url = urljoin(baseurl, path_prefix + location)
|
||||
with requests.get(url, stream=True) as primary:
|
||||
sha256 = hashlib.sha256(primary.content).hexdigest()
|
||||
if sha256 != sha256_expected:
|
||||
@ -1050,7 +1054,7 @@ class CommandLineInterface(ToolBase.CommandLineInterface):
|
||||
# Could look at .repo file or repomd.xml, but larger change.
|
||||
return 'update-' + os.path.basename(os.path.normpath(baseurl)), 'update'
|
||||
|
||||
url = urlparse.urljoin(baseurl, 'media.1/media')
|
||||
url = urljoin(baseurl, 'media.1/media')
|
||||
with requests.get(url) as media:
|
||||
for i, line in enumerate(media.iter_lines()):
|
||||
if i != 1:
|
||||
@ -1060,7 +1064,7 @@ class CommandLineInterface(ToolBase.CommandLineInterface):
|
||||
if name is not None and '-Build' in name:
|
||||
return name, 'media'
|
||||
|
||||
url = urlparse.urljoin(baseurl, 'media.1/build')
|
||||
url = urljoin(baseurl, 'media.1/build')
|
||||
with requests.get(url) as build:
|
||||
name = build.content.strip()
|
||||
|
||||
@ -1283,7 +1287,7 @@ class CommandLineInterface(ToolBase.CommandLineInterface):
|
||||
return
|
||||
|
||||
# Cache dir specific to hostname and project.
|
||||
host = urlparse.urlparse(api.apiurl).hostname
|
||||
host = urlparse(api.apiurl).hostname
|
||||
cache_dir = CacheManager.directory('pkglistgen', host, opts.project)
|
||||
|
||||
if not opts.no_checkout:
|
||||
@ -1433,13 +1437,13 @@ class CommandLineInterface(ToolBase.CommandLineInterface):
|
||||
logger.warning('no baseurl configured for {}'.format(project))
|
||||
continue
|
||||
|
||||
urls = [urlparse.urljoin(baseurl, 'repo/oss/')]
|
||||
urls = [urljoin(baseurl, 'repo/oss/')]
|
||||
if baseurl_update:
|
||||
urls.append(urlparse.urljoin(baseurl_update, 'oss/'))
|
||||
urls.append(urljoin(baseurl_update, 'oss/'))
|
||||
if project_config.get('nonfree'):
|
||||
urls.append(urlparse.urljoin(baseurl, 'repo/non-oss/'))
|
||||
urls.append(urljoin(baseurl, 'repo/non-oss/'))
|
||||
if baseurl_update:
|
||||
urls.append(urlparse.urljoin(baseurl_update, 'non-oss/'))
|
||||
urls.append(urljoin(baseurl_update, 'non-oss/'))
|
||||
|
||||
names = []
|
||||
for url in urls:
|
||||
|
@ -1,5 +1,7 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import argparse
|
||||
from datetime import datetime, timedelta
|
||||
from collections import defaultdict
|
||||
@ -46,7 +48,7 @@ class StagingReport(object):
|
||||
|
||||
if write_comment or force:
|
||||
if osc.conf.config['debug']:
|
||||
print 'Updating comment'
|
||||
print('Updating comment')
|
||||
if comment:
|
||||
self.comment.delete(comment['id'])
|
||||
self.comment.add_comment(project_name=project, comment=report)
|
||||
@ -124,9 +126,9 @@ class StagingReport(object):
|
||||
self.update_status_comment(project, report, force=force, only_replace=only_replace)
|
||||
|
||||
if osc.conf.config['debug']:
|
||||
print project
|
||||
print '-' * len(project)
|
||||
print report
|
||||
print(project)
|
||||
print('-' * len(project))
|
||||
print(report)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -1,5 +1,7 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import sys
|
||||
import os
|
||||
import osc
|
||||
@ -39,7 +41,7 @@ def compare_results(factory, rebuild, testmode):
|
||||
com_res = set(rebuild).symmetric_difference(set(factory))
|
||||
|
||||
if testmode != False:
|
||||
print com_res
|
||||
print(com_res)
|
||||
|
||||
return com_res
|
||||
|
||||
@ -69,22 +71,22 @@ def rebuild_pkg_in_factory(package, prj, arch, testmode, code=None):
|
||||
u = osc.core.makeurl(osc.conf.config['apiurl'], ['build', prj], query=query)
|
||||
|
||||
if testmode != False:
|
||||
print "Trigger rebuild for this package: " + u
|
||||
print("Trigger rebuild for this package: " + u)
|
||||
|
||||
else:
|
||||
try:
|
||||
print 'tried to trigger rebuild for project \'%s\' package \'%s\'' % (prj, pkg)
|
||||
print('tried to trigger rebuild for project \'%s\' package \'%s\'' % (prj, pkg))
|
||||
f = osc.core.http_POST(u)
|
||||
|
||||
except:
|
||||
print 'could not trigger rebuild for project \'%s\' package \'%s\'' % (prj, pkg)
|
||||
print('could not trigger rebuild for project \'%s\' package \'%s\'' % (prj, pkg))
|
||||
|
||||
testmode = False
|
||||
try:
|
||||
if sys.argv[1] != None:
|
||||
if sys.argv[1] == '-test':
|
||||
testmode = True
|
||||
print "testmode: "+str(testmode)
|
||||
print("testmode: "+str(testmode))
|
||||
else:
|
||||
testmode = False
|
||||
except:
|
||||
@ -97,10 +99,8 @@ for arch in architectures:
|
||||
fact_result = check_pkgs(fact_result)
|
||||
result = compare_results(fact_result, rebuild_result, testmode)
|
||||
|
||||
print sorted(result)
|
||||
print(sorted(result))
|
||||
|
||||
for package in result:
|
||||
rebuild_pkg_in_factory(package, 'openSUSE:Factory', arch, testmode, None)
|
||||
rebuild_pkg_in_factory(package, 'openSUSE:Factory:Rebuild', arch, testmode, None)
|
||||
|
||||
|
||||
|
@ -6,7 +6,13 @@ import unittest
|
||||
import logging
|
||||
import httpretty
|
||||
import osc
|
||||
import urlparse
|
||||
|
||||
try:
|
||||
from urllib.parse import urlparse
|
||||
except ImportError:
|
||||
# python 2.x
|
||||
from urlparse import urlparse
|
||||
|
||||
import sys
|
||||
import re
|
||||
from osclib.cache import Cache
|
||||
@ -202,7 +208,7 @@ Pico text editor while also offering a few enhancements.</description>
|
||||
result = {'state_accepted': None}
|
||||
|
||||
def change_request(result, method, uri, headers):
|
||||
u = urlparse.urlparse(uri)
|
||||
u = urlparse(uri)
|
||||
if u.query == 'newstate=accepted&cmd=changereviewstate&by_user=maintbot':
|
||||
result['state_accepted'] = True
|
||||
elif u.query == 'newstate=declined&cmd=changereviewstate&by_user=maintbot':
|
||||
@ -282,4 +288,3 @@ Pico text editor while also offering a few enhancements.</description>
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
|
@ -4,9 +4,14 @@ import logging
|
||||
import httpretty
|
||||
import osc
|
||||
import re
|
||||
import urlparse
|
||||
from osclib.cache import Cache
|
||||
|
||||
try:
|
||||
from urllib.parse import urlparse
|
||||
except ImportError:
|
||||
# python 2.x
|
||||
from urlparse import urlparse
|
||||
|
||||
from check_source_in_factory import FactorySourceChecker
|
||||
|
||||
APIURL = 'https://testhost.example.com'
|
||||
@ -141,7 +146,7 @@ class TestFactorySourceAccept(unittest.TestCase):
|
||||
result = { 'status' : None }
|
||||
|
||||
def change_request(result, method, uri, headers):
|
||||
u = urlparse.urlparse(uri)
|
||||
u = urlparse(uri)
|
||||
if u.query == 'newstate=accepted&cmd=changereviewstate&by_user=factory-source':
|
||||
result['status'] = True
|
||||
else:
|
||||
@ -265,7 +270,7 @@ class TestFactorySourceAccept(unittest.TestCase):
|
||||
result = { 'factory_source_declined' : None }
|
||||
|
||||
def change_request(result, method, uri, headers):
|
||||
u = urlparse.urlparse(uri)
|
||||
u = urlparse(uri)
|
||||
if u.query == 'newstate=declined&cmd=changereviewstate&by_user=factory-source':
|
||||
result['factory_source_declined'] = True
|
||||
return (200, headers, '<status code="ok"/>')
|
||||
@ -282,4 +287,3 @@ class TestFactorySourceAccept(unittest.TestCase):
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
|
@ -4,7 +4,12 @@ import logging
|
||||
import httpretty
|
||||
import osc
|
||||
import re
|
||||
import urlparse
|
||||
|
||||
try:
|
||||
from urllib.parse import urlparse
|
||||
except ImportError:
|
||||
# python 2.x
|
||||
from urlparse import urlparse
|
||||
|
||||
from check_maintenance_incidents import MaintenanceChecker
|
||||
|
||||
@ -122,7 +127,7 @@ class TestMaintenance(unittest.TestCase):
|
||||
result = { 'devel_review_added' : None }
|
||||
|
||||
def change_request(result, method, uri, headers):
|
||||
u = urlparse.urlparse(uri)
|
||||
u = urlparse(uri)
|
||||
if u.query == 'by_package=mysql-workbench&cmd=addreview&by_project=server%3Adatabase':
|
||||
result['devel_review_added'] = True
|
||||
return (200, headers, '<status code="ok"/>')
|
||||
@ -241,7 +246,7 @@ class TestMaintenance(unittest.TestCase):
|
||||
result = { 'devel_review_added' : None }
|
||||
|
||||
def change_request(result, method, uri, headers):
|
||||
u = urlparse.urlparse(uri)
|
||||
u = urlparse(uri)
|
||||
if u.query == 'by_package=mysql-workbench&cmd=addreview&by_project=server%3Adatabase':
|
||||
result['devel_review_added'] = True
|
||||
return (200, headers, '<status code="ok"/>')
|
||||
@ -350,7 +355,7 @@ class TestMaintenance(unittest.TestCase):
|
||||
result = { 'factory_review_added' : None }
|
||||
|
||||
def change_request(result, method, uri, headers):
|
||||
u = urlparse.urlparse(uri)
|
||||
u = urlparse(uri)
|
||||
if u.query == 'cmd=addreview&by_user=factory-source':
|
||||
result['factory_review_added'] = True
|
||||
return (200, headers, '<status code="ok"/>')
|
||||
@ -367,4 +372,3 @@ class TestMaintenance(unittest.TestCase):
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
|
28
tests/obs.py
28
tests/obs.py
@ -5,14 +5,14 @@ import os
|
||||
import re
|
||||
import string
|
||||
import time
|
||||
import urllib
|
||||
|
||||
try:
|
||||
from urllib.parse import unquote
|
||||
from urllib.parse import unquote, urlparse, urlencode, parse_qs, urljoin
|
||||
except ImportError:
|
||||
# python 2.x
|
||||
from urllib import unquote
|
||||
from urllib import unquote, urlencode
|
||||
from urlparse import urlparse, urljoin, parse_qs
|
||||
|
||||
import urlparse
|
||||
import xml.etree.cElementTree as ET
|
||||
|
||||
import httpretty
|
||||
@ -42,7 +42,7 @@ _table = {
|
||||
|
||||
def router_handler(route_table, method, request, uri, headers):
|
||||
"""Route the URLs in a deterministic way."""
|
||||
uri_parsed = urlparse.urlparse(uri)
|
||||
uri_parsed = urlparse(uri)
|
||||
for path, fn in route_table:
|
||||
match = False
|
||||
if not isinstance(path, str):
|
||||
@ -416,13 +416,13 @@ class OBS(object):
|
||||
|
||||
def _request(self, request_id):
|
||||
"""Utility function to recover a request from the ID."""
|
||||
template = string.Template(self._fixture(urlparse.urljoin(APIURL, '/request/' + request_id)))
|
||||
template = string.Template(self._fixture(urljoin(APIURL, '/request/' + request_id)))
|
||||
return template.substitute(self.requests[request_id])
|
||||
|
||||
@POST(re.compile(r'/request/\d+'))
|
||||
def review_request(self, request, uri, headers):
|
||||
request_id = re.search(r'(\d+)', uri).group(1)
|
||||
qs = urlparse.parse_qs(urlparse.urlparse(uri).query)
|
||||
qs = parse_qs(urlparse(uri).query)
|
||||
|
||||
response = (404, headers, '<result>Not found</result>')
|
||||
|
||||
@ -457,7 +457,7 @@ class OBS(object):
|
||||
@GET('/request')
|
||||
def request_search(self, request, uri, headers):
|
||||
"""Request search function."""
|
||||
qs = urlparse.parse_qs(urlparse.urlparse(uri).query)
|
||||
qs = parse_qs(urlparse(uri).query)
|
||||
states = qs['states'][0].split(',')
|
||||
|
||||
response = (404, headers, '<result>Not found</result>')
|
||||
@ -738,7 +738,7 @@ class OBS(object):
|
||||
@GET(re.compile(r'/source/home:Admin/\w+'))
|
||||
def source_project(self, request, uri, headers):
|
||||
"""Return information of a source package."""
|
||||
qs = urlparse.parse_qs(urlparse.urlparse(uri).query)
|
||||
qs = parse_qs(urlparse(uri).query)
|
||||
index = re.search(r'/source/([\w:]+/\w+)', uri).group(1)
|
||||
project, package = index.split('/')
|
||||
response = (404, headers, '<result>Not found</result>')
|
||||
@ -830,7 +830,7 @@ class OBS(object):
|
||||
@GET('/search/project/id')
|
||||
def search_project_id(self, request, uri, headers):
|
||||
"""Return a search result /search/project/id."""
|
||||
assert urlparse.urlparse(uri).query == urllib.urlencode(
|
||||
assert urlparse(uri).query == urlencode(
|
||||
{'match': 'starts-with(@name, "openSUSE:Factory:Staging:")'})
|
||||
|
||||
response = (404, headers, '<result>Not found</result>')
|
||||
@ -857,7 +857,7 @@ class OBS(object):
|
||||
@GET('/search/request')
|
||||
def search_request(self, request, uri, headers):
|
||||
"""Return a search result for /search/request."""
|
||||
query = unquote(urlparse.urlparse(uri).query)
|
||||
query = unquote(urlparse(uri).query)
|
||||
assert query in (
|
||||
"match=state/@name='review'+and+review[@by_group='factory-staging'+and+@state='new']+and+(target[@project='openSUSE:Factory']+or+target[@project='openSUSE:Factory:NonFree'])",
|
||||
"match=state/@name='review'+and+review[@by_user='factory-repo-checker'+and+@state='new']+and+(target[@project='openSUSE:Factory']+or+target[@project='openSUSE:Factory:NonFree'])"
|
||||
@ -896,7 +896,7 @@ class OBS(object):
|
||||
@GET('/search/request/id')
|
||||
def search_request_id(self, request, uri, headers):
|
||||
"""Return a search result for /search/request/id."""
|
||||
query = urlparse.urlparse(uri).query
|
||||
query = urlparse(uri).query
|
||||
project = re.search(r"@by_project='([^']+)'", query).group(1)
|
||||
|
||||
response = (404, headers, '<result>Not found</result>')
|
||||
@ -978,7 +978,7 @@ class OBS(object):
|
||||
"""Return a JSON fixture."""
|
||||
response = (404, headers, '<result>Not found</result>')
|
||||
try:
|
||||
path = urlparse.urlparse(uri).path + '.json'
|
||||
path = urlparse(uri).path + '.json'
|
||||
template = string.Template(self._fixture(path=path))
|
||||
response = (200, headers, template.substitute({
|
||||
'update_at_too_recent': (datetime.utcnow() - timedelta(minutes=2)).isoformat(),
|
||||
@ -1016,7 +1016,7 @@ class OBS(object):
|
||||
def _fixture(self, uri=None, path=None, filename=None):
|
||||
"""Read a file as a fixture."""
|
||||
if not path:
|
||||
path = urlparse.urlparse(uri).path
|
||||
path = urlparse(uri).path
|
||||
path = path[1:] if path.startswith('/') else path
|
||||
|
||||
if filename:
|
||||
|
@ -1,5 +1,7 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import argparse
|
||||
from lxml import etree as ET
|
||||
from osc import conf
|
||||
|
Loading…
x
Reference in New Issue
Block a user