Import urllib2 python agnostic

This commit is contained in:
Stephan Kulow 2018-11-16 08:32:25 +01:00
parent ac7b288e74
commit ea9061ccf5
22 changed files with 160 additions and 73 deletions

View File

@ -28,7 +28,12 @@ except ImportError:
from osc import conf from osc import conf
import osc.core import osc.core
import urllib2 try:
from urllib.error import HTTPError, URLError
except ImportError:
# python 2.x
from urllib2 import HTTPError, URLError
from itertools import count from itertools import count
class PackageLookup(object): class PackageLookup(object):
@ -57,7 +62,7 @@ class PackageLookup(object):
try: try:
return osc.core.http_GET(osc.core.makeurl(self.apiurl, return osc.core.http_GET(osc.core.makeurl(self.apiurl,
['source', prj, '00Meta', 'lookup.yml'])) ['source', prj, '00Meta', 'lookup.yml']))
except urllib2.HTTPError as e: except HTTPError as e:
# in case the project doesn't exist yet (like sle update) # in case the project doesn't exist yet (like sle update)
if e.code != 404: if e.code != 404:
raise e raise e
@ -458,7 +463,7 @@ class ReviewBot(object):
url = osc.core.makeurl(apiurl, ('source', project, package), query=query) url = osc.core.makeurl(apiurl, ('source', project, package), query=query)
try: try:
return ET.parse(osc.core.http_GET(url)).getroot() return ET.parse(osc.core.http_GET(url)).getroot()
except (urllib2.HTTPError, urllib2.URLError): except (HTTPError, URLError):
return None return None
def get_originproject(self, project, package, rev=None): def get_originproject(self, project, package, rev=None):
@ -493,7 +498,7 @@ class ReviewBot(object):
url = osc.core.makeurl(self.apiurl, ('source', src_project, src_package), query=query) url = osc.core.makeurl(self.apiurl, ('source', src_project, src_package), query=query)
try: try:
root = ET.parse(osc.core.http_GET(url)).getroot() root = ET.parse(osc.core.http_GET(url)).getroot()
except urllib2.HTTPError: except HTTPError:
return (None, None) return (None, None)
if root is not None: if root is not None:
@ -521,7 +526,7 @@ class ReviewBot(object):
return True return True
if self.review_group and self._has_open_review_by(root, 'by_group', self.review_group): if self.review_group and self._has_open_review_by(root, 'by_group', self.review_group):
return True return True
except urllib2.HTTPError as e: except HTTPError as e:
print('ERROR in URL %s [%s]' % (url, e)) print('ERROR in URL %s [%s]' % (url, e))
return False return False
@ -670,7 +675,7 @@ class ReviewBot(object):
self.logger.debug("checking %s in %s"%(package, project)) self.logger.debug("checking %s in %s"%(package, project))
try: try:
si = osc.core.show_package_meta(self.apiurl, project, package) si = osc.core.show_package_meta(self.apiurl, project, package)
except (urllib2.HTTPError, urllib2.URLError): except (HTTPError, URLError):
si = None si = None
if si is None: if si is None:
self.logger.debug("new package") self.logger.debug("new package")
@ -686,7 +691,7 @@ class ReviewBot(object):
u = osc.core.makeurl(self.apiurl, [ 'source', project, package, '_history' ], { 'limit': history_limit }) u = osc.core.makeurl(self.apiurl, [ 'source', project, package, '_history' ], { 'limit': history_limit })
try: try:
r = osc.core.http_GET(u) r = osc.core.http_GET(u)
except urllib2.HTTPError as e: except HTTPError as e:
self.logger.debug("package has no history!?") self.logger.debug("package has no history!?")
return None return None

View File

