Пример #1
0
    def get_packageinfo_from_packagefile(cls, file_path):
        """
        Extract the Package-Name and the Package-Version from the Debian-Package.

        :param file_path: Path to the Rpm-Package
        :return: A PackageInfo()-Object with Package-Version and Package-Name.
        """
        command_args_package_name = [
            cls.executable, "--query", "--package", "--queryformat", "%{name}",
            file_path
        ]
        command_args_package_version = [
            cls.executable, "--query", "--package", "--queryformat",
            "%{version}", file_path
        ]

        package_name_output = CM.run_command_check_output(
            command_args_package_name)
        package_version_output = CM.run_command_check_output(
            command_args_package_version)

        package_info = PackageInfo()
        package_info.package = package_name_output
        package_info.version = package_version_output

        return package_info
Пример #2
0
    def get_packageinfo_from_packagefile(cls, file_path, ctx=None):
        """
        Extract the Package-Name and the Package-Version from the Debian-Package.

        :param file_path: Path to the Debian-Package
        :param ctx: ctx, needed for dpkg_include_package_arch
        :return: A PackageInfo()-Object with Package-Version and Package-Name.
        """
        command_args_packagename = [cls.executable, '-f', file_path, 'Package']
        command_args_version = [cls.executable, '-f', file_path, 'Version']
        command_args_arch = [cls.executable, '-f', file_path, 'Architecture']
        package_name = CM.run_command_check_output(command_args_packagename)
        package_version = CM.run_command_check_output(command_args_version)

        package_info = PackageInfo()
        package_info.package = package_name.strip()

        if ctx and ctx['dpkg_include_package_arch']:
            package_arch = CM.run_command_check_output(command_args_arch)
            package_info.version = package_version.strip(
            ) + '.' + package_arch.strip()
        else:
            package_info.version = package_version.strip()

        return package_info
Пример #3
0
 def validate_signature(output_swid_tag):
     folder_info = create_temp_folder('nofile')
     file_path = folder_info['save_location'] + '/swid_tag.xml'
     with open(file_path, 'w') as file:
         file.write(output_swid_tag)
     CommandManager.run_command_check_output(
         ["xmlsec1", "--verify", file_path])
Пример #4
0
 def validate_signature(output_swid_tag):
     ca_certificate = "tests/ca/swidgen-ca.pem"
     folder_info = create_temp_folder('nofile')
     file_path = folder_info['save_location'] + '/swid_tag.xml'
     with open(file_path, 'w') as file:
         file.write(output_swid_tag)
     CommandManager.run_command_check_output(["xmlsec1", "--verify", "--trusted-pem", ca_certificate, file_path])
Пример #5
0
    def get_files_from_packagefile(cls, file_path):
        """
        Extract all information of a .rpm package.
        - List of all files
        - List of all Configuration-files

        This Method extract all the information in a temporary directory. The Rpm package
        is extracted to the temporary directory, this because the files are needed to compute the File-Hash.

        :param file_pathname: Path to the .rpm package
        :return: Lexicographical sorted List of FileInfo()-Objects (Conffiles and normal Files)
        """
        all_file_info = []

        save_options = create_temp_folder(file_path)

        command_args_file_list = [
            cls.executable, "--query", "--package", file_path, '-l'
        ]
        command_args_conffile_list = [
            cls.executable, "--query", "--package", file_path, '-c'
        ]
        command_args_rpm2cpio = ["rpm2cpio", file_path]
        command_args_cpio = ["cpio", "-id", "--quiet"]

        file_list_output = CM.run_command_check_output(command_args_file_list)
        conffile_list_output = CM.run_command_check_output(
            command_args_conffile_list)

        normal_files = filter(lambda fp: len(fp) > 0,
                              file_list_output.split('\n'))
        config_files = filter(lambda fp: len(fp) > 0,
                              conffile_list_output.split('\n'))

        rpm2cpio = CM.run_command_popen(command_args_rpm2cpio,
                                        stdout=subprocess.PIPE)
        CM.run_command_check_output(
            command_args_cpio,
            stdin=rpm2cpio.stdout,
            working_directory=save_options['save_location'])

        for file_path in config_files:
            temporary_path = save_options['save_location'] + file_path
            if cls._is_file(temporary_path):
                file_info = FileInfo(file_path, actual_path=False)
                file_info.set_actual_path(temporary_path)
                file_info.mutable = True
                all_file_info.append(file_info)

        for file_path in normal_files:
            temporary_path = save_options['save_location'] + file_path
            if cls._is_file(temporary_path) and file_path not in config_files:
                file_info = FileInfo(file_path, actual_path=False)
                file_info.set_actual_path(temporary_path)
                all_file_info.append(file_info)

        return all_file_info
