コード例 #1
0
 def install_debfile(self, path, kwargs=None):
     if not os.path.isfile(path):
         raise WorkitemError(4, "%s is unreadable file" % path)
     try:
         debfile = DebPackage(path)
     except IOError:
         raise WorkitemError(4, "%s is unreadable file" % path)
     except Exception as e:
         raise WorkitemError(5, e)
     self.cache.open()
     pkgName = debfile._sections["Package"]
     debfile.check(
     )  #do debfile.check for the next to do debfile.missing_deps
     if 0 == len(debfile.missing_deps):
         # try:
         res = debfile.install()
         if res:
             raise WorkitemError(6, "package manager failed")
         else:
             kwarg = {
                 "apt_appname": pkgName,
                 "apt_percent": str(200),
                 "action": str(AppActions.INSTALLDEBFILE),
             }
             self.dbus_service.software_apt_signal("apt_finish", kwarg)
             if pkgName == "ubuntu-kylin-software-center" and AppActions.INSTALLDEBFILE == "upgrade":
                 pass
             else:
                 self.dbus_service.set_uksc_not_working()
     else:
         raise WorkitemError(6, "dependence not be satisfied")
コード例 #2
0
def build_debian_package(package_fetcher, package_name, apt_cache, rd_obj, levels=0, get_dependencies=False):
  unstable_target_distros = { 'groovy': 'quantal', 'hydro': 'raring' }
  target_ubuntu_distro = unstable_target_distros[rd_obj._rosdistro]
  level_prefix = '--' * levels
  print("%s> Building package %s" % (level_prefix, package_name))
  deb_package_name = rd_obj.debianize_package_name(package_name)
  deb_package_version = rd_obj.get_version(package_name, full_version=True) + target_ubuntu_distro
  print("%s--> Checking if installed (%s, %s).." % (level_prefix, deb_package_name, deb_package_version)),
  if deb_package_name in apt_cache:
    installed = apt_cache[deb_package_name].installed
    if installed is not None and installed.version == deb_package_version:
      print("OK")
      print("%s is installed already - remove the package if you want to re-install." % (package_name))
      return True
  print("missing!")
  if get_dependencies:
    dependencies = package_build_order([package_name], distro_name=rd_obj._rosdistro)
    print("%s--> Checking Dependencies:" % (level_prefix))
    for dep_pkg_name in dependencies:
      if dep_pkg_name != package_name:
        print("%s---- %s....." % (level_prefix, dep_pkg_name)),
        debian_pkg_name = rd_obj.debianize_package_name(dep_pkg_name)
        if debian_pkg_name in apt_cache and apt_cache[debian_pkg_name].installed is not None:
          print(" OK! (installed version %s)" % apt_cache[debian_pkg_name].installed.version)
        else:
          print(" Needs build, building...")
          build_debian_package(package_fetcher, dep_pkg_name, apt_cache, rd_obj, levels + 1)
    print("%s<<-- Dependencies OKAY." % (level_prefix))
  print("%s>>> Build debian package %s from repo %s" % (level_prefix, deb_package_name, package_fetcher.url(package_name)))
  repo_path = package_fetcher.checkout_package(package_name)
  client = GitClient(repo_path)
  deb_package_tag = deb_package_name + '_' + rd_obj.get_version(package_name, full_version=True) + '_' + target_ubuntu_distro
  bloom_package_version = 'debian/' + deb_package_tag
  client.update(bloom_package_version)
  installed_builddeps = install_debian_build_dependencies(repo_path)
  if not installed_builddeps:
    raise RosGitBuildError("%s!!! Error building %s from %s: Can't install build-dependencies!" % (level_prefix, deb_package_name, package_fetcher.url(package_name)))
  (returncode, result, message) = run_shell_command('debuild clean', repo_path, shell=True, show_stdout=False)
  if returncode != 0:
    raise RosGitBuildError("%s!!! Error building %s from %s: %s \n %s" % (level_prefix, deb_package_name, package_fetcher.url(package_name), 'debuild clean', message))
  (returncode, result, message) = run_shell_command('debuild binary', repo_path, shell=True, show_stdout=False)
  if returncode != 0:
    raise RosGitBuildError("%s!!! Error building %s from %s: %s \n %s" % (level_prefix, deb_package_name, package_fetcher.url(package_name), 'debuild binary', message))
  deb_files = glob.glob(os.path.join(repo_path, '..', '%s*.deb' % (deb_package_name + '_' + rd_obj.get_version(package_name, full_version=True))))
  if len(deb_files) > 0:
    # install the deb
    from apt.debfile import DebPackage
    deb_pkg = DebPackage(deb_files[0])
    deb_pkg.check()
    packages_needed = ' '.join(deb_pkg.missing_deps)
    (returncode, result, message) = run_shell_command('sudo apt-get -y install %s' % packages_needed, shell=True, show_stdout=True)
    if returncode != 0:
      raise RosGitBuildError("%s!!! Error building %s: can't install dependent packages %s" % (level_prefix, deb_package_name, packages_needed))
    (returncode, result, message) = run_shell_command('sudo dpkg -i %s' % deb_files[0], shell=True, show_stdout=True)
    if returncode != 0:
      raise RosGitBuildError("%s!!! Error building %s from %s: %s \n %s" % (level_prefix, deb_package_name, package_fetcher.url(package_name), 'debuild binary', message))
  else:
    raise RosGitBuildError("%s!!! Can't find a built debian package for %s after the build!" % (level_prefix, deb_package_name))
