예제 #1
0
    def add_key(self, key_file):
        """adds a list of keys to the local repo

        :param string key_files: key files paths
        """
        lgr.debug('Adding key {0}'.format(key_file))
        # can't do import=key_file as import is unusable as an argument
        sh.rpm('--import', key_file)
예제 #2
0
파일: yum.py 프로젝트: neofort/packman
    def add_key(self, key_file):
        """adds a list of keys to the local repo

        :param string key_files: key files paths
        """
        lgr.debug('Adding key {0}'.format(key_file))
        # can't do import=key_file as import is unusable as an argument
        sh.rpm('--import', key_file)
예제 #3
0
    def add_src_repos(self, source_repos):
        """adds a list of source repos to the apt repo

        :param list source_repos: repos to add to sources list
        """
        for source_repo in source_repos:
            lgr.debug('Adding source repository {0}'.format(source_repo))
            if os.path.splitext(source_repo)[1] == '.rpm':
                sh.rpm('-ivh', source_repo, _ok_code=[0, 1])
            else:
                self.download(source_repo, dir='/etc/yum.repos.d/')
예제 #4
0
파일: yum.py 프로젝트: neofort/packman
    def add_src_repos(self, source_repos):
        """adds a list of source repos to the apt repo

        :param list source_repos: repos to add to sources list
        """
        for source_repo in source_repos:
            lgr.debug('Adding source repository {0}'.format(source_repo))
            if os.path.splitext(source_repo)[1] == '.rpm':
                sh.rpm('-ivh', source_repo, _ok_code=[0, 1])
            else:
                self.download(source_repo, dir='/etc/yum.repos.d/')
예제 #5
0
    def check_if_package_is_installed(self, package):
        """checks if a package is installed

        :param string package: package name to check
        :rtype: `bool` representing whether package is installed or not
        """

        lgr.debug('Checking if {0} is installed'.format(package))
        r = sh.grep(sh.rpm('-qa', _ok_code=[0, 1]), package)
        if r.exit_code == 0:
            lgr.debug('{0} is installed'.format(package))
            return True
        else:
            lgr.error('{0} is not installed'.format(package))
            return False
예제 #6
0
파일: yum.py 프로젝트: neofort/packman
    def check_if_package_is_installed(self, package):
        """checks if a package is installed

        :param string package: package name to check
        :rtype: `bool` representing whether package is installed or not
        """

        lgr.debug('Checking if {0} is installed'.format(package))
        r = sh.grep(sh.rpm('-qa', _ok_code=[0, 1]), package)
        if r.exit_code == 0:
            lgr.debug('{0} is installed'.format(package))
            return True
        else:
            lgr.error('{0} is not installed'.format(package))
            return False
예제 #7
0
    def __get_software(self):
        """Retrieve installed software information"""
        data = []
        if Config().PLATFORM == 'android':
            import jnius
            EPCService = jnius.autoclass(Config().JAVA_SERVICE)
            from epc.android.utils import PythonListIterator
            pm = EPCService.mService.getPackageManager()
            installed = pm.getInstalledPackages(0)
            for package in PythonListIterator(installed):
                data.append(
                    dict(name=package.packageName,
                         installTime=arrow.get(package.firstInstallTime /
                                               1000).isoformat(),
                         updateTime=arrow.get(package.lastUpdateTime /
                                              1000).isoformat(),
                         version=package.versionName))

        elif Config().PLATFORM == 'unix':
            if platform.system().lower().startswith("darwin"):
                import sh
                import plistlib
                xml = sh.system_profiler("SPApplicationsDataType", "-xml")
                plist = plistlib.loads(xml.stdout)
                for package in plist[0]["_items"]:
                    pkg_data = {}
                    if "_name" in package:
                        pkg_data["name"] = package["_name"]
                    else:
                        continue
                    if "version" in package:
                        pkg_data["version"] = package["version"]
                    if "lastModified" in package:
                        pkg_data["installTime"] = package[
                            "lastModified"].isoformat()
                        pkg_data["updateTime"] = pkg_data["installTime"]
                    data.append(pkg_data)
            else:
                import distro
                import sh
                distrib = distro.linux_distribution(
                    full_distribution_name=False)
                if distrib in ("rhel", "centos", "sles"):
                    for package in sh.rpm(
                            '-qa',
                            queryformat=
                            "%{NAME} %{VERSION}%{RELEASE} %{INSTALLTIME}\n",
                            _iter=True):
                        name, version, installTime = package.split()
                        data.append(
                            dict(name=name,
                                 version=version,
                                 installTime=arrow.get(
                                     installTime).isoformat()))
                elif distrib in ("debian", "ubuntu"):
                    for package in sh.Command('dpkg-query')(
                            '-W', f='${binary:Package} ${Version}\n',
                            _iter=True):
                        pkg_data = {}
                        name, version = package.split()
                        pkg_data['name'], pkg_data['version'] = name, version
                        infolist = Path(
                            '/var/lib/dpkg/info') / "{}.list".format(name)
                        if infolist.exists():
                            pkg_data['installTime'] = arrow.get(
                                infolist.stat().st_ctime).isoformat()
                            pkg_data['updateTime'] = arrow.get(
                                infolist.stat().st_atime).isoformat()
                        data.append(pkg_data)

        elif Config().PLATFORM == 'win32':
            from epclib.registry.utils import list_uninstall
            for package in list_uninstall():
                pkg_data = {}
                if "DisplayName" in package:
                    pkg_data["name"] = package["DisplayName"]
                else:
                    continue
                if "DisplayVersion" in package:
                    pkg_data["version"] = package["DisplayVersion"]
                if "InstallDate" in package:
                    pkg_data["installTime"] = arrow.get(
                        package["InstallDate"], "YYYYMMDD").isoformat()
                    pkg_data["updateTime"] = pkg_data["installTime"]
                data.append(pkg_data)

        return data