else: isInstalled = installdb.isInstalled( mainCategory, mainPackage, mainVersion, "" ) else: isInstalled = portage.isInstalled( mainCategory, mainPackage, mainVersion, buildType ) if ( isInstalled and not ignoreInstalled ) and not ( isInstalled and (outDateVCS or (outDatePackage and isLastPackage) ) and target in targetList ): if utils.verbose() > 1 and mainPackage == packageName: utils.warning( "already installed %s/%s-%s" % ( mainCategory, mainPackage, mainVersion ) ) elif utils.verbose() > 2 and not mainPackage == packageName: utils.warning( "already installed %s/%s-%s" % ( mainCategory, mainPackage, mainVersion ) ) else: # find the installed version of the package if isDBEnabled(): instver = installdb.findInstalled( mainCategory, mainPackage ) else: instver = portage.findInstalled( mainCategory, mainPackage ) # in case we only want to see which packages are still to be build, simply return the package name if ( doPretend ): if utils.verbose() > 0: msg = " " if emergePlatform.isCrossCompilingEnabled(): if isDBEnabled(): hostEnabled = portage.isHostBuildEnabled( mainCategory, mainPackage, mainVersion ) targetEnabled = portage.isTargetBuildEnabled( mainCategory, mainPackage, mainVersion ) hostInstalled = installdb.isInstalled( mainCategory, mainPackage, mainVersion, "" ) targetInstalled = installdb.isInstalled( mainCategory, mainPackage, mainVersion, os.getenv( "EMERGE_TARGET_PLATFORM" ) ) msg += portage.getHostAndTarget( hostEnabled and not hostInstalled, targetEnabled and not targetInstalled ) else: msg = "" utils.warning( "pretending %s/%s-%s%s" % ( mainCategory, mainPackage, mainVersion, msg ) )
def main(): """ Testing the class""" # add two databases tempdbpath1 = os.path.join( os.getenv("KDEROOT"), "tmp", "temp1.db" ) tempdbpath2 = os.path.join( os.getenv("KDEROOT"), "tmp", "temp2.db" ) if not os.path.exists( os.path.join( os.getenv( "KDEROOT" ), "tmp" ) ): os.makedirs( os.path.join( os.getenv( "KDEROOT" ), "tmp" ) ) if os.path.exists( tempdbpath1 ): os.remove( tempdbpath1 ) if os.path.exists( tempdbpath2 ): os.remove( tempdbpath2 ) db_temp = InstallDB( tempdbpath1 ) db = InstallDB( tempdbpath2 ) utils.debug( 'testing installation database' ) utils.debug( 'testing if package win32libs/dbus-src with version 1.4.0 is installed: %s' % db.isPkgInstalled( 'win32libs', 'dbus-src', '1.4.0' ) ) # in case the package is still installed, remove it first silently if db.isInstalled( 'win32libs', 'dbus-src', '1.4.0' ): packageList = db.remInstalled( 'win32libs', 'dbus-src', '1.4.0' ) # really commit uninstall for package in packageList: package.uninstall() utils.debug_line() utils.new_line() # add a package utils.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 utils.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() utils.debug_line() utils.new_line() utils.debug( 'checking installed packages' ) utils.debug( 'get installed package (release): %s' % db.getInstalled( 'win32libs', 'dbus-src', 'release' ) ) utils.debug( 'get installed package (debug): %s' % db.getInstalled( 'win32libs', 'dbus-src', 'debug' ) ) utils.new_line() utils.debug( 'now trying to remove package & revert it again later' ) # remove the package again packageList = db.remInstalled( 'win32libs', 'dbus-src', '1.4.0' ) for pac in packageList: for line in pac.getFiles(): # pylint: disable=W0612 # we could remove the file here # print line pass utils.debug_line() utils.new_line() utils.debug( 'checking installed packages' ) utils.debug( 'get installed package (release): %s' % db.getInstalled( 'win32libs', 'dbus-src', 'release' ) ) utils.debug( 'get installed package (debug): %s' % db.getInstalled( 'win32libs', 'dbus-src', 'debug' ) ) utils.debug_line() utils.new_line() utils.debug( 'reverting removal' ) # now instead of completing the removal, revert it for pac in packageList: pac.revert() utils.debug( 'checking installed packages' ) utils.debug( 'get installed package (release): %s' % db.getInstalled( 'win32libs', 'dbus-src', 'release' ) ) utils.debug( 'get installed package (debug): %s' % db.getInstalled( 'win32libs', 'dbus-src', 'debug' ) ) utils.debug_line() db.getInstalled() db.getInstalled( category='win32libs', prefix='debug' ) db.getInstalled( package='dbus-src' ) utils.new_line() utils.debug( 'now really remove the package' ) packageList = db.remInstalled( 'win32libs', 'dbus-src', '1.4.0') for pac in packageList: utils.debug( 'removing %s files' % len( pac.getFiles() ) ) pac.uninstall() utils.debug( 'get installed package (release): %s' % db.getInstalled( 'win32libs', 'dbus-src', 'release' ) ) utils.debug( 'get installed package (debug): %s' % db.getInstalled( 'win32libs', 'dbus-src', 'debug' ) ) utils.debug_line() # test the import from the old style (manifest based) databases utils.new_line() db_temp.importExistingDatabase() print("getInstalled:", db_temp.getInstalled()) print("findInstalled:", portage.findInstalled( 'win32libs', 'dbus-src' )) print("getFileListFromManifest:", len( utils.getFileListFromManifest( os.getenv( "KDEROOT" ), 'dbus-src' ) ))