コード例 #3
0
class DebFile():

    # the deb file which user selected
    debfile = ''

    path = ''
    name = ''
    version = ''
    installedsize = -1
    description = ''

    def __init__(self, path):
        self.debfile = DebPackage(path)
        self.get_deb_info()

        self.path = path

    # check if the deb file is installable
    @property
    def is_installable(self):
        return self.debfile.check()

    # get missing dependencies
    def get_missing_deps(self):
        self.debfile.check()  #do check for get missing_deps
        return self.debfile.missing_deps

    # get deb file name, version, installedsize, description
    def get_deb_info(self):
        try:
            self.name = self.debfile._sections["Package"]
        except:
            self.name = ""
        try:
            self.version = self.debfile._sections["Version"]
        except:
            self.version = ""
        try:
            self.installedsize = int(
                float(self.debfile._sections["Installed-Size"]))
        except:
            try:
                self.installedsize = int(float(self.debfile._sections["Size"]))
            except:
                self.installedsize = 0
        try:
            self.description = self.debfile._sections["Description"]
        except:
            self.description = ""

    # install the deb file
    def install_deb(self):
        self.debfile.install(AptProcess(self.debfile.pkgname))
コード例 #4
0
 def install_debfile(self, path, sender=None):
     print("####install deb file: ", path)
     # path = "".join([chr(character) for character in path]) # add by zhangxin for chinese .deb path 11.19
     granted = self.auth_with_policykit(sender, PACKAGES_MANAGER_TOOLS)
     if not granted:
         kwarg = {
             "appname": path,
             "action": AppActions.INSTALLDEBFILE,
         }
         self.software_auth_signal("auth_cancel", kwarg)
         return False
     else:
         kwarg = {
             "appname": path,
             "action": AppActions.INSTALLDEBFILE,
         }
         self.software_auth_signal("auth_ensure", kwarg)
         #print("send auth signal")
     if not os.path.isfile(path):
         raise WorkitemError(4, "%s is unreadable file" % path)
     try:
         debfile = DebPackage(path)
     except IOError:
         raise WorkitemError(4, "%s is unreadable file" % path)
     except Exception as e:
         raise WorkitemError(5, e)
     #self.cache.open()
     pkgName = debfile._sections["Package"]
     debfile.check(
     )  #do debfile.check for the next to do debfile.missing_deps
     if 0 == len(debfile.missing_deps):
         # try:
         res = debfile.install()
         if res:
             kwarg = {
                 "apt_appname": pkgName,
                 "apt_percent": str(-200),
                 "action": str(AppActions.INSTALLDEBFILE),
             }
             self.software_apt_signal("apt_finish", kwarg)
             raise WorkitemError(6, "package manager failed")
         else:
             kwarg = {
                 "apt_appname": pkgName,
                 "apt_percent": str(200),
                 "action": str(AppActions.INSTALLDEBFILE),
             }
             self.software_apt_signal("apt_finish", kwarg)
     else:
         raise WorkitemError(16, "dependence not be satisfied")
     return True
