def __init__(self, defaultType=eval( emergeSettings.get("Packager", "PackageType", "SevenZipPackager"))): EmergeDebug.debug("TypePackager __init__ %s" % defaultType, 2) PackagerBase.__init__(self) self.__packager = defaultType
def unpack(self): """unpacking all zipped(gz, zip, bz2) tarballs""" EmergeDebug.debug("ArchiveSource.unpack called", 2) filenames = self.localFileNames() # TODO: this might delete generated patches utils.cleanDirectory(self.workDir()) if not self.checkDigest(): return False binEndings = (".exe", ".bat", ".msi") for filename in filenames: if filename.endswith(binEndings): filePath = os.path.abspath( os.path.join(EmergeStandardDirs.downloadDir(), filename) ) if self.subinfo.options.unpack.runInstaller: _, ext = os.path.splitext( filename ) if ext == ".exe": return utils.system("%s" % filePath ) elif ( ext == ".msi" ): return utils.system("msiexec /package %s" % filePath ) if not utils.copyFile( filePath, os.path.join(self.workDir(), filename) ): return False else: if not utils.unpackFile( EmergeStandardDirs.downloadDir(), filename, self.workDir()): return False ret = self.applyPatches() if emergeSettings.getboolean("General","EMERGE_HOLD_ON_PATCH_FAIL",False): return ret return True
def getPackageInstance(self, category, package): """return instance of class Package from package file""" fileName = getFilename( category, package ) pack = None mod = None if fileName.endswith(".py") and os.path.isfile(fileName): if not fileName in self._packageDict: EmergeDebug.debug("module to import: %s" % fileName, 2) if not os.path.isfile( fileName ): try: mod = builtins.__import__( fileName ) except ImportError as e: EmergeDebug.warning('import failed for module %s: %s' % (fileName, str(e))) mod = None else: modulename = os.path.basename( fileName )[:-3].replace('.', '_') loader = importlib.machinery.SourceFileLoader(modulename, fileName) try: mod = loader.load_module() except Exception as e: raise PortageException("Failed to load file %s" % fileName, category, package, e) if not mod is None: subpackage, package = getSubPackage( category, package ) self._CURRENT_MODULE = ( fileName, category,subpackage, package, mod ) pack = mod.Package( ) self._packageDict[ fileName ] = pack else: raise PortageException("Failed to find package", category, package) else: pack = self._packageDict[ fileName ] return pack
def getDependencies( category, package, runtimeOnly = False ): """returns the dependencies of this package as list of strings: category/package""" subpackage, package = getSubPackage( category, package ) if subpackage: EmergeDebug.debug("solving package %s/%s/%s %s" % (category, subpackage, package, getFilename( category, package ))) else: EmergeDebug.debug("solving package %s/%s %s" % (category, package, getFilename(category, package))) subpackage = package deps = [] for pkg in [ subpackage ]: info = _getSubinfo(category, pkg) if not info is None: depDict = info.dependencies depDict.update( info.runtimeDependencies ) if not runtimeOnly: depDict.update( info.buildDependencies ) for line in list(depDict.keys()): (category, package) = line.split( "/" ) version = PortageInstance.getNewestVersion( category, package ) deps.append( [ category, package, version, depDict[ line ] ] ) return deps
def getFiles( urls, destdir, suffix='' , filenames = ''): """download files from 'url' into 'destdir'""" EmergeDebug.debug("getfiles called. urls: %s, filenames: %s, suffix: %s" % (urls, filenames, suffix), 1) # make sure distfiles dir exists if ( not os.path.exists( destdir ) ): os.makedirs( destdir ) if type(urls) == list: urlList = urls else: urlList = urls.split() if filenames == '': filenames = [ os.path.basename(x) for x in urlList ] if type(filenames) == list: filenameList = filenames else: filenameList = filenames.split() dlist = list(zip( urlList , filenameList )) for url,filename in dlist: if ( not getFile( url + suffix, destdir , filename ) ): return False return True
def fetch( self, repopath=None ): """try to clone or update the repository""" EmergeDebug.trace("HgSource.fetch called", 2) # get the path where the repositories should be stored to if repopath == None: repopath = self.repositoryUrl() # in case you need to move from a read only Url to a writeable one, here it gets replaced # repoString = utils.replaceVCSUrl( repopath ) repopath = repopath.replace("[hg]", "") repoUrl, repoBranch, _ = utils.splitVCSUrl( repopath ) ret = True # only run if wanted (e.g. no --offline is given on the commandline) or no hg support is given by the python installation if ( not self.noFetch and self.enableHg ): # question whether mercurial stuff uses these proxies self.setProxy() checkoutDir = self.checkoutDir() # check corrupted checkout dir if os.path.exists( checkoutDir ) and not os.path.exists( checkoutDir + "\.hg" ): os.rmdir( checkoutDir ) if not os.path.exists( checkoutDir ): os.makedirs( checkoutDir ) os.chdir( checkoutDir ) ret = self.system( "%s clone %s ." % ( self.hgExecutable, repoUrl ) ) # TODO: check return code for success if os.path.exists( checkoutDir ): os.chdir( checkoutDir ) ret = self.system( "%s update %s" % ( self.hgExecutable, repoBranch ) ) # TODO: check return code for success else: EmergeDebug.debug("skipping hg fetch (--offline)") return ret
def fetch( self, dummyRepopath = None ): """fetch normal tarballs""" EmergeDebug.debug("ArchiveSource.fetch called", 2) filenames = self.localFileNames() if ( self.noFetch ): EmergeDebug.debug("skipping fetch (--offline)") return True self.setProxy() if self.subinfo.hasTarget(): if self.__checkFilesPresent(filenames): EmergeDebug.debug("files and digests available, no need to download files", 1) return True result = utils.getFiles( self.subinfo.target(), EmergeStandardDirs.downloadDir() , filenames = self.subinfo.archiveName() ) if not result: EmergeDebug.debug("failed to download files", 1) return False if result and self.subinfo.hasTargetDigestUrls(): if type(self.subinfo.targetDigestUrl()) == tuple: url, alg = self.subinfo.targetDigestUrl() return utils.getFiles(url, EmergeStandardDirs.downloadDir(), filenames = self.subinfo.archiveName()[0] + EmergeHash.HashAlgorithm.fileEndings().get(alg)) else: return utils.getFiles( self.subinfo.targetDigestUrl(), EmergeStandardDirs.downloadDir(), filenames = '' ) else: EmergeDebug.debug("no digestUrls present", 2) return True else: return utils.getFiles( "", EmergeStandardDirs.downloadDir() )
def deleteFile(fileName): """delete file """ if not os.path.exists( fileName ): return False EmergeDebug.debug("delete file %s " % (fileName), 2) os.remove( fileName ) return True
def PackagerFactory(parent, packagerType): """provides multi packager type api return PackagerBase derived instance for recent settings""" EmergeDebug.debug("PackagerFactory called", 2) packagers = [] if packagerType: for packagerClass in packagerType: if not issubclass(packagerClass, PackagerBase): EmergeDebug.die("PackagerFactory: unsupported packager %s" % packagerClass) else: packager = packagerClass() init(packager, parent) packagers.append(packager) else: # automatic detection packager = InnoSetupPackager() init(packager, parent) if packager.configFile() != None: packagers.append(packager) # default packager if len(packagers) == 0: packager = KDEWinPackager() init(packager, parent) packagers.append(packager) return packagers
def getDependencies(category, package, runtimeOnly=False): """returns the dependencies of this package as list of strings: category/package""" subpackage, package = getSubPackage(category, package) if subpackage: EmergeDebug.debug( "solving package %s/%s/%s %s" % (category, subpackage, package, getFilename(category, package))) else: EmergeDebug.debug("solving package %s/%s %s" % (category, package, getFilename(category, package))) deps = [] info = _getSubinfo(category, package) if not info is None: depDict = info.dependencies depDict.update(info.runtimeDependencies) if not runtimeOnly: depDict.update(info.buildDependencies) for line in depDict: (category, package) = line.split("/") version = PortageInstance.getNewestVersion(category, package) deps.append([category, package, version, depDict[line]]) return deps
def PackagerFactory(parent, packagerType): """provides multi packager type api return PackagerBase derived instance for recent settings""" EmergeDebug.debug("PackagerFactory called", 2) packagers = [] if packagerType: for packagerClass in packagerType: if not issubclass(packagerClass, PackagerBase): EmergeDebug.die("PackagerFactory: unsupported packager %s" % packagerClass) else: packager = packagerClass() init(packager, parent) packagers.append(packager) else: # automatic detection packager = InnoSetupPackager() init(packager, parent) if packager.configFile() != None: packagers.append(packager) # default packager if len(packagers) == 0: packager = KDEWinPackager() init(packager, parent) packagers.append(packager) return packagers
def _fixCmakeImageDir(self, imagedir, rootdir ): """ when using DESTDIR=foo under windows, it does not _replace_ CMAKE_INSTALL_PREFIX with it, but prepends destdir to it. so when we want to be able to install imagedir into KDEROOT, we have to move things around... """ EmergeDebug.debug("fixImageDir: %s %s" % (imagedir, rootdir), 1) # imagedir = e:\foo\thirdroot\tmp\dbus-0\image # rootdir = e:\foo\thirdroot # files are installed to # e:\foo\thirdroot\tmp\dbus-0\image\foo\thirdroot _, rootpath = os.path.splitdrive( rootdir ) #print "rp:", rootpath if ( rootpath.startswith( os.path.sep ) ): rootpath = rootpath[1:] # CMAKE_INSTALL_PREFIX = X:\ # -> files are installed to # x:\build\foo\dbus\image\ # --> all fine in this case #print("rp:", rootpath) if len(rootpath) == 0: return tmp = os.path.join( imagedir, rootpath ) EmergeDebug.debug("tmp: %s" % tmp, 1) tmpdir = os.path.join( imagedir, "tMpDiR" ) if ( not os.path.isdir( tmpdir ) ): os.mkdir( tmpdir ) utils.moveEntries( tmp, tmpdir ) os.chdir( imagedir ) os.removedirs( rootpath ) utils.moveEntries( tmpdir, imagedir ) utils.cleanDirectory( tmpdir ) os.rmdir( tmpdir )
def __init__(self): EmergeDebug.debug("SetupPackageBase.__init__ called", 2) PackageBase.__init__(self) MultiSource.__init__(self) BuildSystemBase.__init__(self) PackagerBase.__init__(self) self.subinfo.options.unpack.runInstaller = True
def __init__(self): EmergeDebug.debug("SetupPackageBase.__init__ called", 2) PackageBase.__init__(self) MultiSource.__init__(self) BuildSystemBase.__init__(self) PackagerBase.__init__(self) self.subinfo.options.unpack.runInstaller = True
def renameDir(src, dest): """ rename a directory """ EmergeDebug.debug("rename directory from %s to %s" % (src, dest), 2) if os.rename( src, dest ) == 0: return False else: return True
def cleanImage( self ): """cleanup before install to imagedir""" if ( os.path.exists( self.imageDir() ) ): EmergeDebug.debug("cleaning image dir: %s" % self.imageDir(), 1) utils.cleanDirectory( self.imageDir() ) os.rmdir(self.imageDir()) return True
def checkFilesDigests(downloaddir, filenames, digests=None, digestAlgorithm=HashAlgorithm.SHA1): """check digest of (multiple) files specified by 'filenames' from 'downloaddir'""" if type(digests) == list: digestList = digests else: digestList = [digests] for digests, filename in zip(digestList, filenames): EmergeDebug.debug("checking digest of: %s" % filename, 1) pathName = os.path.join(downloaddir, filename) if digests == None: for digestAlgorithm, digestFileEnding in HashAlgorithm.fileEndings().items(): digestFileName = pathName + digestFileEnding if not os.path.exists(digestFileName): digestFileName, _ = os.path.splitext(pathName) digestFileName += digestFileEnding if not os.path.exists(digestFileName): continue currentHash = digestFile(pathName, digestAlgorithm) with open(digestFileName, "rt+") as f: data = f.read() if not re.findall(currentHash, data): EmergeDebug.error("%s hash for file %s (%s) does not match (%s)" % ( digestAlgorithm.name, pathName, currentHash, data)) return False # digest provided in digests parameter else: currentHash = digestFile(pathName, digestAlgorithm) if len(digests) != len(currentHash) or digests.find(currentHash) == -1: EmergeDebug.error("%s hash for file %s (%s) does not match (%s)" % ( digestAlgorithm.name, pathName, currentHash, digests)) return False return True
def _defaulVersions( self ): if self.__defaulVersions is None: name = self.subinfo.parent.filename if name in VersionInfo._VERSION_INFOS_HINTS: if VersionInfo._VERSION_INFOS_HINTS[ name ] == None: return None else: #utils.debug("Using cached version info for %s in %s" % (name, _VERSION_INFOS_HINTS[ name ])) return VersionInfo._VERSION_INFOS[ VersionInfo._VERSION_INFOS_HINTS[ name ] ] root = os.path.dirname( name ) if self._fileName is None: possibleInis= [ os.path.join( root, "version.ini" ), os.path.join( root, "..", "version.ini" ), os.path.join( root, "..", "..", "version.ini" ) ] else: possibleInis = [self._fileName] for iniPath in possibleInis: iniPath = os.path.abspath( iniPath ) if iniPath in VersionInfo._VERSION_INFOS.keys( ): VersionInfo._VERSION_INFOS_HINTS[ name ] = iniPath EmergeDebug.debug("Found a version info for %s in cache" % name, 2) return VersionInfo._VERSION_INFOS[ iniPath ] elif os.path.exists( iniPath ): config = configparser.ConfigParser( ) config.read( iniPath ) VersionInfo._VERSION_INFOS[ iniPath ] = config VersionInfo._VERSION_INFOS_HINTS[ name ] = iniPath EmergeDebug.debug("Found a version info for %s in %s" % (name, iniPath), 2) return config VersionInfo._VERSION_INFOS_HINTS[ name ] = None return self.__defaulVersions
def getFile( url, destdir , filename='' ): """download file from 'url' into 'destdir'""" EmergeDebug.debug("getFile called. url: %s" % url, 1) if url == "": EmergeDebug.error("fetch: no url given") return False if UtilsCache.findApplication("wget"): return wgetFile( url, destdir , filename ) if not filename: _, _, path, _, _, _ = urllib.parse.urlparse( url ) filename = os.path.basename( path ) if os.path.exists(os.path.join( destdir, filename )): return True width, _ = shutil.get_terminal_size((80,20)) def dlProgress(count, blockSize, totalSize): percent = int(count * blockSize * 100 / totalSize) times = int((width - 20)/100 * percent) sys.stdout.write(("\r%s%3d%%" % ("#" * times, percent))) sys.stdout.flush() urllib.request.urlretrieve(url, filename = os.path.join( destdir, filename ), reporthook= dlProgress if EmergeDebug.verbose() >= 0 else None ) if EmergeDebug.verbose()>=0: sys.stdout.write("\n") sys.stdout.flush() return True
def cleanBuild( self ) -> bool: """cleanup currently used build dir""" if os.path.exists( self.buildDir() ): utils.cleanDirectory( self.buildDir() ) EmergeDebug.debug("cleaning build dir: %s" % self.buildDir(), 1) return True
def __fetchSingleBranch(self, repopath=None): EmergeDebug.trace("GitSource __fetchSingleBranch", 2) # get the path where the repositories should be stored to if repopath == None: repopath = self.repositoryUrl() EmergeDebug.debug("fetching %s" % repopath) # in case you need to move from a read only Url to a writeable one, here it gets replaced repopath = repopath.replace("[git]", "") repoString = utils.replaceVCSUrl(repopath) [repoUrl, repoBranch, repoTag] = utils.splitVCSUrl(repoString) if not repoBranch and not repoTag: repoBranch = "master" ret = True # only run if wanted (e.g. no --offline is given on the commandline) if not self.noFetch: self.setProxy() safePath = os.environ["PATH"] # add the git path to the PATH variable so that git can be called without path os.environ["PATH"] = os.path.join(self.rootdir, "git", "bin") + ";" + safePath checkoutDir = self.checkoutDir() # if we only have the checkoutdir but no .git within, # clean this up first if os.path.exists(checkoutDir) and not os.path.exists(checkoutDir + "\.git"): os.rmdir(checkoutDir) if os.path.exists(checkoutDir): if not repoTag: self.__git("fetch") ret = self.__git("checkout", repoBranch or "master") and self.__git("merge") if self.subinfo.options.fetch.checkoutSubmodules: self.__git("submodule update --init --recursive") else: # it doesn't exist so clone the repo os.makedirs(checkoutDir) # first try to replace with a repo url from etc/portage/emergehosts.conf recursive = "--recursive" if self.subinfo.options.fetch.checkoutSubmodules else "" ret = self.__git("clone", recursive, repoUrl, ".") # if a branch is given, we should check first if the branch is already downloaded # locally, otherwise we can track the remote branch if ret and repoBranch and not repoTag: track = "" if not self.__isLocalBranch(repoBranch): track = "--track origin/" ret = self.__git("checkout", "%s%s" % (track, repoBranch)) # we can have tags or revisions in repoTag if ret and repoTag: if self.__isTag(repoTag): if not self.__isLocalBranch("_" + repoTag): ret = self.__git("checkout", "-b", "_%s" % repoTag, repoTag) else: ret = self.__git("checkout", "_%s" % repoTag) else: ret = self.__git("checkout", repoTag) else: EmergeDebug.debug("skipping git fetch (--offline)") return ret
def cleanImage( self ) -> bool: """cleanup before install to imagedir""" if ( os.path.exists( self.imageDir() ) ): EmergeDebug.debug("cleaning image dir: %s" % self.imageDir(), 1) utils.cleanDirectory( self.imageDir() ) os.rmdir(self.imageDir()) return True
def _fixCmakeImageDir(self, imagedir, rootdir): """ when using DESTDIR=foo under windows, it does not _replace_ CMAKE_INSTALL_PREFIX with it, but prepends destdir to it. so when we want to be able to install imagedir into KDEROOT, we have to move things around... """ EmergeDebug.debug("fixImageDir: %s %s" % (imagedir, rootdir), 1) # imagedir = e:\foo\thirdroot\tmp\dbus-0\image # rootdir = e:\foo\thirdroot # files are installed to # e:\foo\thirdroot\tmp\dbus-0\image\foo\thirdroot _, rootpath = os.path.splitdrive(rootdir) #print "rp:", rootpath if (rootpath.startswith(os.path.sep)): rootpath = rootpath[1:] # CMAKE_INSTALL_PREFIX = X:\ # -> files are installed to # x:\build\foo\dbus\image\ # --> all fine in this case #print("rp:", rootpath) if len(rootpath) == 0: return tmp = os.path.join(imagedir, rootpath) EmergeDebug.debug("tmp: %s" % tmp, 1) tmpdir = os.path.join(imagedir, "tMpDiR") if (not os.path.isdir(tmpdir)): os.mkdir(tmpdir) utils.moveEntries(tmp, tmpdir) os.chdir(imagedir) os.removedirs(rootpath) utils.moveEntries(tmpdir, imagedir) utils.cleanDirectory(tmpdir) os.rmdir(tmpdir)
def dumpCMakeDependencies(self): """dump package dependencies as pdf (requires installed dot)""" srcDir = self.sourceDir() outDir = self.buildDir() self.enterBuildDir() outFile = os.path.join(outDir, self.package + '-cmake.dot') a = CMakeDependencies() if not a.parse(srcDir): EmergeDebug.debug( "could not find source files for generating cmake dependencies" ) return False title = "%s cmake dependency chart - version %s" % (self.package, self.version) a.toPackageList(title, srcDir) if not a.toDot(title, srcDir, outFile): EmergeDebug.debug("could not create dot file") return False graphviz = GraphViz(self) if not graphviz.runDot(outFile, outFile + '.pdf', 'pdf'): return False return graphviz.openOutput()
def unpack(self): """unpacking all zipped(gz, zip, bz2) tarballs""" EmergeDebug.debug("ArchiveSource.unpack called", 2) filenames = self.localFileNames() # TODO: this might delete generated patches utils.cleanDirectory(self.workDir()) if not self.checkDigest(): return False binEndings = (".exe", ".bat", ".msi") for filename in filenames: if filename.endswith(binEndings): filePath = os.path.abspath( os.path.join(EmergeStandardDirs.downloadDir(), filename) ) if self.subinfo.options.unpack.runInstaller: _, ext = os.path.splitext( filename ) if ext == ".exe": return utils.system("%s" % filePath ) elif ( ext == ".msi" ): return utils.system("msiexec /package %s" % filePath ) if not utils.copyFile( filePath, os.path.join(self.workDir(), filename) ): return False else: if not utils.unpackFile( EmergeStandardDirs.downloadDir(), filename, self.workDir()): return False ret = self.applyPatches() if emergeSettings.getboolean("General","EMERGE_HOLD_ON_PATCH_FAIL",False): return ret return True
def __readDependenciesForChildren(self, deps): children = [] if deps: for line in deps: (category, package) = line.split("/") EmergeDebug.debug( "category: %s, name: %s" % (category, package), 2) try: version = PortageInstance.getNewestVersion( category, package) except PortageException as e: EmergeDebug.warning( "%s for %s/%s as a dependency of %s/%s" % (e, e.category, e.package, self.category, self.name)) continue if not line in self._dependencyList.keys(): p = DependencyPackage(category, package, False, self) EmergeDebug.debug( "adding package %s/%s-%s" % (category, package, version), 2) self._dependencyList[line] = p p.__readChildren() else: p = self._dependencyList[line] children.append(p) return children
def buildDir(self): EmergeDebug.debug("EmergeBase.buildDir() called", 2) builddir = os.path.join(self.workDir(), self.workDirPattern()) if self.subinfo.options.unpack.unpackIntoBuildDir and self.subinfo.hasTargetSourcePath(): builddir = os.path.join(builddir, self.subinfo.targetSourcePath()) EmergeDebug.debug("package builddir is: %s" % builddir, 2) return self.__adjustPath(builddir)
def fetch( self, dummyRepopath = None ): """fetch normal tarballs""" EmergeDebug.debug("ArchiveSource.fetch called", 2) filenames = self.localFileNames() if ( self.noFetch ): EmergeDebug.debug("skipping fetch (--offline)") return True self.setProxy() if self.subinfo.hasTarget(): if self.__checkFilesPresent(filenames): EmergeDebug.debug("files and digests available, no need to download files", 1) return True result = utils.getFiles( self.subinfo.target(), EmergeStandardDirs.downloadDir() , filenames = self.subinfo.archiveName() ) if not result: EmergeDebug.debug("failed to download files", 1) return False if result and self.subinfo.hasTargetDigestUrls(): if type(self.subinfo.targetDigestUrl()) == tuple: url, alg = self.subinfo.targetDigestUrl() return utils.getFiles(url, EmergeStandardDirs.downloadDir(), filenames = self.subinfo.archiveName() + EmergeHash.HashAlgorithm.fileEndings().get(alg)) else: return utils.getFiles( self.subinfo.targetDigestUrl(), EmergeStandardDirs.downloadDir(), filenames = '' ) else: EmergeDebug.debug("no digestUrls present", 2) return True else: return utils.getFiles( "", EmergeStandardDirs.downloadDir() )
def cleanBuild( self ): """cleanup currently used build dir""" if os.path.exists( self.buildDir() ): utils.cleanDirectory( self.buildDir() ) EmergeDebug.debug("cleaning build dir: %s" % self.buildDir(), 1) return True
def __getImageDirectories( self ): """ return the image directories where the files are stored """ imageDirs = [] runtimeDependencies = portage.getDependencies(self.category, self.package) depList = [] for ( category, package, _, _ ) in runtimeDependencies: # we only want runtime dependencies since we want to build a binary installer portage.solveDependencies(category, package, depList = depList, depType = DependencyType.Runtime, ignoredPackages = self.ignoredPackages) depList.reverse() # make sure current package is added to the list, too if not self.package.endswith("-package"): depList.append(DependencyPackage(self.category, self.package)) for x in depList: if portage.PortageInstance.isVirtualPackage(x.category, x.package): EmergeDebug.debug("Ignoring package b/c it is virtual: %s/%s" % (x.category, x.package)) continue _package = portage.getPackageInstance( x.category, x.package ) imageDirs.append(( os.path.join( self.rootdir, "build", x.category, x.package, self.__imageDirPattern( _package, _package.buildTarget )), _package.subinfo.options.merge.destinationPath , _package.subinfo.options.package.disableStriping ) ) # this loop collects the files from all image directories EmergeDebug.debug("__getImageDirectories: category: %s, package: %s, version: %s, defaultTarget: %s" % (_package.category, x.package, _package.version, _package.buildTarget), 2) if emergeSettings.getboolean("QtSDK", "Enabled", "false"): imageDirs.append((os.path.join( emergeSettings.get("QtSDK", "Path") , emergeSettings.get("QtSDK", "Version"), emergeSettings.get("QtSDK", "Compiler")), None, False)) return imageDirs
def unmergeFileList(rootdir, fileList, forced=False): """ delete files in the fileList if has matches or forced is True """ for filename, filehash in fileList: fullPath = os.path.join(rootdir, os.path.normcase( filename)) if os.path.isfile(fullPath): algorithm = EmergeHash.HashAlgorithm.getAlgorithmFromPrefix(filehash) if not algorithm: currentHash = EmergeHash.digestFile(fullPath, EmergeHash.HashAlgorithm.MD5) else: currentHash = algorithm.stringPrefix() + EmergeHash.digestFile(fullPath, algorithm) if currentHash == filehash or filehash == "": EmergeDebug.debug("deleting file %s" % fullPath, 2) try: os.remove(fullPath) except OSError: system( "cmd /C \"attrib -R %s\"" % fullPath ) os.remove(fullPath) else: if forced: EmergeDebug.warning("file %s has different hash: %s %s, deleting anyway" % \ (fullPath, currentHash, filehash )) try: os.remove(fullPath) except OSError: system( "cmd /C \"attrib -R %s\"" % fullPath ) os.remove(fullPath) else: EmergeDebug.warning("file %s has different hash: %s %s, run with option --force to delete it anyway" % \ (fullPath, currentHash, filehash )) elif not os.path.isdir(fullPath): EmergeDebug.warning("file %s does not exist" % fullPath)
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 getFile( url, destdir , filename='' ): """download file from 'url' into 'destdir'""" EmergeDebug.debug("getFile called. url: %s" % url, 1) if url == "": EmergeDebug.error("fetch: no url given") return False wgetpath = WGetExecutable if ( os.path.exists( wgetpath ) ): return wgetFile( url, destdir , filename ) scheme, host, path, _, _, _ = urllib.parse.urlparse( url ) filename = os.path.basename( path ) EmergeDebug.debug("%s\n%s\n%s\n%s" % (scheme, host, path, filename)) if ( scheme == "http" ): return getHttpFile( host, path, destdir, filename ) elif ( scheme == "ftp" ): return getFtpFile( host, path, destdir, filename ) else: EmergeDebug.error("getFile: protocol not understood") return False
def getHttpFile( host, path, destdir, filename ): """download file from a http host specified by 'host' and 'path' into 'destdir' using 'filename' as file name""" # FIXME check return values here (implement useful error handling)... EmergeDebug.debug("getHttpFile called. %s %s" % (host, path), 1) conn = http.client.HTTPConnection( host ) conn.request( "GET", path ) r1 = conn.getresponse() EmergeDebug.debug("status: %s; reason: %s" % (str(r1.status), str(r1.reason))) count = 0 while r1.status == 302: if count > 10: EmergeDebug.debug("Redirect loop") return False count += 1 _, host, path, _, _, _ = urllib.parse.urlparse( r1.getheader( "Location" ) ) EmergeDebug.debug("Redirection: %s %s" % (host, path), 1) conn = http.client.HTTPConnection( host ) conn.request( "GET", path ) r1 = conn.getresponse() EmergeDebug.debug("status: %s; reason: %s" % (str(r1.status), str(r1.reason))) data = r1.read() with open( os.path.join( destdir, filename ), "wb" ) as f: f.write( data ) return True
def setBuildTarget( self, buildTarget = None): """setup current build target""" self.buildTarget = self.defaultTarget if not buildTarget == None: self.buildTarget = buildTarget if not self.buildTarget in list(self.targets.keys()) and not self.buildTarget in list(self.svnTargets.keys()) : EmergeDebug.debug("build target %s not defined in available targets %s %s setting default target to %s" % (self.buildTarget, list(self.targets.keys()), list(self.svnTargets.keys()), self.defaultTarget), 1) self.buildTarget = self.defaultTarget
def getFiles(self): """ get the list of files for the given package """ cmd = '''SELECT filename FROM fileList WHERE packageId=?;''' EmergeDebug.debug( "executing sqlcmd '%s' with parameter %s" % (cmd, str(self.packageId)), 2) self.cursor.execute(cmd, (self.packageId, )) return self.cursor.fetchall()
def localFileNamesBase(self): """ collect local filenames """ EmergeDebug.debug("ArchiveSource.localFileNamesBase called", 2) filenames = [] for i in range(self.repositoryUrlCount()): filenames.append(os.path.basename(self.repositoryUrl(i))) return filenames
def localFileNamesBase(self): """ collect local filenames """ EmergeDebug.debug("ArchiveSource.localFileNamesBase called", 2) filenames = [] for i in range(self.repositoryUrlCount()): filenames.append( os.path.basename( self.repositoryUrl( i ) ) ) return filenames
def buildDir(self): EmergeDebug.debug("EmergeBase.buildDir() called", 2) builddir = os.path.join(self.workDir(), self.workDirPattern()) if self.subinfo.options.unpack.unpackIntoBuildDir and self.subinfo.hasTargetSourcePath( ): builddir = os.path.join(builddir, self.subinfo.targetSourcePath()) EmergeDebug.debug("package builddir is: %s" % builddir, 2) return self.__adjustPath(builddir)
def rm(path, force=False): EmergeDebug.debug("deleting file %s" % path, 3) try: os.remove(path) return True except OSError as e: EmergeDebug.warning("could not delete file %s: %s" % (path, e)) return False
def applyPatch(sourceDir, f, patchLevel='0'): """apply single patch""" cmd = 'patch -d "%s" -p%s -i "%s"' % (sourceDir, patchLevel, f) EmergeDebug.debug("applying %s" % cmd) result = system( cmd ) if not result: EmergeDebug.warning("applying %s failed!" % f) return result
def setDependencies( self ): EmergeDebug.debug("emergebuildsystem:subinfo.setDependencies not implemented yet", 1) # we need at least qmake #self.dependencies['libs/qt'] = 'default' self.buildDependencies['dev-util/jom'] = 'default' if compiler.isMinGW(): self.buildDependencies['dev-util/mingw-w64'] = 'default'
def systemWithoutShell(cmd, **kw): """execute cmd. All keywords are passed to Popen. stdout and stderr might be changed depending on the chosen logging options.""" EmergeDebug.debug("executing command: %s" % cmd, 1) if EmergeDebug.verbose() == -1 and not 'stdout' in kw and not 'stderr' in kw: kw['stdout'] = kw['stderr'] = subprocess.DEVNULL return subprocess.call(cmd, **kw) == 0
def sourceDir(self, index=0 ): EmergeDebug.trace("VersionSystemSourceBase sourceDir", 2) sourcedir = self.checkoutDir( index ) if self.subinfo.hasTargetSourcePath(): sourcedir = os.path.join(sourcedir, self.subinfo.targetSourcePath()) EmergeDebug.debug("using sourcedir: %s" % sourcedir, 2) return os.path.abspath(sourcedir)
def getCategory( self, package ): """ returns the category of this package """ EmergeDebug.debug("getCategory: %s" % package, 2) for cat in list(self.categories.keys()): if package in self.categories[ cat ]: EmergeDebug.debug("getCategory: found category %s for package %s" % (cat, package), 3) return cat return False
def isPackageUpdateable( category, package ): EmergeDebug.debug("isPackageUpdateable: importing file %s" % getFilename(category, package), 2) subinfo = _getSubinfo( category, package ) if not subinfo is None: if len( subinfo.svnTargets ) == 1 and not subinfo.svnTargets[ list(subinfo.svnTargets.keys())[0] ]: return False return len( subinfo.svnTargets ) > 0 else: return False
def moveDir( srcdir, destdir ): """ move directory from srcdir to destdir """ EmergeDebug.debug("moveDir called. srcdir: %s, destdir: %s" % (srcdir, destdir), 1) try: shutil.move( srcdir, destdir ) except Exception as e: EmergeDebug.warning(e) return False return True
def createPatch( self ): """create patch file from git source into the related package dir. The patch file is named autocreated.patch""" EmergeDebug.trace('GitSource createPatch', 2) patchFileName = os.path.join( self.packageDir(), "%s-%s.patch" % \ ( self.package, str( datetime.date.today() ).replace('-', '') ) ) EmergeDebug.debug("git diff %s" % patchFileName, 1) with open(patchFileName,'wt+') as patchFile: return self.__git('diff', stdout=patchFile)
def rmDir(path, force=False): EmergeDebug.debug("deleting directory %s" % path, 3) try: shutil.rmtree(path) return True except OSError as e: EmergeDebug.warning("could not delete directory %s: %s" % (path, e)) return False return False
def enterBuildDir(self): EmergeDebug.trace("EmergeBase.enterBuildDir called") if (not os.path.exists(self.buildDir())): os.makedirs(self.buildDir()) EmergeDebug.debug("creating: %s" % self.buildDir()) os.chdir(self.buildDir()) EmergeDebug.debug("entering: %s" % self.buildDir())