Ejemplo n.º 1
0
    def add_package(self, path, repo_uri):
        package = Package(path, 'r')
        # extract control files
        util.clean_dir(ctx.config.install_dir())
        package.extract_PISI_files(ctx.config.install_dir())

        md = metadata.MetaData()
        md.read(os.path.join(ctx.config.install_dir(), ctx.const.metadata_xml))
        md.package.packageSize = os.path.getsize(path)
        if ctx.config.options and ctx.config.options.absolute_uris:
            # FIXME: the name "absolute_uris" does not seem to fit below :/
            md.package.packageURI = os.path.realpath(path)
        else:  # create relative path by default
            # TODO: in the future well do all of this with purl/pfile/&helpers
            # really? heheh -- future exa
            md.package.packageURI = util.removepathprefix(repo_uri, path)
        # check package semantics
        errs = md.errors()
        if md.errors():
            ctx.ui.error(
                _('Package %s: metadata corrupt, skipping...') %
                md.package.name)
            ctx.ui.error(unicode(Error(*errs)))
        else:
            self.packages.append(md.package)
Ejemplo n.º 2
0
    def add_package(self, path, deltas, repo_uri):
        package = Package(path, 'r')
        md = package.get_metadata()
        md.package.packageSize = os.path.getsize(path)
        md.package.packageHash = util.sha1_file(path)
        if ctx.config.options and ctx.config.options.absolute_urls:
            md.package.packageURI = os.path.realpath(path)
        else:                           # create relative path by default
            # TODO: in the future well do all of this with purl/pfile/&helpers
            # really? heheh -- future exa
            md.package.packageURI = util.removepathprefix(repo_uri, path)
        # check package semantics
        errs = md.errors()
        if md.errors():
            ctx.ui.error(_('Package %s: metadata corrupt, skipping...') % md.package.name)
            ctx.ui.error(unicode(Error(*errs)))
        else:
            # No need to carry these with index (#3965)
            md.package.files = None
            md.package.additionalFiles = None

            if md.package.name in deltas:
                for delta_path in deltas[md.package.name]:
                    delta = metadata.Delta()
                    delta.packageURI = util.removepathprefix(repo_uri, delta_path)
                    delta.packageSize = os.path.getsize(delta_path)
                    delta.packageHash = util.sha1_file(delta_path)
                    name, buildFrom, buildTo = util.parse_delta_package_name(delta_path)
                    delta.buildFrom = buildFrom
                    md.package.deltaPackages.append(delta)

            self.packages.append(md.package)
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 = 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.º 4
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.º 5
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.º 6
0
 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
Ejemplo n.º 7
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.º 8
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.º 9
0
 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
Ejemplo n.º 10
0
 def __init__(self, package_fname, ignore_dep = None):
     "initialize from a file name"
     super(Install, self).__init__(ignore_dep)
     self.package = Package(package_fname)
     ctx.ui.notify(pisi.ui.downloading, url = package_fname)        
     self.package.read()
     self.metadata = self.package.metadata
     self.files = self.package.files
     self.pkginfo = self.metadata.package
Ejemplo n.º 11
0
 def add_package(self, path, repo_uri):
     package = Package(path, 'r')
     md = package.get_metadata()
     md.package.packageSize = os.path.getsize(path)
     md.package.packageHash = util.sha1_file(path)
     if ctx.config.options and ctx.config.options.absolute_urls:
         md.package.packageURI = os.path.realpath(path)
     else:                           # create relative path by default
         # TODO: in the future well do all of this with purl/pfile/&helpers
         # really? heheh -- future exa
         md.package.packageURI = util.removepathprefix(repo_uri, path)
     # check package semantics
     errs = md.errors()
     if md.errors():
         ctx.ui.error(_('Package %s: metadata corrupt, skipping...') % md.package.name)
         ctx.ui.error(unicode(Error(*errs)))
     else:
         self.packages.append(md.package)
Ejemplo n.º 12
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.º 13
0
    def add_package(self, path, repo_uri):
        package = Package(path, 'r')
        # extract control files
        util.clean_dir(ctx.config.install_dir())
        package.extract_PISI_files(ctx.config.install_dir())

        md = metadata.MetaData()
        md.read(os.path.join(ctx.config.install_dir(), ctx.const.metadata_xml))
        if ctx.config.options and ctx.config.options.absolute_uris:
            md.package.packageURI = os.path.realpath(path)
        else:                           # create relative path by default
            # TODO: in the future we'll do all of this with purl/pfile/&helpers
            # After that, we'll remove the ugly repo_uri parameter from this
            # function.
            md.package.packageURI = util.removepathprefix(repo_uri, path)
        # check package semantics
        if md.has_errors():
            ctx.ui.error(_('Package %s: metadata corrupt') % md.package.name)
        else:
            self.packages.append(md.package)