コード例 #5
0
class DebFile():

    # the deb file which user selected
    debfile = ''

    path = ''
    name = ''
    version = ''
    installedsize = -1
    description = ''

    def __init__(self, path):
        self.debfile = DebPackage(path)
        self.get_deb_info()

        self.path = path

    # check if the deb file is installable
    def is_installable(self):
        return self.debfile.check()

    # get missing dependencies
    def get_missing_deps(self):
        return self.debfile.missing_deps

    # get deb file name, version, installedsize, description
    def get_deb_info(self):
        self.name = self.debfile._sections["Package"]
        self.version = self.debfile._sections["Version"]
        self.installedsize = int(self.debfile._sections["Installed-Size"])
        self.description = self.debfile._sections["Description"]

    # install the deb file
    def install_deb(self):
        self.debfile.install(AptProcess(self.debfile.pkgname))
コード例 #6
0
    def install_deps(self, path, kwargs=None):
        debfile = DebPackage(path)
        pkgName = debfile._sections["Package"]
        debfile.check()
        deps = debfile.missing_deps

        if(len(deps) > 0):
            self.cache.open()
            for pkgn in deps:
                pkg = self.get_pkg_by_name(pkgn)
                pkg.mark_install()

            try:
                self.cache.commit(FetchProcess(self.dbus_service, pkgName, AppActions.INSTALLDEPS), AptProcess(self.dbus_service, pkgName, AppActions.INSTALLDEPS))
            except Exception, e:
                print e
                print "install err"
コード例 #7
0
    def install_deps(self, path, kwargs=None):
        debfile = DebPackage(path)
        pkgName = debfile._sections["Package"]
        debfile.check()
        deps = debfile.missing_deps

        if(len(deps) > 0):
            self.cache.open()
            for pkgn in deps:
                pkg = self.get_pkg_by_name(pkgn)
                pkg.mark_install()

            try:
                self.cache.commit(FetchProcess(self.dbus_service, pkgName, AppActions.INSTALLDEPS), AptProcess(self.dbus_service, pkgName, AppActions.INSTALLDEPS))
            except Exception as e:
                print(e)
                print("install err")
コード例 #8
0
def main(package):
    cache = apt.Cache()
    debfile = DebPackage(package, cache=cache)
    if debfile.check():
        show_dependencies(debfile)
        prompt = "Do you want to continue [Y/n]? "
        choice = input(prompt)
        if "y" == choice.lower() or not choice:
            try:
                cache.commit(apt.progress.text.AcquireProgress())
            except apt.cache.FetchFailedException as e:
                print(e)
        else:
            print("Abort.")
コード例 #9
0
ファイル: debfile-deps.py プロジェクト: pombredanne/wajig
def main(package):
    cache = apt.Cache()
    debfile = DebPackage(package, cache=cache)
    if debfile.check():
        show_dependencies(debfile)
        prompt = "Do you want to continue [Y/n]? "
        choice = input(prompt)
        if "y" == choice.lower() or not choice:
            try:
                cache.commit(apt.progress.text.AcquireProgress())
            except apt.cache.FetchFailedException as e:
                print(e)
        else:
            print("Abort.")