@ -8,7 +8,12 @@ import logging
import signal import signal
import sys import sys
import time import time
import urllib2
try:
from urllib.error import HTTPError
except ImportError:
# python 2.x
from urllib2 import HTTPError
import osc.conf import osc.conf
import osc.core import osc.core
@ -48,7 +53,7 @@ class ToolBase(object):
def retried_GET(self, url): def retried_GET(self, url):
try: try:
return http_GET(url) return http_GET(url)
except urllib2.HTTPError as e: except HTTPError as e:
if 500 <= e.code <= 599: if 500 <= e.code <= 599:
print 'Retrying {}'.format(url) print 'Retrying {}'.format(url)
time.sleep(1) time.sleep(1)

View File

@ -24,7 +24,12 @@ import osc.conf
import osc.core import osc.core
from osc.util.cpio import CpioRead from osc.util.cpio import CpioRead
import urllib2 try:
from urllib.error import HTTPError
except ImportError:
# python 2.x
from urllib2 import HTTPError
import rpm import rpm
from collections import namedtuple from collections import namedtuple
from osclib.pkgcache import PkgCache from osclib.pkgcache import PkgCache
@ -783,7 +788,7 @@ class ABIChecker(ReviewBot.ReviewBot):
[ 'view=cpioheaders' ]) [ 'view=cpioheaders' ])
try: try:
r = osc.core.http_GET(u) r = osc.core.http_GET(u)
except urllib2.HTTPError as e: except HTTPError as e:
raise FetchError('failed to fetch header information: %s'%e) raise FetchError('failed to fetch header information: %s'%e)
tmpfile = NamedTemporaryFile(prefix="cpio-", delete=False) tmpfile = NamedTemporaryFile(prefix="cpio-", delete=False)
for chunk in r: for chunk in r:
@ -813,7 +818,7 @@ class ABIChecker(ReviewBot.ReviewBot):
url = osc.core.makeurl(self.apiurl, ('build', prj, repo, arch, pkg)) url = osc.core.makeurl(self.apiurl, ('build', prj, repo, arch, pkg))
try: try:
root = ET.parse(osc.core.http_GET(url)).getroot() root = ET.parse(osc.core.http_GET(url)).getroot()
except urllib2.HTTPError: except HTTPError:
return None return None
return dict([(node.attrib['filename'], node.attrib['mtime']) for node in root.findall('binary')]) return dict([(node.attrib['filename'], node.attrib['mtime']) for node in root.findall('binary')])
@ -828,7 +833,7 @@ class ABIChecker(ReviewBot.ReviewBot):
'srcmd5' : rev } 'srcmd5' : rev }
url = osc.core.makeurl(self.apiurl, ('build', src_project, '_result'), query) url = osc.core.makeurl(self.apiurl, ('build', src_project, '_result'), query)
return ET.parse(osc.core.http_GET(url)).getroot() return ET.parse(osc.core.http_GET(url)).getroot()
except urllib2.HTTPError as e: except HTTPError as e:
if e.code != 404: if e.code != 404:
self.logger.error('ERROR in URL %s [%s]' % (url, e)) self.logger.error('ERROR in URL %s [%s]' % (url, e))
raise raise
@ -855,7 +860,7 @@ class ABIChecker(ReviewBot.ReviewBot):
url = osc.core.makeurl(self.apiurl, ('source', project, '_meta')) url = osc.core.makeurl(self.apiurl, ('source', project, '_meta'))
try: try:
root = ET.parse(osc.core.http_GET(url)).getroot() root = ET.parse(osc.core.http_GET(url)).getroot()
except urllib2.HTTPError: except HTTPError:
return None return None
repos = set() repos = set()
@ -912,7 +917,7 @@ class ABIChecker(ReviewBot.ReviewBot):
url = osc.core.makeurl(self.apiurl, ('source', src_project, '_meta')) url = osc.core.makeurl(self.apiurl, ('source', src_project, '_meta'))
try: try:
root = ET.parse(osc.core.http_GET(url)).getroot() root = ET.parse(osc.core.http_GET(url)).getroot()
except urllib2.HTTPError: except HTTPError:
return None return None
# set of source repo name, target repo name, arch # set of source repo name, target repo name, arch
@ -1087,4 +1092,3 @@ class CommandLineInterface(ReviewBot.CommandLineInterface):
if __name__ == "__main__": if __name__ == "__main__":
app = CommandLineInterface() app = CommandLineInterface()
sys.exit( app.main() ) sys.exit( app.main() )

