diff --git a/TODO b/TODO index c41519066..c9210aa63 100644 --- a/TODO +++ b/TODO @@ -22,6 +22,7 @@ TODO list: - install only looks inside the configured branch - if a mirror fails several times, disable it - move branches to version naming (3.5, 3.6, 3.7) instead of using stable, unstable... + - embed python and pysqlite to avoid dependency from the one installed on the system Project Status: - entropy: will handle all the three tools below diff --git a/client/confTools.py b/client/confTools.py index d8c27b49b..f2b974042 100644 --- a/client/confTools.py +++ b/client/confTools.py @@ -215,7 +215,7 @@ def removefromcache(filepath): ''' def confinfo(): print_info(yellow(" @@ ")+darkgreen("These are the files that would be updated:")) - data = scanfs(quiet = False, dcache = True) + data = scanfs(quiet = True, dcache = False) counter = 0 for file in data: counter += 1 diff --git a/client/dumpTools.py b/client/dumpTools.py index 0d7f9aa57..0b48a7f24 100644 --- a/client/dumpTools.py +++ b/client/dumpTools.py @@ -41,6 +41,8 @@ def dumpobj(name,object): data.appendChild(text) # etpConst['dumpstoragedir'] try: + if not os.path.isdir(etpConst['dumpstoragedir']): + os.makedirs(etpConst['dumpstoragedir']) f = open(etpConst['dumpstoragedir']+"/"+name+".dmp","w") #FIXME add check f.writelines(doc.toprettyxml(indent=" ")) f.flush() diff --git a/client/equo b/client/equo index 614fcc4bb..939443499 100644 --- a/client/equo +++ b/client/equo @@ -153,7 +153,7 @@ try: import confTools scandata = confTools.scanfs(quiet = True, dcache = True) if len(scandata) > 0: - print_warning(darkgreen("There are "+str(len(scandata))+" configuration files that need update.")) + print_warning(darkgreen("There are "+str(len(scandata))+" configuration files that need(s) to be updated.")) print_warning(red("Please run: ")+bold("etc-update")) # FIXME: add our tool sys.exit(rc) diff --git a/client/equoTools.py b/client/equoTools.py index df038c6d7..eb21cbc3f 100644 --- a/client/equoTools.py +++ b/client/equoTools.py @@ -31,6 +31,7 @@ from outputTools import * from remoteTools import downloadData, getOnlineContent from entropyTools import unpackGzip, compareMd5, bytesIntoHuman, convertUnixTimeToHumanTime, askquestion, getRandomNumber, isjustname, dep_getkey, compareVersions as entropyCompareVersions, filterDuplicatedEntries, extactDuplicatedEntries, uncompressTarBz2, extractXpak, applicationLockCheck, countdown, isRoot, spliturl, dep_striptag, md5sum, allocateMaskedFile, istextfile from databaseTools import etpDatabase +import triggerTools import confTools import xpak import time @@ -1151,7 +1152,7 @@ def installPackage(infoDict): clientDbconn = openClientDatabase() package = infoDict['download'] - + # load content cache if found empty if etpConst['collisionprotect'] > 0: if (not contentCache): @@ -1183,7 +1184,6 @@ def installPackage(infoDict): mask = etpRepositories[infoDict['repository']]['configprotectmask'] packageContent = [] - # setup imageDir properly imageDir = imageDir.encode(sys.getfilesystemencoding()) # merge data into system @@ -2246,12 +2246,16 @@ def installPackages(packages = [], atomsdata = [], ask = False, pretend = False, newcontent = dbconn.retrieveContent(idpackage) actionQueue[pkgatom]['removecontent'] = [x for x in oldcontent if x not in newcontent] + # get data for triggerring tool + etpInstallTriggers[pkgatom] = dbconn.getPackageData(idpackage) # XXX: maybe that actionQueue is enough? + dbconn.closeDB() if (not onlyfetch): # install + steps.append("preinstall") steps.append("install") - steps.append("cleanup") + steps.append("postinstall") #print "steps for "+pkgatom+" -> "+str(steps) print_info(red(" @@ ")+bold("(")+blue(str(currentqueue))+"/"+red(totalqueue)+bold(") ")+">>> "+darkgreen(pkgatom)) @@ -2262,9 +2266,6 @@ def installPackages(packages = [], atomsdata = [], ask = False, pretend = False, clientDbconn.closeDB() return -1,rc - # regenerate depends table - #print_info(red(" @@ ")+blue("Regenerating depends caching table..."), back = True) - #regenerateDependsTable(clientDbconn, output = False) print_info(red(" @@ ")+blue("Install Complete.")) closeClientDatabase(clientDbconn) @@ -2557,6 +2558,21 @@ def stepExecutor(step,infoDict): errormsg = red("An error occured while trying to remove the package. Check if you have enough disk space on your hard disk. Error "+str(output)) print_error(errormsg) + elif step == "postinstall": + # analyze atom + pkgdata = etpInstallTriggers.get(infoDict['atom']) + if pkgdata: + triggerTools.postinstall(pkgdata) + + #elif step == "preinstall": + # analyze atom +# match = etpInstallTriggers.get(infoDict['atom']) +# if match: +# prematch = match.get('prematch') +# if prematch: + # run post-install triggers +# print prematch + closeClientDatabase(clientDbconn) return output diff --git a/client/triggerTools.py b/client/triggerTools.py new file mode 100644 index 000000000..673bde81f --- /dev/null +++ b/client/triggerTools.py @@ -0,0 +1,79 @@ +#!/usr/bin/python +''' + # DESCRIPTION: + # Equo general purpose triggering scripts for pre/post install and remove + + Copyright (C) 2007 Fabio Erculiani + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +''' + +import sys +import os +sys.path.append('../libraries') +from outputTools import * + + +''' + @description: pkgdata parser that triggers proper post-install scripts +''' +def postinstall(pkgdata): + + # fonts configuration + if pkgdata['category'] == "media-fonts": + fontdirs = set() + for xdir in pkgdata['content']: + if xdir.startswith("/usr/share/fonts"): + origdir = xdir[16:] + if origdir: + if origdir.startswith("/"): + origdir = origdir.split("/")[1] + if os.path.isdir(xdir[:16]+"/"+origdir): + fontdirs.add(xdir[:16]+"/"+origdir) + if (fontdirs): + print_info(" "+brown("[POST] Configuring fonts directory...")) + for fontdir in fontdirs: + setupfontdir(fontdir) + setupfontcache(fontdir) + + + +######################################################## +#### +## Internal functions +# + +''' + @description: creates Xfont files + @output: returns int() as exit status +''' +def setupfontdir(fontdir): + # mkfontscale + if os.access('/usr/bin/mkfontscale',os.X_OK): + os.system('/usr/bin/mkfontscale '+unicode(fontdir)) + # mkfontdir + if os.access('/usr/bin/mkfontdir',os.X_OK): + os.system('/usr/bin/mkfontdir -e /usr/share/fonts/encodings -e /usr/share/fonts/encodings/large '+unicode(fontdir)) + return 0 + +''' + @description: creates font cache + @output: returns int() as exit status +''' +def setupfontcache(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)) + return 0 \ No newline at end of file diff --git a/libraries/clientConstants.py b/libraries/clientConstants.py index 7ce1016eb..f15e67155 100644 --- a/libraries/clientConstants.py +++ b/libraries/clientConstants.py @@ -27,6 +27,14 @@ import random import sys from entropyConstants import * +### Equo triggering functions for pre/post-install scripts +### index: package atom, content: name of the function to call +etpInstallTriggers = {} + +### Equo triggering functions for pre/post-remove scripts +### structure same as above +etpRemovalTriggers = {} + # Client packages/database repositories # used by equo etpRepositories = {}