コード例 #1
0
def initialize_config(config_file_path):
    """
    Checks the given config and initializes it if it is not set and does not
    exist.

    @param config_file_path The path to config file, or None in case the
                            default onw should be used.
    """
    help_url = "http://confluence.rnd.samsung.ru/display/TC/Config+file+format"
    global default_path
    if config_file_path is None:
        config_file_path = os.path.expanduser(default_path)
        if not os.path.isfile(config_file_path):
            logging.warning("Default config {0} does not exist! It will "
                            "be generated, but you should complete it with "
                            "repository paths, package names and other "
                            " options.".format(config_file_path))
            config = configparser.SafeConfigParser(allow_no_value=True)
            config.add_section('general')
            config.set('general', '# See documentation about combirepo '
                       'config file format at page {0}'.format(help_url))
            with open(config_file_path, 'wb') as config_file:
                config.write(config_file)
    else:
        config_file_path = os.path.expanduser(config_file_path)
        check.file_exists(config_file_path)

    default_path = config_file_path
コード例 #2
0
def __disable_all():
    """
    Disables or registered binary formats
    """
    binfmt_status_path = os.path.join(binfmt_directory, "status")
    check.file_exists(binfmt_status_path)
    with open(binfmt_status_path, 'w') as binfmt_status:
        binfmt_status.write("-1\n")
コード例 #3
0
 def __do_idle_tasks(self):
     """
     Does idle tasks, i. e. just copies RPMs in case when RPM patching is
     totally disabled.
     """
     tasks = []
     for task in self._tasks:
         package_name, package_path, target, _, _ = task
         check.file_exists(package_path)
         tasks.append((package_name, package_path, target))
     hidden_subprocess.function_call_list("Copying w/o patching",
                                          shutil.copy, tasks)
コード例 #4
0
ファイル: files.py プロジェクト: d-nikiforov/combirepo
def create_symlink(package_name, location_from, directory_to):
    """
    Creates symlink from file to the file with the same name in the another
    directory.

    @param package          The name of package
    @param location_from    Source of the symlink
    @param directory_to     Destination directory of the symlink
    """
    check.file_exists(location_from)

    location_to = os.path.join(directory_to, os.path.basename(location_from))

    logging.debug("Creating symlink from {0} to {1}".format(
        location_from, location_to))
    os.symlink(location_from, location_to)
コード例 #5
0
def prepare_repositories(parameters):
    """
    Prepares repository pairs for use.

    @param parameters           The combirepo run-time parameters (for
                                explanation, see combirepo/parameters.py).
    @return                     The path to the used kickstart file.
    """
    repository_pairs = parameters.repository_pairs
    kickstart_file_path = parameters.kickstart_file_path
    if len(repository_pairs) == 0:
        raise Exception("No repository pairs given!")
    # Check that user has given correct arguments for repository names:
    names = [repository_pair.name for repository_pair in repository_pairs]
    logging.debug("Repository names: {0}".format(names))
    if kickstart_file_path is not None and os.path.isfile(kickstart_file_path):
        logging.info("Kickstart file {0} specified by user will be "
                     "used".format(kickstart_file_path))
        check_repository_names(names, kickstart_file_path)
    global repository_cache_directory_path
    repository_manager = RepositoryManager(repository_cache_directory_path,
                                           check_rpm_name)
    authenticator = base64.encodestring("{0}:{1}".format(
        parameters.user, parameters.password))
    authenticator = authenticator.replace('\n', '')
    path = repository_manager.prepare(parameters.sup_repo_url, authenticator)
    parameters.sup_repo_url = path
    for repository_pair in repository_pairs:
        path = repository_manager.prepare(repository_pair.url, authenticator)
        repository_pair.url = path
        path_marked = repository_manager.prepare(repository_pair.url_marked,
                                                 authenticator)
        repository_pair.url_marked = path_marked

    if repodata_regeneration_enabled:
        for repository_pair in parameters.repository_pairs:
            regenerate_repodata(repository_pair.url,
                                repository_pair.url_marked)
    if kickstart_file_path is None or not os.path.isfile(kickstart_file_path):
        kickstart_file_path = get_kickstart_from_repos(repository_pairs,
                                                       kickstart_file_path)
        check.file_exists(kickstart_file_path)
        check_repository_names(names, kickstart_file_path)
    logging.info("The following kickstart file will be used: "
                 "{0}".format(kickstart_file_path))
    return kickstart_file_path
