Ejemplo n.º 1
0
    def calc_build_no(self, package_name):
        """Calculate build number"""

        # find previous build in ctx.config.options.output_dir
        found = []
        for root, dirs, files in os.walk(ctx.config.options.output_dir):
            for fn in files:
                fn = fn.decode('utf-8')
                if fn.startswith(package_name + '-') and \
                    fn.endswith(ctx.const.package_prefix):
                    old_package_fn = os.path.join(root, fn)
                    ctx.ui.info('(found old version %s)' % old_package_fn)
                    old_pkg = Package(old_package_fn, 'r')
                    old_pkg.read(os.path.join(ctx.config.tmp_dir(), 'oldpkg'))
                    old_build = old_pkg.metadata.package.build
                    found.append( (old_package_fn, old_build) )
        if not found:
            return 0
            ctx.ui.warning('(no previous build found, setting build no to 0.)')
        else:
            a = filter(lambda (x,y): y != None, found)
            if a:
                a.sort(lambda x,y : cmp(x[1],y[1]))
                old_package_fn = a[0][0]
                old_build = a[0][1]
            else:
                old_build = None

            # compare old files.xml with the new one..
            old_pkg = Package(old_package_fn, 'r')
            old_pkg.read(os.path.join(ctx.config.tmp_dir(), 'oldpkg'))

            # FIXME: TAKE INTO ACCOUNT MINOR CHANGES IN METADATA
            changed = False
            fnew = self.files.list
            fold = old_pkg.files.list
            fold.sort(lambda x,y : cmp(x.path,y.path))
            fnew.sort(lambda x,y : cmp(x.path,y.path))
            if len(fnew) != len(fold):
                changed = True
            else:
                for i in range(len(fold)):
                    fo = fold.pop(0)
                    fn = fnew.pop(0)
                    if fo.path != fn.path:
                        changed = True
                        break
                    else:
                        if fo.hash != fn.hash:
                            changed = True
                            break

            # set build number
            if old_build is None:
                ctx.ui.warning('(old package lacks a build no, setting build no to 0.)')
                return 0
            elif changed:
                return old_build + 1
            else:
                return old_build
Ejemplo n.º 2
0
 def locate_package_names(files):
     for fn in files:
         fn = fn.decode("utf-8")
         if util.is_package_name(fn, package_name):
             old_package_fn = util.join_path(root, fn)
             ctx.ui.info("(found old version %s)" % old_package_fn)
             old_pkg = Package(old_package_fn, "r")
             old_pkg.read(util.join_path(ctx.config.tmp_dir(), "oldpkg"))
             if str(old_pkg.metadata.package.name) != package_name:
                 ctx.ui.warning("Skipping %s with wrong pkg name " % old_package_fn)
                 continue
             old_build = old_pkg.metadata.package.build
             found.append((old_package_fn, old_build))
Ejemplo n.º 3
0
 def locate_package_names(files):
      for fn in files:
          fn = fn.decode('utf-8')
          if util.is_package_name(fn, package_name):
              old_package_fn = os.path.join(root, fn)
              ctx.ui.info('(found old version %s)' % old_package_fn)
              old_pkg = Package(old_package_fn, 'r')
              old_pkg.read(os.path.join(ctx.config.tmp_dir(), 'oldpkg'))
              if str(old_pkg.metadata.package.name) != package_name:
                  ctx.ui.warning('Skipping %s with wrong pkg name ' %
                                 old_package_fn)
                  continue
              old_build = old_pkg.metadata.package.build
              found.append( (old_package_fn, old_build) )
Ejemplo n.º 4
0
 def locate_old_package(old_package_fn):
     if util.is_package_name(os.path.basename(old_package_fn), package_name):
         try:
             old_pkg = Package(old_package_fn, 'r')
             old_pkg.read(util.join_path(ctx.config.tmp_dir(), 'oldpkg'))
             ctx.ui.info(_('(found old version %s)') % old_package_fn)
             if str(old_pkg.metadata.package.name) != package_name:
                 ctx.ui.warning(_('Skipping %s with wrong pkg name ') %
                                         old_package_fn)
                 return
             old_build = old_pkg.metadata.package.build
             found.append( (old_package_fn, old_build) )
         except Error:
             ctx.ui.warning('Package file %s may be corrupt. Skipping.' % old_package_fn)
