Beispiel #1
0
    def __init__(self, package, instruction, **kwargs):
        # package and instruction are required.
        # Others can be None
        self.package = package
        self.instruction = instruction
        self.dependencies = kwargs.get("dependencies", None)
        self.options = kwargs.get("options", None)
        self.conditional_versions = kwargs.get("conditional_versions", None)
        self.conflicts = kwargs.get("conflicts", None)
        self.inline_option_targets = kwargs.get("inline_option_targets", None)

        # Internal variables
        self.repodb = api.RepositoryDB()
        self.instdb = api.InstallDB()
        self.download_plan = []
        self.extract_plan = []
        self.urls = []
        self.internals = internals.InternalFunctions()
        self.internals.env.raw.update({
            "get": self.internals.get,
            "cmd_options": [],
            "options": []
        })
        self.config = conf.LPMSConfig()
        if self.instruction.unset_env_variables is not None:
            utils.set_environment_variables()
        self.revisioned = False
        self.revision = None
Beispiel #2
0
 def __init__(self, environment):
     self.symlinks = []
     self.backup = []
     self.environment = environment
     self.instdb = api.InstallDB()
     self.repodb = api.RepositoryDB()
     self.conf = conf.LPMSConfig()
     self.info_files = []
     self.previous_files = []
     self.filesdb = api.FilesDB()
     self.file_relationsdb = api.FileRelationsDB()
     self.reverse_dependsdb = api.ReverseDependsDB()
     self.binary_filetypes = ('application/x-executable', 'application/x-archive', \
             'application/x-sharedlib')
     self.merge_conf_file = os.path.join(self.environment.real_root, \
             cst.merge_conf_file)
     self.previous_files = self.filesdb.get_paths_by_package(self.environment.name, \
             repo=self.environment.repo, category=self.environment.category, \
             version=self.environment.previous_version)
     # Unfortunately, this seems very ugly :(
     self.strip_debug_symbols = True if self.environment.no_strip is not None and \
             ((self.environment.applied_options is not None and \
             "debug" in self.env.applied_options) or \
             utils.check_cflags("-g") or utils.check_cflags("-ggdb") \
             or utils.check_cflags("-g3")) else False
Beispiel #3
0
    def __init__(self, package, installdb=False):
        self.package = package
        self.repo = None
        self.category = None
        self.name = None
        self.version = None
        self.slot = None
        self.conf = conf.LPMSConfig()
        self.custom_arch_request = {}
        self.locked_packages = []
        if not installdb:
            self.database = dbapi.RepositoryDB()
            arch_file = os.path.join(cst.user_dir, "arch")
            if os.path.isfile(arch_file):
                with open(arch_file) as lines:
                    for line in lines.readlines():
                        if not line.strip():
                            continue
                        self.custom_arch_request.update(utils.ParseArchFile(line.strip(), \
                                self.database).parse())

            lock_file = os.path.join(cst.user_dir, "lock")
            if os.path.isfile(lock_file):
                with open(lock_file) as lines:
                    for line in lines.readlines():
                        if not line.strip():
                            continue
                        self.locked_packages.extend(utils.ParseUserDefinedFile(line.strip(), \
                                self.database).parse())
        else:
            self.database = dbapi.InstallDB()
Beispiel #4
0
def main(pkgname, real_root):
    instdb = dbapi.InstallDB()
    filesdb = dbapi.FilesDB()

    # start remove operation
    repo, category, name, version = pkgname
    # initialize remove class
    rmpkg = Remove(repo, category, name, version, real_root)
    
    lpms.logger.info("removing %s/%s/%s-%s from %s" % \
            (repo, category, name, version, rmpkg.real_root))
    out.normal("removing %s/%s/%s-%s from %s" % \
            (repo, category, name, version, rmpkg.real_root))
    
    # remove the package content
    rmpkg.remove_content()
    # remove entries from the database
    package_id = instdb.find_package(package_repo=repo, package_category=category, \
            package_name=name, package_version=version).get(0).id
    instdb.database.delete_build_info(package_id)
    instdb.delete_conditional_versions(package_id=package_id)
    instdb.delete_inline_options(package_id=package_id)
    instdb.delete_package(package_repo=repo, package_category=category, \
            package_name=name, package_version=version, commit=True)
    # remove paths from files table
    filesdb.delete_item_by_pkgdata(category, name, version, commit=True)
    # unlock
    if shelltools.is_exists(cst.lock_file):
        shelltools.remove_file(cst.lock_file)