コード例 #10
0
ファイル: debfile.py プロジェクト: feiying/AppStream
class AppDetailsDebFile(AppDetails):

    def __init__(self, db, doc=None, application=None):
        super(AppDetailsDebFile, self).__init__(db, doc, application)
        if doc:
            raise ValueError("doc must be None for deb files")

        try:
            with ExecutionTime("create DebPackage"):
                # Cache() used to be faster here than self._cache._cache
                # but that is no longer the case with the latest apt
                self._deb = DebPackage(self._app.request, self._cache._cache)
        except:
            self._deb = None
            self._pkg = None
            if not os.path.exists(self._app.request):
                self._error = _("Not found")
                self._error_not_found = utf8(_(u"The file \u201c%s\u201d "
                    "does not exist.")) % utf8(self._app.request)
            else:
                mimetype = guess_type(self._app.request)
                if mimetype[0] != "application/x-debian-package":
                    self._error = _("Not found")
                    self._error_not_found = utf8(_(u"The file \u201c%s\u201d "
                        "is not a software package.")) % utf8(
                        self._app.request)
                else:
                    # deb files which are corrupt
                    self._error = _("Internal Error")
                    self._error_not_found = utf8(_(u"The file \u201c%s\u201d "
                        "could not be opened.")) % utf8(self._app.request)
            return

        if self.pkgname and self.pkgname != self._app.pkgname:
            # this happens when the deb file has a quirky file name
            self._app.pkgname = self.pkgname

            # load pkg cache
            self._pkg = None
            if (self._app.pkgname in self._cache and
                self._cache[self._app.pkgname].candidate):
                self._pkg = self._cache[self._app.pkgname]
            # load xapian document
            self._doc = None
            try:
                self._doc = self._db.get_xapian_document(
                    self._app.appname, self._app.pkgname)
            except:
                pass

        # check deb and set failure state on error
        with ExecutionTime("AppDetailsDebFile._deb.check()"):
            if not self._deb.check():
                self._error = self._deb._failure_string.strip()

    @property
    def description(self):
        if self._deb:
            description = self._deb._sections["Description"]
            s = ('\n').join(description.split('\n')[1:]).replace(" .\n", "")
            return utf8(s)
        return ""

    @property
    def maintenance_status(self):
        pass

    @property
    def pkgname(self):
        if self._deb:
            return self._deb._sections["Package"]

    @property
    def pkg_state(self):
        if self._error:
            if self._error_not_found:
                return PkgStates.NOT_FOUND
            else:
                return PkgStates.ERROR
        if self._deb:
            deb_state = self._deb.compare_to_version_in_cache()
            if deb_state == DebPackage.VERSION_NONE:
                return PkgStates.UNINSTALLED
            elif deb_state == DebPackage.VERSION_OUTDATED:
                if self._cache[self.pkgname].installed:
                    return PkgStates.INSTALLED
                else:
                    return PkgStates.UNINSTALLED
            elif deb_state == DebPackage.VERSION_SAME:
                return PkgStates.REINSTALLABLE
            elif deb_state == DebPackage.VERSION_NEWER:
                if self._cache[self.pkgname].installed:
                    return PkgStates.UPGRADABLE
                else:
                    return PkgStates.UNINSTALLED

    @property
    def summary(self):
        if self._deb:
            description = self._deb._sections["Description"]
            # ensure its utf8(), see #738771
            return utf8(description.split('\n')[0])

    @property
    def display_summary(self):
        if self._doc:
            name = self._db.get_appname(self._doc)
            if name:
                return self.summary
            else:
                # by spec..
                return self._db.get_pkgname(self._doc)
        return self.summary

    @property
    def version(self):
        if self._deb:
            return self._deb._sections["Version"]

    @property
    def installed_size(self):
        installed_size = 0
        if self._deb:
            try:
                installed_size = long(self._deb._sections["Installed-Size"])
            except:
                pass
        return installed_size * 1024

    @property
    def warning(self):
        # FIXME: use more concise warnings
        if self._deb:
            deb_state = self._deb.compare_to_version_in_cache(
                use_installed=False)
            if deb_state == DebPackage.VERSION_NONE:
                return utf8(
                    _("Only install this file if you trust the origin."))
            elif (not self._cache[self.pkgname].installed and
                  self._cache[self.pkgname].candidate and
                  self._cache[self.pkgname].candidate.downloadable):
                if deb_state == DebPackage.VERSION_OUTDATED:
                    return utf8(_("Please install \"%s\" via your normal "
                        "software channels. Only install this file if you "
                        "trust the origin.")) % utf8(self.name)
                elif deb_state == DebPackage.VERSION_SAME:
                    return utf8(_("Please install \"%s\" via your normal "
                        "software channels. Only install this file if you "
                        "trust the origin.")) % utf8(self.name)
                elif deb_state == DebPackage.VERSION_NEWER:
                    return utf8(_("An older version of \"%s\" is available in "
                        "your normal software channels. Only install this "
                        "file if you trust the origin.")) % utf8(self.name)

    @property
    def website(self):
        if self._deb:
            website = None
            try:
                website = self._deb._sections["Homepage"]
            except:
                pass
            if website:
                return website