View File

@ -4,7 +4,11 @@ from xml.etree import cElementTree as ET
import sys import sys
import cmdln import cmdln
import logging import logging
import urllib2 try:
from urllib.error import HTTPError
except ImportError:
# python 2.x
from urllib2 import HTTPError
import osc.core import osc.core
import ToolBase import ToolBase
@ -158,7 +162,7 @@ class BiArchTool(ToolBase.ToolBase):
try: try:
x = ET.fromstring(self.cached_GET(self.makeurl(['source', self.project, pkg, '_history'], {'rev': '1'}))) x = ET.fromstring(self.cached_GET(self.makeurl(['source', self.project, pkg, '_history'], {'rev': '1'})))
# catch deleted packages # catch deleted packages
except urllib2.HTTPError as e: except HTTPError as e:
if e.code == 404: if e.code == 404:
continue continue
raise e raise e
@ -202,7 +206,7 @@ class BiArchTool(ToolBase.ToolBase):
self.http_PUT(pkgmetaurl, data=ET.tostring(pkgmeta)) self.http_PUT(pkgmetaurl, data=ET.tostring(pkgmeta))
if self.caching: if self.caching:
self._invalidate__cached_GET(pkgmetaurl) self._invalidate__cached_GET(pkgmetaurl)
except urllib2.HTTPError as e: except HTTPError as e:
logger.error('failed to update %s: %s', pkg, e) logger.error('failed to update %s: %s', pkg, e)
def add_explicit_disable(self, wipebinaries=False): def add_explicit_disable(self, wipebinaries=False):
@ -242,7 +246,7 @@ class BiArchTool(ToolBase.ToolBase):
'cmd' : 'wipe', 'cmd' : 'wipe',
'arch': self.arch, 'arch': self.arch,
'package' : pkg })) 'package' : pkg }))
except urllib2.HTTPError as e: except HTTPError as e:
logger.error('failed to update %s: %s', pkg, e) logger.error('failed to update %s: %s', pkg, e)
@ -326,7 +330,7 @@ class BiArchTool(ToolBase.ToolBase):
'cmd' : 'wipe', 'cmd' : 'wipe',
'arch': self.arch, 'arch': self.arch,
'package' : pkg })) 'package' : pkg }))
except urllib2.HTTPError as e: except HTTPError as e:
logger.error('failed to update %s: %s', pkg, e) logger.error('failed to update %s: %s', pkg, e)
class CommandLineInterface(ToolBase.CommandLineInterface): class CommandLineInterface(ToolBase.CommandLineInterface):
@ -399,4 +403,3 @@ class CommandLineInterface(ToolBase.CommandLineInterface):
if __name__ == "__main__": if __name__ == "__main__":
app = CommandLineInterface() app = CommandLineInterface()
sys.exit( app.main() ) sys.exit( app.main() )

View File

@ -13,7 +13,11 @@ except ImportError:
import osc.conf import osc.conf
import osc.core import osc.core
import urllib2 try:
from urllib.error import HTTPError, URLError
except ImportError:
# python 2.x
from urllib2 import HTTPError, URLError
import yaml import yaml
from osclib.memoize import memoize from osclib.memoize import memoize
@ -56,7 +60,7 @@ class MaintenanceChecker(ReviewBot.ReviewBot):
url = osc.core.makeurl(apiurl, ('source', project, '00Meta', 'lookup.yml')) url = osc.core.makeurl(apiurl, ('source', project, '00Meta', 'lookup.yml'))
try: try:
return yaml.safe_load(osc.core.http_GET(url)) return yaml.safe_load(osc.core.http_GET(url))
except (urllib2.HTTPError, urllib2.URLError): except (HTTPError, URLError):
return None return None
# check if pkgname was submitted by the correct maintainer. If not, set # check if pkgname was submitted by the correct maintainer. If not, set
@ -165,4 +169,3 @@ if __name__ == "__main__":
app = ReviewBot.CommandLineInterface() app = ReviewBot.CommandLineInterface()
app.clazz = MaintenanceChecker app.clazz = MaintenanceChecker
sys.exit( app.main() ) sys.exit( app.main() )