Beispiel #5
0
 def __init__(self, params):
     self.instdb = api.InstallDB()
     self.repodb = api.RepositoryDB()
     self.params = params
     self.repo = None
     self.category = None
     self.name = None
     self.version = None
Beispiel #6
0
    def __init__(self, packages,
            command_line_options=[],
            custom_options={},
            use_new_options=False):
        self.packages = packages
        self.command_line_options = command_line_options
        self.custom_options = custom_options
        self.use_new_options = use_new_options
        self.conflicts = {}
        self.current_package = None
        self.parent_package = None
        self.conf = conf.LPMSConfig()
        self.instdb = api.InstallDB()
        self.repodb = api.RepositoryDB()
        self.conditional_packages = {}
        self.processed = {}
        self.package_heap = {}
        self.control_chars = ["||"]
        self.inline_options = {}
        self.inline_option_targets = {}
        self.package_dependencies = {}
        self.postmerge_dependencies = set()
        self.package_options = {}
        self.repository_cache = {}
        self.user_defined_options = {}
        self.package_query = []
        self.locked_packages = []
        self.global_options = set()
        self.forbidden_options = set()
        self.dependency_keywords = (
                'static_depends_build',
                'static_depends_runtime',
                'static_depends_conflict',
                'static_depends_postmerge',
                'optional_depends_build',
                'optional_depends_runtime',
                'optional_depends_conflict',
                'optional_depends_postmerge'
        )
        for option in self.conf.options.split(" "):
            if option.strip():
                if not option.startswith("-"):
                    self.global_options.add(option)
                else:
                    self.forbidden_options.add(option[1:])
        self.get_user_defined_files()
        self.parse_user_defined_options_file()
        if hasattr(self, "user_defined_lock_file"):
            for locked_item in self.user_defined_lock_file:
                self.locked_packages.extend(self.parse_user_defined_file(locked_item))

        self.custom_arch_requests = {}
        if hasattr(self, "user_defined_arch_file"):
            for arch_item in self.user_defined_arch_file:
                self.custom_arch_requests.update(utils.ParseArchFile(arch_item, \
                        self.repodb).parse())
Beispiel #7
0
 def __init__(self, keyword, instruct):
     self.instruct = instruct
     self.instruct["ask"] = True
     self.keyword = ""
     for key in keyword:
         if not key in ('--only-installed', '--in-name', '--in-summary',
                        '--interactive'):
             self.keyword += key + " "
     self.keyword = self.keyword.strip()
     root = cst.root if instruct["real_root"] is None \
             else instruct['real_root']
     self.connection = sqlite3.connect(os.path.join(root, cst.db_path, \
             cst.repositorydb)+cst.db_prefix)
     self.cursor = self.connection.cursor()
     self.repodb = dbapi.RepositoryDB()
     self.instdb = dbapi.InstallDB()
Beispiel #8
0
 def __init__(self):
     self.upgrade_pkg = []
     self.notfound_pkg = []
     self.packages = []
     self.repodb = dbapi.RepositoryDB()
     self.instdb = dbapi.InstallDB()
     self.locked_packages = {}
     lock_file = os.path.join(cst.user_dir, "lock")
     if os.access(lock_file, os.R_OK):
         with open(lock_file) as data:
             for line in data.readlines():
                 lock_category, lock_name, lock_version = utils.parse_user_defined_file(line.strip(), \
                         self.repodb)
                 key = lock_category + "/" + lock_name
                 if key in self.locked_packages:
                     if isinstance(lock_version, list):
                         self.locked_packages[key].extend(lock_version)
                     else:
                         self.locked_packages[key].append(lock_version)
                 else:
                     if isinstance(lock_version, list):
                         self.locked_packages[key] = lock_version
                     else:
                         self.locked_packages[key] = [lock_version]