コード例 #11
0
class AppDetailsDebFile(AppDetails):
    def __init__(self, db, doc=None, application=None):
        super(AppDetailsDebFile, self).__init__(db, doc, application)
        if doc:
            raise ValueError("doc must be None for deb files")

        try:
            with ExecutionTime("create DebPackage"):
                # Cache() used to be faster here than self._cache._cache
                # but that is no longer the case with the latest apt
                self._deb = DebPackage(self._app.request, self._cache._cache)
        except:
            self._deb = None
            self._pkg = None
            if not os.path.exists(self._app.request):
                self._error = _("Not found")
                self._error_not_found = utf8(
                    _(u"The file \u201c%s\u201d "
                      "does not exist.")) % utf8(self._app.request)
            else:
                mimetype = guess_type(self._app.request)
                if mimetype[0] != "application/x-debian-package":
                    self._error = _("Not found")
                    self._error_not_found = utf8(
                        _(u"The file \u201c%s\u201d "
                          "is not a software package.")) % utf8(
                              self._app.request)
                else:
                    # deb files which are corrupt
                    self._error = _("Internal Error")
                    self._error_not_found = utf8(
                        _(u"The file \u201c%s\u201d "
                          "could not be opened.")) % utf8(self._app.request)
            return

        if self.pkgname and self.pkgname != self._app.pkgname:
            # this happens when the deb file has a quirky file name
            self._app.pkgname = self.pkgname

            # load pkg cache
            self._pkg = None
            if (self._app.pkgname in self._cache
                    and self._cache[self._app.pkgname].candidate):
                self._pkg = self._cache[self._app.pkgname]
            # load xapian document
            self._doc = None
            try:
                self._doc = self._db.get_xapian_document(
                    self._app.appname, self._app.pkgname)
            except:
                pass

        # check deb and set failure state on error
        with ExecutionTime("AppDetailsDebFile._deb.check()"):
            if not self._deb.check():
                self._error = self._deb._failure_string.strip()

    @property
    def description(self):
        if self._deb:
            description = self._deb._sections["Description"]
            s = ('\n').join(description.split('\n')[1:]).replace(" .\n", "")
            return utf8(s)
        return ""

    @property
    def maintenance_status(self):
        pass

    @property
    def pkgname(self):
        if self._deb:
            return self._deb._sections["Package"]

    @property
    def pkg_state(self):
        if self._error:
            if self._error_not_found:
                return PkgStates.NOT_FOUND
            else:
                return PkgStates.ERROR
        if self._deb:
            deb_state = self._deb.compare_to_version_in_cache()
            if deb_state == DebPackage.VERSION_NONE:
                return PkgStates.UNINSTALLED
            elif deb_state == DebPackage.VERSION_OUTDATED:
                if self._cache[self.pkgname].installed:
                    return PkgStates.INSTALLED
                else:
                    return PkgStates.UNINSTALLED
            elif deb_state == DebPackage.VERSION_SAME:
                return PkgStates.REINSTALLABLE
            elif deb_state == DebPackage.VERSION_NEWER:
                if self._cache[self.pkgname].installed:
                    return PkgStates.UPGRADABLE
                else:
                    return PkgStates.UNINSTALLED

    @property
    def summary(self):
        if self._deb:
            description = self._deb._sections["Description"]
            # ensure its utf8(), see #738771
            return utf8(description.split('\n')[0])

    @property
    def display_summary(self):
        if self._doc:
            name = self._db.get_appname(self._doc)
            if name:
                return self.summary
            else:
                # by spec..
                return self._db.get_pkgname(self._doc)
        return self.summary

    @property
    def version(self):
        if self._deb:
            return self._deb._sections["Version"]

    @property
    def installed_size(self):
        installed_size = 0
        if self._deb:
            try:
                installed_size = long(self._deb._sections["Installed-Size"])
            except:
                pass
        return installed_size * 1024

    @property
    def warning(self):
        # FIXME: use more concise warnings
        if self._deb:
            deb_state = self._deb.compare_to_version_in_cache(
                use_installed=False)
            if deb_state == DebPackage.VERSION_NONE:
                return utf8(
                    _("Only install this file if you trust the origin."))
            elif (not self._cache[self.pkgname].installed
                  and self._cache[self.pkgname].candidate
                  and self._cache[self.pkgname].candidate.downloadable):
                if deb_state == DebPackage.VERSION_OUTDATED:
                    return utf8(
                        _("Please install \"%s\" via your normal "
                          "software channels. Only install this file if you "
                          "trust the origin.")) % utf8(self.name)
                elif deb_state == DebPackage.VERSION_SAME:
                    return utf8(
                        _("Please install \"%s\" via your normal "
                          "software channels. Only install this file if you "
                          "trust the origin.")) % utf8(self.name)
                elif deb_state == DebPackage.VERSION_NEWER:
                    return utf8(
                        _("An older version of \"%s\" is available in "
                          "your normal software channels. Only install this "
                          "file if you trust the origin.")) % utf8(self.name)

    @property
    def website(self):
        if self._deb:
            website = None
            try:
                website = self._deb._sections["Homepage"]
            except:
                pass
            if website:
                return website
