Пример #1
0
 def _find_package(self, package_name):
     try:
         if self.is_installed(package_name):
             package = Package(self, package_name)
         else:
             _, _, platform = package_name.split("_", 2)
             link_dir = self._get_state_link_dir(self.published_path,
                                                 platform)
             link_path = os.path.join(link_dir, package_name)
             domain_home = os.path.dirname(os.path.realpath(link_path))
             domain = Domain(domain_home)
             package = Package(domain, package_name)
     except:
         package = None
     return package
Пример #2
0
    def get_packages_with_state(self, state, platform=None):
        """Return map of packages in a particular state.
        """
        if state == "broken":
            paths = self.get_broken()
        elif state == "installed":
            paths = self.get_installed()
        elif state == "published":
            paths = self.get_published(platform)
        else:
            paths = []

        m = {}
        for path in paths:
            domain_home = os.path.normpath(os.path.dirname(path))
            package_name = os.path.basename(path)
            if domain_home == self.path:
                domain = self
            else:
                domain = Domain(domain_home)
            m[package_name] = Package(domain, package_name)
            if domain != self:
                del domain
        return m
Пример #3
0
            # populating subdomains
            utils.print_verbose("setting subdomains")
            dst_domain.set_subdomains(src_domain.get_subdomains())

        if clone_installed:
            # populate with installed
            src_installed_map = src_domain.get_packages_with_state("installed")
            for src_package_name, src_package in src_installed_map.items():
                utils.print_verbose("installing package (%s)" %
                                    src_package_name)
                tarf = repo.get(src_package_name)
                if tarf == None:
                    utils.print_warning(
                        "warning: could not find package (%s)" %
                        src_package_name)
                dst_package = Package(dst_domain, src_package_name)
                try:
                    dst_package.install(tarf, None, None, False)
                except:
                    utils.print_warning(
                        "warning: could not install package (%s)" %
                        src_package_name)

        if clone_published:
            # populate with published
            for publish_platform in src_domain.get_published_platforms():
                src_published_map = src_domain.get_packages_with_state(
                    "published", publish_platform)
                for src_package_name, src_package in src_published_map.items():
                    if alt_src_domain:
                        # publish from alt src domain
Пример #4
0
                raise Exception()
    except SystemExit:
        raise
    except:
        if globls.debug:
            traceback.print_exc()
        utils.print_exit("error: bad/missing argument(s)")

    if not package_name:
        utils.print_exit("error: missing package name")

    try:
        domain = Domain(domain_home)
        if not domain.is_compatible():
            utils.print_exit(MSG_INCOMPATIBLE_DOMAIN)
        pkg = Package(domain, package_name)
        if domain.is_published(package_name):
            utils.print_exit("error: package is published")
        if not pkg.exists() and not domain.is_installed(package_name):
            utils.print_exit("error: package is not installed")
        pkg.uninstall()
    except SystemExit:
        raise
    except utils.SSMExitException, detail:
        utils.print_exit(detail)
    except Exception, detail:
        if globls.debug:
            traceback.print_exc()
        utils.print_exit("error: operation failed")
    sys.exit(0)
Пример #5
0
 if output_type == "long":
     for path in paths:
         if find_type == "package":
             package_name = path[len(domain_home) +
                                 1:].split("/", 1)[0]
             print "%s" % (package_name, )
         else:
             print "%s" % (path, )
     if paths:
         print
 elif output_type == "summary":
     fmt = "%-2s %-30s"
     lines = []
     published_platforms = domain.get_published_platforms()
     for package_name in package_names:
         package = Package(domain, package_name)
         if package.platform in published_platforms:
             for publish_platform in published_platforms:
                 state = domain.get_package_state(
                     package_name, publish_platform)
                 if state in ["", "I"]:
                     continue
                 if package.platform == publish_platform:
                     lines.append(fmt %
                                  (state, package_name))
                 else:
                     lines.append(
                         fmt %
                         (state, "%s (%s)" %
                          (package_name, publish_platform)))
         else:
Пример #6
0
     if domain.is_installed(package_name) and skip_on_installed:
         utils.print_verbose("skipping installed package")
     else:
         if sources == None:
             sources = domain.get_sources().split("\n")
         for source in sources:
             source = source.strip()
             if source == "":
                 continue
             repo = Repository(source)
             tarf = repo.get(package_name)
             if tarf != None:
                 utils.print_verbose(
                     "installing package (%s) from repository (%s)" %
                     (package_name, source))
                 pkg = Package(domain, package_name)
                 pkg.install(tarf, username, groupname, clobber)
                 break
         else:
             utils.print_exit("error: could not find package")
 except SystemExit:
     raise
 except utils.SSMExitException, detail:
     utils.print_exit(detail)
 except Exception, detail:
     if globls.debug:
         traceback.print_exc()
     utils.print_exit("error: operation failed")
 #finally:
 #if tarf:
 #tarf.close()