Ejemplo n.º 5
0
class Install(AtomicOperation):
    "Install class, provides install routines for pisi packages"

    def __init__(self, package_fname, ignore_dep = None):
        "initialize from a file name"
        super(Install, self).__init__(ignore_dep)
        self.package = Package(package_fname)
        self.package.read()
        self.metadata = self.package.metadata
        self.files = self.package.files
        self.pkginfo = self.metadata.package

    def install(self, ask_reinstall = True):
        "entry point"
        ctx.ui.status(_('Installing %s, version %s, release %s, build %s') %
                (self.pkginfo.name, self.pkginfo.version,
                 self.pkginfo.release, self.pkginfo.build))
        ctx.ui.notify(pisi.ui.installing, package = self.pkginfo, files = self.files)

        self.ask_reinstall = ask_reinstall
        self.check_requirements()
        self.check_relations()
        self.check_reinstall()
        self.extract_install()
        self.store_pisi_files()
        if ctx.comar:
            import pisi.comariface as comariface
            self.register_comar_scripts()
            ctx.ui.notify(pisi.ui.configuring, package = self.pkginfo, files = self.files)
            comariface.run_postinstall(self.pkginfo.name)
            ctx.ui.notify(pisi.ui.configured, package = self.pkginfo, files = self.files)

        txn = ctx.dbenv.txn_begin()
        try:
            self.update_databases(txn)
            txn.commit()
        except db.DBError, e:
            txn.abort()
            raise e

        self.update_environment()
        ctx.ui.status()
        if self.upgrade:
            event = pisi.ui.upgraded
        else:
            event = pisi.ui.installed
        ctx.ui.notify(event, package = self.pkginfo, files = self.files)
Ejemplo n.º 6
0
 def locate_package_names(files):
     for fn in files:
         if util.is_package_name(fn, package_name):
             old_package_fn = util.join_path(root, fn)
             try:
                 old_pkg = Package(old_package_fn, 'r')
                 old_pkg.read(util.join_path(ctx.config.tmp_dir(), 'oldpkg'))
                 ctx.ui.info(_('(found old version %s)') % old_package_fn)
                 if str(old_pkg.metadata.package.name) != package_name:
                     ctx.ui.warning(_('Skipping %s with wrong pkg name ') %
                                    old_package_fn)
                     continue
                 old_build = old_pkg.metadata.package.build
                 found.append( (old_package_fn, old_build) )
             except:
                 ctx.ui.warning('Package file %s may be corrupt. Skipping.' % old_package_fn)
                 continue
Ejemplo n.º 7
0
 def locate_old_package(old_package_fn):
     if util.is_package_name(os.path.basename(old_package_fn),
                             package_name):
         try:
             old_pkg = Package(old_package_fn, 'r')
             old_pkg.read(util.join_path(ctx.config.tmp_dir(),
                                         'oldpkg'))
             ctx.ui.info(_('(found old version %s)') % old_package_fn)
             if str(old_pkg.metadata.package.name) != package_name:
                 ctx.ui.warning(
                     _('Skipping %s with wrong pkg name ') %
                     old_package_fn)
                 return
             old_build = old_pkg.metadata.package.build
             found.append((old_package_fn, old_build))
         except Exception, e:
             print e
             ctx.ui.warning(
                 'Package file %s may be corrupt. Skipping.' %
                 old_package_fn)
Ejemplo n.º 8
0
    def calc_build_no(self, package_name):
        """Calculate build number"""

        def metadata_changed(old_metadata, new_metadata):
            for key in old_metadata.package.__dict__.keys():
                if old_metadata.package.__dict__[key] != new_metadata.package.__dict__[key]:
                    if key != "build":
                        return True

            return False
            
        # find previous build in packages dir
        found = []        
        def locate_old_package(old_package_fn):
            if util.is_package_name(os.path.basename(old_package_fn), package_name):
                try:
                    old_pkg = Package(old_package_fn, 'r')
                    old_pkg.read(util.join_path(ctx.config.tmp_dir(), 'oldpkg'))
                    ctx.ui.info(_('(found old version %s)') % old_package_fn)
                    if str(old_pkg.metadata.package.name) != package_name:
                        ctx.ui.warning(_('Skipping %s with wrong pkg name ') %
                                                old_package_fn)
                        return
                    old_build = old_pkg.metadata.package.build
                    found.append( (old_package_fn, old_build) )
                except Error:
                    ctx.ui.warning('Package file %s may be corrupt. Skipping.' % old_package_fn)

        for root, dirs, files in os.walk(ctx.config.packages_dir()):
            for file in files:
                locate_old_package(join(root,file))

        outdir=ctx.get_option('output_dir')
        if not outdir:
            outdir = '.'
        for file in [join(outdir,entry) for entry in os.listdir(outdir)]:
            if os.path.isfile(file):
                locate_old_package(file)

        if not found:
            return (1, None)
            ctx.ui.warning(_('(no previous build found, setting build no to 1.)'))
        else:
            a = filter(lambda (x,y): y != None, found)
            ctx.ui.debug(str(a))
            if a:
                # sort in order of increasing build number
                a.sort(lambda x,y : cmp(x[1],y[1]))
                old_package_fn = a[-1][0]   # get the last one
                old_build = a[-1][1]

                # compare old files.xml with the new one..
                old_pkg = Package(old_package_fn, 'r')
                old_pkg.read(util.join_path(ctx.config.tmp_dir(), 'oldpkg'))
    
                changed = False
                fnew = self.files.list
                fold = old_pkg.files.list
                fold.sort(lambda x,y : cmp(x.path,y.path))
                fnew.sort(lambda x,y : cmp(x.path,y.path))
                    
                if len(fnew) != len(fold):
                    changed = True
                else:
                    for i in range(len(fold)):
                        fo = fold.pop(0)
                        fn = fnew.pop(0)
                        if fo.path != fn.path:
                            changed = True
                            break
                        else:
                            if fo.hash != fn.hash:
                                changed = True
                                break
                
                if metadata_changed(old_pkg.metadata, self.metadata):
                    changed = True

                self.old_packages.append(os.path.basename(old_package_fn))
            else: # no old build had a build number
                old_build = None

            ctx.ui.debug('old build number: %s' % old_build)
                            
            # set build number
            if old_build is None:
                ctx.ui.warning(_('(old package lacks a build no, setting build no to 1.)'))
                return (1, None)
            elif changed:
                ctx.ui.info(_('There are changes, incrementing build no to %d') % (old_build + 1))
                return (old_build + 1, old_build)
            else:
                ctx.ui.info(_('There is no change from previous build %d') % old_build)
                return (old_build, old_build)