Ejemplo n.º 14
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.º 15
0
    def add_package(self, path, repo_uri):
        package = Package(path, 'r')
        # extract control files
        util.clean_dir(ctx.config.install_dir())
        package.extract_PISI_files(ctx.config.install_dir())

        md = metadata.MetaData()
        md.read(os.path.join(ctx.config.install_dir(), ctx.const.metadata_xml))
        if ctx.config.options and ctx.config.options.absolute_uris:
            # FIXME: the name "absolute_uris" does not seem to fit below :/
            md.package.packageURI = os.path.realpath(path)
        else:                           # create relative path by default
            # TODO: in the future well do all of this with purl/pfile/&helpers
            # really? heheh -- future exa
            md.package.packageURI = util.removepathprefix(repo_uri, path)
        # check package semantics
        errs = md.errors()
        if md.errors():
            ctx.ui.error(_('Package %s: metadata corrupt') % md.package.name)
            ctx.ui.error(str(Error(*errs)))
        else:
            self.packages.append(md.package)
Ejemplo n.º 16
0
    def build_packages(self):
        """Build each package defined in PSPEC file. After this process there
        will be .pisi files hanging around, AS INTENDED ;)"""
        for package in self.spec.packages:

            # store additional files
            c = os.getcwd()
            os.chdir(self.pspecDir)
            install_dir = self.bctx.pkg_dir() + ctx.const.install_dir_suffix
            for afile in package.additionalFiles:
                src = os.path.join(ctx.const.files_dir, afile.filename)
                dest = os.path.join(install_dir + os.path.dirname(afile.target), os.path.basename(afile.target))
                util.copy_file(src, dest)
                if afile.permission:
                    # mode is octal!
                    os.chmod(dest, int(afile.permission, 8))

            os.chdir(c)

            name = util.package_name(package.name,
                                     self.spec.source.version,
                                     self.spec.source.release)
            
            ctx.ui.action(_("** Building package %s") % package.name);

            ctx.ui.action(_("Generating %s...") % ctx.const.files_xml)
            self.gen_files_xml(package)
            ctx.ui.info(_(" done."))
           
            ctx.ui.action(_("Generating %s...") % ctx.const.metadata_xml)
            self.gen_metadata_xml(package)
            ctx.ui.info(_(" done."))

            ctx.ui.action(_("Creating PISI package %s") % name)
            
            pkg = Package(name, 'w')

            # add comar files to package
            os.chdir(self.pspecDir)
            for pcomar in package.providesComar:
                fname = os.path.join(ctx.const.comar_dir,
                                     pcomar.script)
                pkg.add_to_package(fname)

            # add xmls and files
            os.chdir(self.bctx.pkg_dir())
        
            pkg.add_to_package(ctx.const.metadata_xml)
            pkg.add_to_package(ctx.const.files_xml)

            # Now it is time to add files to the packages using newly
            # created files.xml
            files = Files()
            files.read(ctx.const.files_xml)
            for finfo in files.list:
                pkg.add_to_package("install/" + finfo.path)

            pkg.close()
            os.chdir(c)
            self.set_state("buildpackages")
            util.xterm_title_reset()