Пример #6
0
 def validate_signature(output_swid_tag):
     ca_certificate = "tests/ca/swidgen-ca.pem"
     folder_info = create_temp_folder('nofile')
     file_path = folder_info['save_location'] + '/swid_tag.xml'
     with open(file_path, 'w') as file:
         file.write(output_swid_tag)
     CommandManager.run_command_check_output([
         "xmlsec1", "--verify", "--trusted-pem", ca_certificate, file_path
     ])
Пример #7
0
    def get_files_for_package(cls, package_info):
        """
        Get list of files related to the specified package.

        Args:
            package_info (PackageInfo):
                The ``PackageInfo`` instance for the query.

        Returns:
            List of ``FileInfo`` instances.

        """

        result = []
        stripped_lines = []

        command_args_normal_files = [
            cls.executable_query, '-L', package_info.package
        ]
        command_normal_file_output = CM.run_command_check_output(
            command_args_normal_files)

        lines = command_normal_file_output.rstrip().split('\n')
        normal_files = filter(cls._is_file, lines)

        command_args_config_files = [
            cls.executable_query, '-W', '-f=${conffiles}\\n',
            package_info.package
        ]
        command_config_file_output = CM.run_command_check_output(
            command_args_config_files)

        lines = command_config_file_output.split('\n')

        for line in lines:
            if len(line) != 0:
                path_without_md5 = line.strip()[:len(line.strip()) -
                                                cls.md5_hash_length].strip()
                stripped_lines.append(path_without_md5)

        config_files = filter(cls._is_file, stripped_lines)

        for config_file_path in config_files:
            file_info = FileInfo(config_file_path)
            file_info.mutable = True
            result.append(file_info)

        for file_path in normal_files:
            if file_path not in config_files:
                result.append(FileInfo(file_path))

        return sorted(result, key=lambda f: f.full_pathname)
Пример #8
0
    def get_package_list(cls, ctx=None):
        """
        Get list of installed packages.

        Returns:
            List of ``PackageInfo`` instances.

        """
        result = []
        if ctx and ctx['dpkg_include_package_arch']:
            command_args = [cls.executable_query, '-W', '-f=${Package}\\n${Version}.${Architecture}\\n${Status}\\n'
                                                        '${binary:Summary}\\n${conffiles}\\t']
        else:
            command_args = [cls.executable_query, '-W', '-f=${Package}\\n${Version}\\n${Status}\\n'
                                                        '${binary:Summary}\\n${conffiles}\\t']

        command_output = CM.run_command_check_output(command_args)

        line_list = command_output.split('\t')

        for line in line_list:
            split_line = line.split('\n')

            if len(split_line) >= 5:
                package_info = PackageInfo()
                package_info.package = split_line[0]
                package_info.version = split_line[1]
                package_info.status = split_line[2]
                package_info.summary = split_line[3]

                result.append(package_info)

        return [r for r in result if cls._package_installed(r)]
    def get_files_for_package(cls, package_info):
        """
        Get list of files related to the specified package.

        Caching could be implemented by using `Ql` without any package name.

        Args:
            package_name (str):
                The package name as string (e.g. ``cowsay``).

        Returns:
            List of ``FileInfo`` instances.

        """
        command_args_files = [cls.executable, '-Ql', package_info.package]
        files_output = CM.run_command_check_output(command_args_files)
        lines = filter(None, files_output.rstrip().split('\n'))
        result = []
        for line in lines:
            split_line = line.split(' ', 1)
            assert len(split_line) == 2, repr(split_line)
            file_path = split_line[1]
            if cls._is_file(file_path):
                file_info = FileInfo(file_path)
                # With the assumption that files in the '/etc'-Folders are mostly Configuration-Files
                if file_path.startswith("/etc/"):
                    file_info.mutable = True
                result.append(file_info)
        return result