Пример #7
0
def get_output_records(domain_home, publish_platform, format_fields):
    """Produce records for a domain according to the selected
    format_fields.
    """
    records = []
    try:
        if os.path.isdir(domain_home):
            domain = Domain(domain_home)
            #published_platforms = domain.get_published_platforms()
            published_packages = domain.get_packages_with_state(
                "published", publish_platform)

            # generate record for each package
            for package_name in domain.get_package_names(package_name_pattern):
                dom_package = Package(domain, package_name)

                #if package_name in published_packages:
                #platforms = published_platforms
                #else:
                #platforms = [""]

                # for each publish platform
                #for publish_platform in platforms:
                #if publish_platform != "" \
                #and not domain.is_published(package_name, publish_platform):
                ## must be installed or published
                #continue

                if package_name.endswith(
                        "_" + publish_platform) or domain.is_published(
                            package_name, publish_platform):
                    state = domain.get_package_state(package_name,
                                                     publish_platform)
                    pub_package = published_packages.get(package_name)
                    package = pub_package or dom_package

                    publish_timestamp = pub_package and utils.get_path_timestamp(
                        pub_package.path)
                    timestamp = install_timestamp = utils.get_path_timestamp(
                        package.path)

                    # generate record
                    record = []
                    for fname in format_fields:
                        if fname in ["title"]:
                            # load only if necessary
                            control_map = package and package.get_control(
                            ) or {}

                        if fname.startswith("_"):
                            record.append("")
                        elif fname in ["domain", "publish_domain"]:
                            record.append(domain.path)
                        elif fname in ["domain_owner", "publish_domain_owner"]:
                            record.append(domain.get_owner())
                        elif fname in ["domain_state", "publish_domain_state"]:
                            record.append(domain.is_frozen() and "F" or "")
                        elif fname == "domains":
                            record.append("%s (%s)" %
                                          (domain.path, package.domain.path))
                        elif fname == "install_domain":
                            record.append(package.domain.path)
                        elif fname == "install_domain_owner":
                            record.append(package.domain.get_owner())
                        elif fname == "install_domain_state":
                            record.append(package.domain.is_frozen() and "F"
                                          or "")
                        elif fname == "install_timestamp":
                            record.append(install_timestamp)
                        elif fname == "name":
                            record.append(package_name)
                        elif fname == "name_and_publish_platform":
                            if not publish_platform or package_name.endswith(
                                    "_" + publish_platform):
                                record.append(package_name)
                            else:
                                record.append("%s (%s)" %
                                              (package_name, publish_platform))
                        elif fname == "publish_platform":
                            record.append(publish_platform or "")
                        elif fname == "publish_timestamp":
                            record.append(publish_timestamp or "")
                        elif fname == "state":
                            record.append(state)
                        elif fname == "title":
                            record.append(control_map.get("title", "***"))
                        else:
                            record.append("***")
                    records.append(record)
    except:
        if globls.debug:
            traceback.print_exc()
        raise
    return records
Пример #8
0
    if not package_name:
        utils.print_exit("error: missing package name")

    try:
        domain = Domain(domain_home)
        if not domain.is_domain():
            utils.print_exit("error: cannot find domain (%s)" % domain_home)
        if not domain.is_compatible():
            utils.print_exit(MSG_INCOMPATIBLE_DOMAIN)
        if publish_home == None:
            publish_home = domain_home
        publish_domain = Domain(publish_home)
        if not publish_domain.is_domain():
            utils.print_exit("error: cannot find domain (%s)" % publish_domain)
        package = Package(domain, package_name)
        publish_platform = publish_platform or package.platform

        # check for package
        if not package.domain.is_installed(package_name):
            utils.print_exit("error: cannot find package (%s)" % package_name)

        # unpublish named package if necessary
        if publish_domain.is_published(package_name, publish_platform):
            if skip_on_published:
                utils.print_exit("skipping published package", 0)
            if not globls.force and not globls.auto_yes:
                if utils.prompt("unpublish current package (y/n)?").lower() not in ["y"]:
                    utils.print_exit("operation aborted")
            publish_domain.unpublish_package(package, publish_platform)