Ejemplo n.º 9
0
class Installer:
    "Installer class, provides install routines for pisi packages"

    def __init__(self, package_fname):
        "initialize from a file name"
        self.package = Package(package_fname)
        self.package.read()
        self.metadata = self.package.metadata
        self.files = self.package.files
        self.pkginfo = self.metadata.package

    def install(self, ask_reinstall = True):
        "entry point"
        ctx.ui.info('Installing %s, version %s, release %s, build %s' %
                (self.pkginfo.name, self.pkginfo.version,
                 self.pkginfo.release, self.pkginfo.build))
        self.ask_reinstall = ask_reinstall
        self.check_requirements()
        self.check_relations()
        self.reinstall()
        self.extract_install()
        self.store_pisi_files()
        if ctx.comard:
            self.register_comar_scripts()
        self.update_databases()

    def check_requirements(self):
        """check system requirements"""
        #TODO: IS THERE ENOUGH SPACE?
        # what to do if / is split into /usr, /var, etc.
        pass

    def check_relations(self):
        # check if package is in database
        # If it is not, put it into 3rd party packagedb
        if not packagedb.has_package(self.pkginfo.name):
            db = packagedb.thirdparty_packagedb
            db.add_package(self.pkginfo)

        # check conflicts
        for pkg in self.metadata.package.conflicts:
            if ctx.installdb.is_installed(self.pkginfo):
                raise InstallError("Package conflicts " + pkg)

        # check dependencies
        if not ctx.config.get_option('ignore_dependency'):
            if not dependency.installable(self.pkginfo.name):
                ctx.ui.error('Dependencies for ' + self.pkginfo.name +
                             ' not satisfied')
                raise InstallError("Package not installable")

    def reinstall(self):
        "check reinstall, confirm action, and remove package if reinstall"

        pkg = self.pkginfo

        if ctx.installdb.is_installed(pkg.name): # is this a reinstallation?
            (iversion, irelease, ibuild) = ctx.installdb.get_version(pkg.name)

            # determine if same version
            same_ver = False
            ignore_build = ctx.config.options and ctx.config.options.ignore_build_no
            if (not ibuild) or (not pkg.build) or ignore_build:
                # we don't look at builds to compare two package versions
                if pkg.version == iversion and pkg.release == irelease:
                    same_ver = True
            else:
                if pkg.build == ibuild:
                    same_ver = True

            if same_ver:
                if self.ask_reinstall:
                    if not ctx.ui.confirm('Re-install same version package?'):
                        raise InstallError('Package re-install declined')
            else:
                upgrade = False
                # is this an upgrade?
                # determine and report the kind of upgrade: version, release, build
                if pkg.version > iversion:
                    ctx.ui.info('Upgrading to new upstream version')
                    upgrade = True
                elif pkg.release > irelease:
                    ctx.ui.info('Upgrading to new distribution release')
                    upgrade = True
                elif ((not ignore_build) and ibuild and pkg.build
                       and pkg.build > ibuild):
                    ctx.ui.info('Upgrading to new distribution build')
                    upgrade = True

                # is this a downgrade? confirm this action.
                if self.ask_reinstall and (not upgrade):
                    if pkg.version < iversion:
                        x = 'Downgrade to old upstream version?'
                    elif pkg.release < irelease:
                        x = 'Downgrade to old distribution release?'
                    else:
                        x = 'Downgrade to old distribution build?'
                    if not ctx.ui.confirm(x):
                        raise InstallError('Package downgrade declined')

            # remove old package then
            operations.remove_single(pkg.name)

    def extract_install(self):
        "unzip package in place"

        ctx.ui.info('Extracting files,')
        self.package.extract_dir_flat('install', ctx.config.destdir)
 
    def store_pisi_files(self):
        """put files.xml, metadata.xml, actions.py and COMAR scripts
        somewhere in the file system. We'll need these in future..."""

        ctx.ui.info('Storing %s, ' % ctx.const.files_xml)
        self.package.extract_file(ctx.const.files_xml, self.package.pkg_dir())

        ctx.ui.info('%s.' % ctx.const.metadata_xml)
        self.package.extract_file(ctx.const.metadata_xml, self.package.pkg_dir())

        for pcomar in self.metadata.package.providesComar:
            fpath = os.path.join(ctx.const.comar_dir, pcomar.script)
            # comar prefix is added to the pkg_dir while extracting comar
            # script file. so we'll use pkg_dir as destination.
            ctx.ui.info('Storing %s' % fpath)
            self.package.extract_file(fpath, self.package.pkg_dir())

    def register_comar_scripts(self):
        "register COMAR scripts"

        com = ctx.comard

        for pcomar in self.metadata.package.providesComar:
            scriptPath = os.path.join(self.package.comar_dir(),pcomar.script)
            ctx.ui.info("Registering COMAR script %s" % pcomar.script)

            com.register(pcomar.om,
                         self.metadata.package.name,
                         scriptPath)
            while 1:
                reply = com.read_cmd()
                if reply[0] == com.RESULT:
                    break
                elif reply[1] == com.ERROR:
                    raise InstallError, "COMAR.register failed!"


    def update_databases(self):
        "update databases"

        # installdb
        ctx.installdb.install(self.metadata.package.name,
                          self.metadata.package.version,
                          self.metadata.package.release,
                          self.metadata.package.build,
                          self.metadata.package.distribution)

        # installed packages
        packagedb.inst_packagedb.add_package(self.pkginfo)