Пример #10
0
    def get_package_list(cls, ctx=None):
        """
        Get list of installed packages.

        Returns:
            List of ``PackageInfo`` instances.

        """

        command_args_package_list = [cls.executable, '-qa', '--queryformat',
                                     '\t%{name} %{version}-%{release}.%{arch} %{summary}']
        package_list_output = CM.run_command_check_output(command_args_package_list)

        line_list = package_list_output.split('\t')
        result = []

        for line in line_list:
            split_line = line.replace('\n', " ").split(" ", 2)
            if len(split_line) == 3:
                package_info = PackageInfo()
                package_info.package = split_line[0]
                package_info.version = split_line[1]
                package_info.summary = split_line[2]
                result.append(package_info)
        return result
Пример #11
0
    def get_package_list(cls):
        """
        Get list of installed packages.

        Returns:
            List of ``PackageInfo`` instances.

        """
        result = []
        command_args = [
            cls.executable_query, '-W',
            '-f=${Package}\\n${Version}\\n${Status}\\n${conffiles}\\t'
        ]

        command_output = CM.run_command_check_output(command_args)

        line_list = command_output.split('\t')

        for line in line_list:
            split_line = line.split('\n')

            if len(split_line) >= 4:
                package_info = PackageInfo()
                package_info.package = split_line[0]
                package_info.version = split_line[1]
                package_info.status = split_line[2]

                result.append(package_info)

        return [r for r in result if cls._package_installed(r)]
Пример #12
0
    def get_files_for_package(cls, package_info):
        """
        Get list of files related to the specified package.

        Caching could be implemented by using `Ql` without any package name.

        Args:
            package_name (str):
                The package name as string (e.g. ``cowsay``).

        Returns:
            List of ``FileInfo`` instances.

        """
        command_args_files = [cls.executable, '-Ql', package_info.package]
        files_output = CM.run_command_check_output(command_args_files)
        lines = filter(None, files_output.rstrip().split('\n'))
        result = []
        for line in lines:
            split_line = line.split(' ', 1)
            assert len(split_line) == 2, repr(split_line)
            file_path = split_line[1]
            if cls._is_file(file_path):
                file_info = FileInfo(file_path)
                # With the assumption that files in the '/etc'-Folders are mostly Configuration-Files
                if file_path.startswith("/etc/"):
                    file_info.mutable = True
                result.append(file_info)
        return result
Пример #13
0
    def get_packageinfo_from_packagefile(cls, file_path):
        """
        Extract the Package-Name and the Package-Version from the Debian-Package.

        :param file_path: Path to the Debian-Package
        :return: A PackageInfo()-Object with Package-Version and Package-Name.
        """
        command_args_packagename = [cls.executable, '-f', file_path, 'Package']
        command_args_version = [cls.executable, '-f', file_path, 'Version']
        package_name = CM.run_command_check_output(command_args_packagename)
        package_version = CM.run_command_check_output(command_args_version)

        package_info = PackageInfo()
        package_info.package = package_name.strip()
        package_info.version = package_version.strip()

        return package_info
Пример #14
0
    def get_files_from_packagefile(cls, file_path):
        """
        Extract all information of a .rpm package.
        - List of all files
        - List of all Configuration-files

        This Method extract all the information in a temporary directory. The Rpm package
        is extracted to the temporary directory, this because the files are needed to compute the File-Hash.

        :param file_pathname: Path to the .rpm package
        :return: Lexicographical sorted List of FileInfo()-Objects (Conffiles and normal Files)
        """
        all_file_info = []

        save_options = create_temp_folder(file_path)

        command_args_file_list = [cls.executable, "--query", "--package", file_path, '-l']
        command_args_conffile_list = [cls.executable, "--query", "--package", file_path, '-c']
        command_args_rpm2cpio = ["rpm2cpio", file_path]
        command_args_cpio = ["cpio", "-id", "--quiet"]

        file_list_output = CM.run_command_check_output(command_args_file_list)
        conffile_list_output = CM.run_command_check_output(command_args_conffile_list)

        normal_files = filter(lambda fp: len(fp) > 0, file_list_output.split('\n'))
        config_files = filter(lambda fp: len(fp) > 0, conffile_list_output.split('\n'))

        rpm2cpio = CM.run_command_popen(command_args_rpm2cpio, stdout=subprocess.PIPE)
        CM.run_command_check_output(command_args_cpio, stdin=rpm2cpio.stdout, working_directory=save_options['save_location'])

        for file_path in config_files:
            temporary_path = save_options['save_location'] + file_path
            if cls._is_file(temporary_path):
                file_info = FileInfo(file_path, actual_path=False)
                file_info.set_actual_path(temporary_path)
                file_info.mutable = True
                all_file_info.append(file_info)

        for file_path in normal_files:
            temporary_path = save_options['save_location'] + file_path
            if cls._is_file(temporary_path) and file_path not in config_files:
                file_info = FileInfo(file_path, actual_path=False)
                file_info.set_actual_path(temporary_path)
                all_file_info.append(file_info)

        return all_file_info