Ejemplo n.º 17
0
    def build_packages(self):
        """Build each package defined in PSPEC file. After this process there
        will be .pisi files hanging around, AS INTENDED ;)"""

        self.fetch_component() # bug 856

        # Strip install directory before building .pisi packages.
        self.strip_install_dir()

        package_names = []

        for package in self.spec.packages:
            # store additional files
            c = os.getcwd()
            os.chdir(self.specdir)
            install_dir = self.pkg_dir() + ctx.const.install_dir_suffix
            for afile in package.additionalFiles:
                src = os.path.join(ctx.const.files_dir, afile.filename)
                dest = os.path.join(install_dir + os.path.dirname(afile.target), os.path.basename(afile.target))
                util.copy_file(src, dest)
                if afile.permission:
                    # mode is octal!
                    os.chmod(dest, int(afile.permission, 8))

            os.chdir(c)
           
            ctx.ui.action(_("** Building package %s") % package.name);

            ctx.ui.info(_("Generating %s,") % ctx.const.files_xml)
            self.gen_files_xml(package)

            ctx.ui.info(_("Generating %s,") % ctx.const.metadata_xml)
            self.gen_metadata_xml(package)

            ctx.ui.info(_("Creating PISI package %s.") % package.name)

            name = util.package_name(package.name,
                                     self.spec.source.version,
                                     self.spec.source.release,
                                     self.metadata.package.build)
            pkg = Package(name, 'w')
            package_names.append(name)

            # add comar files to package
            os.chdir(self.specdir)
            for pcomar in package.providesComar:
                fname = util.join_path(ctx.const.comar_dir,
                                     pcomar.script)
                pkg.add_to_package(fname)

            # add xmls and files
            os.chdir(self.pkg_dir())
        
            pkg.add_to_package(ctx.const.metadata_xml)
            pkg.add_to_package(ctx.const.files_xml)

            # Now it is time to add files to the packages using newly
            # created files.xml
            files = Files()
            files.read(ctx.const.files_xml)
            for finfo in files.list:
                pkg.add_to_package(join("install", finfo.path))

            pkg.close()
            os.chdir(c)
            self.set_state("buildpackages")
            ctx.ui.info(_("Done."))
           
        if ctx.config.values.general.autoclean is True:
            ctx.ui.info(_("Cleaning Build Directory..."))
            util.clean_dir(self.pkg_dir())
        else:
            ctx.ui.info(_("Keeping Build Directory"))

        return package_names
Ejemplo n.º 18
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.º 19
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.º 20
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.º 21
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.º 22
0
    def build_packages(self):
        """Build each package defined in PSPEC file. After this process there
        will be .pisi files hanging around, AS INTENDED ;)"""

        self.fetch_component()  # bug 856

        # Strip install directory before building .pisi packages.
        self.strip_install_dir()

        if ctx.get_option('create_static'):
            obj = self.generate_static_package_object()
            if obj:
                self.spec.packages.append(obj)

        if ctx.config.values.build.generatedebug:
            obj = self.generate_debug_package_object()
            if obj:
                self.spec.packages.append(obj)

        new_packages = []
        old_package_names = []

        for package in self.spec.packages:
            old_package_name = None
            # store additional files
            c = os.getcwd()
            os.chdir(self.specdir)
            install_dir = self.pkg_dir() + ctx.const.install_dir_suffix
            for afile in package.additionalFiles:
                src = os.path.join(ctx.const.files_dir, afile.filename)
                dest = os.path.join(
                    install_dir + os.path.dirname(afile.target),
                    os.path.basename(afile.target))
                util.copy_file(src, dest)
                if afile.permission:
                    # mode is octal!
                    os.chmod(dest, int(afile.permission, 8))
            os.chdir(c)

            ctx.ui.action(_("** Building package %s") % package.name)

            ctx.ui.info(_("Generating %s,") % ctx.const.files_xml)
            self.gen_files_xml(package)

            # build number
            if ctx.config.options.ignore_build_no or not ctx.config.values.build.buildno:
                build_no = old_build_no = None
                ctx.ui.warning(
                    _('Build number is not available. For repo builds you must enable buildno in pisi.conf.'
                      ))
            else:
                build_no, old_build_no = self.calc_build_no(package.name)

            ctx.ui.info(_("Generating %s,") % ctx.const.metadata_xml)
            self.gen_metadata_xml(package, build_no)

            # Calculate new and oldpackage names for buildfarm
            name = util.package_name(package.name, self.spec.source.version,
                                     self.spec.source.release,
                                     self.metadata.package.build)

            if old_build_no:
                old_package_name = util.package_name(package.name,
                                                     self.spec.source.version,
                                                     self.spec.source.release,
                                                     old_build_no)
            old_package_names.append(old_package_name)

            outdir = ctx.get_option('output_dir')
            if outdir:
                name = pisi.util.join_path(outdir, name)
            new_packages.append(name)

            ctx.ui.info(_("Creating PISI package %s.") % name)

            pkg = Package(name, 'w')

            # add comar files to package
            os.chdir(self.specdir)
            for pcomar in package.providesComar:
                fname = util.join_path(ctx.const.comar_dir, pcomar.script)
                pkg.add_to_package(fname)

            # add xmls and files
            os.chdir(self.pkg_dir())

            pkg.add_to_package(ctx.const.metadata_xml)
            pkg.add_to_package(ctx.const.files_xml)

            # Now it is time to add files to the packages using newly
            # created files.xml
            files = Files()
            files.read(ctx.const.files_xml)

            if ctx.get_option('package_format') == "1.0":
                for finfo in files.list:
                    orgname = arcname = join("install", finfo.path)
                    if package.debug_package:
                        orgname = join("debug", finfo.path)
                    pkg.add_to_package(orgname, arcname)
                pkg.close()
            else:  # default package format is 1.1, so make it fallback.
                ctx.build_leftover = join(self.pkg_dir(),
                                          ctx.const.install_tar_lzma)
                tar = archive.ArchiveTar(ctx.const.install_tar_lzma, "tarlzma")
                for finfo in files.list:
                    #print finfo.path
                    orgname = arcname = join("install", finfo.path)
                    if package.debug_package:
                        orgname = join("debug", finfo.path)
                    tar.add_to_archive(orgname, arcname.lstrip("install"))
                tar.close()
                pkg.add_to_package(ctx.const.install_tar_lzma)
                pkg.close()
                os.unlink(ctx.const.install_tar_lzma)
                ctx.build_leftover = None

            os.chdir(c)
            self.set_state("buildpackages")
            ctx.ui.info(_("Done."))

        #show the files those are not collected from the install dir
        if ctx.get_option('show_abandoned_files') or ctx.get_option('debug'):
            abandoned_files = self.get_abandoned_files()
            if abandoned_files:
                ctx.ui.warning(
                    _('Abandoned files under the install dir (%s):') %
                    (install_dir))
                for f in abandoned_files:
                    ctx.ui.info('    - %s' % (f))
            else:
                ctx.ui.warning(
                    _('All of the files under the install dir (%s) has been collected by package(s)'
                      ) % (install_dir))

        if ctx.config.values.general.autoclean is True:
            ctx.ui.info(_("Cleaning Build Directory..."))
            util.clean_dir(self.pkg_dir())
        else:
            ctx.ui.info(_("Keeping Build Directory"))

        # reset environment variables after build.  this one is for
        # buildfarm actually. buildfarm re-inits pisi for each build
        # and left environment variables go directly into initial dict
        # making actionsapi.variables.exportFlags() useless...
        os.environ = {}
        os.environ = deepcopy(ctx.config.environ)

        return new_packages, old_package_names