Ejemplo n.º 10
0
    def calc_build_no(self, package_name):
        """Calculate build number"""

        # find previous build in output dir and packages dir
        found = []        
        def locate_package_names(files):
            for fn in files:
                fn = fn.decode('utf-8')
                if util.is_package_name(fn, package_name):
                    old_package_fn = util.join_path(root, fn)
                    try:
                        old_pkg = Package(old_package_fn, 'r')
                        old_pkg.read(util.join_path(ctx.config.tmp_dir(), 'oldpkg'))
                        ctx.ui.info(_('(found old version %s)') % old_package_fn)
                        if str(old_pkg.metadata.package.name) != package_name:
                            ctx.ui.warning(_('Skipping %s with wrong pkg name ') %
                                           old_package_fn)
                            continue
                        old_build = old_pkg.metadata.package.build
                        found.append( (old_package_fn, old_build) )
                    except:
                        ctx.ui.warning('Package file %s may be corrupt. Skipping.' % old_package_fn)
                        continue

        for root, dirs, files in os.walk(ctx.config.options.output_dir):
            dirs = [] # don't recurse
            locate_package_names(files)
        for root, dirs, files in os.walk(ctx.config.packages_dir()):
            locate_package_names(files)

        if not found:
            return 1
            ctx.ui.warning(_('(no previous build found, setting build no to 1.)'))
        else:
            a = filter(lambda (x,y): y != None, found)
            ctx.ui.debug(str(a))
            if a:
                # sort in order of increasing build number
                a.sort(lambda x,y : cmp(x[1],y[1]))
                old_package_fn = a[-1][0]   # get the last one
                old_build = a[-1][1]

                # compare old files.xml with the new one..
                old_pkg = Package(old_package_fn, 'r')
                old_pkg.read(util.join_path(ctx.config.tmp_dir(), 'oldpkg'))
    
                # FIXME: TAKE INTO ACCOUNT MINOR CHANGES IN METADATA
                changed = False
                fnew = self.files.list
                fold = old_pkg.files.list
                fold.sort(lambda x,y : cmp(x.path,y.path))
                fnew.sort(lambda x,y : cmp(x.path,y.path))
                    
                if len(fnew) != len(fold):
                    changed = True
                else:
                    for i in range(len(fold)):
                        fo = fold.pop(0)
                        fn = fnew.pop(0)
                        if fo.path != fn.path:
                            changed = True
                            break
                        else:
                            #FIXME: workaround for .a issue, skip .a files
                            if fn.path.endswith('.a') and fn.type=='library':
                                continue
                            if fo.hash != fn.hash:
                                changed = True
                                break
            else: # no old build had a build number
                old_build = None

            ctx.ui.debug('old build number: %s' % old_build)
                            
            # set build number
            if old_build is None:
                ctx.ui.warning(_('(old package lacks a build no, setting build no to 1.)'))
                return 1
            elif changed:
                ctx.ui.info(_('There are changes, incrementing build no to %d') % (old_build + 1))
                return old_build + 1
            else:
                ctx.ui.info(_('There is no change from previous build %d') % old_build)
                return old_build