Пример #15
0
    def get_files_for_package(cls, package_info):
        """
        Get list of files related to the specified package.

        Args:
            package_info (PackageInfo):
                The ``PackageInfo`` instance for the query.

        Returns:
            List of ``FileInfo`` instances.

        """

        result = []
        stripped_lines = []

        command_args_normal_files = [cls.executable_query, '-L', package_info.package]
        command_normal_file_output = CM.run_command_check_output(command_args_normal_files)

        lines = command_normal_file_output.rstrip().split('\n')
        normal_files = filter(cls._is_file, lines)

        command_args_config_files = [cls.executable_query, '-W', '-f=${conffiles}\\n', package_info.package]
        command_config_file_output = CM.run_command_check_output(command_args_config_files)

        lines = command_config_file_output.split('\n')

        for line in lines:
            if len(line) != 0:
                path_without_md5 = line.strip()[:len(line.strip()) - cls.md5_hash_length].strip()
                stripped_lines.append(path_without_md5)

        config_files = filter(cls._is_file, stripped_lines)

        for config_file_path in config_files:
            file_info = FileInfo(config_file_path)
            file_info.mutable = True
            result.append(file_info)

        for file_path in normal_files:
            if file_path not in config_files:
                result.append(FileInfo(file_path))

        return sorted(result, key=lambda f: f.full_pathname)
Пример #16
0
    def get_files_for_package(cls, package_info):
        """
        Get list of files related to the specified package.

        Args:
            package_info (PackageInfo):
                The ``PackageInfo`` instance for the query.

        Returns:
            List of ``FileInfo`` instances.

        """
        result = []

        command_args_file_list = [cls.executable, '-ql', package_info.package]
        command_args_package_list = [
            cls.executable, '-qa', '--queryformat', '%{name}\n', '-c',
            package_info.package
        ]

        file_list_output = CM.run_command_check_output(command_args_file_list)
        lines_file_list = file_list_output.rstrip().split('\n')
        files = filter(cls._is_file, lines_file_list)

        config_file_list_output = CM.run_command_check_output(
            command_args_package_list)
        config_files = config_file_list_output.split('\n')
        config_files = (filter(lambda f: len(f) > 0, config_files))

        for conf_file_path in config_files:
            if cls._is_file(conf_file_path):
                file_info = FileInfo(conf_file_path)
                file_info.mutable = True
                result.append(file_info)

        for file_path in files:
            if cls._is_file(file_path) and file_path not in config_files:
                file_info = FileInfo(file_path)
                result.append(file_info)

        return result
Пример #17
0
    def get_files_from_packagefile(cls, file_fullpathname):
        """
        Extract all information of a .pkg.tar.xz package.
        - List of all files
        - List of all Configuration-files

        This Method extract all the information in a temporary directory. The Debian package
        is extracted to the temporary directory, this because the files are needed to compute the File-Hash.

        :param file_pathname: Path to the .pkg.tar.xz package
        :return: Lexicographical sorted List of FileInfo()-Objects (Conffiles and normal Files)
        """
        all_files = []

        save_options = create_temp_folder(file_fullpathname)

        command_args_extract_package = [
            'tar', '-xf', save_options['absolute_package_path']
        ]
        command_args_files = [cls.executable, '-Qlp', file_fullpathname]

        files_output = CM.run_command_check_output(command_args_files)

        lines = files_output.split('\n')
        lines = filter(lambda l: len(l) > 0, lines)

        CM.run_command(command_args_extract_package,
                       working_directory=save_options['save_location'])

        for line in lines:
            path = line.split(' ')[1]
            temporary_path = save_options['save_location'] + path
            if cls._is_file(temporary_path):
                file_info = FileInfo(path, actual_path=False)
                file_info.set_actual_path(temporary_path)
                # With the assumption that files in the '/etc'-Folders are mostly Configuration-Files
                if path.startswith("/etc/"):
                    file_info.mutable = True
                all_files.append(file_info)

        return all_files
