diff --git a/TODO b/TODO index 3dc37528d..0459b3143 100644 --- a/TODO +++ b/TODO @@ -2,15 +2,15 @@ TODO list: CLIENT: - add external triggerable hooks support - include more triggers - - finalize smartapps tool - use depgraph generation function to generate dependencies - installPackages should pull conflicts depends too + - find a way to better handle real smartapps deps Project Status: - reagent: complete. Stabilization mode. - activator: complete. Stabilization mode. ============ -- equo (client): 90% +- equo (client): 92% - EAPI1+ info: http://www.pkgcore.org/trac/pkgcore/doc/doc/extended-atom-syntax.rst diff --git a/client/confTools.py b/client/confTools.py index b30773894..4ceea9799 100644 --- a/client/confTools.py +++ b/client/confTools.py @@ -23,7 +23,6 @@ import sys import commands import string -sys.path.append('../libraries') from entropyConstants import * from clientConstants import * from outputTools import * diff --git a/client/equo b/client/equo index 73c80270e..29f25f903 100644 --- a/client/equo +++ b/client/equo @@ -53,7 +53,7 @@ def print_help(): print_info(" \t\t"+red("--pretend")+"\t\t just show what would be done") print_info(" \t\t"+red("--fetch")+"\t\t\t just download packages without doing the install") print_info(" \t\t"+red("--nodeps")+"\t\t do not manage any dependency") - print_info(" \t\t"+red("--empty")+"\t\t\t also include already installed packages") + print_info(" \t\t"+red("--empty")+"\t\t\t set all dependencies as unsatisfied") print_info(" \t\t"+red("--deep")+"\t\t\t analyze dependencies deeply") print_info(" \t\t"+red("--verbose")+"\t\t show more details about what's going on") print_info(" \t\t"+red("--configfiles")+"\t\t also remove old configuration files [use with care]") @@ -86,6 +86,13 @@ def print_help(): print_info(" \t\t"+red("--verbose")+"\t\t show more details") print_info(" \t\t"+red("--quiet")+"\t\t\t print results in a scriptable way") + print_info(" \t"+blue("smart")+brown("\t\t handle extended functionalities")) + print_info(" \t\tUnpack and run applications") + print_info(" \t\t"+darkgreen("application")+red("\t\t generate a smart application for the provided atoms (experimental)")) + print_info(" \t\t\t"+red("--empty")+"\t\t set all dependencies as unsatisfied") + print_info(" \t\tA .tbz2 package that can contain multiple packages (breaks Gentoo compatibility)") + print_info(" \t\t"+darkgreen("package")+red("\t\t generate a smart package for the provided atoms")) + print_info(" \t"+blue("database")+brown("\t handle installed packages database")) print_info(" \t\t"+darkgreen("generate")+red("\t\t generate installed packages database")) print_info(" \t\t"+darkgreen("resurrect")+red("\t\t generate installed packages database using system content [last hope]")) @@ -160,10 +167,10 @@ try: if "--pretend" not in options: options.append("--pretend") rc = equoTools.package(options) - print_info(red(" @@ ")+darkblue("Caching equo conf"), back = True) + print_info(red(" @@ ")+blue("Caching equo conf"), back = True) import confTools scandata = confTools.scanfs(quiet = True, dcache = True) - print_info(red(" @@ ")+darkblue("Caching complete.")) + print_info(red(" @@ ")+blue("Caching complete.")) if len(scandata) > 0: print_warning(darkgreen("There are "+str(len(scandata))+" configuration file(s) that need(s) to be updated.")) print_warning(red("Please run: ")+bold("equo conf update")) @@ -174,6 +181,13 @@ try: import queryTools rc = queryTools.query(options[1:]) + # smartapps tool + elif (options[0] == "smart"): + rc = 0 + if len(options) > 1: + import smartTools + rc = smartTools.smart(options[1:]) + elif (options[0] == "conf"): import confTools rc = confTools.configurator(options[1:]) @@ -197,10 +211,10 @@ try: entropyTools.cleanup([ etpConst['packagestmpdir'], etpConst['logdir'], etpConst['entropyunpackdir'], etpConst['packagesbindir'] ]) rc = 0 # kill threads - #threads = entropyTools.threading.enumerate() - #for thread in threads: - # if thread.getName() == "download": # equo current download speed thread - # thread.kill() + threads = entropyTools.threading.enumerate() + for thread in threads: + if thread.getName() == "download": # equo current download speed thread + thread.kill() sys.exit(rc) except SystemExit: pass diff --git a/client/equoTools.py b/client/equoTools.py index abef1a8f3..52698ce80 100644 --- a/client/equoTools.py +++ b/client/equoTools.py @@ -29,8 +29,8 @@ from entropyConstants import * from clientConstants import * from outputTools import * from remoteTools import downloadData, getOnlineContent -from entropyTools import unpackGzip, unpackBzip2, compareMd5, bytesIntoHuman, askquestion, getRandomNumber, isjustname, dep_getkey, compareVersions as entropyCompareVersions, filterDuplicatedEntries, extractDuplicatedEntries, uncompressTarBz2, extractXpak, applicationLockCheck, countdown, isRoot, spliturl, remove_tag, dep_striptag, md5sum, allocateMaskedFile, istextfile, isnumber, extractEdb -from databaseTools import etpDatabase, openRepositoryDatabase, openClientDatabase, openGenericDatabase +from entropyTools import unpackGzip, unpackBzip2, compareMd5, bytesIntoHuman, askquestion, getRandomNumber, isjustname, dep_getkey, compareVersions as entropyCompareVersions, filterDuplicatedEntries, extractDuplicatedEntries, uncompressTarBz2, extractXpak, applicationLockCheck, countdown, isRoot, spliturl, remove_tag, dep_striptag, md5sum, allocateMaskedFile, istextfile, isnumber, extractEdb, getNewerVersion, getNewerVersionTag +from databaseTools import etpDatabase, openRepositoryDatabase, openClientDatabase, openGenericDatabase, fetchRepositoryIfNotAvailable import triggerTools import confTools import dumpTools @@ -348,18 +348,6 @@ def backupClientDatabase(): return dest return "" -def fetchRepositoryIfNotAvailable(reponame): - # open database - rc = 0 - dbfile = etpRepositories[reponame]['dbpath']+"/"+etpConst['etpdatabasefile'] - if not os.path.isfile(dbfile): - # sync - rc = syncRepositories([reponame]) - if not os.path.isfile(dbfile): - # so quit - print_error(red("Database file for '"+bold(etpRepositories[reponame]['description'])+red("' does not exist. Cannot search."))) - return rc - ######################################################## #### @@ -1487,7 +1475,7 @@ def installPackage(infoDict): return rc # remove unpack dir - shutil.rmtree(imageDir,True) + shutil.rmtree(unpackDir,True) return 0 ''' @@ -1580,35 +1568,36 @@ def installPackageIntoGentooDatabase(infoDict,packageFile): 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) - - # update counter - if os.path.isfile("/var/cache/edb/counter"): - # fetch number - try: - f = open("/var/cache/edb/counter","r") - counter = int(f.readline().strip()) - f.close() - # write new counter to file - if os.path.isfile(destination+"/"+dbCOUNTER): - f = open(destination+"/"+dbCOUNTER,"w") - f.write(str(counter)+"\n") - f.flush() - f.close() - counter += 1 - f = open("/var/cache/edb/counter","w") - f.write(str(counter)+"\n") - f.flush() - f.close() - except: - pass + xpakstatus = extractXpak(packageFile,extractPath) + if extractXpak != None: + 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) + + # update counter + if os.path.isfile("/var/cache/edb/counter"): + # fetch number + try: + f = open("/var/cache/edb/counter","r") + counter = int(f.readline().strip()) + f.close() + # write new counter to file + if os.path.isfile(destination+"/"+dbCOUNTER): + f = open(destination+"/"+dbCOUNTER,"w") + f.write(str(counter)+"\n") + f.flush() + f.close() + counter += 1 + f = open("/var/cache/edb/counter","w") + f.write(str(counter)+"\n") + f.flush() + f.close() + except: + pass return 0 @@ -2098,7 +2087,7 @@ def worldUpdate(ask = False, pretend = False, verbose = False, onlyfetch = False time.sleep(5) # run removePackages with --nodeps - removePackages(atomsdata = removedList, ask = ask, verbose = verbose, deps = False) + removePackages(atomsdata = removedList, ask = ask, verbose = verbose, deps = False, systemPackagesCheck = False) else: print_info(red(" @@ ")+blue("Calculation complete.")) @@ -2486,13 +2475,17 @@ def installPackages(packages = [], atomsdata = [], ask = False, pretend = False, # differential remove list if (actionQueue[pkgatom]['removeidpackage'] != -1): - oldcontent = clientDbconn.retrieveContent(actionQueue[pkgatom]['removeidpackage']) - newcontent = dbconn.retrieveContent(idpackage) - 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'].copy() + # is it still available? + if clientDbconn.isIDPackageAvailable(actionQueue[pkgatom]['removeidpackage']): + oldcontent = clientDbconn.retrieveContent(actionQueue[pkgatom]['removeidpackage']) + newcontent = dbconn.retrieveContent(idpackage) + 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'].copy() + else: + actionQueue[pkgatom]['removeidpackage'] = -1 # get data for triggerring tool etpInstallTriggers[pkgatom] = dbconn.getPackageData(idpackage) diff --git a/client/triggerTools.py b/client/triggerTools.py index 021f04a3d..3897e710a 100644 --- a/client/triggerTools.py +++ b/client/triggerTools.py @@ -23,7 +23,6 @@ import sys import os import commands -sys.path.append('../libraries') from outputTools import * from entropyConstants import * import entropyTools @@ -49,7 +48,7 @@ def postinstall(pkgdata): functions.add("fontconfig") # opengl configuration - if (pkgdata['category'] == "x11-drivers") and (not pkgdata['name'].startswith("xf86-")): + if (pkgdata['category'] == "x11-drivers") and (pkgdata['name'].startswith("nvidia-") or pkgdata['name'].startswith("ati-")): functions.add("openglsetup") # gcc configuration @@ -71,6 +70,10 @@ def postinstall(pkgdata): if "kde" in pkgdata['eclasses']: functions.add("kbuildsycoca") + # kde package ? + if pkgdata['category']+"/"+pkgdata['name'] == "sys-apps/shadow": + functions.add("susetuid") + # update mime if "fdo-mime" in pkgdata['eclasses']: functions.add('mimeupdate') @@ -134,7 +137,7 @@ def postremove(pkgdata): functions = set() # opengl configuration - if (pkgdata['category'] == "x11-drivers") and (not pkgdata['name'].startswith("xf86-")): + if (pkgdata['category'] == "x11-drivers") and (pkgdata['name'].startswith("nvidia-") or pkgdata['name'].startswith("ati-")): functions.add("openglsetup_xorg") # kde package ? @@ -210,14 +213,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(red(" ##")+brown(" [POST] Configuring fonts directory...")) + print_info(red(" ##")+brown(" 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(red(" ##")+brown(" [POST] Configuring GCC Profile...")) + print_info(red(" ##")+brown(" Configuring GCC Profile...")) # get gcc profile pkgsplit = entropyTools.catpkgsplit(pkgdata['category']+"/"+pkgdata['name']+"-"+pkgdata['version']) profile = pkgdata['chost']+"-"+pkgsplit[2] @@ -225,7 +228,7 @@ def gccswitch(pkgdata): def iconscache(pkgdata): equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Updating icons cache...") - print_info(red(" ##")+brown(" [POST] Updating icons cache...")) + print_info(red(" ##")+brown(" Updating icons cache...")) mycnt = set(pkgdata['content']) for file in mycnt: if file.startswith("/usr/share/icons") and file.endswith("index.theme"): @@ -234,27 +237,27 @@ def iconscache(pkgdata): def mimeupdate(pkgdata): equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Updating shared mime info database...") - print_info(red(" ##")+brown(" [POST] Updating shared mime info database...")) + print_info(red(" ##")+brown(" 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(red(" ##")+brown(" [POST] Updating desktop mime database...")) + print_info(red(" ##")+brown(" 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(red(" ##")+brown(" [POST] Updating scrollkeeper database...")) + print_info(red(" ##")+brown(" Updating scrollkeeper database...")) update_scrollkeeper_db() def gconfreload(pkgdata): equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Reloading GConf2 database...") - print_info(red(" ##")+brown(" [POST] Reloading GConf2 database...")) + print_info(red(" ##")+brown(" Reloading GConf2 database...")) reload_gconf_db() def binutilsswitch(pkgdata): equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Configuring Binutils Profile...") - print_info(red(" ##")+brown(" [POST] Configuring Binutils Profile...")) + print_info(red(" ##")+brown(" Configuring Binutils Profile...")) # get binutils profile pkgsplit = entropyTools.catpkgsplit(pkgdata['category']+"/"+pkgdata['name']+"-"+pkgdata['version']) profile = pkgdata['chost']+"-"+pkgsplit[2] @@ -263,20 +266,20 @@ def binutilsswitch(pkgdata): def kernelmod(pkgdata): if pkgdata['category'] != "sys-kernel": equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Updating moduledb...") - print_info(red(" ##")+brown(" [POST] Updating moduledb...")) + print_info(red(" ##")+brown(" Updating moduledb...")) item = 'a:1:'+pkgdata['category']+"/"+pkgdata['name']+"-"+pkgdata['version'] update_moduledb(item) - print_info(red(" ##")+brown(" [POST] Running depmod...")) + print_info(red(" ##")+brown(" Running depmod...")) run_depmod() def pythoninst(pkgdata): equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Configuring Python...") - print_info(red(" ##")+brown(" [POST] Configuring Python...")) + print_info(red(" ##")+brown(" Configuring Python...")) python_update_symlink() def sqliteinst(pkgdata): equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Configuring SQLite...") - print_info(red(" ##")+brown(" [POST] Configuring SQLite...")) + print_info(red(" ##")+brown(" Configuring SQLite...")) sqlite_update_symlink() def initdisable(pkgdata): @@ -293,14 +296,14 @@ 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(red(" ##")+brown(" [PRE] A new service will be installed: ")+file) + print_info(red(" ##")+brown(" A new service will be installed: ")+file) def removeinit(pkgdata): - mycnt = set(pkgdata['content']) + mycnt = set(pkgdata['removecontent']) 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)) + print_info(red(" ##")+brown(" Removing boot service: ")+os.path.basename(file)) try: os.system('rc-update del '+os.path.basename(file)+' &> /dev/null') except: @@ -316,21 +319,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(red(" ##")+brown(" [POST] Reconfiguring OpenGL...")) + print_info(red(" ##")+brown(" 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(red(" ##")+brown(" [POST] Eselect NOT found, cannot run OpenGL trigger")) + print_info(red(" ##")+brown(" 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(red(" ##")+brown(" [POST] Reconfiguring OpenGL...")) + print_info(red(" ##")+brown(" 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(red(" ##")+brown(" [POST] Eselect NOT found, cannot run OpenGL trigger")) + print_info(red(" ##")+brown(" Eselect NOT found, cannot run OpenGL trigger")) # FIXME: this only supports grub (no lilo support) def addbootablekernel(pkgdata): @@ -341,7 +344,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(red(" ##")+brown(" [POST] Configuring GRUB bootloader. Adding the new kernel...")) + print_info(red(" ##")+brown(" Configuring GRUB bootloader. Adding the new kernel...")) configure_boot_grub(kernel,initramfs) @@ -354,7 +357,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(red(" ##")+brown(" [POST] Configuring GRUB bootloader. Removing the selected kernel...")) + print_info(red(" ##")+brown(" Configuring GRUB bootloader. Removing the selected kernel...")) remove_boot_grub(kernel,initramfs) def mountboot(pkgdata): @@ -371,10 +374,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(red(" ##")+brown(" [PRE] Mounted /boot successfully")) + print_info(red(" ##")+brown(" Mounted /boot successfully")) elif rc != 8192: # already mounted equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[PRE] Cannot mount /boot automatically !!") - print_info(red(" ##")+brown(" [PRE] Cannot mount /boot automatically !!")) + print_info(red(" ##")+brown(" Cannot mount /boot automatically !!")) break def kbuildsycoca(pkgdata): @@ -392,14 +395,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(red(" ##")+brown(" [POST] Running kbuildsycoca to build global KDE database")) + print_info(red(" ##")+brown(" 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(red(" ##")+brown(" [POST] Installing GConf2 schemas...")) + print_info(red(" ##")+brown(" Installing GConf2 schemas...")) for schema in schemas: os.system(""" unset GCONF_DISABLE_MAKEFILE_SCHEMA_INSTALL @@ -419,6 +422,10 @@ def pygtkremove(pkgdata): if os.path.isfile(file[:-4]): os.remove(file[:-4]) +def susetuid(pkgdata): + if os.path.isfile("/bin/su"): + os.chown("/bin/su",0,0) + os.chmod("/bin/su",4755) ######################################################## #### ## Internal functions @@ -634,15 +641,16 @@ def remove_boot_grub(kernel,initramfs): grub_conf = f.readlines() kernelname = os.path.basename(kernel) new_conf = [] - skip = False - for line in grub_conf: - if (line.find(kernelname) != -1) or (line.find(initramfs) != -1): - skip = True - continue - if (skip) and (line.find("root ") != -1): - skip = False - continue - new_conf.append(line) + myconf = "" + for x in grub_conf: myconf += x + myconf = myconf.split("title") + for chunk in myconf: + if (chunk.find(kernelname) != -1) or (chunk.find(initramfs) != -1): + continue + if chunk.strip().startswith("="): + new_conf.append("title"+chunk) + else: + new_conf.append(chunk) f = open("/boot/grub/grub.conf","w") f.writelines(new_conf) f.flush() diff --git a/libraries/databaseTools.py b/libraries/databaseTools.py index c56222c15..ed5053657 100644 --- a/libraries/databaseTools.py +++ b/libraries/databaseTools.py @@ -504,6 +504,18 @@ def openRepositoryDatabase(repositoryName, xcache = True): etpRepositories[repositoryName]['configprotectmask'] += [x for x in etpConst['configprotectmask'] if x not in etpRepositories[repositoryName]['configprotectmask']] return conn +def fetchRepositoryIfNotAvailable(reponame): + # open database + rc = 0 + dbfile = etpRepositories[reponame]['dbpath']+"/"+etpConst['etpdatabasefile'] + if not os.path.isfile(dbfile): + # sync + rc = syncRepositories([reponame]) + if not os.path.isfile(dbfile): + # so quit + print_error(red("Database file for '"+bold(etpRepositories[reponame]['description'])+red("' does not exist. Cannot search."))) + return rc + ''' @description: open the installed packages database and returns the pointer @output: database pointer or, -1 if error @@ -533,8 +545,9 @@ def openServerDatabase(readOnly = True, noUpload = True): @description: open a generic client database and returns the pointer. @output: database pointer ''' -def openGenericDatabase(dbfile): - conn = etpDatabase(readOnly = False, dbFile = dbfile, clientDatabase = True, dbname = "generic", xcache = False) +def openGenericDatabase(dbfile, dbname = None): + if dbname == None: dbname = "generic" + conn = etpDatabase(readOnly = False, dbFile = dbfile, clientDatabase = True, dbname = dbname, xcache = False) return conn # this class simply describes the current database status @@ -598,7 +611,7 @@ class databaseStatus: class etpDatabase: - def __init__(self, readOnly = False, noUpload = False, dbFile = etpConst['etpdatabasefilepath'], clientDatabase = False, xcache = True, dbname = 'etpdb'): + def __init__(self, readOnly = False, noUpload = False, dbFile = etpConst['etpdatabasefilepath'], clientDatabase = False, xcache = False, dbname = 'etpdb'): dbLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_VERBOSE,"etpDatabase.__init__ called.") @@ -611,10 +624,9 @@ class etpDatabase: self.dbname = dbname # caching dictionaries - if (self.xcache) and (dbname != 'etpdb'): - ''' database query cache ''' + ''' database query cache ''' broken1 = False dbinfo = dbCacheStore.get(etpCache['dbInfo']+self.dbname) if dbinfo == None: diff --git a/libraries/entropyConstants.py b/libraries/entropyConstants.py index f2c72ac4b..8f9fb64bf 100644 --- a/libraries/entropyConstants.py +++ b/libraries/entropyConstants.py @@ -307,6 +307,7 @@ ETP_UPLOADDIR = "/upload/"+ETP_ARCH_CONST ETP_STOREDIR = "/store/"+ETP_ARCH_CONST ETP_TRIGGERSDIR = "/triggers/"+ETP_ARCH_CONST ETP_SMARTAPPSDIR = "/smartapps/"+ETP_ARCH_CONST +ETP_SMARTPACKAGESDIR = "/smartpackages/"+ETP_ARCH_CONST ETP_XMLDIR = "/xml/" ETP_CONF_DIR = "/etc/entropy" ETP_ROOT_DIR = "/" @@ -326,6 +327,7 @@ etpConst = { # by the clients: to query if a package has been already downloaded # by the servers or rsync mirrors: to store already uploaded packages to the main rsync server 'smartappsdir': ETP_DIR+ETP_SMARTAPPSDIR, # etpConst['smartappsdir'] location where smart apps files are places + 'smartpackagesdir': ETP_DIR+ETP_SMARTPACKAGESDIR, # etpConst['smartpackagesdir'] location where smart packages files are places 'triggersdir': ETP_DIR+ETP_TRIGGERSDIR, # etpConst['triggersdir'] location where external triggers are placed 'packagesstoredir': ETP_DIR+ETP_STOREDIR, # etpConst['packagesstoredir'] --> directory where .tbz2 files are stored waiting for being processed by reagent 'packagessuploaddir': ETP_DIR+ETP_UPLOADDIR, # etpConst['packagessuploaddir'] --> directory where .tbz2 files are stored waiting for being uploaded to our main mirror diff --git a/libraries/entropyTools.py b/libraries/entropyTools.py index 16bd1f1ce..9fe8d82e7 100644 --- a/libraries/entropyTools.py +++ b/libraries/entropyTools.py @@ -145,19 +145,22 @@ def extractXpak(tbz2file,tmpdir = None): # extract xpak content xpakpath = suckXpak(tbz2file, etpConst['packagestmpdir']) - import xpak - if tmpdir is None: - tmpdir = etpConst['packagestmpdir']+"/"+os.path.basename(tbz2file)[:-5]+"/" - if os.path.isdir(tmpdir): - spawnCommand("rm -rf "+tmpdir) - os.makedirs(tmpdir) - xpakdata = xpak.getboth(xpakpath) - xpak.xpand(xpakdata,tmpdir) try: - os.remove(xpakpath) + import xpak + if tmpdir is None: + tmpdir = etpConst['packagestmpdir']+"/"+os.path.basename(tbz2file)[:-5]+"/" + if os.path.isdir(tmpdir): + spawnCommand("rm -rf "+tmpdir) + os.makedirs(tmpdir) + xpakdata = xpak.getboth(xpakpath) + xpak.xpand(xpakdata,tmpdir) + try: + os.remove(xpakpath) + except: + pass + return tmpdir except: - pass - return tmpdir + return None def suckXpak(tbz2file, outputpath): entropyLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_VERBOSE,"suckXpak: called -> "+tbz2file+" and "+outputpath) @@ -956,10 +959,7 @@ def spliturl(url): def compressTarBz2(storepath,pathtocompress): cmd = "tar cjf "+storepath+" ." - rc = spawnCommand( - "cd "+pathtocompress+";" - ""+cmd, "&> /dev/null" - ) + rc = spawnCommand("cd "+pathtocompress+" && "+cmd, "&> /dev/null") return rc # tar.bz2 uncompress function... diff --git a/libraries/reagentTools.py b/libraries/reagentTools.py index fc29a02e9..622799dc3 100644 --- a/libraries/reagentTools.py +++ b/libraries/reagentTools.py @@ -904,229 +904,3 @@ def dependenciesTest(options): dbconn.closeDB() return 0,packagesNeeded,packagesNotFound - - -def smartapps(options): - - reagentLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_VERBOSE,"smartapps: called -> options: "+str(options)) - - if (len(options) == 0): - print_error(yellow(" * ")+red("No valid tool specified.")) - sys.exit(501) - - if (options[0] == "create"): - myopts = options[1:] - - if (len(myopts) == 0): - print_error(yellow(" * ")+red("No packages specified.")) - sys.exit(502) - - # open db - dbconn = databaseTools.openServerDatabase(readOnly = True, noUpload = True) - - # seek valid apps (in db) - validPackages = [] - for opt in myopts: - pkgsfound = dbconn.searchPackages(opt) - for pkg in pkgsfound: - validPackages.append(pkg) - - dbconn.closeDB() - - if (len(validPackages) == 0): - print_error(yellow(" * ")+red("No valid packages specified.")) - sys.exit(503) - - print_info(red(" @@ ")+blue("ATTENTION: you need to have equo.conf properly configured only for your running repository !!")) - sys.path.append('../client') - import equoTools - equoTools.syncRepositories() - - # print the list - print_info(green(" * ")+red("This is the list of the packages that would be worked out:")) - for pkg in validPackages: - print_info(green("\t[SMART] - ")+bold(pkg[0])) - - rc = askquestion(">> Would you like to create the packages above ?") - if rc == "No": - sys.exit(0) - - for pkg in validPackages: - print_info(green(" * ")+red("Creating smartapp package from ")+bold(pkg[0])) - smartgenerator(pkg) - - print_info(green(" * ")+red("Smartapps creation done, remember to test them before publishing.")) - - -# tool that generates .tar.bz2 packages with all the binary dependencies included -# @returns the package file path -# NOTE: this section is highly portage dependent -def smartgenerator(atomInfo): - - reagentLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_VERBOSE,"smartgenerator: called -> package: "+str(atomInfo)) - dbconn = databaseTools.openServerDatabase(readOnly = True, noUpload = True) - - sys.path.append('../client') - import equoTools - - idpackage = atomInfo[1] - atom = atomInfo[0] - - # check if the application package is available, otherwise, download - pkgfilepath = dbconn.retrieveDownloadURL(idpackage) - pkgcontent = dbconn.retrieveContent(idpackage) - pkgbranch = dbconn.retrieveBranch(idpackage) - pkgfilename = os.path.basename(pkgfilepath) - pkgname = pkgfilename.split(".tbz2")[0] - - pkgdependencies, result = equoTools.getRequiredPackages([[idpackage,etpConst['officialrepositoryname']]], emptydeps = True) - # flatten them - pkgs = [] - if (result == 0): - for x in range(len(pkgdependencies))[::-1]: - #print x - for a in pkgdependencies[x]: - pkgs.append(a) - elif (result == -2): - print_error(green(" * ")+red("Missing dependencies: ")+str(pkgdependencies)) - sys.exit(505) - elif (result == -1): - print_error(green(" * ")+red("Database file not found or no database connection. --> ")+str(pkgdependencies)) - sys.exit(506) - - print_info(green(" * ")+red("This is the list of the dependencies that would be included:")) - for i in pkgs: - atom = dbconn.retrieveAtom(i[0]) - print_info(green(" [] ")+red(atom)) - - # create the working directory - pkgtmpdir = etpConst['packagestmpdir']+"/"+pkgname - #print "DEBUG: "+pkgtmpdir - if os.path.isdir(pkgtmpdir): - spawnCommand("rm -rf "+pkgtmpdir) - mainBinaryPath = etpConst['packagesbindir']+"/"+pkgbranch+"/"+pkgfilename - print_info(green(" * ")+red("Unpacking main package ")+bold(str(pkgfilename))) - uncompressTarBz2(mainBinaryPath,pkgtmpdir) # first unpack - - binaryExecs = [] - for file in pkgcontent: - # remove / - filepath = pkgtmpdir+file - import commands - if os.access(filepath,os.X_OK): - # test if it's an exec - out = commands.getoutput("file "+filepath).split("\n")[0] - if out.find("LSB executable") != -1: - binaryExecs.append(file) - # check if file is executable - - - # now uncompress all the rest - for dep in pkgs: - download = os.path.basename(dbconn.retrieveDownloadURL(dep[0])) - depbranch = dbconn.retrieveBranch(dep[0]) - print_info(green(" * ")+red("Unpacking dependency package ")+bold(str(download))) - deppath = etpConst['packagesbindir']+"/"+depbranch+"/"+download - uncompressTarBz2(deppath,pkgtmpdir) # first unpack - - - # remove unwanted files (header files) - os.system('for file in `find '+contentdir+' -name "*.h"`; do rm $file; done') - - # now create the bash script for each binaryExecs - os.makedirs(contentdir+"/wrp") - bashScript = [] - bashScript.append( - '#!/bin/sh\n' - 'cd $1\n' - - 'MYPYP=$(find $PWD/lib/python2.4/site-packages/ -type d -printf %p: 2> /dev/null)\n' - 'MYPYP2=$(find $PWD/lib/python2.5/site-packages/ -type d -printf %p: 2> /dev/null)\n' - 'export PYTHONPATH=$MYPYP:MYPYP2:$PYTHONPATH\n' - - 'export PATH=$PWD:$PWD/sbin:$PWD/bin:$PWD/usr/bin:$PWD/usr/sbin:$PWD/usr/X11R6/bin:$PWD/libexec:$PWD/usr/local/bin:$PWD/usr/local/sbin:$PATH\n' - - 'export LD_LIBRARY_PATH=' - '$PWD/lib:' - '$PWD/lib64:' - '$PWD/usr/lib:' - '$PWD/usr/lib64:' - '$PWD/usr/lib/nss:' - '$PWD/usr/lib/nspr:' - '$PWD/usr/lib64/nss:' - '$PWD/usr/lib64/nspr:' - '$PWD/usr/qt/3/lib:' - '$PWD/usr/qt/3/lib64:' - '$PWD/usr/kde/3.5/lib:' - '$PWD/usr/kde/3.5/lib64:' - '$LD_LIBRARY_PATH\n' - - 'export KDEDIRS=$PWD/usr/kde/3.5:$PWD/usr:$KDEDIRS\n' - - 'export PERL5LIB=$PWD/usr/lib/perl5:$PWD/share/perl5:$PWD/usr/lib/perl5/5.8.1' - ':$PWD/usr/lib/perl5/5.8.2:' - ':$PWD/usr/lib/perl5/5.8.3:' - ':$PWD/usr/lib/perl5/5.8.4:' - ':$PWD/usr/lib/perl5/5.8.5:' - ':$PWD/usr/lib/perl5/5.8.6:' - ':$PWD/usr/lib/perl5/5.8.7:' - ':$PWD/usr/lib/perl5/5.8.8:' - ':$PWD/usr/lib/perl5/5.8.9:' - ':$PWD/usr/lib/perl5/5.8.10\n' - - 'export MANPATH=$PWD/share/man:$MANPATH\n' - 'export GUILE_LOAD_PATH=$PWD/share/:$GUILE_LOAD_PATH\n' - 'export SCHEME_LIBRARY_PATH=$PWD/share/slib:$SCHEME_LIBRARY_PATH\n' - - '# Setup pango\n' - 'MYPANGODIR=$(find $PWD/usr/lib/pango -name modules)\n' - 'if [ -n "$MYPANGODIR" ]; then\n' - ' export PANGO_RC_FILE=$PWD/etc/pango/pangorc\n' - ' echo "[Pango]" > $PANGO_RC_FILE\n' - ' echo "ModulesPath=${MYPANGODIR}" >> $PANGO_RC_FILE\n' - ' echo "ModuleFiles=${PWD}/etc/pango/pango.modules" >> $PANGO_RC_FILE\n' - ' pango-querymodules > ${PWD}/etc/pango/pango.modules\n' - 'fi\n' - '$2\n' - ) - f = open(contentdir+"/wrp/wrapper","w") - f.writelines(bashScript) - f.flush() - f.close() - # chmod - os.chmod(contentdir+"/wrp/wrapper",0755) - - - - # now list files in /sh and create .desktop files - for file in binaryExecs: - file = file.split("/")[len(file.split("/"))-1] - runFile = [] - runFile.append( - '#include \n' - '#include \n' - '#include \n' - 'int main() {\n' - ' int rc = system(\n' - ' "pid=$(pidof '+file+'.exe);"\n' - ' "listpid=$(ps x | grep $pid);"\n' - ' "filename=$(echo $listpid | cut -d\' \' -f 5);"' - ' "currdir=$(dirname $filename);"\n' - ' "/bin/sh $currdir/wrp/wrapper $currdir '+file+'" );\n' - ' return rc;\n' - '}\n' - ) - f = open(contentdir+"/"+file+".cc","w") - f.writelines(runFile) - f.flush() - f.close() - # now compile - spawnCommand("cd "+contentdir+"/ ; g++ -Wall "+file+".cc -o "+file+".exe") - os.remove(contentdir+"/"+file+".cc") - - # now compress in .tar.bz2 and place in etpConst['smartappsdir'] - #print etpConst['smartappsdir']+"/"+pkgname+"-"+etpConst['currentarch']+".tar.bz2" - #print pkgtmpdir+"/" - compressTarBz2(etpConst['smartappsdir']+"/"+pkgname+"-"+etpConst['currentarch']+".tbz2",contentdir+"/") - - dbconn.closeDB() \ No newline at end of file diff --git a/libraries/smartTools.py b/libraries/smartTools.py new file mode 100644 index 000000000..635fea689 --- /dev/null +++ b/libraries/smartTools.py @@ -0,0 +1,400 @@ +#!/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 os +import shutil +import string +from entropyConstants import * +from clientConstants import * +from outputTools import * +import entropyTools +import equoTools +from databaseTools import openClientDatabase, openRepositoryDatabase, openGenericDatabase + +def smart(options): + + # Options available for all the packages submodules + smartRequestEmpty = False + newopts = [] + for opt in options: + if (opt == "--empty"): + smartRequestEmpty = True + else: + newopts.append(opt) + options = newopts + + rc = 0 + if (options[0] == "application"): + rc = smartappsHandler(options[1:], emptydeps = smartRequestEmpty) + elif (options[0] == "package"): + rc = smartPackagesHanlder(options[1:]) + + return rc + + +def smartPackagesHanlder(mypackages): + + if (not mypackages): + print_error(darkred(" * ")+red("No packages specified.")) + return 1 + + packages = set() + for opt in mypackages: + match = equoTools.atomMatch(opt) + if match[0] != -1: + packages.add(match) + else: + print_warning(darkred(" * ")+red("Cannot find: ")+bold(opt)) + + if (not packages): + print_error(darkred(" * ")+red("No valid packages specified.")) + return 2 + + # print the list + print_info(darkgreen(" * ")+red("This is the list of the packages that would be merged into a single one:")) + pkgInfo = {} + for pkg in packages: + dbconn = openRepositoryDatabase(pkg[1]) + atom = dbconn.retrieveAtom(pkg[0]) + pkgInfo[pkg] = atom + print_info(brown("\t[")+red("from:")+pkg[1]+brown("]")+" - "+atom) + dbconn.closeDB() + + rc = entropyTools.askquestion(">> Would you like to create the packages above ?") + if rc == "No": + return 0 + + print_info(darkgreen(" * ")+red("Creating merged Smart Package...")) + rc = smartpackagegenerator(packages) + if rc != 0: + print_error(darkred(" * ")+red("Cannot continue.")) + return rc + + return 0 + + +def smartpackagegenerator(matchedPackages): + + fetchdata = [] + matchedAtoms = {} + for x in matchedPackages: + xdbconn = openRepositoryDatabase(x[1]) + matchedAtoms[x] = {} + xatom = xdbconn.retrieveAtom(x[0]) + xdownload = xdbconn.retrieveDownloadURL(x[0]) + xrevision = xdbconn.retrieveRevision(x[0]) + matchedAtoms[x]['atom'] = xatom + matchedAtoms[x]['download'] = xdownload + matchedAtoms[x]['revision'] = xrevision + fetchdata.append([xatom,x]) + xdbconn.closeDB() + # run installPackages with onlyfetch + rc = equoTools.installPackages(atomsdata = fetchdata, deps = False, onlyfetch = True) + if rc[1] != 0: + return rc[0] + + # create unpack dir and unpack all packages + unpackdir = etpConst['entropyunpackdir']+"/smartpackage-"+str(entropyTools.getRandomNumber()) + while os.path.isdir(unpackdir): + unpackdir = etpConst['entropyunpackdir']+"/smartpackage-"+str(entropyTools.getRandomNumber()) + if os.path.isdir(unpackdir): + shutil.rmtree(unpackdir) + os.makedirs(unpackdir) + os.mkdir(unpackdir+"/content") + os.mkdir(unpackdir+"/db") + # create master database + dbfile = unpackdir+"/db/merged.db" + mergeDbconn = openGenericDatabase(dbfile, dbname = "client") + mergeDbconn.initializeDatabase() + tmpdbfile = dbfile+"--readingdata" + for package in matchedPackages: + print_info(darkgreen(" * ")+brown(matchedAtoms[package]['atom'])+": "+red("collecting Entropy metadata")) + entropyTools.extractEdb(etpConst['entropyworkdir']+"/"+matchedAtoms[package]['download'],tmpdbfile) + # read db and add data to mergeDbconn + mydbconn = openGenericDatabase(tmpdbfile) + idpackages = mydbconn.listAllIdpackages() + for myidpackage in idpackages: + data = mydbconn.getPackageData(myidpackage) + # add + mergeDbconn.handlePackage(etpData = data, forcedRevision = matchedAtoms[package]['revision']) # get the original rev + mydbconn.closeDB() + os.remove(tmpdbfile) + + # now we have the new database + mergeDbconn.closeDB() + + # merge packages + for package in matchedPackages: + print_info(darkgreen(" * ")+brown(matchedAtoms[package]['atom'])+": "+red("unpacking content")) + rc = entropyTools.uncompressTarBz2(etpConst['entropyworkdir']+"/"+matchedAtoms[x]['download'], extractPath = unpackdir+"/content") + if rc != 0: + print_error(darkred(" * ")+red("Unpack failed due to unknown reasons.")) + return rc + + if not os.path.isdir(etpConst['smartpackagesdir']): + os.makedirs(etpConst['smartpackagesdir']) + print_info(darkgreen(" * ")+red("Compressing smart package")) + atoms = [] + for x in matchedAtoms: + atoms.append(matchedAtoms[x]['atom'].split("/")[1]) + atoms = string.join(atoms,"+") + rc = entropyTools.compressTarBz2(etpConst['smartpackagesdir']+"/"+atoms+".tbz2",unpackdir+"/content") + if rc != 0: + print_error(darkred(" * ")+red("Compress failed due to unknown reasons.")) + return rc + # adding entropy database + if not os.path.isfile(etpConst['smartpackagesdir']+"/"+atoms+".tbz2"): + print_error(darkred(" * ")+red("Compressed file does not exist.")) + return 1 + + entropyTools.aggregateEdb(etpConst['smartpackagesdir']+"/"+atoms+".tbz2",dbfile) + print_info("\t"+etpConst['smartpackagesdir']+"/"+atoms+".tbz2") + shutil.rmtree(unpackdir,True) + return 0 + + +def smartappsHandler(mypackages, emptydeps = False): + + if (not mypackages): + print_error(darkred(" * ")+red("No packages specified.")) + return 1 + + gplusplus = os.system("which g++ &> /dev/null") + if gplusplus != 0: + print_error(darkred(" * ")+red("Cannot find G++ compiler.")) + return gplusplus + + packages = set() + for opt in mypackages: + match = equoTools.atomMatch(opt) + if match[0] != -1: + packages.add(match) + else: + print_warning(darkred(" * ")+red("Cannot find: ")+bold(opt)) + + if (not packages): + print_error(darkred(" * ")+red("No valid packages specified.")) + return 2 + + # print the list + print_info(darkgreen(" * ")+red("This is the list of the packages that would be worked out:")) + pkgInfo = {} + for pkg in packages: + dbconn = openRepositoryDatabase(pkg[1]) + atom = dbconn.retrieveAtom(pkg[0]) + pkgInfo[pkg] = atom + print_info(brown("\t[")+red("from:")+pkg[1]+red("|SMART")+brown("]")+" - "+atom) + dbconn.closeDB() + + rc = entropyTools.askquestion(">> Would you like to create the packages above ?") + if rc == "No": + return 0 + + for pkg in packages: + print_info(darkgreen(" * ")+red("Creating Smart Application from ")+bold(pkgInfo[pkg])) + rc = smartgenerator(pkg, emptydeps = emptydeps) + if rc != 0: + print_error(darkred(" * ")+red("Cannot continue.")) + return rc + return 0 + +# tool that generates .tar.bz2 packages with all the binary dependencies included +def smartgenerator(atomInfo, emptydeps = False): + + dbconn = openRepositoryDatabase(atomInfo[1]) + idpackage = atomInfo[0] + atom = dbconn.retrieveAtom(idpackage) + + # check if the application package is available, otherwise, download + pkgfilepath = dbconn.retrieveDownloadURL(idpackage) + pkgcontent = dbconn.retrieveContent(idpackage) + pkgbranch = dbconn.retrieveBranch(idpackage) + pkgfilename = os.path.basename(pkgfilepath) + pkgname = pkgfilename.split(".tbz2")[0] + + pkgdependencies, result = equoTools.getRequiredPackages([atomInfo], emptydeps = emptydeps) + # flatten them + pkgs = [] + if (result == 0): + for x in range(len(pkgdependencies))[::-1]: + #print x + for a in pkgdependencies[x]: + pkgs.append(a) + else: + print_error(darkgreen(" * ")+red("Missing dependencies: ")) + for x in pkgdependencies: + print_error(darkgreen(" ## ")+str(x)) + return 1 + + pkgs = [x for x in pkgs if x != atomInfo] + if pkgs: + print_info(darkgreen(" * ")+red("This is the list of the dependencies that would be included:")) + for i in pkgs: + mydbconn = openRepositoryDatabase(i[1]) + atom = mydbconn.retrieveAtom(i[0]) + print_info(darkgreen(" (x) ")+red(atom)) + mydbconn.closeDB() + + fetchdata = [] + fetchdata.append([atom,atomInfo]) + for x in pkgs: + xdbconn = openRepositoryDatabase(x[1]) + xatom = xdbconn.retrieveAtom(x[0]) + fetchdata.append([xatom,x]) + xdbconn.closeDB() + # run installPackages with onlyfetch + rc = equoTools.installPackages(atomsdata = fetchdata, deps = False, onlyfetch = True) + if rc[1] != 0: + return rc[0] + + # create the working directory + pkgtmpdir = etpConst['entropyunpackdir']+"/"+pkgname + #print "DEBUG: "+pkgtmpdir + if os.path.isdir(pkgtmpdir): + shutil.rmtree(pkgtmpdir) + os.makedirs(pkgtmpdir) + mainBinaryPath = etpConst['packagesbindir']+"/"+pkgbranch+"/"+pkgfilename + print_info(darkgreen(" * ")+red("Unpacking main package ")+bold(str(pkgfilename))) + entropyTools.uncompressTarBz2(mainBinaryPath,pkgtmpdir) # first unpack + + binaryExecs = [] + for file in pkgcontent: + # remove / + filepath = pkgtmpdir+file + import commands + if os.access(filepath,os.X_OK): + # test if it's an exec + out = commands.getoutput("file "+filepath).split("\n")[0] + if out.find("LSB executable") != -1: + binaryExecs.append(file) + # check if file is executable + + # now uncompress all the rest + for dep in pkgs: + mydbconn = openRepositoryDatabase(dep[1]) + download = os.path.basename(mydbconn.retrieveDownloadURL(dep[0])) + depbranch = mydbconn.retrieveBranch(dep[0]) + depatom = mydbconn.retrieveAtom(dep[0]) + print_info(darkgreen(" * ")+red("Unpacking dependency package ")+bold(depatom)) + deppath = etpConst['packagesbindir']+"/"+depbranch+"/"+download + entropyTools.uncompressTarBz2(deppath,pkgtmpdir) # first unpack + mydbconn.closeDB() + + + # remove unwanted files (header files) + os.system('for file in `find '+pkgtmpdir+' -name "*.h"`; do rm $file; done') + + # now create the bash script for each binaryExecs + os.makedirs(pkgtmpdir+"/wrp") + bashScript = [] + bashScript.append( + '#!/bin/sh\n' + 'cd $1\n' + + 'MYPYP=$(find $PWD/lib/python2.4/site-packages/ -type d -printf %p: 2> /dev/null)\n' + 'MYPYP2=$(find $PWD/lib/python2.5/site-packages/ -type d -printf %p: 2> /dev/null)\n' + 'export PYTHONPATH=$MYPYP:MYPYP2:$PYTHONPATH\n' + + 'export PATH=$PWD:$PWD/sbin:$PWD/bin:$PWD/usr/bin:$PWD/usr/sbin:$PWD/usr/X11R6/bin:$PWD/libexec:$PWD/usr/local/bin:$PWD/usr/local/sbin:$PATH\n' + + 'export LD_LIBRARY_PATH=' + '$PWD/lib:' + '$PWD/lib64:' + '$PWD/usr/lib:' + '$PWD/usr/lib64:' + '$PWD/usr/lib/nss:' + '$PWD/usr/lib/nspr:' + '$PWD/usr/lib64/nss:' + '$PWD/usr/lib64/nspr:' + '$PWD/usr/qt/3/lib:' + '$PWD/usr/qt/3/lib64:' + '$PWD/usr/kde/3.5/lib:' + '$PWD/usr/kde/3.5/lib64:' + '$LD_LIBRARY_PATH\n' + + 'export KDEDIRS=$PWD/usr/kde/3.5:$PWD/usr:$KDEDIRS\n' + + 'export PERL5LIB=$PWD/usr/lib/perl5:$PWD/share/perl5:$PWD/usr/lib/perl5/5.8.1' + ':$PWD/usr/lib/perl5/5.8.2:' + ':$PWD/usr/lib/perl5/5.8.3:' + ':$PWD/usr/lib/perl5/5.8.4:' + ':$PWD/usr/lib/perl5/5.8.5:' + ':$PWD/usr/lib/perl5/5.8.6:' + ':$PWD/usr/lib/perl5/5.8.7:' + ':$PWD/usr/lib/perl5/5.8.8:' + ':$PWD/usr/lib/perl5/5.8.9:' + ':$PWD/usr/lib/perl5/5.8.10\n' + + 'export MANPATH=$PWD/share/man:$MANPATH\n' + 'export GUILE_LOAD_PATH=$PWD/share/:$GUILE_LOAD_PATH\n' + 'export SCHEME_LIBRARY_PATH=$PWD/share/slib:$SCHEME_LIBRARY_PATH\n' + + '# Setup pango\n' + 'MYPANGODIR=$(find $PWD/usr/lib/pango -name modules)\n' + 'if [ -n "$MYPANGODIR" ]; then\n' + ' export PANGO_RC_FILE=$PWD/etc/pango/pangorc\n' + ' echo "[Pango]" > $PANGO_RC_FILE\n' + ' echo "ModulesPath=${MYPANGODIR}" >> $PANGO_RC_FILE\n' + ' echo "ModuleFiles=${PWD}/etc/pango/pango.modules" >> $PANGO_RC_FILE\n' + ' pango-querymodules > ${PWD}/etc/pango/pango.modules\n' + 'fi\n' + '$2\n' + ) + f = open(pkgtmpdir+"/wrp/wrapper","w") + f.writelines(bashScript) + f.flush() + f.close() + # chmod + os.chmod(pkgtmpdir+"/wrp/wrapper",0755) + + # now list files in /sh and create .desktop files + for file in binaryExecs: + file = file.split("/")[len(file.split("/"))-1] + runFile = [] + runFile.append( + '#include \n' + '#include \n' + '#include \n' + 'int main() {\n' + ' int rc = system(\n' + ' "pid=$(pidof '+file+'.exe);"\n' + ' "listpid=$(ps x | grep $pid);"\n' + ' "filename=$(echo $listpid | cut -d\' \' -f 5);"' + ' "currdir=$(dirname $filename);"\n' + ' "/bin/sh $currdir/wrp/wrapper $currdir '+file+'" );\n' + ' return rc;\n' + '}\n' + ) + f = open(pkgtmpdir+"/"+file+".cc","w") + f.writelines(runFile) + f.flush() + f.close() + # now compile + entropyTools.spawnCommand("cd "+pkgtmpdir+"/ ; g++ -Wall "+file+".cc -o "+file+".exe") + os.remove(pkgtmpdir+"/"+file+".cc") + + smartpath = etpConst['smartappsdir']+"/"+pkgname+"-"+etpConst['currentarch']+".tbz2" + print_info(darkgreen(" * ")+red("Compressing smart application: ")+bold(atom)) + print_info("\t"+smartpath) + entropyTools.compressTarBz2(smartpath,pkgtmpdir+"/") + shutil.rmtree(pkgtmpdir,True) + + return 0 \ No newline at end of file diff --git a/server/reagent b/server/reagent index 88b1c530a..71a101b82 100644 --- a/server/reagent +++ b/server/reagent @@ -57,8 +57,6 @@ def print_help(): print_info(" \t"+green("deptest")+yellow("\t\t Look for unsatisfied dependencies inside database")) print_info(" \t"+green("depends")+yellow("\t\t Regenerate depends table (plus database lock and bump)")) print_info(" \t\t"+red("--quiet")+"\t\t\t\t just print the dependencies list") - print_info(" \t"+green("smartapps")+yellow("\t Entropy application tool to create self-dependant applications [EXPERIMENTAL]")) - print_info(" \t\t"+green("create")+"\t\t\t\t Create a smartapp package using the package names provided") print_info(" \t"+green("cleanup")+yellow("\t\t to clean temporary files")) options = sys.argv[1:] @@ -111,11 +109,6 @@ elif (options[0] == "database"): databaseTools.database(options[1:]) sys.exit(0) -# smartapps tool -elif (options[0] == "smartapps"): - reagentTools.smartapps(options[1:]) - sys.exit(0) - # deptest tool elif (options[0] == "deptest"): reagentTools.dependenciesTest(options[1:])