Ejemplo n.º 11
0
class Install(AtomicOperation):
    "Install class, provides install routines for pisi packages"

    @staticmethod
    def from_name(name):
        # download package and return an installer object
        # find package in repository
        repo = packagedb.which_repo(name)
        if repo:
            repo = ctx.repodb.get_repo(repo)
            pkg = packagedb.get_package(name)
    
            # FIXME: let pkg.packageURI be stored as URI type rather than string
            pkg_uri = URI(pkg.packageURI)
            if pkg_uri.is_absolute_path():
                pkg_path = str(pkg.packageURI)
            else:
                pkg_path = os.path.join(os.path.dirname(repo.indexuri.get_uri()),
                                        str(pkg_uri.path()))
    
            ctx.ui.debug(_("Package URI: %s") % pkg_path)
    
            return Install(pkg_path)
        else:
            raise Error(_("Package %s not found in any active repository.") % name)

    def __init__(self, package_fname, ignore_dep = None):
        "initialize from a file name"
        super(Install, self).__init__(ignore_dep)
        self.package = Package(package_fname)
        self.package.read()
        self.metadata = self.package.metadata
        self.files = self.package.files
        self.pkginfo = self.metadata.package

    def install(self, ask_reinstall = True):
        "entry point"
        ctx.ui.status(_('Installing %s, version %s, release %s, build %s') %
                (self.pkginfo.name, self.pkginfo.version,
                 self.pkginfo.release, self.pkginfo.build))
        ctx.ui.notify(pisi.ui.installing, package = self.pkginfo, files = self.files)

        self.ask_reinstall = ask_reinstall
        self.check_requirements()
        self.check_relations()
        self.check_reinstall()
        self.extract_install()
        self.store_pisi_files()

        self.config_later = False

        if self.metadata.package.providesComar:
            if ctx.comar:
                import pisi.comariface as comariface
                self.register_comar_scripts()
            else:
                self.config_later = True # configure-pending will register scripts later

        if 'System.Package' in [x.om for x in self.metadata.package.providesComar]:
            if ctx.comar:
                ctx.ui.notify(pisi.ui.configuring, package = self.pkginfo, files = self.files)
                comariface.run_postinstall(self.pkginfo.name)
                ctx.ui.notify(pisi.ui.configured, package = self.pkginfo, files = self.files)
            else:
                self.config_later = True

        txn = ctx.dbenv.txn_begin()
        try:
            self.update_databases(txn)
            txn.commit()
        except db.DBError, e:
            txn.abort()
            raise e

        self.update_environment()
        ctx.ui.status()
        if self.upgrade:
            event = pisi.ui.upgraded
        else:
            event = pisi.ui.installed
        ctx.ui.notify(event, package = self.pkginfo, files = self.files)