Пример #18
0
    def get_packageinfo_from_packagefile(cls, file_path, ctx=None):
        """
        Extract the Package-Name and the Package-Version from the Debian-Package.

        :param file_path: Path to the Rpm-Package
        :param ctx: ignored
        :return: A PackageInfo()-Object with Package-Version and Package-Name.
        """
        command_args_package_name = [cls.executable, "--query", "--package", "--queryformat", "%{name}", file_path]
        command_args_package_version = [cls.executable, "--query", "--package", "--queryformat", "%{version}-%{release}.%{arch}", file_path]
        command_args_package_summary = [cls.executable, "--query", "--package", "--queryformat", "%{summary}", file_path]

        package_name_output = CM.run_command_check_output(command_args_package_name)
        package_version_output = CM.run_command_check_output(command_args_package_version)
        package_summary_output = CM.run_command_check_output(command_args_package_summary)

        package_info = PackageInfo()
        package_info.package = package_name_output
        package_info.version = package_version_output
        package_info.summary = package_summary_output

        return package_info
Пример #19
0
    def get_files_from_packagefile(cls, file_fullpathname):
        """
        Extract all information of a .pkg.tar.xz package.
        - List of all files
        - List of all Configuration-files

        This Method extract all the information in a temporary directory. The Debian package
        is extracted to the temporary directory, this because the files are needed to compute the File-Hash.

        :param file_pathname: Path to the .pkg.tar.xz package
        :return: Lexicographical sorted List of FileInfo()-Objects (Conffiles and normal Files)
        """
        all_files = []

        save_options = create_temp_folder(file_fullpathname)

        command_args_extract_package = ['tar', '-xf', save_options['absolute_package_path']]
        command_args_files = [cls.executable, '-Qlp', file_fullpathname]

        files_output = CM.run_command_check_output(command_args_files)

        lines = files_output.split('\n')
        lines = filter(lambda l: len(l) > 0, lines)

        CM.run_command(command_args_extract_package, working_directory=save_options['save_location'])

        for line in lines:
            path = line.split(' ')[1]
            temporary_path = save_options['save_location'] + path
            if cls._is_file(temporary_path):
                file_info = FileInfo(path, actual_path=False)
                file_info.set_actual_path(temporary_path)
                # With the assumption that files in the '/etc'-Folders are mostly Configuration-Files
                if path.startswith("/etc/"):
                    file_info.mutable = True
                all_files.append(file_info)

        return all_files
Пример #20
0
    def get_files_for_package(cls, package_info):
        """
        Get list of files related to the specified package.

        Args:
            package_info (PackageInfo):
                The ``PackageInfo`` instance for the query.

        Returns:
            List of ``FileInfo`` instances.

        """
        result = []

        command_args_file_list = [cls.executable, '-ql', package_info.package]
        command_args_package_list = [cls.executable, '-qa', '--queryformat', '%{name}\n', '-c', package_info.package]

        file_list_output = CM.run_command_check_output(command_args_file_list)
        lines_file_list = file_list_output.rstrip().split('\n')
        files = filter(cls._is_file, lines_file_list)

        config_file_list_output = CM.run_command_check_output(command_args_package_list)
        config_files = config_file_list_output.split('\n')
        config_files = (filter(lambda f: len(f) > 0, config_files))

        for conf_file_path in config_files:
            if cls._is_file(conf_file_path):
                file_info = FileInfo(conf_file_path)
                file_info.mutable = True
                result.append(file_info)

        for file_path in files:
            if cls._is_file(file_path) and file_path not in config_files:
                file_info = FileInfo(file_path)
                result.append(file_info)

        return result