Beispiel #9
0
def get_convenient_package(packages, locked_packages, arch_data, \
        convenient_arches, instdb, slot=None):
    results = []
    repositories = available_repositories()
    primary = None

    # Remove locked packages from the package list
    packages = [package for package in packages if not package.id \
            in locked_packages]
    if not packages: raise LockedPackage

    # Firstly, select the correct repository

    # Select the convenient slot for the package
    if slot is not None and slot.endswith("*"):
        slots = [package.slot for package in packages if \
                package.slot.startswith(slot[:-1])]
        slot = best_version(slots)

    for repository in repositories:
        for package in packages:
            if not package.arch in convenient_arches:
                if not package.id in arch_data:
                    continue
                else:
                    if not package.arch in arch_data[package.id]:
                        continue
            if slot is not None and \
                    package.slot != slot:
                continue
            if primary is None and package.repo == repository:
                results.append(package)
                primary = package.repo
                continue
            elif primary is not None and package.repo == primary:
                if not package in results:
                    results.append(package)
                continue
        if repository != primary: continue

    # Secondly, select the best version
    if not results:
        return None
    my_package = results[0].category + "/" + results[0].name + "/" + results[
        0].slot
    versions = [result.version for result in results]
    # Is this a convenient way for getting instance's class name?
    if instdb.__class__.__name__ != "InstallDB":
        from lpms.db import api
        instdb = api.InstallDB()
    conditions = instdb.find_conditional_versions(target=my_package)
    if conditions:
        convenient_versions = []
        for condition in conditions:
            for version in versions:
                compare_result = vercmp(version, \
                        condition.decision_point["version"])
                if condition.decision_point["type"] == ">=":
                    if compare_result in (1, 0):
                        convenient_versions.append(version)
                elif condition.decision_point["type"] == "<=":
                    if compare_result in (-1, 0):
                        convenient_versions.append(version)
                elif condition.decision_point["type"] == "<":
                    if compare_result == -1:
                        convenient_versions.append(version)
                elif condition.decision_point["type"] == ">":
                    if compare_result == 1:
                        convenient_versions.append(version)
                elif condition.decision_point["type"] == "==":
                    if compare_result == 0:
                        convenient_versions.append(version)
        the_best_version = best_version(convenient_versions)
    else:
        the_best_version = best_version(versions)
    for result in results:
        if result.version == the_best_version:
            return result
    raise UnavailablePackage