Ejemplo n.º 23
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.º 24
0
def create_delta_package(old_package, new_package):

    if old_package == new_package:
        ctx.ui.error(_("Cannot create delta for same package!"))
        return

    oldpkg = Package(old_package, "r")
    newpkg = Package(new_package, "r")

    newmd = newpkg.get_metadata()
    oldmd = oldpkg.get_metadata()

    oldfiles = oldpkg.get_files()
    newfiles = newpkg.get_files()

    files_delta = find_delta(oldfiles, newfiles)

    ctx.ui.info(_("Creating delta PiSi package between %s %s") % (old_package, new_package))

    # Unpack new package to temp
    newpkg_name = util.package_name(newmd.package.name, newmd.package.version, newmd.package.release, newmd.package.build, False)
    newpkg_path = util.join_path(ctx.config.tmp_dir(), newpkg_name)
    newpkg.extract_to(newpkg_path, True)

    tar = archive.ArchiveTar(util.join_path(newpkg_path, ctx.const.install_tar_lzma), "tarlzma", False, False)
    tar.unpack_dir(newpkg_path)

    # Create delta package
    deltaname = "%s-%s-%s%s" % (oldmd.package.name, oldmd.package.build, newmd.package.build, ctx.const.delta_package_suffix)

    outdir = ctx.get_option("output_dir")
    if outdir:
        deltaname = util.join_path(outdir, deltaname)

    deltapkg = Package(deltaname, "w")

    c = os.getcwd()
    os.chdir(newpkg_path)

    # add comar files to package
    for pcomar in newmd.package.providesComar:
        fname = util.join_path(ctx.const.comar_dir, pcomar.script)
        deltapkg.add_to_package(fname)

    # add xmls and files
    deltapkg.add_to_package(ctx.const.metadata_xml)
    deltapkg.add_to_package(ctx.const.files_xml)

    # only metadata information may change in a package, so no install.tar.lzma added to delta package
    if files_delta:
        ctx.build_leftover = util.join_path(ctx.config.tmp_dir(), ctx.const.install_tar_lzma)

        tar = archive.ArchiveTar(util.join_path(ctx.config.tmp_dir(), ctx.const.install_tar_lzma), "tarlzma")
        for file in files_delta:
            tar.add_to_archive(file.path)
        tar.close()

        os.chdir(ctx.config.tmp_dir())
        deltapkg.add_to_package(ctx.const.install_tar_lzma)

    deltapkg.close()

    tmp_file = util.join_path(ctx.config.tmp_dir(), ctx.const.install_tar_lzma)
    if os.path.exists(tmp_file):
        os.unlink(tmp_file)

    ctx.build_leftover = None
    os.chdir(c)

    ctx.ui.info(_("Done."))
