diff options
Diffstat (limited to 'pym/portage')
-rw-r--r-- | pym/portage/__init__.py | 12 | ||||
-rw-r--r-- | pym/portage/checksum.py | 7 | ||||
-rw-r--r-- | pym/portage/data.py | 5 | ||||
-rw-r--r-- | pym/portage/dbapi/bintree.py | 17 | ||||
-rw-r--r-- | pym/portage/dispatch_conf.py | 8 | ||||
-rw-r--r-- | pym/portage/getbinpkg.py | 39 | ||||
-rw-r--r-- | pym/portage/glsa.py | 7 | ||||
-rw-r--r-- | pym/portage/output.py | 7 | ||||
-rw-r--r-- | pym/portage/sets/__init__.py | 5 | ||||
-rw-r--r-- | pym/portage/util.py | 13 |
10 files changed, 85 insertions, 35 deletions
diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py index e6e5f5bda..deb7b2ff9 100644 --- a/pym/portage/__init__.py +++ b/pym/portage/__init__.py @@ -28,7 +28,10 @@ try: import pickle import stat - import commands + try: + from subprocess import getstatusoutput as subprocess_getstatusoutput + except ImportError: + from commands import getstatusoutput as subprocess_getstatusoutput from time import sleep from random import shuffle from itertools import chain, izip @@ -434,7 +437,7 @@ if platform.system() in ('FreeBSD',): @classmethod def chflags(cls, path, flags, opts=""): cmd = 'chflags %s %o %s' % (opts, flags, _shell_quote(path)) - status, output = commands.getstatusoutput(cmd) + status, output = subprocess_getstatusoutput(cmd) if os.WIFEXITED(status) and os.WEXITSTATUS(status) == os.EX_OK: return # Try to generate an ENOENT error if appropriate. @@ -1990,7 +1993,10 @@ class config(object): self._local_repo_configs = {} self._local_repo_conf_path = \ os.path.join(abs_user_config, 'repos.conf') - from ConfigParser import SafeConfigParser, ParsingError + try: + from configparser import SafeConfigParser, ParsingError + except ImportError: + from ConfigParser import SafeConfigParser, ParsingError repo_conf_parser = SafeConfigParser() try: repo_conf_parser.readfp( diff --git a/pym/portage/checksum.py b/pym/portage/checksum.py index 01637b1a6..ee2e51c71 100644 --- a/pym/portage/checksum.py +++ b/pym/portage/checksum.py @@ -12,7 +12,10 @@ from portage import _unicode_encode import errno import stat import tempfile -import commands +try: + from subprocess import getstatusoutput as subprocess_getstatusoutput +except ImportError: + from commands import getstatusoutput as subprocess_getstatusoutput #dict of all available hash functions hashfunc_map = {} @@ -112,7 +115,7 @@ hashfunc_map["size"] = getsize prelink_capable = False if os.path.exists(PRELINK_BINARY): - results = commands.getstatusoutput(PRELINK_BINARY+" --version > /dev/null 2>&1") + results = subprocess_getstatusoutput(PRELINK_BINARY+" --version > /dev/null 2>&1") if (results[0] >> 8) == 0: prelink_capable=1 del results diff --git a/pym/portage/data.py b/pym/portage/data.py index 0ce760a92..c30a3688a 100644 --- a/pym/portage/data.py +++ b/pym/portage/data.py @@ -100,7 +100,10 @@ userpriv_groups = [portage_gid] if secpass >= 2: # Get a list of group IDs for the portage user. Do not use grp.getgrall() # since it is known to trigger spurious SIGPIPE problems with nss_ldap. - from commands import getstatusoutput + try: + from subprocess import getstatusoutput + except ImportError: + from commands import getstatusoutput mystatus, myoutput = getstatusoutput("id -G portage") if mystatus == os.EX_OK: for x in myoutput.split(): diff --git a/pym/portage/dbapi/bintree.py b/pym/portage/dbapi/bintree.py index e020415ab..bc91152a6 100644 --- a/pym/portage/dbapi/bintree.py +++ b/pym/portage/dbapi/bintree.py @@ -660,7 +660,10 @@ class binarytree(object): base_url = self.settings["PORTAGE_BINHOST"] from portage.const import CACHE_PATH - from urlparse import urlparse + try: + from urllib.parse import urlparse + except ImportError: + from urlparse import urlparse urldata = urlparse(base_url) pkgindex_file = os.path.join(self.settings["ROOT"], CACHE_PATH, "binhost", urldata[1] + urldata[2], "Packages") @@ -678,13 +681,16 @@ class binarytree(object): if e.errno != errno.ENOENT: raise local_timestamp = pkgindex.header.get("TIMESTAMP", None) - import urllib, urlparse + try: + from urllib.request import urlopen as urllib_request_urlopen + except ImportError: + from urllib import urlopen as urllib_request_urlopen rmt_idx = self._new_pkgindex() try: # urlparse.urljoin() only works correctly with recognized # protocols and requires the base url to have a trailing # slash, so join manually... - f = urllib.urlopen(base_url.rstrip("/") + "/Packages") + f = urllib_request_urlopen(base_url.rstrip("/") + "/Packages") try: rmt_idx.readHeader(f) remote_timestamp = rmt_idx.header.get("TIMESTAMP", None) @@ -1082,7 +1088,10 @@ class binarytree(object): mydest = os.path.dirname(self.getname(pkgname)) self._ensure_dir(mydest) - from urlparse import urlparse + try: + from urllib.parse import urlparse + except ImportError: + from urlparse import urlparse # urljoin doesn't work correctly with unrecognized protocols like sftp if self._remote_has_index: rel_url = self._remotepkgs[pkgname].get("PATH") diff --git a/pym/portage/dispatch_conf.py b/pym/portage/dispatch_conf.py index e18eb34fa..971f9eb5f 100644 --- a/pym/portage/dispatch_conf.py +++ b/pym/portage/dispatch_conf.py @@ -7,7 +7,11 @@ # Library by Wayne Davison <gentoo@blorf.net>, derived from code # written by Jeremy Wohl (http://igmus.org) -import os, sys, commands, shutil +import os, sys, shutil +try: + from subprocess import getoutput as subprocess_getoutput +except ImportError: + from commands import getoutput as subprocess_getoutput import portage from portage.localization import _ @@ -110,7 +114,7 @@ def file_archive(archive, curconf, newconf, mrgconf): # Archive the current config file if it isn't already saved if os.path.exists(archive) \ - and len(commands.getoutput("diff -aq '%s' '%s'" % (curconf,archive))) != 0: + and len(subprocess_getoutput("diff -aq '%s' '%s'" % (curconf,archive))) != 0: suf = 1 while suf < 9 and os.path.exists(archive + '.' + str(suf)): suf += 1 diff --git a/pym/portage/getbinpkg.py b/pym/portage/getbinpkg.py index adab28fab..c3994d26d 100644 --- a/pym/portage/getbinpkg.py +++ b/pym/portage/getbinpkg.py @@ -11,13 +11,21 @@ from portage import os from portage import _encodings from portage import _unicode_encode -import HTMLParser import sys import socket import time import tempfile import base64 -import urllib2 + +try: + from html.parser import HTMLParser as html_parser_HTMLParser +except ImportError: + from HTMLParser import HTMLParser as html_parser_HTMLParser + +try: + from urllib.parse import unquote as urllib_parse_unquote +except: + from urllib2 import unquote as urllib_parse_unquote try: import cPickle as pickle @@ -30,9 +38,18 @@ except ImportError as e: sys.stderr.write(colorize("BAD","!!! CANNOT IMPORT FTPLIB: ")+str(e)+"\n") try: - import httplib + try: + from http.client import HTTPConnection as http_client_HTTPConnection + from http.client import HTTPSConnection as http_client_HTTPConnection + from http.client import BadStatusLine as http_client_HTTPConnection + from http.client import ResponseNotReady as http_client_HTTPConnection + except ImportError: + from httplib import HTTPConnection as http_client_HTTPConnection + from httplib import HTTPSConnection as http_client_HTTPConnection + from httplib import BadStatusLine as http_client_HTTPConnection + from httplib import ResponseNotReady as http_client_HTTPConnection except ImportError as e: - sys.stderr.write(colorize("BAD","!!! CANNOT IMPORT HTTPLIB: ")+str(e)+"\n") + sys.stderr.write(colorize("BAD","!!! CANNOT IMPORT HTTP.CLIENT: ")+str(e)+"\n") def make_metadata_dict(data): myid,myglob = data @@ -43,12 +60,12 @@ def make_metadata_dict(data): return mydict -class ParseLinks(HTMLParser.HTMLParser): +class ParseLinks(html_parser_HTMLParser): """Parser class that overrides HTMLParser to grab all anchors from an html page and provide suffix and prefix limitors""" def __init__(self): self.PL_anchors = [] - HTMLParser.HTMLParser.__init__(self) + html_parser_HTMLParser.__init__(self) def get_anchors(self): return self.PL_anchors @@ -77,7 +94,7 @@ class ParseLinks(HTMLParser.HTMLParser): for x in attrs: if x[0] == 'href': if x[1] not in self.PL_anchors: - self.PL_anchors.append(urllib2.unquote(x[1])) + self.PL_anchors.append(urllib_parse_unquote(x[1])) def create_conn(baseurl,conn=None): @@ -132,9 +149,9 @@ def create_conn(baseurl,conn=None): if not conn: if protocol == "https": - conn = httplib.HTTPSConnection(host) + conn = http_client_HTTPSConnection(host) elif protocol == "http": - conn = httplib.HTTPConnection(host) + conn = http_client_HTTPConnection(host) elif protocol == "ftp": passive = 1 if(host[-1] == "*"): @@ -637,14 +654,14 @@ def dir_get_metadata(baseurl, conn=None, chunk_size=3000, verbose=1, usingcache= "/".join((baseurl.rstrip("/"), x.lstrip("/"))), conn, chunk_size) break - except httplib.BadStatusLine: + except http_client_BadStatusLine: # Sometimes this error is thrown from conn.getresponse() in # make_http_request(). The docstring for this error in # httplib.py says "Presumably, the server closed the # connection before sending a valid response". conn, protocol, address, params, headers = create_conn( baseurl) - except httplib.ResponseNotReady: + except http_client_ResponseNotReady: # With some http servers this error is known to be thrown # from conn.getresponse() in make_http_request() when the # remote file does not have appropriate read permissions. diff --git a/pym/portage/glsa.py b/pym/portage/glsa.py index 95c3c813c..1f061b231 100644 --- a/pym/portage/glsa.py +++ b/pym/portage/glsa.py @@ -4,7 +4,10 @@ import codecs import sys -import urllib +try: + from urllib.request import urlopen as urllib_request_urlopen +except ImportError: + from urllib import urlopen as urllib_request_urlopen import re import xml.dom.minidom @@ -470,7 +473,7 @@ class Glsa: myurl = "file://"+self.nr else: myurl = repository + "glsa-%s.xml" % str(self.nr) - self.parse(urllib.urlopen(myurl)) + self.parse(urllib_request_urlopen(myurl)) return None def parse(self, myfile): diff --git a/pym/portage/output.py b/pym/portage/output.py index 06073df71..5170d70aa 100644 --- a/pym/portage/output.py +++ b/pym/portage/output.py @@ -5,7 +5,10 @@ __docformat__ = "epytext" import codecs -import commands +try: + from subprocess import getstatusoutput as subprocess_getstatusoutput +except ImportError: + from commands import getstatusoutput as subprocess_getstatusoutput import errno import formatter import re @@ -405,7 +408,7 @@ def get_term_size(): pass except ImportError: pass - st, out = commands.getstatusoutput('stty size') + st, out = subprocess_getstatusoutput('stty size') if st == os.EX_OK: out = out.split() if len(out) == 2: diff --git a/pym/portage/sets/__init__.py b/pym/portage/sets/__init__.py index 6c5f850ad..20923ca2e 100644 --- a/pym/portage/sets/__init__.py +++ b/pym/portage/sets/__init__.py @@ -5,8 +5,11 @@ __all__ = ["SETPREFIX", "get_boolean", "SetConfigError", "SetConfig", "load_default_config"] +try: + from configparser import SafeConfigParser, NoOptionError +except ImportError: + from ConfigParser import SafeConfigParser, NoOptionError from portage import os -from ConfigParser import SafeConfigParser, NoOptionError from portage import load_mod from portage.const import USER_CONFIG_PATH, GLOBAL_CONFIG_PATH from portage.exception import PackageSetNotFound diff --git a/pym/portage/util.py b/pym/portage/util.py index 7b7c2a6f1..1401febae 100644 --- a/pym/portage/util.py +++ b/pym/portage/util.py @@ -12,7 +12,10 @@ __all__ = ['apply_permissions', 'apply_recursive_permissions', 'stack_dicts', 'stack_lists', 'unique_array', 'varexpand', 'write_atomic', 'writedict', 'writemsg', 'writemsg_level', 'writemsg_stdout'] -import commands +try: + from subprocess import getstatusoutput as subprocess_getstatusoutput +except ImportError: + from commands import getstatusoutput as subprocess_getstatusoutput import codecs import errno import logging @@ -21,6 +24,7 @@ import shlex import stat import string import sys +from io import StringIO import portage from portage import os @@ -40,11 +44,6 @@ try: except ImportError: import pickle -try: - from cStringIO import StringIO -except ImportError: - from StringIO import StringIO - noiselimit = 0 def initialize_logger(level=logging.WARN): @@ -1402,7 +1401,7 @@ def find_updated_config_files(target_root, config_protect): mycommand = "find '%s' -maxdepth 1 -name '._cfg????_%s'" % \ os.path.split(x.rstrip(os.path.sep)) mycommand += " ! -name '.*~' ! -iname '.*.bak' -print0" - a = commands.getstatusoutput(mycommand) + a = subprocess_getstatusoutput(mycommand) if a[0] == 0: files = a[1].split('\0') |