Beispiel #10
0
def remove_package(pkgnames, instruction):
    '''Triggers remove operation for given packages'''
    if instruction.like:
        # handle shortened package names
        database = dbapi.InstallDB()
        for item in instruction.like:
            query = database.db.cursor.execute(
                "SELECT name FROM package where name LIKE ?", (item, ))
            results = query.fetchall()
            if results:
                for result in results:
                    pkgnames.append(result[0])
        del database
    file_relationsdb = dbapi.FileRelationsDB()
    #try:
    packages = [
        GetPackage(pkgname, installdb=True).select() for pkgname in pkgnames
    ]
    #except PackageNotFound as package_name:
    #    out.error("%s seems not installed." % package_name)
    #    lpms.terminate()

    instruction.count = len(packages)
    index = 0
    # FIXME: I must create a new reverse dependency handler implementation

    #if instruct["show-reverse-depends"]:
    #    instruct["ask"] = True
    #    # WARNING: the mechanism only shows directly reverse dependencies
    #    # supposing that if A is a reverse dependency of B and C is depends on A.
    #    # when the user removes B, A and C will be broken. But lpms will warn the user about A.
    #    broken_packages = []
    #    reversedb = dbapi.ReverseDependsDB()
    #    out.normal("resolving primary reverse dependencies...\n")
    #    for package in packages:
    #        category, name, version = package[1:]
    #        if lpms.getopt("--use-file-relations"):
    #            broken_packages.extend(file_relations.get_packages(category, name, version))
    #        else:
    #            broken_packages.extend(reversedb.get_reverse_depends(category, name))

    #    if broken_packages:
    #        out.warn("the following packages will be broken:\n")
    #        for broken_package in broken_packages:
    #            broken_repo, broken_category, broken_name, broken_version = broken_package
    #            out.write(" %s %s/%s/%s-%s\n" % (out.color(">", "brightred"), broken_repo, broken_category, \
    #                    broken_name, broken_version))
    #    else:
    #        out.warn("no reverse dependency found.")

    if instruction.ask:
        out.write("\n")
        for package in packages:
            out.write(
                " %s %s/%s/%s-%s\n" % (out.color(
                    ">", "brightgreen"), out.color(package.repo, "green"),
                                       out.color(package.category, "green"),
                                       out.color(package.name, "green"),
                                       out.color(package.version, "green")))
        utils.xterm_title("lpms: confirmation request")
        out.write("\nTotal %s package will be removed.\n\n" %
                  out.color(str(instruction.count), "green"))
        if not utils.confirm("Would you like to continue?"):
            out.write("quitting...\n")
            utils.xterm_title_reset()
            lpms.terminate()

    realroot = instruction.new_root if instruction.new_root else cst.root
    config = conf.LPMSConfig()
    for package in packages:
        fdb = file_collisions.CollisionProtect(package.category, package.name, \
                package.slot, version=package.version, real_root=realroot)
        fdb.handle_collisions()
        if fdb.collisions:
            out.write(out.color(" > ", "brightyellow")+"file collisions detected while removing %s/%s/%s-%s\n\n" \
                    % (package.repo, package.category, package.name, package.version))
        for (c_package, c_path) in fdb.collisions:
            c_category, c_name, c_slot, c_version = c_package
            out.write(out.color(" -- ", "red")+c_category+"/"+c_name+"-"\
                    +c_version+":"+c_slot+" -> "+c_path+"\n")
            if fdb.collisions and config.collision_protect and not \
                    lpms.getopt('--force-file-collision'):
                out.write(
                    "\nquitting... use '--force-file-collision' to continue.\n"
                )
                lpms.terminate()
        index += 1
        instruction.index = index
        if not initpreter.InitializeInterpreter(
                package, instruction, ['remove'], remove=True).initialize():
            out.warn("an error occured during remove operation: %s/%s/%s-%s" % (package.repo, package.category, \
                    package.name, package.version))
        else:
            file_relationsdb.delete_item_by_pkgdata(package.category,
                                                    package.name,
                                                    package.version,
                                                    commit=True)
Beispiel #11
0
 def __init__(self, pkgname):
     self.pkgname = pkgname
     self.filesdb = api.FilesDB()
     self.instdb = api.InstallDB()
Beispiel #12
0
 def __init__(self, keyword):
     self.keyword = keyword
     self.filesdb = api.FilesDB()
     self.instdb = api.InstallDB()
Beispiel #13
0
 def __init__(self):
     self.instdb = dbapi.InstallDB()
Beispiel #14
0
 def __init__(self):
     self.instdb = dbapi.InstallDB()
     self.removable_packages = set()
     self.instdb.database.cursor.execute('''SELECT * FROM package;''')
     self.packages = self.instdb.database.cursor.fetchall()