Ejemplo n.º 25
0
    def build_packages(self):
        """Build each package defined in PSPEC file. After this process there
        will be .pisi files hanging around, AS INTENDED ;)"""

        self.fetch_component() # bug 856

        # Strip install directory before building .pisi packages.
        self.strip_install_dir()

        if ctx.get_option('create_static'):
            obj = self.generate_static_package_object()
            if obj:
                self.spec.packages.append(obj)

        if not ctx.get_option('no_debug'):
            obj = self.generate_debug_package_object()
            if obj:
                self.spec.packages.append(obj)

        package_names = []
        old_package_names = []

        for package in self.spec.packages:
            old_package_name = None
            # store additional files
            c = os.getcwd()
            os.chdir(self.specdir)
            install_dir = self.pkg_dir() + ctx.const.install_dir_suffix
            for afile in package.additionalFiles:
                src = os.path.join(ctx.const.files_dir, afile.filename)
                dest = os.path.join(install_dir + os.path.dirname(afile.target), os.path.basename(afile.target))
                util.copy_file(src, dest)
                if afile.permission:
                    # mode is octal!
                    os.chmod(dest, int(afile.permission, 8))

            os.chdir(c)
           
            ctx.ui.action(_("** Building package %s") % package.name);

            ctx.ui.info(_("Generating %s,") % ctx.const.files_xml)
            self.gen_files_xml(package)

            ctx.ui.info(_("Generating %s,") % ctx.const.metadata_xml)
            build_number, old_build_number = self.gen_metadata_xml(package)

            name =  util.package_name(package.name,
                                     self.spec.source.version,
                                     self.spec.source.release,
                                     self.metadata.package.build)

            outdir = ctx.get_option('output_dir')
            if outdir:
                name = pisi.util.join_path(outdir, name)

            ctx.ui.info(_("Creating PISI package %s.") % name)

            # somebody explain to me why this is done here -- exa
            if old_build_number:
                old_package_name = util.package_name(package.name,
                                     self.spec.source.version,
                                     self.spec.source.release,
                                     old_build_number)
            pkg = Package(name, 'w')
            package_names.append(name)
            old_package_names.append(old_package_name)

            # add comar files to package
            os.chdir(self.specdir)
            for pcomar in package.providesComar:
                fname = util.join_path(ctx.const.comar_dir,
                                     pcomar.script)
                pkg.add_to_package(fname)

            # add xmls and files
            os.chdir(self.pkg_dir())
        
            pkg.add_to_package(ctx.const.metadata_xml)
            pkg.add_to_package(ctx.const.files_xml)

            # Now it is time to add files to the packages using newly
            # created files.xml
            files = Files()
            files.read(ctx.const.files_xml)

            if ctx.get_option('package_format') == "1.1":
                tar = archive.ArchiveTar("install.tar.lzma", "tarlzma")
                for finfo in files.list:
                    orgname = arcname = join("install", finfo.path)
                    if package.debug_package:
                        orgname = join("debug", finfo.path)
                    tar.add_to_archive(orgname, arcname.lstrip("install"))
                tar.close()
                pkg.add_to_package("install.tar.lzma")
                pkg.close()
                os.unlink("install.tar")
                os.unlink("install.tar.lzma")
            else:
                for finfo in files.list:
                    orgname = arcname = join("install", finfo.path)
                    if package.debug_package:
                        orgname = join("debug", finfo.path)
                    pkg.add_to_package(orgname, arcname)
                pkg.close()

            os.chdir(c)
            self.set_state("buildpackages")
            ctx.ui.info(_("Done."))

        #show the files those are not collected from the install dir
        if ctx.get_option('show_abandoned_files') or ctx.get_option('debug'):
            abandoned_files = self.get_abandoned_files()
            if abandoned_files:
                ctx.ui.warning(_('Abandoned files under the install dir (%s):') % (install_dir))
                for f in abandoned_files:
                    ctx.ui.info('    - %s' % (f))
            else:
                ctx.ui.warning(_('All of the files under the install dir (%s) has been collected by package(s)') 
                                                                % (install_dir))
            
        if ctx.config.values.general.autoclean is True:
            ctx.ui.info(_("Cleaning Build Directory..."))
            util.clean_dir(self.pkg_dir())
        else:
            ctx.ui.info(_("Keeping Build Directory"))

        return package_names, old_package_names