Ejemplo n.º 12
0
class Install(AtomicOperation):
    "Install class, provides install routines for pisi packages"

    def __init__(self, package_fname, ignore_dep = None):
        "initialize from a file name"
        super(Install, self).__init__(ignore_dep)
        self.package = Package(package_fname)
        self.package.read()
        self.metadata = self.package.metadata
        self.files = self.package.files
        self.pkginfo = self.metadata.package

    def install(self, ask_reinstall = True):
        "entry point"
        ctx.ui.status(_('Installing %s, version %s, release %s, build %s') %
                (self.pkginfo.name, self.pkginfo.version,
                 self.pkginfo.release, self.pkginfo.build))
        ctx.ui.notify(pisi.ui.installing, package = self.pkginfo, files = self.files)
        self.ask_reinstall = ask_reinstall
        self.check_requirements()
        self.check_relations()
        self.check_reinstall()
        self.extract_install()
        self.store_pisi_files()
        if ctx.comar:
            import pisi.comariface as comariface
            self.register_comar_scripts()
            comariface.run_postinstall(self.pkginfo.name)
        self.update_databases()
        self.update_environment()
        ctx.ui.status()
        if self.upgrade:
            event = pisi.ui.upgraded
        else:
            event = pisi.ui.installed
        ctx.ui.notify(event, package = self.pkginfo, files = self.files)

    def check_requirements(self):
        """check system requirements"""
        #TODO: IS THERE ENOUGH SPACE?
        # what to do if / is split into /usr, /var, etc.
        pass

    def check_relations(self):
        # check conflicts
        for pkg in self.metadata.package.conflicts:
            if ctx.installdb.is_installed(self.pkginfo):
                raise Error(_("Package conflicts %s") % pkg)

        # check dependencies
        if not ctx.config.get_option('ignore_dependency'):
            if not self.pkginfo.installable():
                ctx.ui.error(_('Dependencies for %s not satisfied') %
                             self.pkginfo.name)
                raise Error(_("Package not installable"))

        # check if package is in database
        # If it is not, put it into 3rd party packagedb
        if not packagedb.has_package(self.pkginfo.name):
            db = packagedb.thirdparty_packagedb
            db.add_package(self.pkginfo)

    def check_reinstall(self):
        "check reinstall, confirm action, and schedule reinstall"

        pkg = self.pkginfo

        self.reinstall = False
        self.upgrade = False
        if ctx.installdb.is_installed(pkg.name): # is this a reinstallation?
            (iversion, irelease, ibuild) = ctx.installdb.get_version(pkg.name)

            # determine if same version
            same_ver = False
            ignore_build = ctx.config.options and ctx.config.options.ignore_build_no
            if (not ibuild) or (not pkg.build) or ignore_build:
                # we don't look at builds to compare two package versions
                if pkg.version == iversion and pkg.release == irelease:
                    same_ver = True
            else:
                if pkg.build == ibuild:
                    same_ver = True

            if same_ver:
                if self.ask_reinstall:
                    if not ctx.ui.confirm(_('Re-install same version package?')):
                        raise Error(_('Package re-install declined'))
            else:
                upgrade = False
                # is this an upgrade?
                # determine and report the kind of upgrade: version, release, build
                if pkg.version > iversion:
                    ctx.ui.info(_('Upgrading to new upstream version'))
                    upgrade = True
                elif pkg.release > irelease:
                    ctx.ui.info(_('Upgrading to new distribution release'))
                    upgrade = True
                elif ((not ignore_build) and ibuild and pkg.build
                       and pkg.build > ibuild):
                    ctx.ui.info(_('Upgrading to new distribution build'))
                    upgrade = True
                self.upgrade = upgrade

                # is this a downgrade? confirm this action.
                if self.ask_reinstall and (not upgrade):
                    if pkg.version < iversion:
                        x = _('Downgrade to old upstream version?')
                    elif pkg.release < irelease:
                        x = _('Downgrade to old distribution release?')
                    else:
                        x = _('Downgrade to old distribution build?')
                    if not ctx.ui.confirm(x):
                        raise Error(_('Package downgrade declined'))


            # schedule for reinstall
            self.old_files = ctx.installdb.files(pkg.name)
            self.old_path = ctx.installdb.pkg_dir(pkg.name, iversion, irelease)
            self.reinstall = True
            Remove(pkg.name).run_preremove()

    def extract_install(self):
        "unzip package in place"

        ctx.ui.info(_('Extracting files'))
        self.package.extract_dir_flat('install', ctx.config.dest_dir())

        if self.reinstall:
            # remove left over files
            new = set(map(lambda x: str(x.path), self.files.list))
            old = set(map(lambda x: str(x.path), self.old_files.list))
            leftover = old - new
            old_fileinfo = {}
            for fileinfo in self.old_files.list:
                old_fileinfo[str(fileinfo.path)] = fileinfo
            for path in leftover:
                Remove.remove_file( old_fileinfo[path] )

    def store_pisi_files(self):
        """put files.xml, metadata.xml, actions.py and COMAR scripts
        somewhere in the file system. We'll need these in future..."""

        ctx.ui.info(_('Storing %s, ') % ctx.const.files_xml)
        self.package.extract_file(ctx.const.files_xml, self.package.pkg_dir())

        ctx.ui.info(_('Storing %s.') % ctx.const.metadata_xml)
        self.package.extract_file(ctx.const.metadata_xml, self.package.pkg_dir())

        for pcomar in self.metadata.package.providesComar:
            fpath = os.path.join(ctx.const.comar_dir, pcomar.script)
            # comar prefix is added to the pkg_dir while extracting comar
            # script file. so we'll use pkg_dir as destination.
            ctx.ui.info(_('Storing %s') % fpath)
            self.package.extract_file(fpath, self.package.pkg_dir())

    def register_comar_scripts(self):
        "register COMAR scripts"

        for pcomar in self.metadata.package.providesComar:
            scriptPath = os.path.join(self.package.comar_dir(),pcomar.script)
            import pisi.comariface
            pisi.comariface.register(pcomar, self.metadata.package.name,
                                     scriptPath)

    def update_databases(self):
        "update databases"

        if self.reinstall:
            Remove(self.metadata.package.name).remove_db()
            Remove.remove_pisi_files(self.old_path)

        # installdb
        ctx.installdb.install(self.metadata.package.name,
                          self.metadata.package.version,
                          self.metadata.package.release,
                          self.metadata.package.build,
                          self.metadata.package.distribution)

        # filesdb
        ctx.filesdb.add_files(self.metadata.package.name, self.files)

        # installed packages
        packagedb.inst_packagedb.add_package(self.pkginfo)

    def update_environment(self):
        # check if we have any shared objects or anything under
        # /etc/env.d
        shared = False
        for x in self.files.list:
            if x.path.endswith('.so') or x.path.startswith('/etc/env.d'):
                shared = True
                break
        if not ctx.get_option('bypass_ldconfig'):
            if shared:
                ctx.ui.info(_("Regenerating /etc/ld.so.cache..."))
                util.env_update()
        else:
            ctx.ui.warning(_("Bypassing ldconfig"))