Пример #21
0
    def get_packageinfo_from_packagefile(cls, file_path, ctx=None):
        """
        Extract the Package-Name and the Package-Version from the Debian-Package.

        :param file_path: Path to the Debian-Package
        :param ctx: ctx, needed for dpkg_include_package_arch
        :return: A PackageInfo()-Object with Package-Version and Package-Name.
        """
        command_args_packagename = [cls.executable, '-f', file_path, 'Package']
        command_args_version = [cls.executable, '-f', file_path, 'Version']
        command_args_arch = [cls.executable, '-f', file_path, 'Architecture']
        package_name = CM.run_command_check_output(command_args_packagename)
        package_version = CM.run_command_check_output(command_args_version)

        package_info = PackageInfo()
        package_info.package = package_name.strip()

        if ctx and ctx['dpkg_include_package_arch']:
            package_arch = CM.run_command_check_output(command_args_arch)
            package_info.version = package_version.strip() + '.' + package_arch.strip()
        else:
            package_info.version = package_version.strip()

        return package_info
Пример #22
0
def sign_xml(data, signature_args):
    folder_info = create_temp_folder(signature_args['pkcs12_file'])
    file_path = folder_info['save_location'] + '/swid_tag.xml'
    with open(file_path, 'wb') as file:
        file.write(data)
    if signature_args['pkcs12_password'] is None:
        sign_command = [
            "xmlsec1", "--sign", "--pkcs12", signature_args['pkcs12_file'],
            file_path
        ]
    else:
        sign_command = [
            "xmlsec1", "--sign", "--pkcs12", signature_args['pkcs12_file'],
            "--pwd", signature_args['pkcs12_password'], file_path
        ]

    return CM.run_command_check_output(sign_command)
Пример #23
0
    def get_packageinfo_from_packagefile(cls, file_path, ctx=None):
        """
        Extract the Package-Name and the Package-Version from the Pacman-Package.

        :param file_path: Path to the Pacman-Package
        :param ctx: ignored
        :return: A PackageInfo()-Object with Package-Version and Package-Name.
        """
        command_args_packageinfo = [cls.executable, '--query', '--file', file_path]
        package_info_output = CM.run_command_check_output(command_args_packageinfo)
        line_split = package_info_output.split(' ')

        package_info = PackageInfo()
        package_info.package = line_split[0]
        package_info.version = line_split[1].rstrip()

        return package_info
Пример #24
0
    def get_packageinfo_from_packagefile(cls, file_path):
        """
        Extract the Package-Name and the Package-Version from the Pacman-Package.

        :param file_path: Path to the Pacman-Package
        :return: A PackageInfo()-Object with Package-Version and Package-Name.
        """
        command_args_packageinfo = [
            cls.executable, '--query', '--file', file_path
        ]
        package_info_output = CM.run_command_check_output(
            command_args_packageinfo)
        line_split = package_info_output.split(' ')

        package_info = PackageInfo()
        package_info.package = line_split[0]
        package_info.version = line_split[1].rstrip()

        return package_info
Пример #25
0
    def get_package_list(cls, ctx=None):
        """
        Get list of installed packages.

        Returns:
            List of ``PackageInfo`` instances.

        """

        command_args_packages = [cls.executable, '-Q', '--color', 'never']
        packages_output = CM.run_command_check_output(command_args_packages)
        lines = filter(None, packages_output.rstrip().split('\n'))
        result = []
        for line in lines:
            split_line = line.split()
            assert len(split_line) == 2, repr(split_line)
            info = PackageInfo()
            info.package = split_line[0]
            info.version = split_line[1]
            result.append(info)
        return result
Пример #26
0
    def get_package_list(cls, ctx=None):
        """
        Get list of installed packages.

        Returns:
            List of ``PackageInfo`` instances.

        """

        command_args_packages = [cls.executable, '-Q', '--color', 'never']
        packages_output = CM.run_command_check_output(command_args_packages)
        lines = filter(None, packages_output.rstrip().split('\n'))
        result = []
        for line in lines:
            split_line = line.split()
            assert len(split_line) == 2, repr(split_line)
            info = PackageInfo()
            info.package = split_line[0]
            info.version = split_line[1]
            result.append(info)
        return result