View File

@ -17,7 +17,12 @@ from osclib.conf import Config
from osclib.core import devel_project_get from osclib.core import devel_project_get
from osclib.core import devel_project_fallback from osclib.core import devel_project_fallback
from osclib.core import group_members from osclib.core import group_members
import urllib2 try:
from urllib.error import HTTPError
except ImportError:
# python 2.x
from urllib2 import HTTPError
import ReviewBot import ReviewBot
from osclib.conf import str2bool from osclib.conf import str2bool
@ -124,7 +129,7 @@ class CheckSource(ReviewBot.ReviewBot):
shutil.rmtree(os.path.join(target_package, '.osc')) shutil.rmtree(os.path.join(target_package, '.osc'))
os.rename(target_package, '_old') os.rename(target_package, '_old')
old_info = self.package_source_parse(target_project, target_package) old_info = self.package_source_parse(target_project, target_package)
except urllib2.HTTPError: except HTTPError:
self.logger.error('failed to checkout %s/%s' % (target_project, target_package)) self.logger.error('failed to checkout %s/%s' % (target_project, target_package))
CheckSource.checkout_package(self.apiurl, source_project, source_package, revision=source_revision, CheckSource.checkout_package(self.apiurl, source_project, source_package, revision=source_revision,
@ -218,7 +223,7 @@ class CheckSource(ReviewBot.ReviewBot):
try: try:
xml = ET.parse(osc.core.http_GET(url)).getroot() xml = ET.parse(osc.core.http_GET(url)).getroot()
except urllib2.HTTPError as e: except HTTPError as e:
self.logger.error('ERROR in URL %s [%s]' % (url, e)) self.logger.error('ERROR in URL %s [%s]' % (url, e))
return ret return ret
@ -261,7 +266,7 @@ class CheckSource(ReviewBot.ReviewBot):
try: try:
result = osc.core.show_project_sourceinfo(self.apiurl, action.tgt_project, True, (action.tgt_package)) result = osc.core.show_project_sourceinfo(self.apiurl, action.tgt_project, True, (action.tgt_package))
root = ET.fromstring(result) root = ET.fromstring(result)
except urllib2.HTTPError: except HTTPError:
return None return None
# Decline the delete request if there is another delete/submit request against the same package # Decline the delete request if there is another delete/submit request against the same package

View File

@ -13,7 +13,12 @@ except ImportError:
import osc.conf import osc.conf
import osc.core import osc.core
import urllib2 try:
from urllib.error import HTTPError, URLError
except ImportError:
# python 2.x
from urllib2 import HTTPError, URLError
import yaml import yaml
import ReviewBot import ReviewBot
@ -89,7 +94,7 @@ class FactorySourceChecker(ReviewBot.ReviewBot):
sr = srprefix sr = srprefix
break break
requests = osc.core.get_request_list(apiurl, project, package, None, ['new', 'review'], 'submit') requests = osc.core.get_request_list(apiurl, project, package, None, ['new', 'review'], 'submit')
except (urllib2.HTTPError, urllib2.URLError): except (HTTPError, URLError):
self.logger.error("caught exception while checking %s/%s", project, package) self.logger.error("caught exception while checking %s/%s", project, package)
return None return None
@ -169,4 +174,3 @@ class CommandLineInterface(ReviewBot.CommandLineInterface):
if __name__ == "__main__": if __name__ == "__main__":
app = CommandLineInterface() app = CommandLineInterface()
sys.exit( app.main() ) sys.exit( app.main() )

View File

@ -3,7 +3,12 @@
import argparse import argparse
import logging import logging
import sys import sys
import urllib2 try:
from urllib.error import HTTPError
except ImportError:
# python 2.x
from urllib2 import HTTPError
import re import re
from xml.etree import cElementTree as ET from xml.etree import cElementTree as ET
@ -53,7 +58,7 @@ class CompareList(object):
url = makeurl(self.apiurl, ['source', project, '_meta']) url = makeurl(self.apiurl, ['source', project, '_meta'])
try: try:
http_GET(url) http_GET(url)
except urllib2.HTTPError: except HTTPError:
return False return False
return True return True

View File

@ -3,7 +3,13 @@
import argparse import argparse
import logging import logging
import sys import sys
import urllib2
try:
from urllib.error import HTTPError, URLError
except ImportError:
# python 2.x
from urllib2 import HTTPError, URLError
import random import random
import re import re
from xml.etree import cElementTree as ET from xml.etree import cElementTree as ET
@ -115,7 +121,7 @@ class FccFreezer(object):
l = ET.tostring(flink) l = ET.tostring(flink)
try: try:
http_PUT(url, data=l) http_PUT(url, data=l)
except urllib2.HTTPError as e: except HTTPError as e:
raise e raise e
class FccSubmitter(object): class FccSubmitter(object):
@ -159,7 +165,7 @@ class FccSubmitter(object):
def get_link(self, project, package): def get_link(self, project, package):
try: try:
link = http_GET(makeurl(self.apiurl, ['source', project, package, '_link'])).read() link = http_GET(makeurl(self.apiurl, ['source', project, package, '_link'])).read()
except (urllib2.HTTPError, urllib2.URLError): except (HTTPError, URLError):
return None return None
return ET.fromstring(link) return ET.fromstring(link)
@ -201,7 +207,7 @@ class FccSubmitter(object):
try: try:
logging.debug("Gathering package_meta %s/%s" % (tgt_project, tgt_package)) logging.debug("Gathering package_meta %s/%s" % (tgt_project, tgt_package))
osc.core.show_package_meta(self.apiurl, tgt_project, tgt_package) osc.core.show_package_meta(self.apiurl, tgt_project, tgt_package)
except (urllib2.HTTPError, urllib2.URLError): except (HTTPError, URLError):
return True return True
return False return False
@ -222,7 +228,7 @@ class FccSubmitter(object):
def check_multiple_specfiles(self, project, package): def check_multiple_specfiles(self, project, package):
try: try:
url = makeurl(self.apiurl, ['source', project, package], { 'expand': '1' } ) url = makeurl(self.apiurl, ['source', project, package], { 'expand': '1' } )
except urllib2.HTTPError as e: except HTTPError as e:
if e.code == 404: if e.code == 404:
return None return None
raise e raise e
@ -283,7 +289,7 @@ class FccSubmitter(object):
url = makeurl(self.apiurl, ['source', project, package, '{}?expand=1'.format('fcc_skip_pkgs')]) url = makeurl(self.apiurl, ['source', project, package, '{}?expand=1'.format('fcc_skip_pkgs')])
try: try:
return http_GET(url).read() return http_GET(url).read()
except urllib2.HTTPError: except HTTPError:
return '' return ''
def crawl(self): def crawl(self):

View File

@ -16,7 +16,13 @@ except ImportError:
import osc.core import osc.core
from osclib.conf import Config from osclib.conf import Config
from osclib.core import devel_project_get from osclib.core import devel_project_get
import urllib2
try:
from urllib.error import HTTPError
except ImportError:
# python 2.x
from urllib2 import HTTPError
import yaml import yaml
import ReviewBot import ReviewBot
from check_source_in_factory import FactorySourceChecker from check_source_in_factory import FactorySourceChecker
@ -64,7 +70,7 @@ class Leaper(ReviewBot.ReviewBot):
root = ET.parse(osc.core.http_GET(osc.core.makeurl(self.apiurl, ['source', project], root = ET.parse(osc.core.http_GET(osc.core.makeurl(self.apiurl, ['source', project],
query=query))).getroot() query=query))).getroot()
packages = [i.get('name') for i in root.findall('entry')] packages = [i.get('name') for i in root.findall('entry')]
except urllib2.HTTPError as e: except HTTPError as e:
# in case the project doesn't exist yet (like sle update) # in case the project doesn't exist yet (like sle update)
if e.code != 404: if e.code != 404:
raise e raise e
@ -583,4 +589,3 @@ class CommandLineInterface(ReviewBot.CommandLineInterface):
if __name__ == "__main__": if __name__ == "__main__":
app = CommandLineInterface() app = CommandLineInterface()
sys.exit( app.main() ) sys.exit( app.main() )

View File

@ -12,7 +12,12 @@ import cmdln
import requests as REQ import requests as REQ
import json import json
import time import time
import urllib2
try:
from urllib.error import HTTPError
except ImportError:
# python 2.x
from urllib2 import HTTPError
try: try:
from xml.etree import cElementTree as ET from xml.etree import cElementTree as ET
@ -53,7 +58,7 @@ class LegalAuto(ReviewBot.ReviewBot):
def retried_GET(self, url): def retried_GET(self, url):
try: try:
return http_GET(url) return http_GET(url)
except urllib2.HTTPError, e: except HTTPError, e:
if 500 <= e.code <= 599: if 500 <= e.code <= 599:
print 'Retrying {}'.format(url) print 'Retrying {}'.format(url)
time.sleep(1) time.sleep(1)

View File

@ -12,7 +12,13 @@ import osc.conf
import osc.core import osc.core
from osc.core import get_commitlog from osc.core import get_commitlog
from osc.core import get_request_list from osc.core import get_request_list
import urllib2
try:
from urllib.error import HTTPError
except ImportError:
# python 2.x
from urllib2 import HTTPError
import subprocess import subprocess
import time import time
import yaml import yaml
@ -86,7 +92,7 @@ class Manager42(object):
self.lookup = {} self.lookup = {}
try: try:
self.lookup = yaml.safe_load(self._load_lookup_file(project)) self.lookup = yaml.safe_load(self._load_lookup_file(project))
except urllib2.HTTPError as e: except HTTPError as e:
if e.code != 404: if e.code != 404:
raise raise
@ -118,7 +124,7 @@ class Manager42(object):
def retried_GET(self, url): def retried_GET(self, url):
try: try:
return http_GET(url) return http_GET(url)
except urllib2.HTTPError as e: except HTTPError as e:
if 500 <= e.code <= 599: if 500 <= e.code <= 599:
logger.warn('Retrying {}'.format(url)) logger.warn('Retrying {}'.format(url))
time.sleep(1) time.sleep(1)
@ -135,7 +141,7 @@ class Manager42(object):
query=query))) query=query)))
packages = [i.get('name') for i in root.findall('entry')] packages = [i.get('name') for i in root.findall('entry')]
except urllib2.HTTPError as e: except HTTPError as e:
if e.code == 404: if e.code == 404:
logger.error("{}: {}".format(project, e)) logger.error("{}: {}".format(project, e))
packages = [] packages = []
@ -158,7 +164,7 @@ class Manager42(object):
for package in sorted(packages): for package in sorted(packages):
try: try:
self.check_one_package(package) self.check_one_package(package)
except urllib2.HTTPError as e: except HTTPError as e:
logger.error("Failed to check {}: {}".format(package, e)) logger.error("Failed to check {}: {}".format(package, e))
pass pass
@ -225,7 +231,7 @@ class Manager42(object):
query['deleted'] = 1 query['deleted'] = 1
return self.cached_GET(makeurl(self.apiurl, return self.cached_GET(makeurl(self.apiurl,
['source', project, package, '_history'], query)) ['source', project, package, '_history'], query))
except urllib2.HTTPError as e: except HTTPError as e:
if e.code == 404: if e.code == 404:
return None return None
raise raise
@ -360,7 +366,7 @@ class Manager42(object):
try: try:
link = self.cached_GET(makeurl(self.apiurl, link = self.cached_GET(makeurl(self.apiurl,
['source', project, package, '_link'])) ['source', project, package, '_link']))
except urllib2.HTTPError: except HTTPError:
return None return None
return ET.fromstring(link) return ET.fromstring(link)
@ -430,4 +436,3 @@ if __name__ == '__main__':
http_DELETE = dryrun('DELETE') http_DELETE = dryrun('DELETE')
sys.exit(main(args)) sys.exit(main(args))

View File

@ -10,7 +10,13 @@ from osc.core import http_PUT
from osc.core import makeurl from osc.core import makeurl
from osc.core import show_upstream_rev from osc.core import show_upstream_rev
from osclib.core import project_pseudometa_package from osclib.core import project_pseudometa_package
from urllib2 import HTTPError
try:
from urllib.error import HTTPError
except ImportError:
# python 2.x
from urllib2 import HTTPError
import argparse import argparse
import osc.conf import osc.conf
import sys import sys

View File

@ -11,10 +11,10 @@ import sys
try: try:
from urllib.parse import unquote from urllib.parse import unquote
from urllib.parse import urlsplit, SplitResult from urllib.parse import urlsplit, SplitResult
from urllib.request import URLError, HTTPError from urllib.error import URLError, HTTPError
from io import StringIO from io import StringIO
except ImportError: except ImportError:
#python 2.x # python 2.x
from urlparse import urlsplit, SplitResult from urlparse import urlsplit, SplitResult
from urllib import unquote from urllib import unquote
from urllib2 import URLError, HTTPError from urllib2 import URLError, HTTPError

View File

@ -1,4 +1,9 @@
import urllib2 try:
from urllib.error import HTTPError
except ImportError:
# python 2.x
from urllib2 import HTTPError
from xml.etree import cElementTree as ET from xml.etree import cElementTree as ET
from osc.core import http_GET from osc.core import http_GET
@ -140,7 +145,7 @@ class CycleDetector(object):
# print('Generating _builddepinfo for (%s, %s, %s)' % (project, repository, arch)) # print('Generating _builddepinfo for (%s, %s, %s)' % (project, repository, arch))
url = makeurl(self.apiurl, ['build/%s/%s/%s/_builddepinfo' % (project, repository, arch)]) url = makeurl(self.apiurl, ['build/%s/%s/%s/_builddepinfo' % (project, repository, arch)])
root = http_GET(url).read() root = http_GET(url).read()
except urllib2.HTTPError as e: except HTTPError as e:
print('ERROR in URL %s [%s]' % (url, e)) print('ERROR in URL %s [%s]' % (url, e))
return root return root

View File

@ -4,9 +4,9 @@ import json
import osc import osc
try: try:
from urllib.request import HTTPError from urllib.error import HTTPError
except ImportError: except ImportError:
#python 2.x # python 2.x
from urllib2 import HTTPError from urllib2 import HTTPError
class PrioCommand(object): class PrioCommand(object):

View File

@ -3,9 +3,9 @@ from __future__ import print_function
import re import re
try: try:
from urllib.request import HTTPError from urllib.error import HTTPError
except ImportError: except ImportError:
#python 2.x # python 2.x
from urllib2 import HTTPError from urllib2 import HTTPError
from osc import oscerr from osc import oscerr

View File

@ -19,7 +19,7 @@ try:
from urllib.error import HTTPError, URLError from urllib.error import HTTPError, URLError
from urllib.parse import quote_plus from urllib.parse import quote_plus
except ImportError: except ImportError:
#python 2.x # python 2.x
from urllib2 import HTTPError, URLError from urllib2 import HTTPError, URLError
from urllib import quote_plus from urllib import quote_plus

View File

@ -3,7 +3,12 @@
import argparse import argparse
import logging import logging
import sys import sys
import urllib2 try:
from urllib.error import HTTPError
except ImportError:
# python 2.x
from urllib2 import HTTPError
import re import re
import yaml import yaml
from xml.etree import cElementTree as ET from xml.etree import cElementTree as ET
@ -80,7 +85,7 @@ class StagingHelper(object):
url = makeurl(self.apiurl, ['source', project, pkg], query=query) url = makeurl(self.apiurl, ['source', project, pkg], query=query)
try: try:
root = ET.parse(http_GET(url)).getroot() root = ET.parse(http_GET(url)).getroot()
except urllib2.HTTPError as e: except HTTPError as e:
if e.code == 404: if e.code == 404:
continue continue
raise raise

