diff --git a/client/equo b/client/equo index 5c640796a..6885a0d75 100644 --- a/client/equo +++ b/client/equo @@ -22,6 +22,9 @@ from sys import exit, argv, path path.append('../libraries') +path.append('../client') +path.append('/usr/lib/entropy/client') +path.append('/usr/lib/entropy/libraries') from outputTools import * from entropyConstants import * diff --git a/client/equoTools.py b/client/equoTools.py index 23287d12d..f7efbcdad 100644 --- a/client/equoTools.py +++ b/client/equoTools.py @@ -21,6 +21,8 @@ ''' from sys import path, getfilesystemencoding +path.append('../libraries') +path.append('../client') path.append('/usr/lib/entropy/libraries') import os import shutil @@ -924,79 +926,109 @@ def removePackage(infoDict): # load CONFIG_PROTECT and its mask - client database at this point has been surely opened, so our dicts are already filled protect = etpConst['dbconfigprotect'] mask = etpConst['dbconfigprotectmask'] - - # merge data into system + + # remove files from system + directories = set() for file in content: - # collision check - if etpConst['collisionprotect'] > 0: - if file in contentCache: - print_warning(darkred(" ## ")+red("Collision found during remove for ")+file.encode(getfilesystemencoding())+" - cannot overwrite") - equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"Collision found during remove for "+file.encode(getfilesystemencoding())+" - cannot overwrite") - continue - try: - del contentCache[file] - except: - pass - file = file.encode(getfilesystemencoding()) - - protected = False - if (not infoDict['removeconfig']) and (not infoDict['diffremoval']): - try: - # -- CONFIGURATION FILE PROTECTION -- - if os.access(file,os.R_OK): - for x in protect: - if file.startswith(x): - protected = True - break - if (protected): - for x in mask: - if file.startswith(x): - protected = False - break - if (protected) and os.path.isfile(file): - protected = istextfile(file) - else: - protected = False # it's not a file - # -- CONFIGURATION FILE PROTECTION -- - except: - pass # some filenames are buggy encoded - - if (protected): - equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_VERBOSE,"[remove] Protecting config file: "+file) - print_warning(darkred(" ## ")+red("[remove] Protecting config file: ")+file) - else: + # collision check + if etpConst['collisionprotect'] > 0: + if file in contentCache: + print_warning(darkred(" ## ")+red("Collision found during remove for ")+file+red(" - cannot overwrite")) + equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"Collision found during remove for "+file+" - cannot overwrite") + content.remove(file) + continue try: - exist = os.lstat(file) + del contentCache[file] + except: + pass + + protected = False + if (not infoDict['removeconfig']) and (not infoDict['diffremoval']): + try: + # -- CONFIGURATION FILE PROTECTION -- + if os.access(file,os.R_OK): + for x in protect: + if file.startswith(x): + protected = True + break + if (protected): + for x in mask: + if file.startswith(x): + protected = False + break + if (protected) and os.path.isfile(file): + protected = istextfile(file) + else: + protected = False # it's not a file + # -- CONFIGURATION FILE PROTECTION -- + except: + pass # some filenames are buggy encoded + + if (protected): + equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_VERBOSE,"[remove] Protecting config file: "+file) + print_warning(darkred(" ## ")+red("[remove] Protecting config file: ")+file) + else: + try: + os.lstat(file) except OSError: continue # skip file, does not exist - if stat.S_ISDIR(exist.st_mode) and stat.S_ISLNK(exist.st_mode): + if os.path.isdir(file) and os.path.islink(file): # S_ISDIR returns False for directory symlinks, so using os.path.isdir # valid directory symlink - mylist = os.listdir(file) - if not mylist: - try: - os.remove(file) - except OSError: - pass - elif stat.S_ISDIR(exist.st_mode): + #print "symlink dir",file + directories.add((file,"link")) + elif os.path.isdir(file): # plain directory - mylist = os.listdir(file) - if not mylist: - try: - os.removedirs(file) - except OSError: - pass + #print "plain dir",file + directories.add((file,"dir")) else: # files, symlinks or not - # just a file or something like that + # just a file or symlink or broken directory symlink (remove now) try: + #print "plain file",file os.remove(file) - # is directory of the file now empty? - filedir = os.path.dirname(file) - dirlist = os.listdir(filedir) - if (not dirlist): - os.removedirs(filedir) + # add its parent directory + dirfile = os.path.dirname(file) + if os.path.isdir(dirfile) and os.path.islink(dirfile): + #print "symlink dir2",dirfile + directories.add((dirfile,"link")) + elif os.path.isdir(dirfile): + #print "plain dir2",dirfile + directories.add((dirfile,"dir")) except OSError: pass + + # now handle directories + directories = list(directories) + directories.reverse() + while 1: + taint = False + for directory in directories: + if directory[1] == "link": + try: + mylist = os.listdir(directory[0]) + if not mylist: + try: + os.remove(directory[0]) + taint = True + except OSError: + pass + except OSError: + pass + elif directory[1] == "dir": + try: + mylist = os.listdir(directory[0]) + if not mylist: + try: + os.rmdir(directory[0]) + taint = True + except OSError: + pass + except OSError: + pass + + if not taint: + break + return 0 diff --git a/client/uiTools.py b/client/uiTools.py index 5fd6b656e..01b69142d 100644 --- a/client/uiTools.py +++ b/client/uiTools.py @@ -804,7 +804,7 @@ def removePackages(packages = [], atomsdata = [], ask = False, pretend = False, if (lookForOrphanedPackages): choosenRemovalQueue = [] - print_info(red(" @@ ")+blue("Calculating removal dependencies, please wait...")) + print_info(red(" @@ ")+blue("Calculating...")) treeview = equoTools.generateDependsTree(plainRemovalQueue, deep = deep) treelength = len(treeview[0]) if treelength > 1: @@ -838,11 +838,9 @@ def removePackages(packages = [], atomsdata = [], ask = False, pretend = False, for x in choosenRemovalQueue: removalQueue.append(x) else: - print - + writechar("\n") if (ask): if (deps): - print rc = entropyTools.askquestion(" I am going to start the removal. Are you sure?") if rc == "No": clientDbconn.closeDB() diff --git a/libraries/entropyTools.py b/libraries/entropyTools.py index e78b32ae2..60a3ca5af 100644 --- a/libraries/entropyTools.py +++ b/libraries/entropyTools.py @@ -87,7 +87,7 @@ def getRandomNumber(): def countdown(secs=5,what="Counting...", back = False): if secs: if back: - stdout.write(what) + stdout.write(red(">> ")+what) else: print what for i in range(secs)[::-1]: diff --git a/libraries/reagentTools.py b/libraries/reagentTools.py index afff8a8ce..65e56ecee 100644 --- a/libraries/reagentTools.py +++ b/libraries/reagentTools.py @@ -185,7 +185,7 @@ def update(options): for x in toBeAdded: print_info(yellow(" # ")+red(x[0])) if reagentRequestAsk: - rc = askquestion(">> Would you like to packetize them now ?") + rc = askquestion(">> Would you like to package them now ?") if rc == "No": return 0