コード例 #12
0
 def install_debfile(self, path, sender=None):
     # print("####install deb file: ", path)
     # 开启密码认证机制
     granted = self.auth_with_policykit(sender, PACKAGES_MANAGER_TOOLS)
     if not granted:
         kwarg = {
             "appname": path,
             "action": AppActions.INSTALLDEBFILE,
         }
         self.software_auth_signal("auth_cancel", kwarg)
         return False
     else:
         kwarg = {
             "appname": path,
             "action": AppActions.INSTALLDEBFILE,
         }
         self.software_auth_signal("auth_ensure", kwarg)
         #print("send auth signal")
     if not os.path.isfile(path):
         raise WorkitemError(4, "%s is unreadable file" % path)
     try:
         debfile = DebPackage(path)
     except IOError:
         raise WorkitemError(4, "%s is unreadable file" % path)
     except Exception as e:
         raise WorkitemError(5, e)
     #self.cache.open()
     #获取软件包名
     pkgName = debfile._sections["Package"]
     debfile.check(
     )  #do debfile.check for the next to do debfile.missing_deps
     # print("len:%s" % len(debfile.missing_deps))
     # 安装源中存在的依赖包
     if len(debfile.missing_deps) != 0:
         for deb in debfile.missing_deps:
             pkg = self.get_pkg_by_name(deb)
             # print("lj.pkg:%s" %pkg)
             pkg.mark_install()
             try:
                 self.cache.commit(
                     FetchProcess(self, deb, AppActions.INSTALL_ONE), None)
             except apt.cache.LockFailedException:
                 raise WorkitemError(3, "package manager is running.")
     #安装软件包
     res = debfile.install()
     if res:
         kwarg = {
             "apt_appname": pkgName,
             "apt_percent": str(-200),
             "action": str(AppActions.INSTALLDEBFILE),
         }
         self.software_apt_signal("apt_finish", kwarg)
         raise WorkitemError(6, "package manager failed")
     else:
         kwarg = {
             "apt_appname": pkgName,
             "apt_percent": str(200),
             "action": str(AppActions.INSTALLDEBFILE),
         }
         self.software_apt_signal("apt_finish", kwarg)
     # else:
     #     kwarg = {"apt_appname": pkgName,
     #              "apt_percent": str(-200),
     #              "action": str(AppActions.INSTALLDEBFILE),
     #              }
     #     self.software_apt_signal("apt_error", kwarg)
     #     raise WorkitemError(16, "dependence not be satisfied")
     return True