Beispiel #15
0
    def package_mangler(self, **kwargs):
        def collision_check():
            # TODO: This is a temporary solution. collision_check function
            # must be a reusable part for using in remove operation
            out.normal("checking file collisions...")
            lpms.logger.info("checking file collisions")
            collision_object = file_collisions.CollisionProtect(
                environment.category,
                environment.name,
                environment.slot,
                real_root=environment.real_root,
                source_dir=environment.install_dir)
            collision_object.handle_collisions()
            if collision_object.orphans:
                out.write(
                    out.color(" > ", "brightyellow") +
                    "these files are orphan. the package will adopt the files:\n"
                )
                index = 0
                for orphan in collision_object.orphans:
                    out.notify(orphan)
                    index += 1
                    if index > 100:
                        # FIXME: the files must be logged
                        out.write(
                            out.color(" > ", "brightyellow") +
                            "...and many others.")
                        break

            if collision_object.collisions:
                out.write(
                    out.color(" > ", "brightyellow") +
                    "file collisions detected:\n")
            for item in collision_object.collisions:
                (category, name, slot, version), path = item
                out.write(out.color(" -- ", "red")+category+"/"+name+"-"\
                        +version+":"+slot+" -> "+path+"\n")
            if collision_object.collisions and self.config.collision_protect:
                if environment.force_file_collision:
                    out.warn(
                        "Disregarding these collisions, you have been warned!")
                else:
                    return False
            return True

        names = kwargs.get("names", self.request.names)
        # Prepare build environment
        out.normal("resolving dependencies")
        targets = api.resolve_dependencies(names, self.request.instruction)
        if self.request.instruction.pretend:
            out.write("\n")
            out.normal("these packages will be merged, respectively:\n")
            showplan.show(targets.packages,
                          targets.conflicts,
                          targets.options,
                          installdb=dbapi.InstallDB())
            out.write("\ntotal %s package(s) listed.\n\n" \
                    % out.color(str(len(targets.packages)), "green"))
            raise LpmsTerminate

        if self.request.instruction.ask:
            out.write("\n")
            out.normal("these packages will be merged, respectively:\n")
            showplan.show(targets.packages,
                          targets.conflicts,
                          targets.options,
                          installdb=dbapi.InstallDB())
            utils.xterm_title("lpms: confirmation request")
            out.write("\ntotal %s package(s) will be merged.\n\n" \
                    % out.color(str(len(targets.packages)), "green"))

            if not utils.confirm("Would you like to continue?"):
                # Reset terminal title and terminate lpms.
                utils.xterm_title_reset()
                raise LpmsTerminate

        self.request.instruction.count = len(targets.packages)
        for index, package in enumerate(targets.packages, 1):
            self.request.instruction.index = index
            retval, environment = api.prepare_environment(
                    package,
                    self.request.instruction,
                    dependencies=targets.dependencies[package.id] if package.id in \
                            targets.dependencies else None,
                    options=targets.options[package.id] if package.id in \
                            targets.options else None,
                    conditional_versions=targets.conditional_versions[package.id] \
                            if package.id in targets.conditional_versions else None,
                    conflicts=targets.conflicts[package.id] if package.id \
                            in targets.conflicts else None,
                    inline_option_targets=targets.inline_option_targets[package.id] \
                            if package.id in targets.inline_option_targets else None
            )
            if not retval:
                out.error(
                    "There are some errors while preparing environment to build FOO."
                )
                out.error(
                    "So you should submit a bug report to fix the issue.")
                raise LpmsTerminate("thanks to flying with lpms.")
            # Now, run package script(spec) for configuring, building and install
            retval, environment = self.interpreter.initialize(environment)
            if retval is False:
                out.error(
                    "There are some errors while building FOO from source.")
                out.error("Error messages should be seen above.")
                out.error(
                    "If you want to submit a bug report, please attatch BAR or send above messages in a proper way."
                )
                raise LpmsTerminate("thanks to flying with lpms.")
            elif retval is None:
                raise LpmsTerminate

            if not collision_check():
                out.error(
                    "File collisions detected. If you want to overwrite these files,"
                )
                out.error(
                    "You have to use --force-file-collisions parameter or disable collision_protect in configuration file."
                )
                raise LpmsTerminate("thanks to flying with lpms.")

            # Merge package to livefs
            if environment.not_merge:
                raise LpmsTerminate("not merging...")
            retval, environment = merge.Merge(environment).perform_operation()
            if not retval:
                raise LpmsTerminate("Some errors occured while merging %s" %
                                    environment.fullname)

            lpms.logger.info("finished %s/%s/%s-%s" %
                             (package.repo, package.category, package.name,
                              package.version))

            utils.xterm_title("lpms: %s/%s finished" %
                              (package.category, package.name))

            out.normal("Cleaning build directory")
            shelltools.remove_dir(os.path.dirname(environment.install_dir))
            catdir = os.path.dirname(os.path.dirname(environment.install_dir))
            if not os.listdir(catdir):
                shelltools.remove_dir(catdir)

            # There is no error, exitting...
            out.normal("Completed.")
Beispiel #16
0
 def __init__(self, package):
     if len(package) > 1:
         out.warn("this command takes only one package name.")
     self.package = package[0]
     self.instdb = api.InstallDB()