Ejemplo n.º 26
0
import pisi.config
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.º 27
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.º 28
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)
Ejemplo n.º 29
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.º 30
0
    def build_packages(self):
        """Build each package defined in PSPEC file. After this process there
        will be .pisi files hanging around, AS INTENDED ;)"""

        # Strip install directory before building .pisi packages.
        self.strip_install_dir()

        for package in self.spec.packages:

            # store additional files
            c = os.getcwd()
            os.chdir(self.pspecDir)
            install_dir = self.bctx.pkg_dir() + ctx.const.install_dir_suffix
            for afile in package.additionalFiles:
                destdir = util.join_path(install_dir, os.path.dirname(afile.target))
                for src in glob.glob(util.join_path(ctx.const.files_dir, afile.filename)):
                    destfile = os.path.basename(afile.target)
                    if not destfile:
                        destfile = os.path.basename(src)
                    ctx.ui.debug(_("Copying additional file: '%s' to '%s' as '%s'") % (src, destdir, destfile))
                    util.copy_file(src, util.join_path(destdir, destfile))
                    if afile.permission:
                        # mode is octal!
                        os.chmod(util.join_path(destdir, destfile), int(afile.permission, 8))

            os.chdir(c)

            ctx.ui.action(_("** Building package %s") % package.name)

            ctx.ui.info(_("Generating %s,") % ctx.const.files_xml)
            self.gen_files_xml(package)

            ctx.ui.info(_("Generating %s,") % ctx.const.metadata_xml)
            self.gen_metadata_xml(package)

            ctx.ui.info(_("Creating PISI package %s.") % package.name)

            name = util.package_name(
                package.name, self.spec.source.version, self.spec.source.release, self.metadata.package.build
            )
            pkg = Package(name, "w")

            # add comar files to package
            os.chdir(self.pspecDir)
            for pcomar in package.providesComar:
                fname = util.join_path(ctx.const.comar_dir, pcomar.script)
                pkg.add_to_package(fname)

            # add xmls and files
            os.chdir(self.bctx.pkg_dir())

            pkg.add_to_package(ctx.const.metadata_xml)
            pkg.add_to_package(ctx.const.files_xml)

            # Now it is time to add files to the packages using newly
            # created files.xml
            files = Files()
            files.read(ctx.const.files_xml)
            for finfo in files.list:
                pkg.add_to_package("install/" + finfo.path)

            pkg.close()
            os.chdir(c)
            self.set_state("buildpackages")
            util.xterm_title_reset()
            ctx.ui.info(_("Done."))

        if ctx.config.values.general.autoclean is True:
            ctx.ui.info(_("Cleaning Build Directory..."))
            util.clean_dir(self.bctx.pkg_dir())
        else:
            ctx.ui.info(_("Keeping Build Directory"))