Пример #27
0
    def get_package_list(cls, ctx=None):
        """
        Get list of installed packages.

        Returns:
            List of ``PackageInfo`` instances.

        """
        result = []
        if ctx and ctx['dpkg_include_package_arch']:
            command_args = [
                cls.executable_query, '-W',
                '-f=${Package}\\n${Version}.${Architecture}\\n${Status}\\n'
                '${binary:Summary}\\n${conffiles}\\t'
            ]
        else:
            command_args = [
                cls.executable_query, '-W',
                '-f=${Package}\\n${Version}\\n${Status}\\n'
                '${binary:Summary}\\n${conffiles}\\t'
            ]

        command_output = CM.run_command_check_output(command_args)

        line_list = command_output.split('\t')

        for line in line_list:
            split_line = line.split('\n')

            if len(split_line) >= 5:
                package_info = PackageInfo()
                package_info.package = split_line[0]
                package_info.version = split_line[1]
                package_info.status = split_line[2]
                package_info.summary = split_line[3]

                result.append(package_info)

        return [r for r in result if cls._package_installed(r)]
Пример #28
0
 def get_string_output_from_cmd(command):
     return CommandManager.run_command_check_output(command)
Пример #29
0
    def get_files_from_packagefile(cls, file_pathname):
        """
        Extract all information of a .deb package.
        - List of all files
        - List of all Configuration-files

        This Method extract all the information in a temporary directory. The Debian package
        is extracted to the temporary directory, this because the files are needed to compute the File-Hash.

        :param file_pathname: Path to the .deb package
        :return: Lexicographical sorted List of FileInfo()-Objects (Conffiles and normal Files)
        """
        save_options = create_temp_folder(file_pathname)

        result = []
        result_help_list = []  # needed to check duplications

        command_args_unpack_package = [
            cls.executable, '-x', save_options['absolute_package_path'],
            save_options['save_location']
        ]
        command_args_extract_controlpackage = [
            "ar", "x", save_options['absolute_package_path'],
            cls.control_archive
        ]
        command_args_extract_conffile = [
            "tar", "-zxf", "/".join(
                (save_options['save_location'], cls.control_archive)),
            cls.conffile_file_name
        ]
        command_args_file_list = [cls.executable, '-c', file_pathname]

        def _add_to_result_list(file_path, actual_path, mutable=False):
            result_help_list.append(file_path)
            file_info = FileInfo(file_path, actual_path=False)
            file_info.set_actual_path(actual_path)
            file_info.mutable = mutable
            result.append(file_info)

        # Extraction of all needed Files (Store Files into tmp folder), extract Configuration-Files entries
        try:
            CM.run_command(command_args_unpack_package)
            CM.run_command(command_args_extract_controlpackage,
                           working_directory=save_options['save_location'])
            CM.run_command(command_args_extract_conffile,
                           working_directory=save_options['save_location'])

            temp_conffile_save_location = "/".join(
                (save_options['save_location'], cls.conffile_file_name))

            with open(temp_conffile_save_location, 'rb') as afile:
                file_content = afile.read().encode('utf-8')

        except (IOError, subprocess.CalledProcessError):
            # If no file extracted from command -> no .conffile-File exists
            file_content = None
            config_file_paths = []

        # Extract Configuration-Files-Entries from output
        if file_content is not None:
            config_file_paths = filter(lambda path: len(path) > 0,
                                       file_content.split('\n'))

            for config_file_path in config_file_paths:
                _add_to_result_list(config_file_path,
                                    save_options['save_location'] +
                                    config_file_path,
                                    mutable=True)

        # Extraction of file-list
        output_file_list = CM.run_command_check_output(command_args_file_list)
        line_list = output_file_list.split('\n')

        for line in line_list:

            splitted_line = line.split(' ')
            directory_or_file_path = splitted_line[-1]

            if "->" in splitted_line:
                # symbol-link
                symbol_link = (splitted_line[-3])[1:]
                temp_save_location_symbol_link = "/".join(
                    (save_options['save_location'], symbol_link))
                head, _ = ntpath.split(symbol_link)

                if "../" in directory_or_file_path:
                    root, _ = ntpath.split(head)
                    directory_or_file_path = root + directory_or_file_path[2:]
                else:
                    directory_or_file_path = "/".join(
                        (head, directory_or_file_path))

                if cls._is_file(temp_save_location_symbol_link):
                    if symbol_link not in config_file_paths and symbol_link not in result_help_list:
                        _add_to_result_list(symbol_link,
                                            temp_save_location_symbol_link)
            else:
                directory_or_file_path = directory_or_file_path[1:]

            temp_save_location_file = "/".join(
                (save_options['save_location'], directory_or_file_path))

            if cls._is_file(temp_save_location_file):
                if directory_or_file_path not in config_file_paths and directory_or_file_path not in result_help_list:
                    _add_to_result_list(directory_or_file_path,
                                        temp_save_location_file)

        return sorted(result, key=lambda f: f.full_pathname)
