def restore(self, basedir): '''restore the packages from the snapfile''' # if package record file isn't found, simply return if not os.path.isfile(basedir + "/packages.xml"): return if snap.config.options.log_level_at_least('verbose'): snap.callback.snapcallback.message( "Restoring packages using apt backend") # set DEBIAN_FRONTEND to noninteractive so that we won't launch # any interactive configurations os.environ['DEBIAN_FRONTEND'] = 'noninteractive' # first update the system self.cache.upgrade() # read files from the record file record = PackagesRecordFile(basedir + "/packages.xml") packages = record.read() # mark necessary packages for installation for pkg in packages: decoded_pkgname = PackageRegistry.decode('apt', pkg.name) if snap.config.options.log_level_at_least('verbose'): snap.callback.snapcallback.message("Restoring package " + decoded_pkgname) pkg = self.cache[decoded_pkgname] if not pkg.is_installed: pkg.mark_install() # finally perform install self.cache.commit()
def restore(self, basedir): '''restore the packages from the snapfile''' # if package record file isn't found, simply return if not os.path.isfile(basedir + "/packages.xml"): return if snap.config.options.log_level_at_least('verbose'): snap.callback.snapcallback.message("Restoring packages using apt backend"); # set DEBIAN_FRONTEND to noninteractive so that we won't launch # any interactive configurations os.environ['DEBIAN_FRONTEND'] = 'noninteractive' # first update the system self.cache.upgrade() # read files from the record file record = PackagesRecordFile(basedir + "/packages.xml") packages = record.read() # mark necessary packages for installation for pkg in packages: decoded_pkgname = PackageRegistry.decode('apt', pkg.name) if snap.config.options.log_level_at_least('verbose'): snap.callback.snapcallback.message("Restoring package " + decoded_pkgname); pkg = self.cache[decoded_pkgname] if not pkg.is_installed: pkg.mark_install() # finally perform install self.cache.commit()
def restore(self, basedir): '''restore the packages from the snapfile''' # if package record file isn't found, simply return if not os.path.isfile(basedir + "/packages.xml"): return if snap.config.options.log_level_at_least('verbose'): snap.callback.snapcallback.message("Restoring packages using yum backend"); # set installroot to fs_root self.yum.conf.installroot = self.fs_root # need this to get around gpgcheck in this case (setting gpgcheck to false will not work) self.yum.conf.assumeyes = True self.yum.conf.skip_broken = True # first update the system for pkg in self.yum.rpmdb: self.yum.update(pkg) # read files from the record file record = PackagesRecordFile(basedir + "/packages.xml") packages = record.read() # grab list of packages pl = self.yum.doPackageLists('all') # find the ones available to install for pkg in packages: decoded_pkgname = PackageRegistry.decode('yum', pkg.name) # ignore packages already installed (these are already marked to be updated) if not self.yum.rpmdb.installed(decoded_pkgname): exactmatch, matched, unmatched = yum.packages.parsePackages(pl.available, [decoded_pkgname]) # install packages with best matching architectures archs = {} for match in exactmatch: archs[match.arch] = match arch = self.yum.arch.get_best_arch_from_list(archs.keys()) if arch: pkg = archs[arch] if pkg: if snap.config.options.log_level_at_least('verbose'): snap.callback.snapcallback.message("Restoring package " + decoded_pkgname); self.yum.install(pkg) # build / run the transaction self.yum.buildTransaction() self.yum.processTransaction()
def testBackupPackages(self): backup_target = snap.backends.packages.syum.Syum() backup_target.backup(self.fs_root) pkgs = [] record = PackagesRecordFile(self.fs_root + "/packages.xml") record_packages = record.read() for pkg in record_packages: pkgs.append(pkg.name) # ensure all the system's packages have been encoded and recorded for pkg in yum.YumBase().rpmdb: encoded = PackageRegistry.encode('yum', pkg.name) self.assertIn(encoded, pkgs)
def testBackupPackages(self): backup_target = snap.backends.packages.sapt.Sapt() backup_target.backup(self.fs_root) pkgs = [] record = PackagesRecordFile(self.fs_root + "/packages.xml") record_packages = record.read() for pkg in record_packages: pkgs.append(pkg.name) # ensure all the system's packages have been recorded for pkg in apt.Cache(): if pkg.is_installed: encoded = PackageRegistry.encode('apt', pkg.name) self.assertIn(encoded, pkgs)
def testRestorePackages(self): restore_target = snap.backends.packages.sapt.Sapt() restore_target.backup(self.fs_root) restore_target.fs_root = self.fs_root restore_target.restore(self.fs_root) record = PackagesRecordFile(self.fs_root + "/packages.xml") record_packages = record.read() record_package_names = [] for pkg in record_packages: record_package_names.append(pkg.name) cache = apt.Cache() cache.open(None) for pkg in cache: if pkg.is_installed: encoded = PackageRegistry.encode('apt', pkg.name) self.assertIn(encoded, record_package_names)
def backup(self, basedir, include=[], exclude=[]): '''backup the packages installed locally''' if snap.config.options.log_level_at_least('verbose'): snap.callback.snapcallback.message("Backing up packages using yum backend"); # retrieve installed packages packages=[] packagenames = set() for pkg in self.yum.rpmdb: if not pkg.name in packagenames: if snap.config.options.log_level_at_least('verbose'): snap.callback.snapcallback.message("Backing up package " + pkg.name); packagenames.add(pkg.name) encoded_pkgname = PackageRegistry.encode('yum', pkg.name) packages.append(Package(encoded_pkgname, pkg.version)) # write record file to basedir record = PackagesRecordFile(basedir + "/packages.xml") record.write(packages)
def testRestorePackages(self): restore_target = snap.backends.packages.syum.Syum() restore_target.backup(self.fs_root) restore_target.fs_root = self.fs_root restore_target.restore(self.fs_root) record = PackagesRecordFile(self.fs_root + "/packages.xml") record_packages = record.read() record_package_names = [] for pkg in record_packages: record_package_names.append(pkg.name) installed_package_names = [] lyum = yum.YumBase() lyum.rpmdb.dbpath = self.fs_root + '/var/lib/rpm' for pkg in lyum.rpmdb: installed_package_names.append(pkg.name) for pkg in record_package_names: decoded = PackageRegistry.decode('yum', pkg) self.assertIn(decoded, installed_package_names)