コード例 #6
0
ファイル: files.py プロジェクト: d-nikiforov/combirepo
def unrpm(rpm_path, destination_path):
    """
    Unpacks the RPM package from the given location to the given directory.

    @param rpm_path             The path to the RPM file.
    @param destination_path     The path to the destination directory.
    """
    check.file_exists(rpm_path)
    check.directory_exists(destination_path)
    if not rpm_path.endswith(".rpm"):
        logging.error("Given file {0} is not an RPM package!".format(rpm_path))
    initial_directory = os.getcwd()
    os.chdir(destination_path)
    hidden_subprocess.silent_pipe_call(["rpm2cpio", rpm_path], [
        "cpio", "--extract", "--unconditional", "--preserve-modification-time",
        "--make-directories"
    ])
    os.chdir(initial_directory)
コード例 #7
0
def __register(architecture, qemu_executable_path):
    """
    Register the binary format for the given architecture.

    @param architecture         The architecture.
    @param qemu_executable_path The absolute path to qemu binary INSIDE the
                                chroot directory (after chrooting to it). It
                                must always begin with '/'.
    """
    qemu_type = "qemu"
    if os.path.basename(qemu_executable_path).endswith("-binfmt"):
        qemu_type = "qemu-wrapper"
    binfmt_register_path = os.path.join(binfmt_directory, "register")
    check.file_exists(binfmt_register_path)

    binfmt_name = __get_name(architecture)
    binary_format = ":{0}:M::{1}:{2}:{3}:{4}".format(binfmt_name,
                                                     binfmt_magic[binfmt_name],
                                                     binfmt_mask[binfmt_name],
                                                     qemu_executable_path,
                                                     binfmt_flag[qemu_type])
    with open(binfmt_register_path, 'w') as binfmt_register:
        binfmt_register.write(binary_format)
コード例 #8
0
    def parse(self):
        """
        Parses the given config file and returns the properties structure.

        @return     The parameters structure of combirepo tool.
        """
        check.file_exists(self.path)
        self.parser.read(self.path)
        parameters = RepositoryCombinerParameters()

        # Parse general section:
        self.__check_section_exists("general")
        self.__check_option_exists("general", "profile")
        parameters.profile_name = self.parser.get("general", "profile")

        if self.parser.has_option("general", "tmp_dir"):
            path = self.parser.get("general", "tmp_dir")
            parameters.temporary_directory_path = path

        # Parse profile section:
        profile_name = parameters.profile_name
        self.__check_section_exists(profile_name)
        logging.debug("Detected profile "
                      "{0}".format(profile_name))
        self.__check_option_exists(profile_name, "repos")
        repository_aliases = self.__get_list(profile_name, "repos")

        if self.parser.has_option(profile_name, "user"):
            parameters.user = self.parser.get(profile_name, "user")
        if self.parser.has_option(profile_name, "password"):
            parameters.password = self.parser.get(profile_name, "password")
            if self.parser.has_option(profile_name, "passwordx"):
                logging.error("Both password and passwordx present!")
                sys.exit("Error.")
            self.parser.remove_option(profile_name, "password")
            passwordx = base64.b64encode(parameters.password.encode('bz2'))
            self.parser.set(profile_name, "passwordx", passwordx)
        elif self.parser.has_option(profile_name, "passwordx"):
            passwordx = self.parser.get(profile_name, "passwordx")
            parameters.password = base64.b64decode(passwordx).decode('bz2')

        if self.parser.has_option(profile_name, "repo_supplementary"):
            parameters.sup_repo_url = self.parser.get(profile_name,
                                                      "repo_supplementary")

        if self.parser.has_option(profile_name, "architecture"):
            parameters.architecture = self.parser.get(profile_name,
                                                      "architecture")

        if self.parser.has_option(profile_name, "kickstart"):
            kickstart_file_path = self.parser.get(profile_name, "kickstart")
            parameters.kickstart_file_path = kickstart_file_path

        if self.parser.has_option(profile_name, "out_dir"):
            output_directory_path = self.parser.get(profile_name, "out_dir")
            parameters.output_directory_path = output_directory_path

        mic_options = self.__get_list(profile_name, "mic_options")

        if self.parser.has_option(profile_name, "greedy"):
            greedy_mode = self.parser.getboolean(profile_name, "greedy")
            parameters.greedy_mode = greedy_mode

        if self.parser.has_option(profile_name, "mirror"):
            mirror_mode = self.parser.getboolean(profile_name, "mirror")
            parameters.mirror_mode = mirror_mode

        if self.parser.has_option(profile_name, "preferring_strategy"):
            preferring_strategy = self.parser.get(profile_name,
                                                  "preferring_strategy")
            parameters.preferring_strategy = preferring_strategy

        package_names = {}
        for key in valid_package_keys:
            names = self.__get_list(parameters.profile_name,
                                    "{0}_packages".format(key))
            package_names[key] = names
        parameters.package_names = package_names
        logging.debug("Package names from config: "
                      "{0}".format(parameters.package_names))

        repository_pairs = self.__build_repository_pairs(repository_aliases)
        parameters.repository_pairs = repository_pairs

        with open(self.path, 'wb') as config_file:
            self.parser.write(config_file)
        return parameters