Ejemplo n.º 31
0
    def build_packages(self):
        """Build each package defined in PSPEC file. After this process there
        will be .pisi files hanging around, AS INTENDED ;)"""

        self.fetch_component() # bug 856

        # Strip install directory before building .pisi packages.
        self.strip_install_dir()

        if ctx.get_option('create_static'):
            obj = self.generate_static_package_object()
            if obj:
                self.spec.packages.append(obj)

        if ctx.config.values.build.generatedebug:
            obj = self.generate_debug_package_object()
            if obj:
                self.spec.packages.append(obj)

        self.new_packages = []
        self.old_packages = []

        for package in self.spec.packages:
            old_package_name = None
            # store additional files
            c = os.getcwd()
            os.chdir(self.specdir)
            install_dir = self.pkg_dir() + ctx.const.install_dir_suffix
            for afile in package.additionalFiles:
                src = os.path.join(ctx.const.files_dir, afile.filename)
                dest = os.path.join(install_dir + os.path.dirname(afile.target), os.path.basename(afile.target))
                util.copy_file(src, dest)
                if afile.permission:
                    # mode is octal!
                    os.chmod(dest, int(afile.permission, 8))
            os.chdir(c)
           
            ctx.ui.action(_("** Building package %s") % package.name);

            ctx.ui.info(_("Generating %s,") % ctx.const.files_xml)
            self.gen_files_xml(package)

            ctx.ui.info(_("Generating %s,") % ctx.const.metadata_xml)
            self.gen_metadata_xml(package)

            # build number
            if ctx.config.options.ignore_build_no or not ctx.config.values.build.buildno:
                build_no = old_build_no = None
                ctx.ui.warning(_('Build number is not available. For repo builds you must enable buildno in pisi.conf.'))
            else:
                build_no, old_build_no = self.calc_build_no(package.name)
            
            self.metadata.package.build = build_no
            self.metadata.write(util.join_path(self.pkg_dir(), ctx.const.metadata_xml))

            # Calculate new and oldpackage names for buildfarm
            name =  util.package_name(package.name,
                                     self.spec.source.version,
                                     self.spec.source.release,
                                     self.metadata.package.build)

            outdir = ctx.get_option('output_dir')
            if outdir:
                name = pisi.util.join_path(outdir, name)
            self.new_packages.append(name)

            ctx.ui.info(_("Creating PISI package %s.") % name)

            pkg = Package(name, 'w')

            # add comar files to package
            os.chdir(self.specdir)
            for pcomar in package.providesComar:
                fname = util.join_path(ctx.const.comar_dir,
                                     pcomar.script)
                pkg.add_to_package(fname)

            # add xmls and files
            os.chdir(self.pkg_dir())
        
            pkg.add_to_package(ctx.const.metadata_xml)
            pkg.add_to_package(ctx.const.files_xml)

            # Now it is time to add files to the packages using newly
            # created files.xml
            files = Files()
            files.read(ctx.const.files_xml)

            if ctx.get_option('package_format') == "1.0":
                for finfo in files.list:
                    orgname = arcname = join("install", finfo.path)
                    if package.debug_package:
                        orgname = join("debug", finfo.path)
                    pkg.add_to_package(orgname, arcname)
                pkg.close()
            else: # default package format is 1.1, so make it fallback.
                ctx.build_leftover = join(self.pkg_dir(), ctx.const.install_tar_lzma)
                tar = archive.ArchiveTar(ctx.const.install_tar_lzma, "tarlzma")
                for finfo in files.list:
                    orgname = arcname = join("install", finfo.path)
                    if package.debug_package:
                        orgname = join("debug", finfo.path)
                    tar.add_to_archive(orgname, arcname.lstrip("install"))
                tar.close()
                pkg.add_to_package(ctx.const.install_tar_lzma)
                pkg.close()
                os.unlink(ctx.const.install_tar_lzma)
                ctx.build_leftover = None

            os.chdir(c)
            self.set_state("buildpackages")
            ctx.ui.info(_("Done."))

        #show the files those are not collected from the install dir
        if ctx.get_option('show_abandoned_files') or ctx.get_option('debug'):
            abandoned_files = self.get_abandoned_files()
            if abandoned_files:
                ctx.ui.warning(_('Abandoned files under the install dir (%s):') % (install_dir))
                for f in abandoned_files:
                    ctx.ui.info('    - %s' % (f))
            else:
                ctx.ui.warning(_('All of the files under the install dir (%s) has been collected by package(s)') 
                                                                % (install_dir))
            
        if ctx.config.values.general.autoclean is True:
            ctx.ui.info(_("Cleaning Build Directory..."))
            util.clean_dir(self.pkg_dir())
        else:
            ctx.ui.info(_("Keeping Build Directory"))


        # reset environment variables after build.  this one is for
        # buildfarm actually. buildfarm re-inits pisi for each build
        # and left environment variables go directly into initial dict
        # making actionsapi.variables.exportFlags() useless...
        os.environ = {}
        os.environ = deepcopy(ctx.config.environ)

        return self.new_packages, self.old_packages
Ejemplo n.º 32
0
import pisi.config
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