Ejemplo n.º 13
0
import pisi.specfile as specfile
import pisi.context as ctx
import pisi.util as util
from pisi.package import Package

locale.setlocale(locale.LC_ALL, '')
options = pisi.config.Options()
if len(sys.argv) > 2:
    options.destdir=sys.argv[2]
else:
    options.destdir = '/'
pisi.api.init(database=True, comar=False, options=options)

filename = sys.argv[1]
package = Package(filename)
package.read()
util.clean_dir('/tmp/install')
package.extract_dir_flat('install', '/tmp/install')
deps = set()
needed = set()
for file in package.files.list:
    #print file.path, file.type
    if file.type == 'executable':
        (ret, lines) = util.run_batch('objdump -p %s' % util.join_path('/tmp/install', file.path))
        for x in lines:
            if x.startswith('  NEEDED'):
                needed.add(x[8:].strip())

#print 'needed guys', needed

for lib in needed:
Ejemplo n.º 14
0
import pisi.specfile as specfile
import pisi.context as ctx
import pisi.util as util
from pisi.package import Package

locale.setlocale(locale.LC_ALL, '')
options = pisi.config.Options()
if len(sys.argv) > 2:
    options.destdir = sys.argv[2]
else:
    options.destdir = '/'
pisi.api.init(database=True, comar=False, options=options)

filename = sys.argv[1]
package = Package(filename)
package.read()
util.clean_dir('/tmp/install')
package.extract_dir_flat('install', '/tmp/install')
deps = set()
needed = set()
for file in package.files.list:
    #print file.path, file.type
    if file.type == 'executable':
        (ret, lines) = util.run_batch(
            'objdump -p %s' % util.join_path('/tmp/install', file.path))
        for x in lines:
            if x.startswith('  NEEDED'):
                needed.add(x[8:].strip())

#print 'needed guys', needed
Ejemplo n.º 15
0
    def calc_build_no(self, package_name):
        """Calculate build number"""

        # find previous build in output dir and packages dir
        found = []

        def locate_package_names(files):
            for fn in files:
                fn = fn.decode("utf-8")
                if util.is_package_name(fn, package_name):
                    old_package_fn = util.join_path(root, fn)
                    ctx.ui.info("(found old version %s)" % old_package_fn)
                    old_pkg = Package(old_package_fn, "r")
                    old_pkg.read(util.join_path(ctx.config.tmp_dir(), "oldpkg"))
                    if str(old_pkg.metadata.package.name) != package_name:
                        ctx.ui.warning("Skipping %s with wrong pkg name " % old_package_fn)
                        continue
                    old_build = old_pkg.metadata.package.build
                    found.append((old_package_fn, old_build))

        for root, dirs, files in os.walk(ctx.config.options.output_dir):
            dirs = []  # don't recurse
            locate_package_names(files)
        for root, dirs, files in os.walk(ctx.config.packages_dir()):
            locate_package_names(files)

        if not found:
            return 1
            ctx.ui.warning(_("(no previous build found, setting build no to 1.)"))
        else:
            a = filter(lambda (x, y): y != None, found)
            ctx.ui.debug(str(a))
            if a:
                a.sort(lambda x, y: cmp(x[1], y[1]))
                old_package_fn = a[0][0]
                old_build = a[0][1]
            else:
                old_build = None

            # compare old files.xml with the new one..
            old_pkg = Package(old_package_fn, "r")
            old_pkg.read(util.join_path(ctx.config.tmp_dir(), "oldpkg"))

            # FIXME: TAKE INTO ACCOUNT MINOR CHANGES IN METADATA
            changed = False
            fnew = self.files.list
            fold = old_pkg.files.list
            fold.sort(lambda x, y: cmp(x.path, y.path))
            fnew.sort(lambda x, y: cmp(x.path, y.path))
            if len(fnew) != len(fold):
                changed = True
            else:
                for i in range(len(fold)):
                    fo = fold.pop(0)
                    fn = fnew.pop(0)
                    if fo.path != fn.path:
                        changed = True
                        break
                    else:
                        if fo.hash != fn.hash:
                            changed = True
                            break

            # set build number
            if old_build is None:
                ctx.ui.warning(_("(old package lacks a build no, setting build no to 0.)"))
                return 0
            elif changed:
                ctx.ui.info(_("There are changes, incrementing build no to %d") % (old_build + 1))
                return old_build + 1
            else:
                ctx.ui.info(_("There is no change from previous build %d ") % old_build)
                return old_build
Ejemplo n.º 16
0
    def calc_build_no(self, package_name):
        """Calculate build number"""

        def found_package(fn):
            "did we find the filename we were looking for?"
            if fn.startswith(package_name + '-'):
                if fn.endswith(ctx.const.package_prefix):
                    # get version string, skip separator '-'
                    verstr = fn[len(package_name) + 1:
                                len(fn)-len(ctx.const.package_prefix)]
                    import string
                    for x in verstr.split('-'):
                        # weak rule: version components start with a digit
                        if x is '' or (not x[0] in string.digits):
                            return False
                    return True
            return False

        # find previous build in ctx.config.options.output_dir
        found = []
