Esempio n. 1
0
def find_domains(base_path, max_depth, hidden=False):
    """Find domain_homes under base_path.
    """
    domain_homes = []
    if Domain(base_path).is_domain():
        domain_homes.append(base_path)
    else:
        path_slash_count = base_path.count("/")
        for root, dirnames, _ in os.walk(base_path, followlinks=True):
            #print root.count("/"),path_slash_count, max_depth
            if root.count("/") - path_slash_count >= max_depth:
                del dirnames[:]
                continue
            for dirname in dirnames[:]:
                if dirname.startswith(".") and not hidden:
                    dirnames.remove(dirname)
                    continue
                if 0 and os.path.islink(os.path.join(root, dirname)):
                    # don't follow symlinks to domain homes!
                    dirnames.remove(dirname)
                    continue
                domain_home = os.path.join(root, dirname)
                if Domain(domain_home).is_domain():
                    domain_homes.append(domain_home)
                    dirnames.remove(dirname)
    return domain_homes
Esempio n. 2
0
def get_all_subdomains(domain_home, level=0):
    if level >= 10:
        return []

    domain = Domain(domain_home)
    paths = []
    for path in domain.get_subdomains():
        paths.append([path, level])
        paths.extend(get_all_subdomains(path, level + 1))
    return paths
Esempio n. 3
0
def __find_in_component(domain_home, prefix, term):
    """Find by "component" in domain packages, e.g.,
        x_1.0_all/bin where bin is the component
    """
    paths = []
    for package_name in Domain(domain_home).get_package_names():
        paths.extend(
            __find_in_path(os.path.join(domain_home, package_name, prefix),
                           term))
    return paths
Esempio n. 4
0
                raise Exception()
    except SystemExit:
        raise
    except:
        if globls.debug:
            traceback.print_exc()
        utils.print_exit("error: bad/missing argument(s)")

    if src_domain_home == dst_domain_home == None:
        utils.print_exit("error: missing argument(s)")

    if not clone_domain and not clone_installed and not clone_published:
        clone_domain = clone_installed = clone_published = True

    try:
        src_domain = Domain(src_domain_home)
        dst_domain = Domain(dst_domain_home)
        alt_src_domain = alt_src_domain_home and Domain(alt_src_domain_home)
        if not src_domain.is_compatible():
            utils.print_exit(MSG_INCOMPATIBLE_DOMAIN)
        if alt_src_domain and not alt_src_domain.is_compatible():
            utils.print_exit(MSG_INCOMPATIBLE_DOMAIN)

        sources = repo_url or (alt_src_domain or src_domain).get_sources()
        repo = Repository(sources)

        if clone_domain:
            # create new domain
            utils.print_verbose("creating new domain (%s)" % dst_domain_home)
            dst_domain.create(label, sources)
Esempio n. 5
0
            #elif arg in ["-y", "--yes"]:
            #globls.auto_yes = True
            else:
                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()
Esempio n. 6
0
                globls.force = True
            elif arg in ["--verbose"]:
                globls.verbose = True
            #elif arg in ["-y", "--yes"]:
                #globls.auto_yes = True
            else:
                raise Exception()
    except SystemExit:
        raise
    except:
        if globls.debug:
            traceback.print_exc()
        utils.print_exit("error: bad/missing argument(s)")

    # TODO: this does not check properly
    if not domain_home:
        utils.print_exit("error: cannot do a create over an existing domain")

    try:
        domain = Domain(domain_home)
        domain.create(label, repo_source)
    except SystemExit:
        raise
    except utils.SSMExitException, detail:
        utils.print_exit(detail)
    except:
        if globls.debug:
            traceback.print_exc()
        utils.print_exit("error: operation failed")
    sys.exit(0)
Esempio n. 7
0
            elif arg in ["--debug"]:
                globls.debug = True
            elif arg in ["--verbose"]:
                globls.verbose = True
            else:
                raise Exception()
    except SystemExit:
        raise
    except:
        if globls.debug:
            traceback.print_exc()
        utils.print_exit("error: bad/missing argument(s)")

    try:
        domain = Domain(domain_home)
        if not domain.is_compatible():
            utils.print_exit(MSG_INCOMPATIBLE_DOMAIN)
        paths = [[domain.path, 0]]
        paths.extend(get_all_subdomains(domain.path, 1))
        for path, level in paths:
            print "%s%s" % ("  " * level, path)
    except SystemExit:
        raise
    except utils.SSMExitException, detail:
        utils.print_exit(detail)
    except:
        if globls.debug:
            traceback.print_exc()
        utils.print_exit("error: could not access domain information")
Esempio n. 8
0
            elif arg in ["-p", "--packageName"] and args:
                package_name_pattern = args.pop(0)

            elif arg in ["--debug"]:
                globls.debug = True
            else:
                raise Exception()
    except SystemExit:
        raise
    except:
        if globls.debug:
            traceback.print_exc()
        utils.print_exit("error: bad/missing argument(s)")

    if domain_home_pattern == None:
        domain_homes = [Domain().path]
    else:
        domain_homes = sorted(glob.glob(domain_home_pattern))

    if output_type == "format":
        headings = None
        fmt = "%s"
    else:
        if output_type == "format_with_headings":
            pass
        elif output_type == "long":
            format_fields = [
                "state", "install_timestamp", "publish_platform", "name",
                "title", "domain_state", "domain", "install_domain_state",
                "install_domain"
            ]
