From 97886f8f8bcd173bc8967d5991d80548c8beb2c7 Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@cd1c1023-2f26-0410-ae45-c471fc1f0318> Date: Mon, 5 Nov 2007 14:48:29 +0000 Subject: [PATCH] more bugfixes git-svn-id: http://svn.sabayonlinux.org/projects/entropy/trunk@615 cd1c1023-2f26-0410-ae45-c471fc1f0318 --- client/confTools.py | 4 +- client/equo | 2 +- client/equoTools.py | 126 +++++++++++++++----------------------- client/triggerTools.py | 81 ++++++++++++++---------- libraries/portageTools.py | 75 +++++++++++++++++++---- 5 files changed, 161 insertions(+), 127 deletions(-) diff --git a/client/confTools.py b/client/confTools.py index fc7e065fc..b30773894 100644 --- a/client/confTools.py +++ b/client/confTools.py @@ -104,7 +104,7 @@ def update(): if not os.path.isfile(scandata[key]['source']): scandata = removefromcache(scandata,key) continue - print_info(darkred("Configuration file: ")+darkgreen(scandata[key]['source'])) + print_info(darkred("Configuration file: ")+darkgreen(scandata[key]['destination'])) if cmd == -3: rc = entropyTools.askquestion(">> Overwrite ?") if rc == "No": @@ -121,7 +121,7 @@ def update(): if not os.path.isfile(scandata[key]['source']): scandata = removefromcache(scandata,key) continue - print_info(darkred("Configuration file: ")+darkgreen(scandata[key]['source'])) + print_info(darkred("Configuration file: ")+darkgreen(scandata[key]['destination'])) if cmd == -7: rc = entropyTools.askquestion(">> Discard ?") if rc == "No": diff --git a/client/equo b/client/equo index 819029ca2..fa7dd758b 100644 --- a/client/equo +++ b/client/equo @@ -199,7 +199,7 @@ try: except SystemExit: pass except KeyboardInterrupt: - pass + sys.exit(0) #except Timeout: # pass except: diff --git a/client/equoTools.py b/client/equoTools.py index 9b45ec51b..f42aa13a5 100644 --- a/client/equoTools.py +++ b/client/equoTools.py @@ -870,65 +870,6 @@ def getRequiredPackages(foundAtoms, emptydeps = False, deepdeps = False, spinnin deptree = {} depcount = -1 - # order foundAtoms - ''' - if len(foundAtoms) > 1: - foundAtoms = list(foundAtoms) - rc = False - - testCache = {} - - while not rc: - swap = False - for x in range(len(foundAtoms)): - pkgA = foundAtoms[x] - try: - pkgB = foundAtoms[x+1] - except: - continue - - cached = testCache.get((pkgA,pkgB)) - if cached: - print "cached" - y,z = cached['result'] - if pkgA != y: - foundAtoms[x] = y - foundAtoms[x+1] = z - swap = True - continue - - - testCache[(pkgA,pkgB)] = {} - odbconn = openRepositoryDatabase(pkgA[1]) - odeps = generateDependencyTree(pkgA, emptydeps = True) - # FIXME: remove conflict ignorance - if odeps[1] != 0: - continue - odeps[0][0] = [] # reset conflicts - for odep in odeps[0]: - br = False - #print odeps[0][0] - dlist = odeps[0][odep] - #print dlist - for y in dlist: - #print y - if y == pkgB: - print str(y)+" reverse -> "+str(pkgA) - foundAtoms[x] = pkgB - foundAtoms[x+1] = pkgA - swap = True - br = True - break - if br: break - if br: break - testCache[(pkgA,pkgB)]['result'] = (foundAtoms[x],foundAtoms[x+1]) - - - odbconn.closeDB() - if (not swap): - rc = True - ''' - if spinning: atomlen = len(foundAtoms); count = 0 for atomInfo in foundAtoms: if spinning: count += 1; print_info(":: "+str(round((float(count)/atomlen)*100,1))+"% ::", back = True) @@ -1304,7 +1245,6 @@ def removePackage(infoDict): except: #print "debug: the dir wasn't empty? -> "+str(file) pass - return 0 @@ -1525,7 +1465,7 @@ def removePackageFromGentooDatabase(atom): _portage_avail = True except: return -1 # no Portage support - + if (_portage_avail): portDbDir = _portage_getPortageAppDbPath() removePath = portDbDir+atom @@ -1535,7 +1475,7 @@ def removePackageFromGentooDatabase(atom): except: pass key = dep_getkey(atom) - othersInstalled = _portage_getInstalledAtoms(key) + othersInstalled = _portage_getInstalledAtoms(key) #FIXME: really slow if othersInstalled == None: # safest way (error free) is to use sed without loading the file # escape / @@ -1593,14 +1533,18 @@ def installPackageIntoGentooDatabase(infoDict,packageFile): #print "removing -> "+removePath ### INSTALL NEW - extractPath = os.path.dirname(packageFile) - extractPath += "/xpak" + extractPath = etpConst['entropyunpackdir']+"/"+os.path.basename(packageFile)+"/xpak" + if os.path.isdir(extractPath): + shutil.rmtree(extractPath) + else: + os.makedirs(extractPath) extractXpak(packageFile,extractPath) if not os.path.isdir(portDbDir+infoDict['category']): os.makedirs(portDbDir+infoDict['category']) destination = portDbDir+infoDict['category']+"/"+infoDict['name']+"-"+infoDict['version'] if os.path.isdir(destination): shutil.rmtree(destination) + os.rename(extractPath,destination) return 0 @@ -2170,6 +2114,7 @@ def worldUpdate(ask = False, pretend = False, verbose = False, onlyfetch = False print_info(red(" @@ ")+blue("Packages matching already up to date:\t")+bold(str(len(fineList)))) # disable collisions protection, better + oldcollprotect = etpConst['collisionprotect'] etpConst['collisionprotect'] = 0 if (updateList): @@ -2180,6 +2125,8 @@ def worldUpdate(ask = False, pretend = False, verbose = False, onlyfetch = False else: print_info(red(" @@ ")+blue("Nothing to update.")) + etpConst['collisionprotect'] = oldcollprotect + if (removedList): removedList = list(removedList) removedList.sort() @@ -2316,6 +2263,7 @@ def installPackages(packages = [], atomsdata = [], ask = False, pretend = False, if (deps): treepackages, result = getRequiredPackages(foundAtoms, emptydeps, deepdeps, spinning = True) # add dependencies, explode them + if (result == -2): print_error(red(" @@ ")+blue("Cannot find needed dependencies: ")+str(treepackages)) for atom in treepackages: @@ -2331,9 +2279,11 @@ def installPackages(packages = [], atomsdata = [], ask = False, pretend = False, print_error(red(" # ")+" [from:"+repo+"] "+darkred(iatom)) rdbconn.closeDB() return 130, -1 + elif (result == -1): # no database connection print_error(red(" @@ ")+blue("Cannot find the Installed Packages Database. It's needed to accomplish dependency resolving. Try to run ")+bold("equo database generate")) return 200, -1 + for x in range(len(treepackages))[::-1]: for z in range(len(treepackages[x]))[::-1]: if z == 0: @@ -2343,6 +2293,10 @@ def installPackages(packages = [], atomsdata = [], ask = False, pretend = False, else: for a in treepackages[x][z]: runQueue.append(a) + + else: + for atomInfo in foundAtoms: + runQueue.append(atomInfo) downloadSize = 0 onDiskUsedSize = 0 @@ -2540,15 +2494,15 @@ def installPackages(packages = [], atomsdata = [], ask = False, pretend = False, if (actionQueue[pkgatom]['removeidpackage'] != -1): oldcontent = clientDbconn.retrieveContent(actionQueue[pkgatom]['removeidpackage']) newcontent = dbconn.retrieveContent(idpackage) - actionQueue[pkgatom]['removecontent'] = [x for x in oldcontent if x not in newcontent] + oldcontent.difference_update(newcontent) + actionQueue[pkgatom]['removecontent'] = oldcontent actionQueue[pkgatom]['diffremoval'] = True etpRemovalTriggers[pkgatom] = clientDbconn.getPackageData(actionQueue[pkgatom]['removeidpackage']) - etpRemovalTriggers[pkgatom]['removecontent'] = actionQueue[pkgatom]['removecontent'][:] + etpRemovalTriggers[pkgatom]['removecontent'] = actionQueue[pkgatom]['removecontent'].copy() # get data for triggerring tool etpInstallTriggers[pkgatom] = dbconn.getPackageData(idpackage) - dbconn.closeDB() if (not onlyfetch): @@ -2726,10 +2680,10 @@ def removePackages(packages = [], atomsdata = [], ask = False, pretend = False, infoDict['removeidpackage'] = idpackage infoDict['removeatom'] = clientDbconn.retrieveAtom(idpackage) infoDict['removecontent'] = clientDbconn.retrieveContent(idpackage) - actionQueue[pkgatom]['diffremoval'] = False + infoDict['diffremoval'] = False infoDict['removeconfig'] = configFiles etpRemovalTriggers[infoDict['removeatom']] = clientDbconn.getPackageData(idpackage) - etpRemovalTriggers[infoDict['removeatom']]['removecontent'] = infoDict['removecontent'][:] + etpRemovalTriggers[infoDict['removeatom']]['removecontent'] = infoDict['removecontent'].copy() steps = [] steps.append("preremove") steps.append("remove") @@ -2874,7 +2828,7 @@ def stepExecutor(step,infoDict): equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"Message from "+infoDict['atom']+" :") for msg in infoDict['messages']: # FIXME: add logging support equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,msg) - print_warning(brown(' ## ')+msg) + print_warning(brown(' ## ')+msg) if infoDict['messages']: equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"End message.") @@ -2896,19 +2850,35 @@ def stepExecutor(step,infoDict): elif step == "preremove": # analyze atom - pkgdata = etpRemovalTriggers.get(infoDict['removeatom']) - if pkgdata: - triggers = triggerTools.preremove(pkgdata) + remdata = etpRemovalTriggers.get(infoDict['removeatom']) + if remdata: + triggers = triggerTools.preremove(remdata) + + if infoDict['diffremoval']: # diffremoval is true only when the remove action is triggered by installPackages() + pkgdata = etpRemovalTriggers.get(infoDict['atom']) + if pkgdata: + # preinstall script shouldn't doulbe run on preremove + itriggers = triggerTools.preinstall(pkgdata) + triggers.difference_update(itriggers) + for trigger in triggers: # code reuse, we'll fetch triggers list on the GUI client and run each trigger by itself - eval("triggerTools."+trigger)(pkgdata) + eval("triggerTools."+trigger)(remdata) elif step == "postremove": # analyze atom - pkgdata = etpRemovalTriggers.get(infoDict['removeatom']) - if pkgdata: - triggers = triggerTools.postremove(pkgdata) + remdata = etpRemovalTriggers.get(infoDict['removeatom']) + if remdata: + triggers = triggerTools.postremove(remdata) + + if infoDict['diffremoval']: # diffremoval is true only when the remove action is triggered by installPackages() + pkgdata = etpRemovalTriggers.get(infoDict['atom']) + if pkgdata: + # postinstall script shouldn't doulbe run on postremove + itriggers = triggerTools.postinstall(pkgdata) + triggers.difference_update(itriggers) + for trigger in triggers: # code reuse, we'll fetch triggers list on the GUI client and run each trigger by itself - eval("triggerTools."+trigger)(pkgdata) + eval("triggerTools."+trigger)(remdata) clientDbconn.closeDB() diff --git a/client/triggerTools.py b/client/triggerTools.py index b0d332335..021f04a3d 100644 --- a/client/triggerTools.py +++ b/client/triggerTools.py @@ -99,12 +99,14 @@ def postinstall(pkgdata): functions.add('scrollkeeper') if x.startswith("/etc/gconf/schemas"): functions.add('gconfreload') - if x.startswith('/lib/modules/') and x.endswith('.ko') and (pkgdata['category'] != 'sys-kernel'): + if x.startswith('/lib/modules/'): functions.add('kernelmod') if x.startswith('/boot/kernel-'): functions.add('addbootablekernel') + #if x.startswith("/etc/init.d/"): do it externally + # functions.add('initadd') - return list(functions) + return functions ''' @description: pkgdata parser that collects pre-install scripts that would be run @@ -122,7 +124,7 @@ def preinstall(pkgdata): if x.startswith("/boot"): functions.add('mountboot') - return list(functions) + return functions ''' @description: pkgdata parser that collects post-remove scripts that would be run @@ -169,8 +171,10 @@ def postremove(pkgdata): functions.add('gconfreload') if x.startswith('/boot/kernel-'): functions.add('removebootablekernel') + if x.startswith('/etc/init.d/'): + functions.add('removeinit') - return list(functions) + return functions ''' @description: pkgdata parser that collects pre-remove scripts that would be run @@ -187,7 +191,7 @@ def preremove(pkgdata): if x.startswith("/boot"): functions.add('mountboot') - return list(functions) + return functions ######################################################## #### @@ -206,14 +210,14 @@ def fontconfig(pkgdata): fontdirs.add(xdir[:16]+"/"+origdir) if (fontdirs): equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Configuring fonts directory...") - print_info(" "+brown("[POST] Configuring fonts directory...")) + print_info(red(" ##")+brown(" [POST] Configuring fonts directory...")) for fontdir in fontdirs: setup_font_dir(fontdir) setup_font_cache(fontdir) def gccswitch(pkgdata): equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Configuring GCC Profile...") - print_info(" "+brown("[POST] Configuring GCC Profile...")) + print_info(red(" ##")+brown(" [POST] Configuring GCC Profile...")) # get gcc profile pkgsplit = entropyTools.catpkgsplit(pkgdata['category']+"/"+pkgdata['name']+"-"+pkgdata['version']) profile = pkgdata['chost']+"-"+pkgsplit[2] @@ -221,7 +225,7 @@ def gccswitch(pkgdata): def iconscache(pkgdata): equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Updating icons cache...") - print_info(" "+brown("[POST] Updating icons cache...")) + print_info(red(" ##")+brown(" [POST] Updating icons cache...")) mycnt = set(pkgdata['content']) for file in mycnt: if file.startswith("/usr/share/icons") and file.endswith("index.theme"): @@ -230,49 +234,49 @@ def iconscache(pkgdata): def mimeupdate(pkgdata): equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Updating shared mime info database...") - print_info(" "+brown("[POST] Updating shared mime info database...")) + print_info(red(" ##")+brown(" [POST] Updating shared mime info database...")) update_mime_db() def mimedesktopupdate(pkgdata): equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Updating desktop mime database...") - print_info(" "+brown("[POST] Updating desktop mime database...")) + print_info(red(" ##")+brown(" [POST] Updating desktop mime database...")) update_mime_desktop_db() def scrollkeeper(pkgdata): equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Updating scrollkeeper database...") - print_info(" "+brown("[POST] Updating scrollkeeper database...")) + print_info(red(" ##")+brown(" [POST] Updating scrollkeeper database...")) update_scrollkeeper_db() def gconfreload(pkgdata): equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Reloading GConf2 database...") - print_info(" "+brown("[POST] Reloading GConf2 database...")) + print_info(red(" ##")+brown(" [POST] Reloading GConf2 database...")) reload_gconf_db() def binutilsswitch(pkgdata): equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Configuring Binutils Profile...") - print_info(" "+brown("[POST] Configuring Binutils Profile...")) + print_info(red(" ##")+brown(" [POST] Configuring Binutils Profile...")) # get binutils profile pkgsplit = entropyTools.catpkgsplit(pkgdata['category']+"/"+pkgdata['name']+"-"+pkgdata['version']) profile = pkgdata['chost']+"-"+pkgsplit[2] set_binutils_profile(profile) def kernelmod(pkgdata): - equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Updating moduledb...") - print_info(" "+brown("[POST] Updating moduledb...")) - item = 'a:1:'+pkgdata['category']+"/"+pkgdata['name']+"-"+pkgdata['version'] - update_moduledb(item) - print_info(" "+brown("[POST] Running depmod...")) - kos = [x for x in pkgdata['content'] if x.startswith("/lib/modules") and x.endswith(".ko")] + if pkgdata['category'] != "sys-kernel": + equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Updating moduledb...") + print_info(red(" ##")+brown(" [POST] Updating moduledb...")) + item = 'a:1:'+pkgdata['category']+"/"+pkgdata['name']+"-"+pkgdata['version'] + update_moduledb(item) + print_info(red(" ##")+brown(" [POST] Running depmod...")) run_depmod() def pythoninst(pkgdata): equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Configuring Python...") - print_info(" "+brown("[POST] Configuring Python...")) + print_info(red(" ##")+brown(" [POST] Configuring Python...")) python_update_symlink() def sqliteinst(pkgdata): equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Configuring SQLite...") - print_info(" "+brown("[POST] Configuring SQLite...")) + print_info(red(" ##")+brown(" [POST] Configuring SQLite...")) sqlite_update_symlink() def initdisable(pkgdata): @@ -289,7 +293,18 @@ def initinform(pkgdata): for file in mycnt: if file.startswith("/etc/init.d/") and not os.path.isfile(file): equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[PRE] A new service will be installed: "+file) - print_info(" "+brown("[PRE] A new service will be installed: ")+file) + print_info(red(" ##")+brown(" [PRE] A new service will be installed: ")+file) + +def removeinit(pkgdata): + mycnt = set(pkgdata['content']) + for file in mycnt: + if file.startswith("/etc/init.d/") and os.path.isfile(file): + equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Removing boot service: "+os.path.basename(file)) + print_info(red(" ##")+brown(" [POST] Removing boot service: ")+os.path.basename(file)) + try: + os.system('rc-update del '+os.path.basename(file)+' &> /dev/null') + except: + pass def openglsetup(pkgdata): opengl = "xorg-x11" @@ -301,21 +316,21 @@ def openglsetup(pkgdata): eselect = os.system("eselect opengl &> /dev/null") if eselect == 0: equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Reconfiguring OpenGL to "+opengl+" ...") - print_info(" "+brown("[POST] Reconfiguring OpenGL...")) + print_info(red(" ##")+brown(" [POST] Reconfiguring OpenGL...")) os.system("eselect opengl set --use-old "+opengl) else: equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Eselect NOT found, cannot run OpenGL trigger") - print_info(" "+brown("[POST] Eselect NOT found, cannot run OpenGL trigger")) + print_info(red(" ##")+brown(" [POST] Eselect NOT found, cannot run OpenGL trigger")) def openglsetup_xorg(pkgdata): eselect = os.system("eselect opengl &> /dev/null") if eselect == 0: equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Reconfiguring OpenGL to fallback xorg-x11 ...") - print_info(" "+brown("[POST] Reconfiguring OpenGL...")) + print_info(red(" ##")+brown(" [POST] Reconfiguring OpenGL...")) os.system("eselect opengl set xorg-x11") else: equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Eselect NOT found, cannot run OpenGL trigger") - print_info(" "+brown("[POST] Eselect NOT found, cannot run OpenGL trigger")) + print_info(red(" ##")+brown(" [POST] Eselect NOT found, cannot run OpenGL trigger")) # FIXME: this only supports grub (no lilo support) def addbootablekernel(pkgdata): @@ -326,7 +341,7 @@ def addbootablekernel(pkgdata): initramfs = '' # configure GRUB equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Configuring GRUB bootloader. Adding the new kernel...") - print_info(" "+brown("[POST] Configuring GRUB bootloader. Adding the new kernel...")) + print_info(red(" ##")+brown(" [POST] Configuring GRUB bootloader. Adding the new kernel...")) configure_boot_grub(kernel,initramfs) @@ -339,7 +354,7 @@ def removebootablekernel(pkgdata): initramfs = '' # configure GRUB equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Configuring GRUB bootloader. Removing the selected kernel...") - print_info(" "+brown("[POST] Configuring GRUB bootloader. Removing the selected kernel...")) + print_info(red(" ##")+brown(" [POST] Configuring GRUB bootloader. Removing the selected kernel...")) remove_boot_grub(kernel,initramfs) def mountboot(pkgdata): @@ -356,10 +371,10 @@ def mountboot(pkgdata): rc = os.system("mount /boot &> /dev/null") if rc == 0: equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[PRE] Mounted /boot successfully") - print_info(" "+brown("[PRE] Mounted /boot successfully")) + print_info(red(" ##")+brown(" [PRE] Mounted /boot successfully")) elif rc != 8192: # already mounted equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[PRE] Cannot mount /boot automatically !!") - print_info(" "+brown("[PRE] Cannot mount /boot automatically !!")) + print_info(red(" ##")+brown(" [PRE] Cannot mount /boot automatically !!")) break def kbuildsycoca(pkgdata): @@ -377,14 +392,14 @@ def kbuildsycoca(pkgdata): os.chown("/usr/share/services",0,0) os.chmod("/usr/share/services",0755) equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Running kbuildsycoca to build global KDE database") - print_info(" "+brown("[POST] Running kbuildsycoca to build global KDE database")) + print_info(red(" ##")+brown(" [POST] Running kbuildsycoca to build global KDE database")) os.system(builddir+"/bin/kbuildsycoca --global --noincremental &> /dev/null") def gconfinstallschemas(pkgdata): gtest = os.system("which gconftool-2 &> /dev/null") if gtest == 0: schemas = [x for x in pkgdata['content'] if x.startswith("/etc/gconf/schemas") and x.endswith(".schemas")] - print_info(" "+brown("[POST] Installing GConf2 schemas...")) + print_info(red(" ##")+brown(" [POST] Installing GConf2 schemas...")) for schema in schemas: os.system(""" unset GCONF_DISABLE_MAKEFILE_SCHEMA_INSTALL @@ -429,7 +444,7 @@ def setup_font_dir(fontdir): def setup_font_cache(fontdir): # fc-cache -f gooooo! if os.access('/usr/bin/fc-cache',os.X_OK): - os.system('HOME="/root" /usr/bin/fc-cache -f '+unicode(fontdir)) + os.system('/usr/bin/fc-cache -f '+unicode(fontdir)) return 0 ''' diff --git a/libraries/portageTools.py b/libraries/portageTools.py index 900557d30..4803af0b2 100644 --- a/libraries/portageTools.py +++ b/libraries/portageTools.py @@ -603,24 +603,73 @@ def quickpkg(atom,dirpath): os.makedirs(tmpdirpath) dbdir = "/var/db/pkg/"+pkgcat+"/"+pkgname+"/" - # crate file list + import tarfile + import stat + tar = tarfile.open(dirpath,"w:bz2") + + # load content f = open(dbdir+dbCONTENTS,"r") pkgcontent = f.readlines() f.close() - _pkgcontent = [] + + content = {} + id_strings = {} + for line in pkgcontent: - line = line.strip().split()[1] - if not ((os.path.isdir(line)) and (os.path.islink(line))): - _pkgcontent.append(line) - pkgcontent = _pkgcontent - f = open(tmpdirpath+"/"+dbCONTENTS,"w") - for i in pkgcontent: - f.write(i+"\n") - f.flush() - f.close() + line = line.strip() + data = line.split() + ftype = data[0] - # package them into a file - rc = entropyTools.spawnCommand("tar cjf "+dirpath+" -C / --files-from='"+tmpdirpath+"/"+dbCONTENTS+"' --no-recursion", redirect = "&>/dev/null") + if ftype == "dir": + file = string.join(data[1:]," ") + content[file] = [] # do not use sets! + content[file].append(ftype) + elif ftype == "sym": + timestamp = data[-1] + symlink = data[-2] + file = string.join(data[1:-3]," ") + content[file] = [] + content[file].append(ftype) + content[file].append(timestamp) + content[file].append(symlink) + else: # == "obj" + # add timestamp + timestamp = data[-1] + checksum = data[-2] + file = string.join(data[1:-2]," ") + content[file] = [] + content[file].append(ftype) + content[file].append(timestamp) + content[file].append(checksum) + + paths = content.keys() + paths.sort() + + for path in paths: + try: + exist = os.lstat(path) + except OSError: + continue # skip file + ftype = content[path][0] + lpath = path + arcname = path[1:] + if ftype == "dir" and stat.S_ISDIR(exist.st_mode) and os.path.isdir(lpath): + lpath = os.path.realpath(lpath) + tarinfo = tar.gettarinfo(lpath, arcname) + tarinfo.uname = id_strings.setdefault(tarinfo.uid, str(tarinfo.uid)) + tarinfo.gname = id_strings.setdefault(tarinfo.gid, str(tarinfo.gid)) + + if stat.S_ISREG(exist.st_mode): + tarinfo.type = tarfile.REGTYPE + f = open(path) + try: + tar.addfile(tarinfo, f) + finally: + f.close() + else: + tar.addfile(tarinfo) + + tar.close() # appending xpak informations import xpak