def generateNSISInstaller(self): """ runs makensis to generate the installer itself """ self.isNsisInstalled() self._setDefaults() if not self.defines["icon"] == "": self.defines[ "icon"] = "!define MUI_ICON \"%s\"" % self.defines["icon"] # make absolute path for output file if not os.path.isabs(self.defines["setupname"]): dstpath = self.packageDestinationDir() self.defines["setupname"] = os.path.join(dstpath, self.defines["setupname"]) definestring = "" for key in self.defines: definestring += " /D%s=\"%s\"" % (key, self.defines[key]) EmergeDebug.new_line() EmergeDebug.debug("generating installer %s" % self.defines["setupname"]) verboseString = "/V4" if EmergeDebug.verbose() > 0 else "/V3" if self.isNsisInstalled: if not utils.systemWithoutShell( "\"%s\" %s %s %s" % (self.nsisExe, verboseString, definestring, self.scriptname), cwd=os.path.abspath(self.packageDir())): EmergeDebug.die("Error in makensis execution")
def getVCRedistLocation(self, compiler): _file = None if compiler.isMSVC2015(): if compiler.isX64(): _file = os.path.join( self.getVCRuntimeLibrariesLocation(), "1033", "vcredist_x64.exe" ) elif compiler.isX86(): _file = os.path.join( self.getVCRuntimeLibrariesLocation(), "1033", "vcredist_x86.exe" ) if not os.path.isfile(_file): _file = None EmergeDebug.new_line() EmergeDebug.error("Assuming we can't find a c++ redistributable because the user hasn't got one. Must be fixed manually.") return _file
def getVCRedistLocation(self, compiler): _file = None if compiler.isMSVC2015(): if compiler.isX64(): _file = os.path.join(self.getVCRuntimeLibrariesLocation(), "1033", "vcredist_x64.exe") elif compiler.isX86(): _file = os.path.join(self.getVCRuntimeLibrariesLocation(), "1033", "vcredist_x86.exe") if not os.path.isfile(_file): _file = None EmergeDebug.new_line() EmergeDebug.error( "Assuming we can't find a c++ redistributable because the user hasn't got one. Must be fixed manually." ) return _file
def generateNSISInstaller( self ): """ runs makensis to generate the installer itself """ self.isInstalled() if self.package.endswith( "-package" ): shortPackage = self.package[ : -8 ] else: shortPackage = self.package if not "setupname" in self.defines or not self.defines[ "setupname" ]: self.defines[ "setupname" ] = "%s-%s-setup-%s.exe" % ( shortPackage, compiler.architecture(), self.buildTarget ) if not "srcdir" in self.defines or not self.defines[ "srcdir" ]: self.defines[ "srcdir" ] = self.imageDir() if not "company" in self.defines or not self.defines[ "company" ]: self.defines[ "company" ] = "KDE" if not "productname" in self.defines or not self.defines[ "productname" ]: self.defines[ "productname" ] = shortPackage.capitalize() if not "version" in self.defines or not self.defines[ "version" ]: self.defines[ "version" ] = self.buildTarget if not "executable" in self.defines or not self.defines[ "executable" ]: self.defines[ "executable" ] = "" if "license" in self.defines and self.defines[ "license" ]: self.defines[ "license" ] = "!insertmacro MUI_PAGE_LICENSE \"%s\"" % self.defines[ "license" ] else: self.defines[ "license" ] = "" if "icon" in self.defines and self.defines[ "icon" ]: self.defines[ "icon" ] = "!define MUI_ICON \"%s\"" % self.defines[ "icon" ] else: self.defines[ "icon" ] = "" if not self.scriptname: self.scriptname = os.path.join( os.path.dirname( __file__ ), "NullsoftInstaller.nsi" ) self.defines[ "architecture" ] = compiler.architecture() # make absolute path for output file if not os.path.isabs( self.defines[ "setupname" ] ): dstpath = self.packageDestinationDir() self.defines[ "setupname" ] = os.path.join( dstpath, self.defines[ "setupname" ] ) definestring = "" for key in self.defines: definestring += " /D" + key + "=\"" + self.defines[ key ] + "\"" EmergeDebug.new_line() EmergeDebug.debug("generating installer %s" % self.defines["setupname"]) if self.isInstalled: if not utils.systemWithoutShell( "\"%s\" %s %s" % ( os.path.join( self.nsisInstallPath, 'makensis.exe' ), definestring, self.scriptname ), cwd = os.path.abspath( self.packageDir() ) ): EmergeDebug.die("Error in makensis execution")
def generateMSInstaller(self): """ runs tools to generate the installer itself """ shortPackage = self.package if not "setupname" in self.defines or not self.defines["setupname"]: self.defines["setupname"] = "%s-setup-%s.msi" % (shortPackage, self.buildTarget) if not "srcdir" in self.defines or not self.defines["srcdir"]: self.defines["srcdir"] = self.imageDir() if not "company" in self.defines or not self.defines["company"]: self.defines["company"] = "KDE" if not "productname" in self.defines or not self.defines["productname"]: self.defines["productname"] = "%s %s" % (shortPackage.capitalize(), self.buildTarget) if not "executable" in self.defines or not self.defines["executable"]: self.defines["executable"] = "" if not "productuid" in self.defines or not self.defines["productuid"]: m = hashlib.md5() m.update(self.defines["productname"]) m.update(self.defines["setupname"]) self.defines["productuid"] = str(uuid.UUID(hex=m.hexdigest())) print(self.defines["productuid"]) if not "upgradeuid" in self.defines or not self.defines["upgradeuid"]: self.defines["upgradeuid"] = str(uuid.uuid4()) if not "componentuid" in self.defines or not self.defines[ "componentuid"]: self.defines["componentuid"] = str(uuid.uuid4()) if not self.scriptname: self.scriptname = os.path.join(os.path.dirname(__file__), "MSInstaller.wxs.template") # make absolute path for output file if not os.path.isabs(self.defines["setupname"]): dstpath = self.packageDestinationDir() self.defines["setupname"] = os.path.join(dstpath, self.defines["setupname"]) EmergeDebug.new_line() EmergeDebug.debug("generating installer %s" % self.defines["setupname"]) wxs = Document() componentRefs = Document() rootObject = wxs.createElement("Directory") componentRoot = componentRefs.createElement("Feature") objectDict = dict() objectDict[self.imageDir()] = rootObject rootObject.setAttribute( "Id", self.__getUniqueIdString(self.defines["productname"])) rootObject.setAttribute("Name", self.defines["productname"]) componentRoot.setAttribute("Id", "DefaultFeature") componentRoot.setAttribute("Title", "default feature") componentRoot.setAttribute("Level", "1") for root, dirs, files in os.walk(self.imageDir()): if root == self.imageDir(): continue if files or dirs: currentDirectory = wxs.createElement("Directory") currentDirectory.setAttribute( "Id", self.__getUniqueIdString(os.path.basename(root))) currentDirectory.setAttribute("Name", os.path.basename(root)) objectDict[os.path.dirname(root)].appendChild(currentDirectory) objectDict[root] = currentDirectory # components could be used to create updateable packages according to current # emerge packaging for _f in files: _fileId = self.__getUniqueIdString(_f) currentComponent = wxs.createElement("Component") currentComponent.setAttribute("Id", _fileId) currentComponent.setAttribute("Guid", str(uuid.uuid4())) currentDirectory.appendChild(currentComponent) currentComponentRef = componentRefs.createElement( "ComponentRef") currentComponentRef.setAttribute("Id", _fileId) componentRoot.appendChild(currentComponentRef) currentFile = wxs.createElement("File") currentFile.setAttribute("Id", _fileId) currentFile.setAttribute( "Source", os.path.join("SourceDir", os.path.relpath(root, self.imageDir()), _f)) currentComponent.appendChild(currentFile) if self.scriptname.endswith(".template"): outName = os.path.join(self.buildDir(), os.path.basename(self.scriptname)[:-9]) else: outName = os.path.join(self.buildDir(), self.scriptname) out = open(outName, 'w') filelistString = StringIO() componentlistString = StringIO() rootObject.writexml(filelistString, " " * 16, " ", "\n") componentRoot.writexml(componentlistString, " " * 8, " ", "\n") self.defines["filelist"] = filelistString.getvalue() self.defines["componentlist"] = componentlistString.getvalue() filelistString.close() componentlistString.close() templateFile = open(self.scriptname, 'r') scriptTemplate = Template(templateFile.read()) substitutedScript = scriptTemplate.safe_substitute(self.defines) out.write(substitutedScript) out.close() utils.system("candle -o %s.wixobj %s" % (outName, outName)) utils.system("light -b %s -o %s %s.wixobj" % (self.imageDir(), os.path.join(self.packageDir(), self.defines["setupname"]), outName))
def handleSinglePackage(packageName, action, args): deplist = [] packageList = [] originalPackageList = [] categoryList = [] targetDict = dict() if action == "update-all": installedPackages = portage.PortageInstance.getInstallables() if portage.PortageInstance.isCategory(packageName): EmergeDebug.debug( "Updating installed packages from category " + packageName, 1) else: EmergeDebug.debug("Updating all installed packages", 1) packageList = [] for mainCategory, mainPackage in installedPackages: if portage.PortageInstance.isCategory(packageName) and ( mainCategory != packageName): continue if InstallDB.installdb.isInstalled( mainCategory, mainPackage, args.buildType ) \ and portage.isPackageUpdateable( mainCategory, mainPackage ): categoryList.append(mainCategory) packageList.append(mainPackage) EmergeDebug.debug("Will update packages: " + str(packageList), 1) elif args.list_file: listFileObject = open(args.list_file, 'r') for line in listFileObject: if line.strip().startswith('#'): continue try: cat, pac, tar, _ = line.split(',') except: continue categoryList.append(cat) packageList.append(pac) originalPackageList.append(pac) targetDict[cat + "/" + pac] = tar elif packageName: packageList, categoryList = portage.getPackagesCategories(packageName) for entry in packageList: EmergeDebug.debug("Checking dependencies for: %s" % entry, 1) for mainCategory, entry in zip(categoryList, packageList): deplist = portage.solveDependencies(mainCategory, entry, deplist, args.dependencyType, maxDepth=args.dependencydepth) # no package found if len(deplist) == 0: category = "" if not packageName.find("/") == -1: (category, package) = packageName.split("/") portageSearch.printSearch(category, packageName) return False for item in deplist: item.enabled = args.ignoreAllInstalled if args.ignoreInstalled and item.category in categoryList and item.package in packageList or packageIsOutdated( item.category, item.package): item.enabled = True if item.category + "/" + item.package in targetDict: item.target = targetDict[item.category + "/" + item.package] if args.target in list( portage.PortageInstance.getAllTargets(item.category, item.package).keys()): # if no target or a wrong one is defined, simply set the default target here item.target = args.target EmergeDebug.debug("dependency: %s" % item, 1) if not deplist: EmergeDebug.debug("<none>", 1) EmergeDebug.debug_line(1) #for item in deplist: # cat = item[ 0 ] # pac = item[ 1 ] # ver = item[ 2 ] # if portage.isInstalled( cat, pac, ver, buildType) and updateAll and not portage.isPackageUpdateable( cat, pac, ver ): # print "remove:", cat, pac, ver # deplist.remove( item ) if action == "install-deps": # the first dependency is the package itself - ignore it # TODO: why are we our own dependency? del deplist[0] elif action == "update-direct-deps": for item in deplist: item.enabled = True deplist.reverse() # package[0] -> category # package[1] -> package # package[2] -> version info = deplist[-1] if not portage.PortageInstance.isVirtualPackage( info.category, info.package ) and \ not action in [ "all", "install-deps"] and\ not args.list_file or\ action in ["print-targets"]:#not all commands should be executed on the deps if we are a virtual packages # if a buildAction is given, then do not try to build dependencies # and do the action although the package might already be installed. # This is still a bit problematic since packageName might not be a valid # package # for list files, we also want to handle fetching & packaging per package if not handlePackage(info.category, info.package, action, args.doContinue, args.update_fast): return False else: if args.dumpDepsFile: dumpDepsFileObject = open(args.dumpDepsFile, 'w+') dumpDepsFileObject.write("# dependency dump of package %s\n" % (packageName)) for info in deplist: isVCSTarget = False if args.dumpDepsFile: dumpDepsFileObject.write( ",".join([info.category, info.package, info.target, ""]) + "\n") isLastPackage = info == deplist[-1] if args.outDateVCS or (args.outDatePackage and isLastPackage): isVCSTarget = portage.PortageInstance.getUpdatableVCSTargets( info.category, info.package) != [] isInstalled = InstallDB.installdb.isInstalled( info.category, info.package) if args.list_file and action != "all": info.enabled = info.package in originalPackageList if (isInstalled and not info.enabled) and not ( isInstalled and (args.outDateVCS or (args.outDatePackage and isLastPackage)) and isVCSTarget): if EmergeDebug.verbose() > 1 and info.package == packageName: EmergeDebug.warning("already installed %s/%s" % (info.category, info.package)) elif EmergeDebug.verbose( ) > 2 and not info.package == packageName: EmergeDebug.warning("already installed %s/%s" % (info.category, info.package)) else: # in case we only want to see which packages are still to be build, simply return the package name if args.probe: EmergeDebug.warning("pretending %s" % info) else: if action in ["install-deps", "update-direct-deps"]: action = "all" if not handlePackage(info.category, info.package, action, args.doContinue, args.update_fast): EmergeDebug.error("fatal error: package %s/%s %s failed" % \ ( info.category, info.package, action )) return False EmergeDebug.new_line() return True
def main(): """ Testing the class""" # add two databases tempdbpath1 = os.path.join( EmergeStandardDirs.emergeRoot(), "tmp", "temp1.db" ) tempdbpath2 = os.path.join( EmergeStandardDirs.emergeRoot(), "tmp", "temp2.db" ) if not os.path.exists( os.path.join( EmergeStandardDirs.emergeRoot(), "tmp" ) ): os.makedirs( os.path.join( EmergeStandardDirs.emergeRoot(), "tmp" ) ) if os.path.exists( tempdbpath1 ): os.remove( tempdbpath1 ) if os.path.exists( tempdbpath2 ): os.remove( tempdbpath2 ) db_temp = InstallDB( tempdbpath1 ) db = InstallDB( tempdbpath2 ) EmergeDebug.debug('testing installation database') # in case the package is still installed, remove it first silently if db.isInstalled( 'win32libs', 'dbus-src', '1.4.0' ): packageList = db.getInstalledPackages( 'win32libs', 'dbus-src' ) # really commit uninstall for package in packageList: package.uninstall() EmergeDebug.debug_line() EmergeDebug.new_line() # add a package EmergeDebug.debug('installing package win32libs/dbus-src-1.4.0 (release)') package = db.addInstalled( 'win32libs', 'dbus-src', '1.4.0', 'release' ) package.addFiles( dict().fromkeys( [ 'test', 'test1', 'test2' ], 'empty hash' ) ) # now really commit the package package.install() # add another package in a different prefix EmergeDebug.debug('installing package win32libs/dbus-src-1.4.0 (debug)') package = db.addInstalled( 'win32libs', 'dbus-src', '1.4.0', 'debug' ) package.addFiles( dict().fromkeys( [ 'test', 'test1', 'test2' ], 'empty hash' ) ) # now really commit the package package.install() EmergeDebug.debug_line() EmergeDebug.new_line() EmergeDebug.debug('checking installed packages') EmergeDebug.debug('get installed package (release): %s' % db.getInstalled('win32libs', 'dbus-src', 'release')) EmergeDebug.debug('get installed package (debug): %s' % db.getInstalled('win32libs', 'dbus-src', 'debug')) EmergeDebug.new_line() EmergeDebug.debug('now trying to remove package & revert it again later') # remove the package again packageList = db.getInstalledPackages( 'win32libs', 'dbus-src' ) for pac in packageList: for line in pac.getFiles(): # pylint: disable=W0612 # we could remove the file here # print line pass EmergeDebug.debug_line() EmergeDebug.new_line() EmergeDebug.debug('checking installed packages') EmergeDebug.debug('get installed package (release): %s' % db.getInstalled('win32libs', 'dbus-src', 'release')) EmergeDebug.debug('get installed package (debug): %s' % db.getInstalled('win32libs', 'dbus-src', 'debug')) EmergeDebug.debug_line() EmergeDebug.new_line() EmergeDebug.debug('reverting removal') # now instead of completing the removal, revert it for pac in packageList: pac.revert() EmergeDebug.debug('checking installed packages') EmergeDebug.debug('get installed package (release): %s' % db.getInstalled('win32libs', 'dbus-src', 'release')) EmergeDebug.debug('get installed package (debug): %s' % db.getInstalled('win32libs', 'dbus-src', 'debug')) EmergeDebug.debug_line() db.getInstalled() db.getInstalled( category='win32libs', prefix='debug' ) db.getInstalled( package='dbus-src' ) EmergeDebug.new_line() EmergeDebug.debug('now really remove the package') packageList = db.getInstalledPackages( 'win32libs', 'dbus-src' ) for pac in packageList: EmergeDebug.debug('removing %s files' % len(pac.getFilesWithHashes())) pac.uninstall() EmergeDebug.debug('get installed package (release): %s' % db.getInstalled('win32libs', 'dbus-src', 'release')) EmergeDebug.debug('get installed package (debug): %s' % db.getInstalled('win32libs', 'dbus-src', 'debug')) EmergeDebug.debug_line() # test the import from the old style (manifest based) databases EmergeDebug.new_line() print("getInstalled:", db_temp.getInstalled())
def handleSinglePackage( packageName, action, args ): deplist = [ ] packageList = [ ] originalPackageList = [ ] categoryList = [ ] targetDict = dict( ) if action == "update-all": installedPackages = portage.PortageInstance.getInstallables( ) if portage.PortageInstance.isCategory( packageName ): EmergeDebug.debug("Updating installed packages from category " + packageName, 1) else: EmergeDebug.debug("Updating all installed packages", 1) packageList = [ ] for mainCategory, mainPackage in installedPackages: if portage.PortageInstance.isCategory( packageName ) and ( mainCategory != packageName ): continue if InstallDB.installdb.isInstalled( mainCategory, mainPackage, args.buildType ) \ and portage.isPackageUpdateable( mainCategory, mainPackage ): categoryList.append( mainCategory ) packageList.append( mainPackage ) EmergeDebug.debug("Will update packages: " + str(packageList), 1) elif args.list_file: listFileObject = open( args.list_file, 'r' ) for line in listFileObject: if line.strip( ).startswith( '#' ): continue try: cat, pac, tar, _ = line.split( ',' ) except: continue categoryList.append( cat ) packageList.append( pac ) originalPackageList.append( pac ) targetDict[ cat + "/" + pac ] = tar elif packageName: packageList, categoryList = portage.getPackagesCategories( packageName ) for entry in packageList: EmergeDebug.debug("Checking dependencies for: %s" % entry, 1) for mainCategory, entry in zip( categoryList, packageList ): deplist = portage.solveDependencies( mainCategory, entry, deplist, args.dependencyType, maxDepth = args.dependencydepth ) # no package found if len( deplist ) == 0: category = "" if not packageName.find( "/" ) == -1: (category, package) = packageName.split( "/" ) portageSearch.printSearch( category, packageName ) return False for item in deplist: item.enabled = args.ignoreAllInstalled if args.ignoreInstalled and item.category in categoryList and item.package in packageList or packageIsOutdated( item.category, item.package ): item.enabled = True if item.category + "/" + item.package in targetDict: item.target = targetDict[ item.category + "/" + item.package ] if args.target in list( portage.PortageInstance.getAllTargets( item.category, item.package ).keys( ) ): # if no target or a wrong one is defined, simply set the default target here item.target = args.target EmergeDebug.debug("dependency: %s" % item, 1) if not deplist: EmergeDebug.debug("<none>", 1) EmergeDebug.debug_line(1) #for item in deplist: # cat = item[ 0 ] # pac = item[ 1 ] # ver = item[ 2 ] # if portage.isInstalled( cat, pac, ver, buildType) and updateAll and not portage.isPackageUpdateable( cat, pac, ver ): # print "remove:", cat, pac, ver # deplist.remove( item ) if action == "install-deps": # the first dependency is the package itself - ignore it # TODO: why are we our own dependency? del deplist[ 0 ] elif action == "update-direct-deps": for item in deplist: item.enabled = True deplist.reverse( ) # package[0] -> category # package[1] -> package # package[2] -> version info = deplist[ -1 ] if not portage.PortageInstance.isVirtualPackage( info.category, info.package ) and \ not action in [ "all", "install-deps" ,"generate-jenkins-job"] and\ not args.list_file or\ action in ["print-targets"]:#not all commands should be executed on the deps if we are a virtual packages # if a buildAction is given, then do not try to build dependencies # and do the action although the package might already be installed. # This is still a bit problematic since packageName might not be a valid # package # for list files, we also want to handle fetching & packaging per package if not handlePackage( info.category, info.package, action, args.doContinue, args.update_fast ): utils.notify( "Emerge %s failed" % action, "%s of %s/%s failed" % ( action, info.category, info.package), action ) return False utils.notify( "Emerge %s finished" % action, "%s of %s/%s finished" % ( action, info.category, info.package), action ) else: if args.dumpDepsFile: dumpDepsFileObject = open( args.dumpDepsFile, 'w+' ) dumpDepsFileObject.write( "# dependency dump of package %s\n" % ( packageName ) ) for info in deplist: isVCSTarget = False if args.dumpDepsFile: dumpDepsFileObject.write( ",".join( [ info.category, info.package, info.target, "" ] ) + "\n" ) isLastPackage = info == deplist[ -1 ] if args.outDateVCS or (args.outDatePackage and isLastPackage): isVCSTarget = portage.PortageInstance.getUpdatableVCSTargets( info.category, info.package ) != [ ] isInstalled = InstallDB.installdb.isInstalled( info.category, info.package ) if args.list_file and action != "all": info.enabled = info.package in originalPackageList if ( isInstalled and not info.enabled ) and not ( isInstalled and (args.outDateVCS or ( args.outDatePackage and isLastPackage) ) and isVCSTarget ): if EmergeDebug.verbose() > 1 and info.package == packageName: EmergeDebug.warning("already installed %s/%s" % (info.category, info.package)) elif EmergeDebug.verbose() > 2 and not info.package == packageName: EmergeDebug.warning("already installed %s/%s" % (info.category, info.package)) else: # in case we only want to see which packages are still to be build, simply return the package name if args.probe: if EmergeDebug.verbose() > 0: EmergeDebug.warning("pretending %s" % info) else: if action in [ "install-deps", "update-direct-deps" ]: action = "all" if not handlePackage( info.category, info.package, action, args.doContinue, args.update_fast ): EmergeDebug.error("fatal error: package %s/%s %s failed" % \ ( info.category, info.package, action )) utils.notify( "Emerge build failed", "Build of %s/%s failed" % ( info.category, info.package), action ) return False utils.notify( "Emerge build finished", "Build of %s/%s finished" % ( info.category, info.package), action ) EmergeDebug.new_line() return True
def generateNSISInstaller( self ): """ runs makensis to generate the installer itself """ self.isInstalled() if not self.scriptname: self.scriptname = os.path.join( os.path.dirname( __file__ ), "NullsoftInstaller.nsi" ) if self.package.endswith( "-package" ): shortPackage = self.package[ : -8 ] else: shortPackage = self.package if not "setupname" in self.defines or not self.defines[ "setupname" ]: self.defines[ "setupname" ] = "%s-%s-setup-%s.exe" % ( shortPackage, compiler.architecture(), self.buildTarget ) if not "srcdir" in self.defines or not self.defines[ "srcdir" ]: self.defines[ "srcdir" ] = self.archiveDir() if not "company" in self.defines or not self.defines[ "company" ]: self.defines[ "company" ] = "KDE" if not "productname" in self.defines or not self.defines[ "productname" ]: self.defines[ "productname" ] = shortPackage.capitalize() if not "version" in self.defines or not self.defines[ "version" ]: self.defines[ "version" ] = self.buildTarget if not "executable" in self.defines or not self.defines[ "executable" ]: self.defines[ "executable" ] = "" if "license" in self.defines and self.defines[ "license" ]: self.defines[ "license" ] = "!insertmacro MUI_PAGE_LICENSE \"%s\"" % self.defines[ "license" ] else: self.defines[ "license" ] = "" if "icon" in self.defines and self.defines[ "icon" ]: self.defines[ "icon" ] = "!define MUI_ICON \"%s\"" % self.defines[ "icon" ] else: self.defines[ "icon" ] = "" self.defines[ "architecture" ] = compiler.architecture() self.defines[ "defaultinstdir" ] = "$PROGRAMFILES64" if compiler.isX64() else "$PROGRAMFILES" # runtime distributable files self.defines[ "vcredist" ] = self.getVCRedistLocation(compiler) if not self.defines[ "vcredist" ]: self.defines[ "vcredist" ] = "none" # for earlier versions of MSVC, simply copy the redist files to the "bin" folder of the installation if compiler.isMSVC(): if compiler.isX64(): redistPath = os.path.join( os.path.join( self.getVCRuntimeLibrariesLocation(), "x64" ) ) else: redistPath = os.path.join( os.path.join( self.getVCRuntimeLibrariesLocation(), "x86" ) ) for root, subdirs, files in os.walk( redistPath ): for f in files: shutil.copy( os.path.join( root, f ), os.path.join( self.archiveDir(), "bin" ) ) elif compiler.isMinGW(): for f in glob.glob( os.path.join( self.rootdir, "mingw", "bin", "*.dll") ): shutil.copy( f, os.path.join( self.archiveDir(), "bin" ) ) else: EmergeDebug.die( "Fixme: Copy runtime libraries for this compiler" ) # make absolute path for output file if not os.path.isabs( self.defines[ "setupname" ] ): dstpath = self.packageDestinationDir() self.defines[ "setupname" ] = os.path.join( dstpath, self.defines[ "setupname" ] ) definestring = "" for key in self.defines: definestring += " /D" + key + "=\"" + self.defines[ key ] + "\"" EmergeDebug.new_line() EmergeDebug.debug("generating installer %s" % self.defines["setupname"]) verboseString = "/V4" if EmergeDebug.verbose() > 0 else "/V3" if self.isInstalled: makensisExe = os.path.join(self.nsisInstallPath, 'makensis.exe') if not utils.systemWithoutShell( "\"%s\" %s %s %s" % (makensisExe, verboseString, definestring, self.scriptname ), cwd = os.path.abspath( self.packageDir() ) ): EmergeDebug.die("Error in makensis execution")
def generateNSISInstaller(self): """ runs makensis to generate the installer itself """ self.isInstalled() if not self.scriptname: self.scriptname = os.path.join(os.path.dirname(__file__), "NullsoftInstaller.nsi") if self.package.endswith("-package"): shortPackage = self.package[:-8] else: shortPackage = self.package if not "setupname" in self.defines or not self.defines["setupname"]: self.defines["setupname"] = "%s-%s-setup-%s.exe" % ( shortPackage, compiler.architecture(), self.buildTarget) if not "srcdir" in self.defines or not self.defines["srcdir"]: self.defines["srcdir"] = self.archiveDir() if not "company" in self.defines or not self.defines["company"]: self.defines["company"] = "KDE" if not "productname" in self.defines or not self.defines["productname"]: self.defines["productname"] = shortPackage.capitalize() if not "version" in self.defines or not self.defines["version"]: self.defines["version"] = self.buildTarget if not "executable" in self.defines or not self.defines["executable"]: self.defines["executable"] = "" if "license" in self.defines and self.defines["license"]: self.defines[ "license"] = "!insertmacro MUI_PAGE_LICENSE \"%s\"" % self.defines[ "license"] else: self.defines["license"] = "" if "icon" in self.defines and self.defines["icon"]: self.defines[ "icon"] = "!define MUI_ICON \"%s\"" % self.defines["icon"] else: self.defines["icon"] = "" self.defines["architecture"] = compiler.architecture() self.defines["defaultinstdir"] = "$PROGRAMFILES64" if compiler.isX64( ) else "$PROGRAMFILES" # runtime distributable files self.defines["vcredist"] = self.getVCRedistLocation(compiler) if not self.defines["vcredist"]: self.defines["vcredist"] = "none" # for earlier versions of MSVC, simply copy the redist files to the "bin" folder of the installation if compiler.isMSVC(): if compiler.isX64(): redistPath = os.path.join( os.path.join(self.getVCRuntimeLibrariesLocation(), "x64")) else: redistPath = os.path.join( os.path.join(self.getVCRuntimeLibrariesLocation(), "x86")) for root, subdirs, files in os.walk(redistPath): for f in files: shutil.copy(os.path.join(root, f), os.path.join(self.archiveDir(), "bin")) elif compiler.isMinGW(): for f in glob.glob( os.path.join(self.rootdir, "mingw", "bin", "*.dll")): shutil.copy(f, os.path.join(self.archiveDir(), "bin")) else: EmergeDebug.die( "Fixme: Copy runtime libraries for this compiler") # make absolute path for output file if not os.path.isabs(self.defines["setupname"]): dstpath = self.packageDestinationDir() self.defines["setupname"] = os.path.join(dstpath, self.defines["setupname"]) definestring = "" for key in self.defines: definestring += " /D" + key + "=\"" + self.defines[key] + "\"" EmergeDebug.new_line() EmergeDebug.debug("generating installer %s" % self.defines["setupname"]) verboseString = "/V4" if EmergeDebug.verbose() > 0 else "/V3" if self.isInstalled: makensisExe = os.path.join(self.nsisInstallPath, 'makensis.exe') if not utils.systemWithoutShell( "\"%s\" %s %s %s" % (makensisExe, verboseString, definestring, self.scriptname), cwd=os.path.abspath(self.packageDir())): EmergeDebug.die("Error in makensis execution")
def main(): """ Testing the class""" # add two databases tempdbpath1 = os.path.join(EmergeStandardDirs.emergeRoot(), "tmp", "temp1.db") tempdbpath2 = os.path.join(EmergeStandardDirs.emergeRoot(), "tmp", "temp2.db") if not os.path.exists(os.path.join(EmergeStandardDirs.emergeRoot(), "tmp")): os.makedirs(os.path.join(EmergeStandardDirs.emergeRoot(), "tmp")) if os.path.exists(tempdbpath1): os.remove(tempdbpath1) if os.path.exists(tempdbpath2): os.remove(tempdbpath2) db_temp = InstallDB(tempdbpath1) db = InstallDB(tempdbpath2) EmergeDebug.debug('testing installation database') # in case the package is still installed, remove it first silently if db.isInstalled('win32libs', 'dbus-src', '1.4.0'): packageList = db.getInstalledPackages('win32libs', 'dbus-src') # really commit uninstall for package in packageList: package.uninstall() EmergeDebug.debug_line() EmergeDebug.new_line() # add a package EmergeDebug.debug('installing package win32libs/dbus-src-1.4.0 (release)') package = db.addInstalled('win32libs', 'dbus-src', '1.4.0', 'release') package.addFiles(dict().fromkeys(['test', 'test1', 'test2'], 'empty hash')) # now really commit the package package.install() # add another package in a different prefix EmergeDebug.debug('installing package win32libs/dbus-src-1.4.0 (debug)') package = db.addInstalled('win32libs', 'dbus-src', '1.4.0', 'debug') package.addFiles(dict().fromkeys(['test', 'test1', 'test2'], 'empty hash')) # now really commit the package package.install() EmergeDebug.debug_line() EmergeDebug.new_line() EmergeDebug.debug('checking installed packages') EmergeDebug.debug('get installed package (release): %s' % db.getInstalled('win32libs', 'dbus-src', 'release')) EmergeDebug.debug('get installed package (debug): %s' % db.getInstalled('win32libs', 'dbus-src', 'debug')) EmergeDebug.new_line() EmergeDebug.debug('now trying to remove package & revert it again later') # remove the package again packageList = db.getInstalledPackages('win32libs', 'dbus-src') for pac in packageList: for line in pac.getFiles(): # pylint: disable=W0612 # we could remove the file here # print line pass EmergeDebug.debug_line() EmergeDebug.new_line() EmergeDebug.debug('checking installed packages') EmergeDebug.debug('get installed package (release): %s' % db.getInstalled('win32libs', 'dbus-src', 'release')) EmergeDebug.debug('get installed package (debug): %s' % db.getInstalled('win32libs', 'dbus-src', 'debug')) EmergeDebug.debug_line() EmergeDebug.new_line() EmergeDebug.debug('reverting removal') # now instead of completing the removal, revert it for pac in packageList: pac.revert() EmergeDebug.debug('checking installed packages') EmergeDebug.debug('get installed package (release): %s' % db.getInstalled('win32libs', 'dbus-src', 'release')) EmergeDebug.debug('get installed package (debug): %s' % db.getInstalled('win32libs', 'dbus-src', 'debug')) EmergeDebug.debug_line() db.getInstalled() db.getInstalled(category='win32libs', prefix='debug') db.getInstalled(package='dbus-src') EmergeDebug.new_line() EmergeDebug.debug('now really remove the package') packageList = db.getInstalledPackages('win32libs', 'dbus-src') for pac in packageList: EmergeDebug.debug('removing %s files' % len(pac.getFilesWithHashes())) pac.uninstall() EmergeDebug.debug('get installed package (release): %s' % db.getInstalled('win32libs', 'dbus-src', 'release')) EmergeDebug.debug('get installed package (debug): %s' % db.getInstalled('win32libs', 'dbus-src', 'debug')) EmergeDebug.debug_line() # test the import from the old style (manifest based) databases EmergeDebug.new_line() print("getInstalled:", db_temp.getInstalled())
def generateMSInstaller( self ): """ runs tools to generate the installer itself """ if self.package.endswith( "-package" ): shortPackage = self.package[ : -8 ] else: shortPackage = self.package if not "setupname" in self.defines or not self.defines[ "setupname" ]: self.defines[ "setupname" ] = "%s-setup-%s.msi" % ( shortPackage, self.buildTarget ) if not "srcdir" in self.defines or not self.defines[ "srcdir" ]: self.defines[ "srcdir" ] = self.imageDir() if not "company" in self.defines or not self.defines[ "company" ]: self.defines[ "company" ] = "KDE" if not "productname" in self.defines or not self.defines[ "productname" ]: self.defines[ "productname" ] = "%s %s" % ( shortPackage.capitalize(), self.buildTarget ) if not "executable" in self.defines or not self.defines[ "executable" ]: self.defines[ "executable" ] = "" if not "productuid" in self.defines or not self.defines[ "productuid" ]: m = hashlib.md5() m.update( self.defines[ "productname" ] ) m.update( self.defines[ "setupname" ] ) self.defines[ "productuid" ] = str( uuid.UUID( hex=m.hexdigest() ) ) print(self.defines[ "productuid" ]) if not "upgradeuid" in self.defines or not self.defines[ "upgradeuid" ]: self.defines[ "upgradeuid" ] = str( uuid.uuid4() ) if not "componentuid" in self.defines or not self.defines[ "componentuid" ]: self.defines[ "componentuid" ] = str( uuid.uuid4() ) if not self.scriptname: self.scriptname = os.path.join( os.path.dirname( __file__ ), "MSInstaller.wxs.template" ) # make absolute path for output file if not os.path.isabs( self.defines[ "setupname" ] ): dstpath = self.packageDestinationDir() self.defines[ "setupname" ] = os.path.join( dstpath, self.defines[ "setupname" ] ) EmergeDebug.new_line() EmergeDebug.debug("generating installer %s" % self.defines["setupname"]) wxs = Document() componentRefs = Document() rootObject = wxs.createElement( "Directory" ) componentRoot = componentRefs.createElement( "Feature" ) objectDict = dict() objectDict[ self.imageDir() ] = rootObject rootObject.setAttribute( "Id", self.__getUniqueIdString( self.defines[ "productname" ] ) ) rootObject.setAttribute( "Name", self.defines[ "productname" ] ) componentRoot.setAttribute( "Id", "DefaultFeature" ) componentRoot.setAttribute( "Title", "default feature" ) componentRoot.setAttribute( "Level", "1" ) for root, dirs, files in os.walk(self.imageDir()): if root == self.imageDir(): continue if files or dirs: currentDirectory = wxs.createElement( "Directory" ) currentDirectory.setAttribute( "Id", self.__getUniqueIdString( os.path.basename(root) ) ) currentDirectory.setAttribute( "Name", os.path.basename(root) ) objectDict[ os.path.dirname(root) ].appendChild( currentDirectory ) objectDict[ root ] = currentDirectory # components could be used to create updateable packages according to current # emerge packaging for _f in files: _fileId = self.__getUniqueIdString( _f ) currentComponent = wxs.createElement( "Component" ) currentComponent.setAttribute( "Id", _fileId ) currentComponent.setAttribute( "Guid", str( uuid.uuid4() ) ) currentDirectory.appendChild( currentComponent ) currentComponentRef = componentRefs.createElement( "ComponentRef" ) currentComponentRef.setAttribute( "Id", _fileId ) componentRoot.appendChild( currentComponentRef ) currentFile = wxs.createElement( "File" ) currentFile.setAttribute( "Id", _fileId ) currentFile.setAttribute( "Source", os.path.join( "SourceDir", os.path.relpath( root, self.imageDir() ), _f ) ) currentComponent.appendChild( currentFile ) if self.scriptname.endswith( ".template" ): outName = os.path.join( self.buildDir(), os.path.basename( self.scriptname )[:-9] ) else: outName = os.path.join( self.buildDir(), self.scriptname ) out = open( outName, 'w' ) filelistString = StringIO() componentlistString = StringIO() rootObject.writexml( filelistString, " "*16, " ", "\n" ) componentRoot.writexml( componentlistString, " "*8, " ", "\n" ) self.defines[ "filelist" ] = filelistString.getvalue() self.defines[ "componentlist" ] = componentlistString.getvalue() filelistString.close() componentlistString.close() templateFile = open( self.scriptname, 'r' ) scriptTemplate = Template( templateFile.read() ) substitutedScript = scriptTemplate.safe_substitute( self.defines ) out.write( substitutedScript ) out.close() utils.system( "candle -o %s.wixobj %s" % ( outName, outName ) ) utils.system( "light -b %s -o %s %s.wixobj" % ( self.imageDir(), os.path.join( self.packageDir(), self.defines[ "setupname" ] ), outName ) )