Esempio n. 9
0
        _, ncols = utils.get_terminal_size()
    except:
        ncols = 80

    for base_path in base_paths:
        try:
            domain_homes = sorted(find_domains(base_path, depth))
            if find_type == "domain" and output_type == "summary":
                fmt = "%-30s"
                lines = domain_homes
                utils.print_columns(lines, None, ncols)
                if lines:
                    print
            else:
                for domain_home in domain_homes:
                    domain = Domain(domain_home)
                    package_names = []
                    paths = []

                    # get package_names or paths; force output_type if necessary
                    if find_type in ["bin", "domain", "lib", "name"]:
                        output_type = "long"
                        if find_type == "bin":
                            paths = find_in_bin(domain_home, term)
                        elif find_type == "domain":
                            paths = domain_homes
                        elif find_type == "lib":
                            paths = find_in_lib(domain_home, term)
                        elif find_type == "name":
                            paths = find_name(domain_home, term, depth)
                    elif find_type == "package":
Esempio n. 10
0
            elif arg in ["--version"]:
                show_version = True

            elif arg in ["--debug"]:
                globls.debug = True
            else:
                raise Exception()
    except SystemExit:
        raise
    except:
        if globls.debug:
            traceback.print_exc()
        utils.print_exit("error: bad/missing argument(s)")

    try:
        domain = Domain(domain_home)
        if show_installed:
            # TODO: should paths or names be shown for installed and published?
            print("%s" % "\n".join(domain.get_installed()))
        if show_label:
            print("%s" % str(domain.get_label()))
        if show_published:
            print("%s" % "\n".join(domain.get_published()))
        if show_sources:
            print("%s" % str(domain.get_sources()))
        if show_subdomains:
            print("\n".join(domain.get_subdomains()))
        if show_version:
            version = domain.get_version()
            version_string = ".".join(map(str, version))
            print("%s" % version_string)
Esempio n. 11
0
                globls.force = True
            elif arg in ["--verbose"]:
                globls.verbose = True
            elif arg in ["-y", "--yes"]:
                globls.auto_yes = True
            else:
                raise Exception()
    except SystemExit:
        raise
    except:
        if globls.debug:
            traceback.print_exc()
        utils.print_exit("error: bad/missing argument(s)")

    try:
        domain = Domain(domain_home)
        if not domain.is_compatible():
            utils.print_exit(MSG_INCOMPATIBLE_DOMAIN)
        if label != None:
            domain.set_label(label)
        if sources != None:
            domain.set_sources(sources)
        if subdomains_filename != None:
            if subdomains_filename == "-":
                f = sys.stdin
            elif subdomains_filename == "--":
                # open editor
                pass
            else:
                f = open(subdomains_filename)
            subdomains = [s for s in f if s.strip() != ""]
Esempio n. 12
0
            #elif arg in ["-y", "--yes"]:
                #globls.auto_yes = True
            else:
                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)
        package = Package(domain, package_name)
        if publish_platform == None:
            _, _, publish_platform = package.name.split("_", 2)
        if not domain.is_published(package_name, publish_platform) and not globls.force:
            utils.print_exit("error: package not published")
        domain.unpublish_package(package, publish_platform)
    except SystemExit:
        raise
    except utils.SSMExitException, detail:
        utils.print_exit(detail)
    except:
        if globls.debug:
            traceback.print_exc()
Esempio n. 13
0
    except:
        if globls.debug:
            traceback.print_exc()
        utils.print_exit("error: bad/missing argument(s)")

    if filename:
        if filename.endswith(".ssm"):
            sources = [os.path.realpath(os.path.dirname(filename))]
            package_name = os.path.basename(filename)[:-4]
        else:
            utils.print_exit("error: bad filename")
    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)

        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:
Esempio n. 14
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
Esempio n. 15
0
            elif arg in ["--debug"]:
                globls.debug = True
            else:
                raise Exception()
    except SystemExit:
        raise
    except:
        if globls.debug:
            traceback.print_exc()
        utils.print_exit("error: bad/missing argument(s)")

    if domain_home == None:
        utils.print_exit("error: bad/missing argument(s)")

    try:
        domain = Domain(domain_home)
        if not domain.is_compatible():
            utils.print_exit(MSG_INCOMPATIBLE_DOMAIN)
        if not domain.is_frozen():
            utils.print_exit("warning: domain not frozen")
        domain.unfreeze()
    except SystemExit:
        raise
    except utils.SSMExitException, detail:
        utils.print_exit(detail)
    except:
        if globls.debug:
            traceback.print_exc()
        utils.print_exit("error: could not unfreeze domain")

    sys.exit(0)
Esempio n. 16
0
            elif arg in ["--verbose"]:
                globls.verbose = True
            else:
                raise Exception()
    except SystemExit:
        raise
    except:
        if globls.debug:
            traceback.print_exc()
        utils.print_exit("error: bad/missing argument(s)")

    try:
        if repo_url:
            sources = repo_url
        else:
            domain = Domain(domain_home)
            sources = domain.get_sources()

        repo = Repository(sources)
        package_map = {}
        package_urls = repo.list()
        for url in repo.list():
            filename = os.path.basename(url)
            if not filename.endswith(".ssm"):
                continue
            package_name = filename[:-4]
            if package_name_pattern and not fnmatch.fnmatch(
                    package_name, package_name_pattern):
                continue
            if platforms_pattern:
                t = package_name.split("_", 3)
Esempio n. 17
0
            elif arg in ["-y", "--yes"]:
                globls.auto_yes = True
            else:
                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_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)