#        for root, dirs, files in os.walk(ctx.config.options.output_dir):
#             for fn in files:
#                 fn = fn.decode('utf-8')
#                 if found_package(fn):
#                     old_package_fn = os.path.join(root, fn)
#                     ctx.ui.info('(found old version %s)' % old_package_fn)
#                     old_pkg = Package(old_package_fn, 'r')
#                     old_pkg.read(os.path.join(ctx.config.tmp_dir(), 'oldpkg'))
#                     if str(old_pkg.metadata.package.name) != package_name:
#                         ctx.ui.warning('Skipping %s with wrong pkg name ' %
#                                        old_package_fn)
#                         continue
#                     old_build = old_pkg.metadata.package.build
#                     found.append( (old_package_fn, old_build) )
#
# FIXME: Following dirty lines of code just search in the output_dir and
# packages dir for previous packages. But we should find a neat way
# for this...
        files = []
        for f in os.listdir(ctx.config.options.output_dir):
            fp = os.path.join(ctx.config.options.output_dir, f)
            if os.path.isfile(fp):
                files.append(fp)

        packages_dir = ctx.config.packages_dir()
        # FIXME: packages_dir() should be there!
        if not os.path.exists(packages_dir):
            os.makedirs(packages_dir)
        for f in os.listdir(packages_dir):
            fp = os.path.join(packages_dir, f)
            if os.path.isfile(fp):
                files.append(fp)

        for fn in files:
            fn = fn.decode('utf-8')
            if found_package(os.path.basename(fn)):
                old_package_fn = fn
                ctx.ui.info('(found old version %s)' % old_package_fn)
                old_pkg = Package(old_package_fn, 'r')
                old_pkg.read(os.path.join(ctx.config.tmp_dir(), 'oldpkg'))
                if str(old_pkg.metadata.package.name) != package_name:
                    ctx.ui.warning('Skipping %s with wrong pkg name ' %
                                   old_package_fn)
                    continue
                old_build = old_pkg.metadata.package.build
                found.append( (old_package_fn, old_build) )
        if not found:
            return 0
            ctx.ui.warning('(no previous build found, setting build no to 0.)')
        else:
            a = filter(lambda (x,y): y != None, found)
            ctx.ui.debug(str(a))
            if a:
                a.sort(lambda x,y : cmp(x[1],y[1]))
                old_package_fn = a[0][0]
                old_build = a[0][1]
            else:
                old_build = None

            # compare old files.xml with the new one..
            old_pkg = Package(old_package_fn, 'r')
            old_pkg.read(os.path.join(ctx.config.tmp_dir(), 'oldpkg'))

            # FIXME: TAKE INTO ACCOUNT MINOR CHANGES IN METADATA
            changed = False
            fnew = self.files.list
            fold = old_pkg.files.list
            fold.sort(lambda x,y : cmp(x.path,y.path))
            fnew.sort(lambda x,y : cmp(x.path,y.path))
            if len(fnew) != len(fold):
                changed = True
            else:
                for i in range(len(fold)):
                    fo = fold.pop(0)
                    fn = fnew.pop(0)
                    if fo.path != fn.path:
                        changed = True
                        break
                    else:
                        if fo.hash != fn.hash:
                            changed = True
                            break

            # set build number
            if old_build is None:
                ctx.ui.warning('(old package lacks a build no, setting build no to 0.)')
                return 0
            elif changed:
                ctx.ui.info('There are changes, incrementing build no to %d' % (old_build + 1))
                return old_build + 1
            else:
                ctx.ui.info('There is no change from previous build %d ' % old_build)                
                return old_build
Ejemplo n.º 17
0
        if not found:
            return (1, None)
            ctx.ui.warning(
                _('(no previous build found, setting build no to 1.)'))
        else:
            a = filter(lambda (x, y): y != None, found)
            ctx.ui.debug(str(a))
            if a:
                # sort in order of increasing build number
                a.sort(lambda x, y: cmp(x[1], y[1]))
                old_package_fn = a[-1][0]  # get the last one
                old_build = a[-1][1]

                # compare old files.xml with the new one..
                old_pkg = Package(old_package_fn, 'r')
                old_pkg.read(util.join_path(ctx.config.tmp_dir(), 'oldpkg'))

                # FIXME: TAKE INTO ACCOUNT MINOR CHANGES IN METADATA
                changed = False
                fnew = self.files.list
                fold = old_pkg.files.list
                fold.sort(lambda x, y: cmp(x.path, y.path))
                fnew.sort(lambda x, y: cmp(x.path, y.path))

                if len(fnew) != len(fold):
                    changed = True
                else:
                    for i in range(len(fold)):
                        fo = fold.pop(0)
                        fn = fnew.pop(0)
                        if fo.path != fn.path: