Import url functions properly for python3
Make it possible to run pkglistgen under python3
This commit is contained in:
parent
2fe9701238
commit
40513d9503
@ -13,13 +13,13 @@ import time
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
from urllib.error import HTTPError
|
from urllib.error import HTTPError
|
||||||
|
from urllib.parse import quote_plus
|
||||||
except ImportError:
|
except ImportError:
|
||||||
# python 2.x
|
# python 2.x
|
||||||
from urllib2 import HTTPError
|
from urllib2 import HTTPError
|
||||||
|
from urllib import quote_plus
|
||||||
import osc.conf
|
import osc.conf
|
||||||
import osc.core
|
import osc.core
|
||||||
from urllib import quote_plus
|
|
||||||
|
|
||||||
from osclib.memoize import memoize
|
from osclib.memoize import memoize
|
||||||
|
|
||||||
|
@ -10,7 +10,6 @@ from collections import namedtuple
|
|||||||
import sys
|
import sys
|
||||||
import cmdln
|
import cmdln
|
||||||
import logging
|
import logging
|
||||||
import urllib2
|
|
||||||
import filecmp
|
import filecmp
|
||||||
from osc.core import checkout_package
|
from osc.core import checkout_package
|
||||||
from osc.core import http_GET, http_PUT
|
from osc.core import http_GET, http_PUT
|
||||||
@ -40,7 +39,12 @@ import subprocess
|
|||||||
import re
|
import re
|
||||||
import yaml
|
import yaml
|
||||||
import requests
|
import requests
|
||||||
import urlparse
|
try:
|
||||||
|
from urllib.parse import urljoin, urlparse
|
||||||
|
except ImportError:
|
||||||
|
# python 2.x
|
||||||
|
from urlparse import urljoin, urlparse
|
||||||
|
|
||||||
import gzip
|
import gzip
|
||||||
import tempfile
|
import tempfile
|
||||||
import traceback
|
import traceback
|
||||||
@ -990,7 +994,7 @@ class CommandLineInterface(ToolBase.CommandLineInterface):
|
|||||||
|
|
||||||
repo = pool.add_repo(''.join(random.choice(string.letters) for _ in range(5)))
|
repo = pool.add_repo(''.join(random.choice(string.letters) for _ in range(5)))
|
||||||
path_prefix = 'suse/' if name and repo_style == 'build' else ''
|
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)
|
repomd = requests.get(url)
|
||||||
ns = {'r': 'http://linux.duke.edu/metadata/repo'}
|
ns = {'r': 'http://linux.duke.edu/metadata/repo'}
|
||||||
root = ET.fromstring(repomd.content)
|
root = ET.fromstring(repomd.content)
|
||||||
@ -1017,7 +1021,7 @@ class CommandLineInterface(ToolBase.CommandLineInterface):
|
|||||||
f.flush()
|
f.flush()
|
||||||
os.lseek(f.fileno(), 0, os.SEEK_SET)
|
os.lseek(f.fileno(), 0, os.SEEK_SET)
|
||||||
repo.add_repomdxml(f, 0)
|
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:
|
with requests.get(url, stream=True) as primary:
|
||||||
sha256 = hashlib.sha256(primary.content).hexdigest()
|
sha256 = hashlib.sha256(primary.content).hexdigest()
|
||||||
if sha256 != sha256_expected:
|
if sha256 != sha256_expected:
|
||||||
@ -1050,7 +1054,7 @@ class CommandLineInterface(ToolBase.CommandLineInterface):
|
|||||||
# Could look at .repo file or repomd.xml, but larger change.
|
# Could look at .repo file or repomd.xml, but larger change.
|
||||||
return 'update-' + os.path.basename(os.path.normpath(baseurl)), 'update'
|
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:
|
with requests.get(url) as media:
|
||||||
for i, line in enumerate(media.iter_lines()):
|
for i, line in enumerate(media.iter_lines()):
|
||||||
if i != 1:
|
if i != 1:
|
||||||
@ -1060,7 +1064,7 @@ class CommandLineInterface(ToolBase.CommandLineInterface):
|
|||||||
if name is not None and '-Build' in name:
|
if name is not None and '-Build' in name:
|
||||||
return name, 'media'
|
return name, 'media'
|
||||||
|
|
||||||
url = urlparse.urljoin(baseurl, 'media.1/build')
|
url = urljoin(baseurl, 'media.1/build')
|
||||||
with requests.get(url) as build:
|
with requests.get(url) as build:
|
||||||
name = build.content.strip()
|
name = build.content.strip()
|
||||||
|
|
||||||
@ -1283,7 +1287,7 @@ class CommandLineInterface(ToolBase.CommandLineInterface):
|
|||||||
return
|
return
|
||||||
|
|
||||||
# Cache dir specific to hostname and project.
|
# 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)
|
cache_dir = CacheManager.directory('pkglistgen', host, opts.project)
|
||||||
|
|
||||||
if not opts.no_checkout:
|
if not opts.no_checkout:
|
||||||
@ -1433,13 +1437,13 @@ class CommandLineInterface(ToolBase.CommandLineInterface):
|
|||||||
logger.warning('no baseurl configured for {}'.format(project))
|
logger.warning('no baseurl configured for {}'.format(project))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
urls = [urlparse.urljoin(baseurl, 'repo/oss/')]
|
urls = [urljoin(baseurl, 'repo/oss/')]
|
||||||
if baseurl_update:
|
if baseurl_update:
|
||||||
urls.append(urlparse.urljoin(baseurl_update, 'oss/'))
|
urls.append(urljoin(baseurl_update, 'oss/'))
|
||||||
if project_config.get('nonfree'):
|
if project_config.get('nonfree'):
|
||||||
urls.append(urlparse.urljoin(baseurl, 'repo/non-oss/'))
|
urls.append(urljoin(baseurl, 'repo/non-oss/'))
|
||||||
if baseurl_update:
|
if baseurl_update:
|
||||||
urls.append(urlparse.urljoin(baseurl_update, 'non-oss/'))
|
urls.append(urljoin(baseurl_update, 'non-oss/'))
|
||||||
|
|
||||||
names = []
|
names = []
|
||||||
for url in urls:
|
for url in urls:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user