from stat import *
from random import *
-import atexit, commands, re, shutil, stat, sys
+import atexit, re, shutil, stat, sys
+try:
+ from subprocess import getoutput as subprocess_getoutput
+ from subprocess import getstatusoutput as subprocess_getstatusoutput
+except ImportError:
+ from commands import getoutput as subprocess_getoutput
+ from commands import getstatusoutput as subprocess_getstatusoutput
try:
import portage
except ImportError:
else:
mrgfail = portage.dispatch_conf.file_archive(archive, conf['current'], conf['new'], mrgconf)
if os.path.exists(archive + '.dist'):
- unmodified = len(commands.getoutput(DIFF_CONTENTS % (conf['current'], archive + '.dist'))) == 0
+ unmodified = len(subprocess_getoutput(DIFF_CONTENTS % (conf['current'], archive + '.dist'))) == 0
else:
unmodified = 0
if os.path.exists(mrgconf):
- if mrgfail or len(commands.getoutput(DIFF_CONTENTS % (conf['new'], mrgconf))) == 0:
+ if mrgfail or len(subprocess_getoutput(DIFF_CONTENTS % (conf['new'], mrgconf))) == 0:
os.unlink(mrgconf)
newconf = conf['new']
else:
if newconf == mrgconf and \
self.options.get('ignore-previously-merged') != 'yes' and \
os.path.exists(archive+'.dist') and \
- len(commands.getoutput(DIFF_CONTENTS % (archive+'.dist', conf['new']))) == 0:
+ len(subprocess_getoutput(DIFF_CONTENTS % (archive+'.dist', conf['new']))) == 0:
# The current update is identical to the archived .dist
# version that has previously been merged.
os.unlink(mrgconf)
newconf = conf['new']
- mystatus, myoutput = commands.getstatusoutput(
+ mystatus, myoutput = subprocess_getstatusoutput(
DIFF_CONTENTS % (conf ['current'], newconf))
same_file = 0 == len(myoutput)
if mystatus >> 8 == 2:
same_cvs = False
same_wsc = False
else:
- same_cvs = 0 == len(commands.getoutput(
+ same_cvs = 0 == len(subprocess_getoutput(
DIFF_CVS_INTERP % (conf ['current'], newconf)))
- same_wsc = 0 == len(commands.getoutput(
+ same_wsc = 0 == len(subprocess_getoutput(
DIFF_WSCOMMENTS % (conf ['current'], newconf)))
# Do options permit?
# mail mode as requested by solar
if mode == "mail":
import portage.mail, socket
- from StringIO import StringIO
+ from io import StringIO
from email.mime.text import MIMEText
# color doesn't make any sense for mail
from __future__ import print_function
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 logging
import time
import platform
+from io import StringIO
from itertools import chain, izip
from stat import S_ISDIR, ST_CTIME
-try:
- from cStringIO import StringIO
-except ImportError:
- from StringIO import StringIO
-
if not hasattr(__builtins__, "set"):
from sets import Set as set
(checkdir, y, m.group(0)))
if desktop_file_validate and desktop_pattern.match(y):
- status, cmd_output = commands.getstatusoutput(
+ status, cmd_output = subprocess_getstatusoutput(
"'%s' '%s'" % (desktop_file_validate, full_path))
if os.WIFEXITED(status) and os.WEXITSTATUS(status) != os.EX_OK:
# Note: in the future we may want to grab the
if xmllint_capable and not metadata_bad:
# xmlint can produce garbage output even on success, so only dump
# the ouput when it fails.
- st, out = commands.getstatusoutput(
+ st, out = subprocess_getstatusoutput(
"xmllint --nonet --noout --dtdvalid '%s' '%s'" % \
(metadata_dtd, os.path.join(checkdir, "metadata.xml")))
if st != os.EX_OK:
if myfile not in expansion:
continue
- myout = commands.getstatusoutput("egrep -q "+headerstring+" "+myfile)
+ myout = subprocess_getstatusoutput("egrep -q "+headerstring+" "+myfile)
if myout[0] == 0:
myheaders.append(myfile)
# $Id$
from _emerge.SpawnProcess import SpawnProcess
-import urlparse
+try:
+ from urllib.parse import urlparse as urllib_parse_urlparse
+except ImportError:
+ from urlparse import urlparse as urllib_parse_urlparse
import sys
import portage
from portage import os
self.wait()
return
- protocol = urlparse.urlparse(uri)[0]
+ protocol = urllib_parse_urlparse(uri)[0]
fcmd_prefix = "FETCHCOMMAND"
if resume:
fcmd_prefix = "RESUMECOMMAND"
import formatter
import sys
import time
-
-try:
- from cStringIO import StringIO
-except ImportError:
- from StringIO import StringIO
+from io import StringIO
import portage
from portage import os
# Distributed under the terms of the GNU General Public License v2
# $Id$
-import commands
+try:
+ from subprocess import getstatusoutput as subprocess_getstatusoutput
+except ImportError:
+ from commands import getstatusoutput as subprocess_getstatusoutput
import errno
import logging
import platform
else:
print("Unknown")
- output=commands.getstatusoutput("distcc --version")
+ output=subprocess_getstatusoutput("distcc --version")
if not output[0]:
print(str(output[1].split("\n",1)[0]), end=' ')
if "distcc" in settings.features:
else:
print("[disabled]")
- output=commands.getstatusoutput("ccache -V")
+ output=subprocess_getstatusoutput("ccache -V")
if not output[0]:
print(str(output[1].split("\n",1)[0]), end=' ')
if "ccache" in settings.features:
"!!! other terminals also.\n"
)
- mystatus, myoutput = commands.getstatusoutput("gcc-config -c")
+ mystatus, myoutput = subprocess_getstatusoutput("gcc-config -c")
if mystatus == os.EX_OK and myoutput.startswith(chost + "-"):
return myoutput.replace(chost + "-", gcc_ver_prefix, 1)
- mystatus, myoutput = commands.getstatusoutput(
+ mystatus, myoutput = subprocess_getstatusoutput(
chost + "-" + gcc_ver_command)
if mystatus == os.EX_OK:
return gcc_ver_prefix + myoutput
- mystatus, myoutput = commands.getstatusoutput(gcc_ver_command)
+ mystatus, myoutput = subprocess_getstatusoutput(gcc_ver_command)
if mystatus == os.EX_OK:
return gcc_ver_prefix + myoutput
import sys
import textwrap
import platform
+try:
+ from subprocess import getstatusoutput as subprocess_getstatusoutput
+except ImportError:
+ from commands import getstatusoutput as subprocess_getstatusoutput
import portage
from portage import os
from portage import _encodings
from portage import _unicode_decode
import _emerge.help
-import portage.xpak, commands, errno, re, time
+import portage.xpak, errno, re, time
from portage.output import colorize, xtermTitle, xtermTitleReset
from portage.output import create_color_func
good = create_color_func("GOOD")
raise
del e
processed_count += 1
- myso=commands.getstatusoutput("LANG=C LANGUAGE=C /usr/bin/install-info --dir-file="+inforoot+"/dir "+inforoot+"/"+x)[1]
+ myso=subprocess_getstatusoutput("LANG=C LANGUAGE=C /usr/bin/install-info --dir-file="+inforoot+"/dir "+inforoot+"/"+x)[1]
existsstr="already exists, for file `"
if myso!="":
if re.search(existsstr,myso):
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
@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.
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(
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 = {}
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
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():
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")
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)
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")
# 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 _
# 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
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
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
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
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):
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] == "*"):
"/".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.
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
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):
__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
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:
__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
'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
import stat
import string
import sys
+from io import StringIO
import portage
from portage import os
except ImportError:
import pickle
-try:
- from cStringIO import StringIO
-except ImportError:
- from StringIO import StringIO
-
noiselimit = 0
def initialize_logger(level=logging.WARN):
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')
]
import codecs
-import commands
import errno
import itertools
import logging
import sys
+try:
+ from subprocess import getstatusoutput as subprocess_getstatusoutput
+except ImportError:
+ from commands import getstatusoutput as subprocess_getstatusoutput
from xml.dom import minidom
from xml.dom import NotFoundErr
if vcs == 'cvs':
logging.info("Performing a " + output.green("cvs -n up") + \
" with a little magic grep to check for updates.")
- retval = commands.getstatusoutput("cvs -n up 2>&1 | " + \
+ retval = subprocess_getstatusoutput("cvs -n up 2>&1 | " + \
"egrep '^[^\?] .*' | " + \
"egrep -v '^. .*/digest-[^/]+|^cvs server: .* -- ignored$'")
if vcs == 'svn':
logging.info("Performing a " + output.green("svn status -u") + \
" with a little magic grep to check for updates.")
- retval = commands.getstatusoutput("svn status -u 2>&1 | " + \
+ retval = subprocess_getstatusoutput("svn status -u 2>&1 | " + \
"egrep -v '^. +.*/digest-[^/]+' | " + \
"head -n-1")