Пример #30
0
    def get_files_from_packagefile(cls, file_pathname):
        """
        Extract all information of a .deb package.
        - List of all files
        - List of all Configuration-files

        This Method extract all the information in a temporary directory. The Debian package
        is extracted to the temporary directory, this because the files are needed to compute the File-Hash.

        :param file_pathname: Path to the .deb package
        :return: Lexicographical sorted List of FileInfo()-Objects (Conffiles and normal Files)
        """
        save_options = create_temp_folder(file_pathname)

        result = []
        result_help_list = []  # needed to check duplications

        command_args_unpack_package = [cls.executable, '-x', save_options['absolute_package_path'], save_options['save_location']]
        command_args_extract_controlpackage = ["ar", "x", save_options['absolute_package_path'], cls.control_archive]
        command_args_extract_conffile = ["tar", "-zxf", "/".join((save_options['save_location'], cls.control_archive)), cls.conffile_file_name]
        command_args_file_list = [cls.executable, '-c', file_pathname]

        def _add_to_result_list(file_path, actual_path, mutable=False):
            result_help_list.append(file_path)
            file_info = FileInfo(file_path, actual_path=False)
            file_info.set_actual_path(actual_path)
            file_info.mutable = mutable
            result.append(file_info)

        # Extraction of all needed Files (Store Files into tmp folder), extract Configuration-Files entries
        try:
            CM.run_command(command_args_unpack_package)
            CM.run_command(command_args_extract_controlpackage, working_directory=save_options['save_location'])
            CM.run_command(command_args_extract_conffile, working_directory=save_options['save_location'])

            temp_conffile_save_location = "/".join((save_options['save_location'], cls.conffile_file_name))

            with open(temp_conffile_save_location, 'rb') as afile:
                file_content = afile.read().encode('utf-8')

        except(IOError, subprocess.CalledProcessError):
            # If no file extracted from command -> no .conffile-File exists
            file_content = None
            config_file_paths = []

        # Extract Configuration-Files-Entries from output
        if file_content is not None:
            config_file_paths = filter(lambda path: len(path) > 0, file_content.split('\n'))

            for config_file_path in config_file_paths:
                _add_to_result_list(config_file_path, save_options['save_location'] + config_file_path, mutable=True)

        # Extraction of file-list
        output_file_list = CM.run_command_check_output(command_args_file_list)
        line_list = output_file_list.split('\n')

        for line in line_list:

            splitted_line = line.split(' ')
            directory_or_file_path = splitted_line[-1]

            if "->" in splitted_line:
                # symbol-link
                symbol_link = (splitted_line[-3])[1:]
                temp_save_location_symbol_link = "/".join((save_options['save_location'], symbol_link))
                head, _ = ntpath.split(symbol_link)

                if "../" in directory_or_file_path:
                    root, _ = ntpath.split(head)
                    directory_or_file_path = root + directory_or_file_path[2:]
                else:
                    directory_or_file_path = "/".join((head, directory_or_file_path))

                if cls._is_file(temp_save_location_symbol_link):
                    if symbol_link not in config_file_paths and symbol_link not in result_help_list:
                        _add_to_result_list(symbol_link, temp_save_location_symbol_link)
            else:
                directory_or_file_path = directory_or_file_path[1:]

            temp_save_location_file = "/".join((save_options['save_location'], directory_or_file_path))

            if cls._is_file(temp_save_location_file):
                if directory_or_file_path not in config_file_paths and directory_or_file_path not in result_help_list:
                    _add_to_result_list(directory_or_file_path, temp_save_location_file)

        return sorted(result, key=lambda f: f.full_pathname)
Пример #31
0
 def get_tree_output_from_cmd(command):
     return ET.fromstring(CommandManager.run_command_check_output(command))
Пример #32
0
 def get_string_output_from_cmd(command):
     return CommandManager.run_command_check_output(command)
Пример #33
0
 def get_tree_output_from_cmd(command):
     return ET.fromstring(CommandManager.run_command_check_output(command))