* rebuilddb -> rebuild-db
* factor rebuild-db stuff into atomicoperations, but this might deserve its own module when I implement other recovery stuff.
This commit is contained in:
+2
-32
@@ -40,7 +40,8 @@ import pisi.installdb
|
||||
import pisi.sourcedb
|
||||
from pisi.index import Index
|
||||
import pisi.cli
|
||||
from pisi.operations import install, remove, upgrade, virtual_install
|
||||
from pisi.operations import install, remove, upgrade
|
||||
from pisi.atomicoperations import resurrect_package
|
||||
from pisi.metadata import MetaData
|
||||
from pisi.files import Files
|
||||
|
||||
@@ -334,34 +335,3 @@ def delete_cache():
|
||||
util.clean_dir(ctx.config.packages_dir())
|
||||
util.clean_dir(ctx.config.archives_dir())
|
||||
util.clean_dir(ctx.config.tmp_dir())
|
||||
|
||||
def resurrect_package(package_fn):
|
||||
"""Resurrect the package in the PiSi databases"""
|
||||
|
||||
metadata_xml = util.join_path(ctx.config.lib_dir(), package_fn, ctx.const.metadata_xml)
|
||||
if not exists(metadata_xml):
|
||||
return
|
||||
|
||||
metadata = MetaData()
|
||||
metadata.read(metadata_xml)
|
||||
|
||||
errs = metadata.has_errors()
|
||||
if errs:
|
||||
util.Checks.print_errors(errs)
|
||||
raise Error, _("MetaData format wrong (%s)") % package_fn
|
||||
|
||||
ctx.ui.info(_('* Adding \'%s\' to db... ') % (metadata.package.name), noln=True)
|
||||
|
||||
files_xml = util.join_path(ctx.config.lib_dir(), package_fn, ctx.const.files_xml)
|
||||
if not exists(files_xml):
|
||||
return
|
||||
|
||||
files = Files()
|
||||
files.read(files_xml)
|
||||
|
||||
if files.has_errors():
|
||||
raise Error, _("Invalid %s") % ctx.const.files_xml
|
||||
|
||||
virtual_install(metadata, files)
|
||||
ctx.ui.info(_('OK.'))
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ import pisi.util as util
|
||||
from pisi.specfile import *
|
||||
from pisi.package import Package
|
||||
from pisi.metadata import MetaData
|
||||
from pisi.files import Files
|
||||
from pisi.uri import URI
|
||||
#import conflicts
|
||||
|
||||
@@ -356,3 +357,82 @@ class Remove(AtomicOperation):
|
||||
|
||||
def remove_single(package_name):
|
||||
Remove(package_name).run()
|
||||
|
||||
def __is_virtual_upgrade(metadata):
|
||||
|
||||
pkg = metadata.package
|
||||
|
||||
(iversion, irelease, ibuild) = ctx.installdb.get_version(pkg.name)
|
||||
|
||||
upgrade = False
|
||||
if pkg.version > iversion:
|
||||
upgrade = True
|
||||
elif pkg.release > irelease:
|
||||
upgrade = True
|
||||
elif (ibuild and pkg.build and pkg.build > ibuild):
|
||||
upgrade = True
|
||||
|
||||
return upgrade
|
||||
|
||||
def virtual_install(metadata, files):
|
||||
"""Recreate the package info for rebuilddb command"""
|
||||
pkg = metadata.package
|
||||
|
||||
# normally this can't be true. Just for backward compatibility
|
||||
# TODO: for speed only ctx.installdb.install exception can be
|
||||
# handled but this is much cleaner
|
||||
if ctx.installdb.is_installed(pkg.name):
|
||||
if __is_virtual_upgrade(metadata):
|
||||
ctx.installdb.remove(pkg.name)
|
||||
packagedb.remove_package(pkg.name)
|
||||
#FIXME: files ne oluyor?
|
||||
#else:
|
||||
# return
|
||||
|
||||
pkginfo = metadata.package
|
||||
|
||||
# installdb
|
||||
ctx.installdb.install(metadata.package.name,
|
||||
metadata.package.version,
|
||||
metadata.package.release,
|
||||
metadata.package.build,
|
||||
metadata.package.distribution)
|
||||
|
||||
# filesdb
|
||||
ctx.filesdb.add_files(metadata.package.name, files)
|
||||
|
||||
# installed packages
|
||||
packagedb.inst_packagedb.add_package(pkginfo)
|
||||
|
||||
def resurrect_package(package_fn):
|
||||
"""Resurrect the package in the PiSi databases"""
|
||||
|
||||
from os.path import exists
|
||||
|
||||
metadata_xml = util.join_path(ctx.config.lib_dir(), package_fn, ctx.const.metadata_xml)
|
||||
if not exists(metadata_xml):
|
||||
raise Error, _("Metadata XML '%s' cannot be found") % metadata_xml
|
||||
|
||||
metadata = MetaData()
|
||||
metadata.read(metadata_xml)
|
||||
|
||||
errs = metadata.has_errors()
|
||||
if errs:
|
||||
util.Checks.print_errors(errs)
|
||||
raise Error, _("MetaData format wrong (%s)") % package_fn
|
||||
|
||||
ctx.ui.info(_('* Adding \'%s\' to db... ') % (metadata.package.name), noln=True)
|
||||
|
||||
files_xml = util.join_path(ctx.config.lib_dir(), package_fn, ctx.const.files_xml)
|
||||
if not exists(files_xml):
|
||||
raise Error, _("Files XML '%s' cannot be found") % files_xml
|
||||
|
||||
files = Files()
|
||||
files.read(files_xml)
|
||||
|
||||
if files.has_errors():
|
||||
raise Error, _("Invalid %s") % ctx.const.files_xml
|
||||
|
||||
import pisi.atomicoperations
|
||||
pisi.atomicoperations.virtual_install(metadata, files)
|
||||
ctx.ui.info(_('OK.'))
|
||||
|
||||
@@ -593,19 +593,18 @@ Rebuilds the PiSi databases
|
||||
def __init__(self):
|
||||
super(RebuildDb, self).__init__()
|
||||
|
||||
name = ("rebuilddb", "rd")
|
||||
name = ("rebuild-db", "rdb")
|
||||
|
||||
def run(self):
|
||||
self.init()
|
||||
self.init(database=False)
|
||||
|
||||
#FIXME: Confirm icin init, unlink icin finalize, rebuild_db icin init lazim :)
|
||||
if ctx.ui.confirm(_('Rebuild PISI databases? ')):
|
||||
if ctx.ui.confirm(_('Rebuild PISI databases?')):
|
||||
self.finalize()
|
||||
import os
|
||||
for db in os.listdir(ctx.config.db_dir()):
|
||||
os.unlink(pisi.util.join_path(ctx.config.db_dir(), db))
|
||||
|
||||
self.init()
|
||||
self.init(database=True)
|
||||
self.rebuild_db()
|
||||
|
||||
self.finalize()
|
||||
|
||||
@@ -420,50 +420,3 @@ in the respective order to satisfy dependencies:
|
||||
atomicoperations.remove_single(x)
|
||||
else:
|
||||
ctx.ui.info(_('Package %s is not installed. Cannot remove.') % x)
|
||||
|
||||
def __is_virtual_upgrade(metadata):
|
||||
|
||||
pkg = metadata.package
|
||||
|
||||
(iversion, irelease, ibuild) = ctx.installdb.get_version(pkg.name)
|
||||
|
||||
upgrade = False
|
||||
if pkg.version > iversion:
|
||||
upgrade = True
|
||||
elif pkg.release > irelease:
|
||||
upgrade = True
|
||||
elif (ibuild and pkg.build
|
||||
and pkg.build > ibuild):
|
||||
upgrade = True
|
||||
|
||||
return upgrade
|
||||
|
||||
def virtual_install(metadata, files):
|
||||
"""Recreate the package info for rebuilddb command"""
|
||||
pkg = metadata.package
|
||||
|
||||
# normally this can't be true. Just for backward compatibility
|
||||
# TODO: for speed only ctx.installdb.install exception can be
|
||||
# handled but this is much cleaner
|
||||
if ctx.installdb.is_installed(pkg.name):
|
||||
if __is_virtual_upgrade(metadata):
|
||||
ctx.installdb.remove(pkg.name)
|
||||
packagedb.remove_package(pkg.name)
|
||||
#FIXME: files ne oluyor?
|
||||
else:
|
||||
return
|
||||
|
||||
pkginfo = metadata.package
|
||||
|
||||
# installdb
|
||||
ctx.installdb.install(metadata.package.name,
|
||||
metadata.package.version,
|
||||
metadata.package.release,
|
||||
metadata.package.build,
|
||||
metadata.package.distribution)
|
||||
|
||||
# filesdb
|
||||
ctx.filesdb.add_files(metadata.package.name, files)
|
||||
|
||||
# installed packages
|
||||
packagedb.inst_packagedb.add_package(pkginfo)
|
||||
|
||||
Reference in New Issue
Block a user