View File

@ -6,7 +6,12 @@ import re
import string import string
import time import time
import urllib import urllib
import urllib2 try:
from urllib.parse import unquote
except ImportError:
# python 2.x
from urllib import unquote
import urlparse import urlparse
import xml.etree.cElementTree as ET import xml.etree.cElementTree as ET
@ -852,7 +857,7 @@ class OBS(object):
@GET('/search/request') @GET('/search/request')
def search_request(self, request, uri, headers): def search_request(self, request, uri, headers):
"""Return a search result for /search/request.""" """Return a search result for /search/request."""
query = urllib2.unquote(urlparse.urlparse(uri).query) query = unquote(urlparse.urlparse(uri).query)
assert query in ( 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_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'])" "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'])"

View File

@ -17,7 +17,13 @@ import json
import os import os
import re import re
import sys import sys
import urllib2
try:
from urllib.error import HTTPError
except ImportError:
# python 2.x
from urllib2 import HTTPError
import logging import logging
import signal import signal
import time import time
@ -101,7 +107,7 @@ class ToTestBase(object):
url = self.api.makeurl(['build', project, self.product_repo, self.product_arch, product]) url = self.api.makeurl(['build', project, self.product_repo, self.product_arch, product])
try: try:
f = self.api.retried_GET(url) f = self.api.retried_GET(url)
except urllib2.HTTPError: except HTTPError:
return [] return []
ret = [] ret = []