コード例 #13
0
def build_debian_package(package_fetcher,
                         package_name,
                         apt_cache,
                         rd_obj,
                         levels=0,
                         get_dependencies=False):
    unstable_target_distros = {'groovy': 'quantal', 'hydro': 'raring'}
    target_ubuntu_distro = unstable_target_distros[rd_obj._rosdistro]
    level_prefix = '--' * levels
    print("%s> Building package %s" % (level_prefix, package_name))
    deb_package_name = rd_obj.debianize_package_name(package_name)
    deb_package_version = rd_obj.get_version(
        package_name, full_version=True) + target_ubuntu_distro
    print("%s--> Checking if installed (%s, %s).." %
          (level_prefix, deb_package_name, deb_package_version)),
    if deb_package_name in apt_cache:
        installed = apt_cache[deb_package_name].installed
        if installed is not None and installed.version == deb_package_version:
            print("OK")
            print(
                "%s is installed already - remove the package if you want to re-install."
                % (package_name))
            return True
    print("missing!")
    if get_dependencies:
        dependencies = package_build_order([package_name],
                                           distro_name=rd_obj._rosdistro)
        print("%s--> Checking Dependencies:" % (level_prefix))
        for dep_pkg_name in dependencies:
            if dep_pkg_name != package_name:
                print("%s---- %s....." % (level_prefix, dep_pkg_name)),
                debian_pkg_name = rd_obj.debianize_package_name(dep_pkg_name)
                if debian_pkg_name in apt_cache and apt_cache[
                        debian_pkg_name].installed is not None:
                    print(" OK! (installed version %s)" %
                          apt_cache[debian_pkg_name].installed.version)
                else:
                    print(" Needs build, building...")
                    build_debian_package(package_fetcher, dep_pkg_name,
                                         apt_cache, rd_obj, levels + 1)
        print("%s<<-- Dependencies OKAY." % (level_prefix))
    print("%s>>> Build debian package %s from repo %s" %
          (level_prefix, deb_package_name, package_fetcher.url(package_name)))
    repo_path = package_fetcher.checkout_package(package_name)
    client = GitClient(repo_path)
    deb_package_tag = deb_package_name + '_' + rd_obj.get_version(
        package_name, full_version=True) + '_' + target_ubuntu_distro
    bloom_package_version = 'debian/' + deb_package_tag
    client.update(bloom_package_version)
    installed_builddeps = install_debian_build_dependencies(repo_path)
    if not installed_builddeps:
        raise RosGitBuildError(
            "%s!!! Error building %s from %s: Can't install build-dependencies!"
            % (level_prefix, deb_package_name,
               package_fetcher.url(package_name)))
    (returncode, result, message) = run_shell_command('debuild clean',
                                                      repo_path,
                                                      shell=True,
                                                      show_stdout=False)
    if returncode != 0:
        raise RosGitBuildError(
            "%s!!! Error building %s from %s: %s \n %s" %
            (level_prefix, deb_package_name, package_fetcher.url(package_name),
             'debuild clean', message))
    (returncode, result, message) = run_shell_command('debuild binary',
                                                      repo_path,
                                                      shell=True,
                                                      show_stdout=False)
    if returncode != 0:
        raise RosGitBuildError(
            "%s!!! Error building %s from %s: %s \n %s" %
            (level_prefix, deb_package_name, package_fetcher.url(package_name),
             'debuild binary', message))
    deb_files = glob.glob(
        os.path.join(
            repo_path, '..',
            '%s*.deb' % (deb_package_name + '_' +
                         rd_obj.get_version(package_name, full_version=True))))
    if len(deb_files) > 0:
        # install the deb
        from apt.debfile import DebPackage
        deb_pkg = DebPackage(deb_files[0])
        deb_pkg.check()
        packages_needed = ' '.join(deb_pkg.missing_deps)
        (returncode, result, message) = run_shell_command(
            'sudo apt-get -y install %s' % packages_needed,
            shell=True,
            show_stdout=True)
        if returncode != 0:
            raise RosGitBuildError(
                "%s!!! Error building %s: can't install dependent packages %s"
                % (level_prefix, deb_package_name, packages_needed))
        (returncode, result,
         message) = run_shell_command('sudo dpkg -i %s' % deb_files[0],
                                      shell=True,
                                      show_stdout=True)
        if returncode != 0:
            raise RosGitBuildError(
                "%s!!! Error building %s from %s: %s \n %s" %
                (level_prefix, deb_package_name,
                 package_fetcher.url(package_name), 'debuild binary', message))
    else:
        raise RosGitBuildError(
            "%s!!! Can't find a built debian package for %s after the build!" %
            (level_prefix, deb_package_name))
コード例 #14
0
ファイル: deb.py プロジェクト: pussbb/sx-installer
class DebFile(AbstractPackageFile):

    def __init__(self, deb_file):
        AbstractPackageFile.__init__(self, deb_file)
        self.package = DebPackage(deb_file, CACHE)
        self.package.check()

    def is_source(self):
        try:
            self.package['Source']
        except KeyError as exception:
            if self.arch == 'source':
                return True
            else:
                return False
        return True

    @property
    def requires(self):
        return self.package.depends

    @property
    def arch(self):
        return self.package['Architecture']

    @property
    def name(self):
        return self.package.pkgname

    @property
    def license(self):
        try:
            return self.package['License']
        except KeyError as _:
            pass

    @property
    def conflicts(self):
        return self.package.conflicts

    @property
    def version(self):
        return self.package['Version']

    @property
    def summary(self):
        return self.description

    @property
    def upgradable(self):
        return super(DebFile, self).upgradable()

    @property
    def provides(self):
        return self.package.provides

    @property
    def platform(self):
        return None

    @property
    def description(self):
        return self.package['Description']

    @property
    def installed(self):
        return self.package.compare_to_version_in_cache() \
               != DebPackage.VERSION_NONE

    @property
    def release(self):
        try:
            return self.package['Distribution']
        except KeyError as _:
            return 'unstable'