introducing smart applications and smart packages
git-svn-id: http://svn.sabayonlinux.org/projects/entropy/trunk@646 cd1c1023-2f26-0410-ae45-c471fc1f0318
This commit is contained in:
@@ -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 <cstdlib>\n'
|
||||
'#include <cstdio>\n'
|
||||
'#include <stdio.h>\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()
|
||||
Reference in New Issue
Block a user