View File

@ -4,7 +4,13 @@ import argparse
import itertools import itertools
import logging import logging
import sys import sys
import urllib2
try:
from urllib.error import HTTPError
except ImportError:
# python 2.x
from urllib2 import HTTPError
import time import time
from xml.etree import cElementTree as ET from xml.etree import cElementTree as ET
@ -79,7 +85,7 @@ class UpdateCrawler(object):
def retried_GET(self, url): def retried_GET(self, url):
try: try:
return http_GET(url) return http_GET(url)
except urllib2.HTTPError as e: except HTTPError as e:
if 500 <= e.code <= 599: if 500 <= e.code <= 599:
print 'Retrying {}'.format(url) print 'Retrying {}'.format(url)
time.sleep(1) time.sleep(1)
@ -191,7 +197,7 @@ class UpdateCrawler(object):
))) )))
if root.get('project') is None and root.get('cicount'): if root.get('project') is None and root.get('cicount'):
return True return True
except urllib2.HTTPError as err: except HTTPError as err:
# if there is no link, it can't be a link # if there is no link, it can't be a link
if err.code == 404: if err.code == 404:
return False return False
@ -370,4 +376,3 @@ if __name__ == '__main__':
http_DELETE = dryrun('DELETE') http_DELETE = dryrun('DELETE')
sys.exit(main(args)) sys.exit(main(args))