From 7c2fa4d826786bf0916770833f6d6abe2244b0c8 Mon Sep 17 00:00:00 2001 From: Fabian Groffen Date: Fri, 12 Jan 2007 23:25:41 +0000 Subject: [PATCH] Merged from trunk 5597:5620 Use startswith and endswith to simplify code. Fix typos from the previous commit. purge string module from emerge (WarnerBro) fix "" " " bug (WarnerBro) another annoy space bug (WarnerBro) purge string module from repoman (WarnerBro) purge string from portage.py, fix minor bug in portage_util (WarnerBro) Fix a typo. Fix a typo. Revert accidentally modified joins. Fix more typos. Fix another typo. Add a few pretty basic comments on writing code, particularly things that portage used to do (and still does) that are...a bit out of style ;) (WarnerBro) ignore py[co] in tests (WarnerBro) remove the last of the string module from portage.py (WarnerBro) svn path=/main/branches/prefix/; revision=5622 --- DEVELOPING | 71 +++++++++++++++++++++++++++++++++ bin/dispatch-conf | 2 +- bin/emerge | 26 ++++++------ bin/md5check.py | 8 +--- bin/repoman | 96 ++++++++++++++++++++++----------------------- pym/getbinpkg.py | 6 +-- pym/portage.py | 89 +++++++++++++++++++++-------------------- pym/portage_dep.py | 2 +- pym/portage_util.py | 4 +- 9 files changed, 185 insertions(+), 119 deletions(-) create mode 100644 DEVELOPING diff --git a/DEVELOPING b/DEVELOPING new file mode 100644 index 000000000..0530d99cf --- /dev/null +++ b/DEVELOPING @@ -0,0 +1,71 @@ +Code Guidelines +--------------- +A few code guidelines to try to stick to, please comment of none of these make +sense, they are pretty basic and mostly apply to old code. However for people +who are looking at current code, they make take up bad habits that exist in the +current codebase. + +Strings +------- +Try not to use the functions in the string module, they are deprecated. + +string.join(," ") + +should be replaced with: + +" ".join() + +and: + +string.split(string, delimeter) + +should be replaced with: + +string.split(delimeter) + +Nearly all other methods in string work on string objects and have similar calling +conventions. + +Comparisons +----------- + +if foo == None + +should be replaced with: + +if foo is not None: + +Is not does a reference comparison (address1 = address2 basically) and +the == forces a by value compare (with __eq__()) + +Dict Lookups +------------ + +Try not to use has_key, you can use + +if foo in dict + +instead of if dict.has_key(foo) + +Also don't do stuff like: + +if foo in dict and dict[foo]: + +Generally you can do two things here, if you are messing with defaults.. + +dict.get(foo, some_default) + +will try to retrieve foo from dict, if there is a KeyError, will insert foo +into dict with the value of some_default. This method is preferred in most cases. + +You can also do something like: + +try: + dict[foo] + ...stuff here.. +except KeyError: + print "holy cow we totally expected a keyerror here" + +in most instances however you are only catching the KeyError to set a default, +in which case you should be using dict.get() or telling the user they are missing +a required dict key. diff --git a/bin/dispatch-conf b/bin/dispatch-conf index eee066442..465385470 100755 --- a/bin/dispatch-conf +++ b/bin/dispatch-conf @@ -362,6 +362,6 @@ d = dispatch () if len(sys.argv) > 1: # for testing - d.grind ("".join( (sys.argv [1:])) + d.grind (" ".join(sys.argv[1:])) else: d.grind (portage.settings ['CONFIG_PROTECT']) diff --git a/bin/emerge b/bin/emerge index 5eec86e18..724ec6323 100755 --- a/bin/emerge +++ b/bin/emerge @@ -31,7 +31,7 @@ except ImportError: del os.environ["PORTAGE_LEGACY_GLOBALS"] from portage import digraph -import emergehelp, xpak, commands, errno, re, socket, string, time, types +import emergehelp, xpak, commands, errno, re, socket, time, types import output from output import blue, bold, colorize, darkblue, darkgreen, darkred, green, \ havecolor, nc_len, nocolor, red, teal, turquoise, white, xtermTitle, \ @@ -151,7 +151,7 @@ def userquery(prompt, responses=None, colours=None): print bold(prompt), try: while True: - response=raw_input("["+string.join([colours[i](responses[i]) for i in range(len(responses))],"/")+"] ") + response=raw_input("["+"/".join([colours[i](responses[i]) for i in range(len(responses))])+"] ") for key in responses: # An empty response will match the first value in responses. if response.upper()==key[:len(response)].upper(): @@ -353,9 +353,9 @@ def getportageversion(portdir, target_root, profile, chost, vardb): for x in libclist: xs=portage.catpkgsplit(x) if libcver: - libcver+=","+string.join(xs[1:], "-") + libcver+=","+"-".join(xs[1:]) else: - libcver=string.join(xs[1:], "-") + libcver="-".join(xs[1:]) if libcver==[]: libcver="unavailable" @@ -586,7 +586,7 @@ def getlist(settings, mode): raise mynewlines=[] for x in mylines: - myline=string.join(string.split(x)) + myline=" ".join(x.split()) if not len(myline): continue elif myline[0]=="#": @@ -1675,7 +1675,7 @@ class depgraph: for p in alleb: mreasons = portage.getmaskingstatus(p, settings=pkgsettings, portdb=portdb) - print "- "+p+" (masked by: "+string.join(mreasons, ", ")+")" + print "- "+p+" (masked by: "+", ".join(mreasons)+")" comment = portage.getmaskingreason(p, settings=pkgsettings, portdb=portdb) if comment and comment != oldcomment: @@ -3415,7 +3415,7 @@ def unmerge(settings, myopts, vartree, unmerge_action, unmerge_files, for y in pkgmap[x]["selected"]: print ">>> Unmerging "+y+"..." emergelog(xterm_titles, "=== Unmerging... ("+y+")") - mysplit=string.split(y,"/") + mysplit=y.split("/") #unmerge... retval = portage.unmerge(mysplit[0], mysplit[1], settings["ROOT"], mysettings, unmerge_action not in ["clean","prune"], @@ -3616,7 +3616,7 @@ def action_sync(settings, trees, mtimedb, myopts, myaction): if not os.path.exists(myportdir): print ">>>",myportdir,"not found, creating it." os.makedirs(myportdir,0755) - syncuri=string.rstrip(settings["SYNC"]) + syncuri=settings["SYNC"].rstrip() os.umask(0022) updatecache_flg = False if myaction == "metadata": @@ -4232,7 +4232,7 @@ def action_info(settings, trees, myopts, myfiles): output=commands.getstatusoutput("distcc --version") if not output[0]: - print str(string.split(output[1],"\n",1)[0]), + print str(output[1].split("\n",1)[0]), if "distcc" in settings.features: print "[enabled]" else: @@ -4240,7 +4240,7 @@ def action_info(settings, trees, myopts, myfiles): output=commands.getstatusoutput("ccache -V") if not output[0]: - print str(string.split(output[1],"\n",1)[0]), + print str(output[1].split("\n",1)[0]), if "ccache" in settings.features: print "[enabled]" else: @@ -4268,7 +4268,7 @@ def action_info(settings, trees, myopts, myfiles): else: print "%-20s %s" % (x+":", "[NOT VALID]") - libtool_vers = string.join(trees["/"]["vartree"].dbapi.match("sys-devel/libtool"), ",") + libtool_vers = ",".join(trees["/"]["vartree"].dbapi.match("sys-devel/libtool")) if "--verbose" in myopts: myvars=settings.keys() @@ -5233,11 +5233,11 @@ def emerge_main(): time.strftime("%b %d, %Y %H:%M:%S", time.localtime())) myelogstr="" if myopts: - myelogstr=string.join(myopts, " ") + myelogstr=" ".join(myopts) if myaction: myelogstr+=" "+myaction if myfiles: - myelogstr+=" "+string.join(myfiles, " ") + myelogstr+=" "+" ".join(myfiles) emergelog(xterm_titles, " *** emerge " + myelogstr) def emergeexitsig(signum, frame): diff --git a/bin/md5check.py b/bin/md5check.py index 220ef8308..b67bf864b 100755 --- a/bin/md5check.py +++ b/bin/md5check.py @@ -10,11 +10,7 @@ try: except ImportError: sys.path.insert(0, "@PORTAGE_BASE@/pym") import portage -from threading import * -from output import red,green,blue,bold -from random import shuffle -from time import sleep - +import portage_util def cstrip(mystr,mychars): newstr = "" @@ -80,7 +76,7 @@ for mycpv in hugelist: # This associates teh md5 with each file. [md5/size] md5joins = md5_list[mybn][2].split(",") - md5joins = " ["+md5_list[mybn][0]+"/"+md5_list[mybn][1]+"],".join(md5joins)) + md5joins = (" ["+md5_list[mybn][0]+"/"+md5_list[mybn][1]+"],").join(md5joins) md5joins += " ["+md5_list[mybn][0]+"/"+md5_list[mybn][1]+"]" portage.writemsg("Colliding md5: %s of %s [%s/%s] and %s\n" % (mybn,mycpv,md5sums[mybn][0],md5sums[mybn][1],md5joins)) diff --git a/bin/repoman b/bin/repoman index c2d6437bd..e9e496853 100755 --- a/bin/repoman +++ b/bin/repoman @@ -20,7 +20,7 @@ map(allowed_filename_chars_set.setdefault, map(chr, range(ord('A'), ord('Z')+1)) map(allowed_filename_chars_set.setdefault, map(chr, range(ord('0'), ord('9')+1))) map(allowed_filename_chars_set.setdefault, map(chr, map(ord, [".", "-", "_", "+", ":"]))) -import string,signal,re,pickle,tempfile +import signal,re,pickle,tempfile os.environ["PORTAGE_LEGACY_GLOBALS"] = "false" try: @@ -271,22 +271,22 @@ def help(exitstatus=1,helpfulness=1): print "|",turquoise(x), print print - print " "+green(string.ljust("Options",20)+" Description") + print " "+green("Options".ljust(20)+" Description") for x in options: if repoman_shortoptions_rev.has_key(x): shopt=repoman_shortoptions_rev[x]+", "+x else: shopt=" "+x - print " "+string.ljust(shopt,20),repoman_options[x] + print " "+shopt.ljust(20),repoman_options[x] print - print " "+green(string.ljust("Modes",20)+" Description") + print " "+green("Modes".ljust(20)+" Description") for x in modes: - print " "+string.ljust(x,20),modeshelp[x] + print " "+x.ljust(20),modeshelp[x] if helpfulness: print - print " "+green(string.ljust("QA keyword",20)+" Description") + print " "+green("QA keyword".ljust(20)+" Description") for x in qacats: - print " "+string.ljust(x,20),qahelp[x] + print " "+x.ljust(20),qahelp[x] print if (exitstatus != -1): sys.exit(exitstatus) @@ -327,7 +327,7 @@ def last(): else: if mymode!="lfull": continue - print " "+string.ljust(x,20), + print " "+ x.ljust(20), if stats[x]==0: print green(`stats[x]`) continue @@ -552,9 +552,9 @@ if not myreporoot: myreporoot += mydir[len(portdir_overlay):-1] if isSvn: - reposplit=string.split(myreporoot,"/") + reposplit=myreporoot.split("/") else: - reposplit=string.split(myreporoot,"/") + reposplit=myreporoot.split("/") repolevel=len(reposplit) # check if it's in $PORTDIR/$CATEGORY/$PN , otherwise bail if commiting. @@ -565,7 +565,7 @@ if mymode == "commit" and repolevel not in [1,2,3]: print red("***")+" Attempting to commit from a packages files directory will be blocked for instance." print red("***")+" This is intended behaviour, to ensure the manifest is recommited for a package." print red("***") - err("Unable to identify level we're commiting from for %s" % string.join(reposplit,'/')) + err("Unable to identify level we're commiting from for %s" % '/'.join(reposplit)) startdir=os.getcwd() @@ -628,11 +628,11 @@ uselist=[] try: uselist=portage.grabfile(portdir+"/profiles/use.desc") for l in range(0,len(uselist)): - uselist[l]=string.split(uselist[l])[0] - for var in string.split(repoman_settings["USE_EXPAND"]): + uselist[l]=uselist[l].split()[0] + for var in repoman_settings["USE_EXPAND"].split(): vardescs = portage.grabfile(portdir+"/profiles/desc/"+var.lower()+".desc") for l in range(0, len(vardescs)): - uselist.append(var.lower() + "_" + string.split(vardescs[l])[0]) + uselist.append(var.lower() + "_" + vardescs[l].split()[0]) except SystemExit, e: raise # Need to propogate this except: @@ -687,7 +687,7 @@ if os.path.exists(descfile): for x in portage.grabfile(descfile): if x[0]=="#": continue - arch=string.split(x) + arch=x.split() if len(arch)!=3: print "wrong format: \""+red(x)+"\" in "+descfile continue @@ -1195,7 +1195,7 @@ for x in scanlist: for mytype in ("DEPEND", "RDEPEND", "PDEPEND", "LICENSE", "PROVIDE"): mydepstr = myaux[mytype] - if (string.find(mydepstr, " ?") != -1): + if mydepstr.find(" ?") != -1: badsyntax.append("'?' preceded by space") try: @@ -1503,7 +1503,7 @@ dowarn=0 #dofull will be set if we should print a "repoman full" informational message dofull=0 for x in qacats: - if not isCvs and not isSvn and (string.find(x, "notadded") != -1): + if not isCvs and not isSvn and (x.find("notadded") != -1): stats[x] = 0 if stats[x]: dowarn=1 @@ -1511,7 +1511,7 @@ for x in qacats: dofail=1 else: continue - print " "+string.ljust(x,30), + print " "+x.ljust(30), if stats[x]==0: print green(`stats[x]`) continue @@ -1536,13 +1536,13 @@ def grouplist(mylist,seperator="/"): To: {"blah":["foo","weee/splat"], "spork":["spatula"]}""" mygroups={} for x in mylist: - xs=string.split(x,seperator) + xs=x.split(seperator) if xs[0]==".": xs=xs[1:] if xs[0] not in mygroups.keys(): - mygroups[xs[0]]=[string.join(xs[1:],seperator)] + mygroups[xs[0]]=[seperator.join(xs[1:])] else: - mygroups[xs[0]]+=[string.join(xs[1:],seperator)] + mygroups[xs[0]]+=[seperator.join(xs[1:])] return mygroups if mymode!="commit": @@ -1571,9 +1571,9 @@ else: if fails["digest.missing"]: print green("Creating missing digests...") for x in fails["digest.missing"]: - xs=string.split(x,"/") + xs=x.split("/") del xs[-2] - myeb=string.join(xs[:-1],"/")+"/"+xs[-1][7:] + myeb="/".join(xs[:-1])+"/"+xs[-1][7:] if "--pretend" in myoptions: print "(ebuild "+portdir+"/"+myeb+".ebuild digest)" else: @@ -1602,7 +1602,7 @@ else: myautoadd=[] if myunadded: for x in range(len(myunadded)-1,-1,-1): - xs=string.split(myunadded[x],"/") + xs=myunadded[x].split("/") if xs[-1]=="files": print "!!! files dir is not added! Please correct this." sys.exit(-1) @@ -1613,7 +1613,7 @@ else: elif len(xs[-1])>=7: if xs[-1][:7]=="digest-": del xs[-2] - myeb=string.join(xs[:-1]+[xs[-1][7:]],"/")+".ebuild" + myeb="/".join(xs[:-1]+[xs[-1][7:]])+".ebuild" if os.path.exists(myeb): # Ebuild exists for digest... So autoadd it. myautoadd+=[myunadded[x]] @@ -1623,15 +1623,15 @@ else: print ">>> Auto-Adding missing digests..." if "--pretend" in myoptions: if isCvs: - print "(cvs add "+string.join(myautoadd)+")" + print "(cvs add "+" ".join(myautoadd)+")" if isSvn: - print "(svn add "+string.join(myautoadd)+")" + print "(svn add "+" ".join(myautoadd)+")" retval=0 else: if isCvs: - retval=os.system("cvs add "+string.join(myautoadd)) + retval=os.system("cvs add "+" ".join(myautoadd)) if isSvn: - retval=os.system("svn add "+string.join(myautoadd)) + retval=os.system("svn add "+" ".join(myautoadd)) if retval: print "!!! Exiting on vcs (shell) error code:",retval sys.exit(retval) @@ -1653,7 +1653,7 @@ else: print "Performing a "+green("svn update -u")+" with a little magic grep to check for updates." retval=getstatusoutput(portage_const.EPREFIX+"/usr/bin/svn status -u 2>&1 | "+portage_const.EPREFIX+"/bin/egrep -v '^. +.*/digest-[^/]+' | "+portage_const.EPREFIX+"/bin/egrep -v '^Status against revision:'") - mylines=string.split(retval[1], "\n") + mylines=retval[1].split("\n") myupdates=[] for x in mylines: if not x: @@ -1675,13 +1675,13 @@ else: if myupdates: print green("Fetching trivial updates...") if "--pretend" in myoptions: - print "(cvs/svn up "+string.join(myupdates)+")" + print "(cvs/svn up "+" ".join(myupdates)+")" retval=0 else: if isCvs: - retval=os.system("cvs up "+string.join(myupdates)) + retval=os.system("cvs up "+" ".join(myupdates)) elif isSvn: - retval=os.system("svn update "+string.join(myupdates)) + retval=os.system("svn update "+" ".join(myupdates)) if retval!=0: print "!!! cvs/svn exited with an error. Terminating." sys.exit(retval) @@ -1778,18 +1778,18 @@ else: retval = None if "--pretend" in myoptions: if isCvs: - print "(cvs -q commit -F "+commitmessagefile+")" + print "(cvs -q commit -F "+commitmessagefile +" "+ " ".join(myupdates)+")" if isSvn: - print "(svn commit -F "+commitmessagefile+")" + print "(svn commit -F "+commitmessagefile +" "+ " ".join(myupdates)+")" retval=0 else: if isCvs: - retval=os.system("cvs -q commit -F "+commitmessagefile) + retval=os.system("cvs -q commit -F "+commitmessagefile + " " +" ".join(myupdates)) if isSvn: - retval=os.system("svn commit -F "+commitmessagefile) - if retval: - print "!!! Exiting on vcs (shell) error code:",retval - sys.exit(retval) + retval=os.system("svn commit -F "+commitmessagefile + " " +" ".join(myupdates)) + if retval: + print "!!! Exiting on vcs (shell) error code:",retval + sys.exit(retval) # Setup the GPG commands def gpgsign(filename): @@ -1836,7 +1836,7 @@ else: myportdb=portdb) elif repolevel==2: # In a category dir for x in myfiles: - xs=string.split(x,"/") + xs=x.split("/") if xs[0]==".": xs=xs[1:] if xs[0] in mydone: @@ -1848,12 +1848,12 @@ else: elif repolevel==1: # repo-cvsroot print green("RepoMan sez:"), "\"You're rather crazy... doing the entire repository.\"\n" for x in myfiles: - xs=string.split(x,"/") + xs=x.split("/") if xs[0]==".": xs=xs[1:] - if string.join(xs[:2],"/") in mydone: + if "/".join(xs[:2]) in mydone: continue - mydone.append(string.join(xs[:2],"/")) + mydone.append("/".join(xs[:2])) repoman_settings["O"]=os.path.join(os.getcwd(), x[0], x[1]) portage.digestgen([], repoman_settings, manifestonly=1, myportdb=portdb) @@ -1887,7 +1887,7 @@ else: elif repolevel==2: # In a category dir mydone=[] for x in myfiles: - xs=string.split(x,"/") + xs=x.split("/") if xs[0]==".": xs=xs[1:] if xs[0] in mydone: @@ -1899,12 +1899,12 @@ else: print green("RepoMan sez:"), "\"You're rather crazy... doing the entire repository.\"\n" mydone=[] for x in myfiles: - xs=string.split(x,"/") + xs=x.split("/") if xs[0]==".": xs=xs[1:] - if string.join(xs[:2],"/") in mydone: + if "/".join(xs[:2]) in mydone: continue - mydone.append(string.join(xs[:2],"/")) + mydone.append("/".join(xs[:2])) repoman_settings["O"] = os.path.join(".", xs[0], xs[1]) gpgsign(os.path.join(repoman_settings["O"], "Manifest")) except portage_exception.PortageException, e: diff --git a/pym/getbinpkg.py b/pym/getbinpkg.py index f8da11c4b..be73a91b0 100644 --- a/pym/getbinpkg.py +++ b/pym/getbinpkg.py @@ -6,7 +6,7 @@ if not hasattr(__builtins__, "set"): from sets import Set as set -from output import * +from output import red, yellow, green import htmllib,HTMLParser,formatter,sys,os,xpak,time,tempfile,base64,urllib2 from portage_const import CACHE_PATH @@ -51,7 +51,7 @@ class ParseLinks(HTMLParser.HTMLParser): def get_anchors_by_prefix(self,prefix): newlist = [] for x in self.PL_anchors: - if (len(x) >= len(prefix)) and (x[:len(suffix)] == prefix): + if x.startswith(prefix): if x not in newlist: newlist.append(x[:]) return newlist @@ -59,7 +59,7 @@ class ParseLinks(HTMLParser.HTMLParser): def get_anchors_by_suffix(self,suffix): newlist = [] for x in self.PL_anchors: - if (len(x) >= len(suffix)) and (x[-len(suffix):] == suffix): + if x.endswith(suffix): if x not in newlist: newlist.append(x[:]) return newlist diff --git a/pym/portage.py b/pym/portage.py index 4246798d9..432191aed 100644 --- a/pym/portage.py +++ b/pym/portage.py @@ -17,7 +17,7 @@ except ImportError: raise try: - import copy, errno, os, re, shutil, string, time, types + import copy, errno, os, re, shutil, time, types try: import cPickle except ImportError: @@ -130,7 +130,7 @@ except ImportError: def load_mod(name): - modname = string.join(string.split(name,".")[:-1],".") + modname = ".".join(name.split(".")[:-1]) mod = __import__(modname) components = name.split('.') for comp in components[1:]: @@ -789,15 +789,15 @@ def ExtractKernelVersion(base_dir): except IOError, details: return (None, str(details)) - lines = map(string.strip, lines) + lines = [l.strip() for l in lines] version = '' #XXX: The following code relies on the ordering of vars within the Makefile for line in lines: # split on the '=' then remove annoying whitespace - items = string.split(line, '=') - items = map(string.strip, items) + items = line.split("=") + items = [i.strip() for i in items] if items[0] == 'VERSION' or \ items[0] == 'PATCHLEVEL': version += items[1] @@ -817,12 +817,12 @@ def ExtractKernelVersion(base_dir): # Append the contents of each to the version string, stripping ALL whitespace for lv in localversions: - version += string.join(string.split(string.join(grabfile(base_dir+"/"+lv))), "") + version += "".join( " ".join( grabfile( base_dir+ "/" + lv ) ).split() ) # Check the .config for a CONFIG_LOCALVERSION and append that too, also stripping whitespace kernelconfig = getconfig(base_dir+"/.config") if kernelconfig and kernelconfig.has_key("CONFIG_LOCALVERSION"): - version += string.join(string.split(kernelconfig["CONFIG_LOCALVERSION"]), "") + version += "".join(kernelconfig["CONFIG_LOCALVERSION"].split()) return (version,None) @@ -1932,7 +1932,7 @@ class config: if self.configdict["defaults"]["ARCH"] not in usesplit: usesplit.insert(0,self.configdict["defaults"]["ARCH"]) - self.configlist[-1]["USE"]=string.join(usesplit," ") + self.configlist[-1]["USE"]= " ".join(usesplit) self.already_in_regenerate = 0 @@ -2170,8 +2170,8 @@ def spawn(mystring, mysettings, debug=0, free=0, droppriv=0, sesandbox=0, **keyw features = mysettings.features # XXX: Negative RESTRICT word droppriv=(droppriv and ("userpriv" in features) and not \ - (("nouserpriv" in string.split(mysettings["RESTRICT"])) or \ - ("userpriv" in string.split(mysettings["RESTRICT"])))) + (("nouserpriv" in mysettings["RESTRICT"].split()) or \ + ("userpriv" in mysettings["RESTRICT"].split()))) if droppriv and not uid and portage_gid and portage_uid: keywords.update({"uid":portage_uid,"gid":portage_gid,"groups":userpriv_groups,"umask":002}) @@ -2189,7 +2189,7 @@ def spawn(mystring, mysettings, debug=0, free=0, droppriv=0, sesandbox=0, **keyw if sesandbox: con = selinux.getcontext() - con = string.replace(con, mysettings["PORTAGE_T"], mysettings["PORTAGE_SANDBOX_T"]) + con = con.replace(mysettings["PORTAGE_T"], mysettings["PORTAGE_SANDBOX_T"]) selinux.setexec(con) retval = spawn_func(mystring, env=env, **keywords) @@ -2460,8 +2460,8 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0, locks_in_subdir=".locks", else: resumecommand=mysettings["RESUMECOMMAND"] - fetchcommand=string.replace(fetchcommand,"${DISTDIR}",mysettings["DISTDIR"]) - resumecommand=string.replace(resumecommand,"${DISTDIR}",mysettings["DISTDIR"]) + fetchcommand=fetchcommand.replace("${DISTDIR}",mysettings["DISTDIR"]) + resumecommand=resumecommand.replace("${DISTDIR}",mysettings["DISTDIR"]) if not can_fetch: if fetched != 2: @@ -2492,8 +2492,8 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0, locks_in_subdir=".locks", locfetch=fetchcommand writemsg_stdout(">>> Downloading '%s'\n" % \ re.sub(r'//(.+):.+@(.+)/',r'//\1:*password*@\2/', loc)) - myfetch=string.replace(locfetch,"${URI}",loc) - myfetch=string.replace(myfetch,"${FILE}",myfile) + myfetch=locfetch.replace("${URI}",loc) + myfetch=myfetch.replace("${FILE}",myfile) spawn_keywords = {} if "userfetch" in mysettings.features and \ @@ -2508,7 +2508,7 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0, locks_in_subdir=".locks", if mysettings.selinux_enabled(): con = selinux.getcontext() - con = string.replace(con, mysettings["PORTAGE_T"], mysettings["PORTAGE_FETCH_T"]) + con = con.replace(mysettings["PORTAGE_T"], mysettings["PORTAGE_FETCH_T"]) selinux.setexec(con) myret = portage_exec.spawn_bash(myfetch, @@ -2910,7 +2910,7 @@ def doebuild_environment(myebuild, mydo, myroot, mysettings, debug, use_cache, m mysettings["ECLASSDIR"] = os.path.join(mysettings["PORTDIR"], "eclass") mysettings["SANDBOX_LOG"] = mycpv.replace(os.path.sep, "_-_") - mysettings["PROFILE_PATHS"] = string.join(mysettings.profiles,"\n")+"\n"+CUSTOM_PROFILE_PATH + mysettings["PROFILE_PATHS"] = "\n".join(mysettings.profiles)+"\n"+CUSTOM_PROFILE_PATH mysettings["P"] = mysplit[0]+"-"+mysplit[1] mysettings["PN"] = mysplit[0] mysettings["PV"] = mysplit[1] @@ -2935,7 +2935,7 @@ def doebuild_environment(myebuild, mydo, myroot, mysettings, debug, use_cache, m mysettings["PVR"]=mysplit[1]+"-"+mysplit[2] if mysettings.has_key("PATH"): - mysplit=string.split(mysettings["PATH"],":") + mysplit=mysettings["PATH"].split(":") else: mysplit=[] if PORTAGE_BIN_PATH not in mysplit: @@ -3258,7 +3258,7 @@ def doebuild(myebuild, mydo, myroot, mysettings, debug=0, listonly=0, for vcount in range(len(validcommands)): if vcount%6 == 0: writemsg("\n!!! ", noiselevel=-1) - writemsg(string.ljust(validcommands[vcount], 11), noiselevel=-1) + writemsg(validcommands[vcount].ljust(11), noiselevel=-1) writemsg("\n", noiselevel=-1) return 1 @@ -4146,7 +4146,7 @@ def dep_check(depstring, mydbapi, mysettings, use="yes", mode=None, myuse=None, if use=="yes": if myuse is None: #default behavior - myusesplit = string.split(mysettings["USE"]) + myusesplit = mysettings["USE"].split() else: myusesplit = myuse # We've been given useflags to use. @@ -4551,7 +4551,7 @@ class portagetree: "returns file location for this particular package (DEPRECATED)" if not pkgname: return "" - mysplit=string.split(pkgname,"/") + mysplit=pkgname.split("/") psplit=pkgsplit(mysplit[1]) return self.portroot+"/"+mysplit[0]+"/"+psplit[0]+"/"+mysplit[1]+".ebuild" @@ -4747,7 +4747,7 @@ class bindbapi(fakedbapi): if aux_cache is not None: return [aux_cache[x] for x in wants] cache_me = True - mysplit = string.split(mycpv,"/") + mysplit = mycpv.split("/") mylist = [] tbz2name = mysplit[1]+".tbz2" if self.bintree and not self.bintree.isremote(mycpv): @@ -5318,7 +5318,7 @@ class vartree(object): for myprovide in mylines: mys = catpkgsplit(myprovide) if not mys: - mys = string.split(myprovide, "/") + mys = myprovide.split("/") myprovides += [mys[0] + "/" + mys[1]] return myprovides except SystemExit, e: @@ -5575,9 +5575,8 @@ class portdbapi(dbapi): mydig = self.findname2(mycpv)[0] if not mydig: return "" - mydigs = string.split(mydig, "/")[:-1] - mydig = string.join(mydigs, "/") - + mydigs = mydig.split("/")[:-1] + mydig = "/".join(mydigs) mysplit = mycpv.split("/") except OSError: return "" @@ -5622,7 +5621,7 @@ class portdbapi(dbapi): return [aux_cache[x] for x in mylist] cache_me = True global auxdbkeys,auxdbkeylen - cat,pkg = string.split(mycpv, "/", 1) + cat,pkg = mycpv.split("/", 1) myebuild, mylocation = self.findname2(mycpv, mytree) @@ -5632,7 +5631,7 @@ class portdbapi(dbapi): writemsg("!!! %s\n" % myebuild, noiselevel=1) raise KeyError(mycpv) - myManifestPath = string.join(myebuild.split("/")[:-1],"/")+"/Manifest" + myManifestPath = "/".join(myebuild.split("/")[:-1])+"/Manifest" if "gpg" in self.mysettings.features: try: mys = portage_gpg.fileStats(myManifestPath) @@ -5757,7 +5756,7 @@ class portdbapi(dbapi): sys.exit(1) if useflags is None: - useflags = string.split(mysettings["USE"]) + useflags = mysettings["USE"].split() myurilist = portage_dep.paren_reduce(myuris) myurilist = portage_dep.use_reduce(myurilist,uselist=useflags,matchall=all) @@ -6402,7 +6401,7 @@ class binarytree(object): noiselevel=-1) del self.remotepkgs[mypkg] continue - mycat=string.strip(self.remotepkgs[mypkg]["CATEGORY"]) + mycat=self.remotepkgs[mypkg]["CATEGORY"].strip() fullpkg=mycat+"/"+mypkg[:-5] mykey=dep_getkey(fullpkg) try: @@ -6465,21 +6464,21 @@ class binarytree(object): def isremote(self,pkgname): "Returns true if the package is kept remotely." - mysplit=string.split(pkgname,"/") + mysplit=pkgname.split("/") remote = (not os.path.exists(self.getname(pkgname))) and self.remotepkgs.has_key(mysplit[1]+".tbz2") return remote def get_use(self,pkgname): - mysplit=string.split(pkgname,"/") + mysplit=pkgname.split("/") if self.isremote(pkgname): - return string.split(self.remotepkgs[mysplit[1]+".tbz2"]["USE"][:]) + return self.remotepkgs[mysplit[1]+".tbz2"]["USE"][:].split() tbz2=xpak.tbz2(self.getname(pkgname)) - return string.split(tbz2.getfile("USE")) + return tbz2.getfile("USE").split() def gettbz2(self,pkgname): "fetches the package from a remote site, if necessary." print "Fetching '"+str(pkgname)+"'" - mysplit = string.split(pkgname,"/") + mysplit = pkgname.split("/") tbz2name = mysplit[1]+".tbz2" if not self.isremote(pkgname): if (tbz2name not in self.invalids): @@ -6634,7 +6633,7 @@ class dblink: myc.close() pos=1 for line in mylines: - mydat = string.split(line) + mydat = line.split() # we do this so we can remove from non-root filesystems # (use the ROOT var to allow maintenance on other partitions) try: @@ -6642,10 +6641,10 @@ class dblink: self.myroot, mydat[1].lstrip(os.path.sep))) if mydat[0]=="obj": #format: type, mtime, md5sum - pkgfiles[string.join(mydat[1:-2]," ")]=[mydat[0], mydat[-1], mydat[-2]] + pkgfiles[" ".join(mydat[1:-2])]=[mydat[0], mydat[-1], mydat[-2]] elif mydat[0]=="dir": #format: type - pkgfiles[string.join(mydat[1:])]=[mydat[0] ] + pkgfiles[" ".join(mydat[1:])]=[mydat[0] ] elif mydat[0]=="sym": #format: type, mtime, dest x=len(mydat)-1 @@ -6661,13 +6660,13 @@ class dblink: x=x-1 if splitter==-1: return None - pkgfiles[string.join(mydat[1:splitter]," ")]=[mydat[0], mydat[-1], string.join(mydat[(splitter+1):-1]," ")] + pkgfiles[" ".join(mydat[1:splitter])]=[mydat[0], mydat[-1], " ".join(mydat[(splitter+1):-1])] elif mydat[0]=="dev": #format: type - pkgfiles[string.join(mydat[1:]," ")]=[mydat[0] ] + pkgfiles[" ".join(mydat[1:])]=[mydat[0] ] elif mydat[0]=="fif": #format: type - pkgfiles[string.join(mydat[1:]," ")]=[mydat[0]] + pkgfiles[" ".join(mydat[1:])]=[mydat[0]] else: return None except (KeyError,IndexError): @@ -6876,7 +6875,7 @@ class dblink: # string.lower is needed because db entries used to be in upper-case. The # string.lower allows for backwards compatibility. - if mymd5 != string.lower(pkgfiles[objkey][2]): + if mymd5 != pkgfiles[objkey][2].lower(): writemsg_stdout("--- !md5 %s %s\n" % ("obj", obj)) continue try: @@ -7612,9 +7611,9 @@ class dblink: if not os.path.exists(self.dbdir+"/"+name): return "" myfile=open(self.dbdir+"/"+name,"r") - mydata=string.split(myfile.read()) + mydata=myfile.read().split() myfile.close() - return string.join(mydata," ") + return " ".join(mydata) def copyfile(self,fname): shutil.copyfile(fname,self.dbdir+"/"+os.path.basename(fname)) @@ -7637,7 +7636,7 @@ class dblink: mylines=myelement.readlines() myreturn=[] for x in mylines: - for y in string.split(x[:-1]): + for y in x[:-1].split(): myreturn.append(y) myelement.close() return myreturn diff --git a/pym/portage_dep.py b/pym/portage_dep.py index 8abacfe3f..0b9e512f8 100644 --- a/pym/portage_dep.py +++ b/pym/portage_dep.py @@ -180,7 +180,7 @@ def use_reduce(deparray, uselist=[], masklist=[], matchall=0, excludeall=[]): sys.stderr.write("Note: Nested use flags without parenthesis (Deprecated)\n") warned = 1 if warned: - sys.stderr.write(" --> "+"".join(map(str,[head]+newdeparray))+"\n") + sys.stderr.write(" --> "+" ".join(map(str,[head]+newdeparray))+"\n") # Check that each flag matches ismatch = True diff --git a/pym/portage_util.py b/pym/portage_util.py index 79724b51a..591cd6f8f 100644 --- a/pym/portage_util.py +++ b/pym/portage_util.py @@ -47,7 +47,7 @@ def grabfile(myfilename, compat_level=0, recursive=0): for x in mylines: #the split/join thing removes leading and trailing whitespace, and converts any whitespace in the line #into single spaces. - myline="".join(x.split()) + myline=" ".join(x.split()) if not len(myline): continue if myline[0]=="#": @@ -154,7 +154,7 @@ def stack_dicts(dicts, incremental=0, incrementals=[], ignore_none=0): final_dict[y] += " "+mydict[y][:] else: final_dict[y] = mydict[y][:] - mydict[y] = "".join(mydict[y].split()) # Remove extra spaces. + mydict[y] = " ".join(mydict[y].split()) # Remove extra spaces. return final_dict def stack_lists(lists, incremental=1): -- 2.26.2