def use_command(plat, ns): def is_version(s): return s.startswith("rel-") or s == "dev" # Cater for the case there only the version has been specified. if not ns.version and is_version(ns.package): ns.version = ns.package ns.package = CONFIG.default_platform_package platform_packages = set(plat.get_platform_packages()) if ns.package not in platform_packages: raise platypus.PlatError("package %s is not a platform package" % ns.package) if not ns.version: ns.version = "rel-current" version = ns.version if version.startswith("rel-"): version = version[4:] msg = "Using package %s, version %s." % (ns.package, ns.version) if ns.version == "dev": msg += " This might take some time." statusmsg(msg) plat.use(ns.package, version)
def components_command(plat, ns): platforms = plat.get_platform_packages() if ns.package not in platforms: raise platypus.PlatError("Package %s is not a platform package" % ns.package) pkg_info = plat.get_installed_version(ns.package) if not pkg_info: raise platypus.PlatError("Package %s is not installed" % ns.package) meta = plat.get_package_metadata(ns.package, pkg_info.version) platform = "%s (%s): %s" % (ns.package, pkg_info.version, meta.get("summary", "")) statusmsg(platform) components = plat.get_package_dependencies(ns.package).values() components = [ "%s (%s)" % (pkg.name, pkg.version) for pkg in components if pkg and util.is_inhouse_package(pkg.name) ] components.sort() for component in components: statusmsg(" " + component)
def undevelop_command(plat, ns): platforms = set([]) for package in ns.package: info = plat.get_installed_version(package) if not info: raise platypus.PlatError("package %s is not installed" % package) if not info.isdevsrc: raise platypus.PlatError( "package %s is not a source installation" % package) platforms.union(plat.get_owning_platforms(package)) statusmsg("Undevelop package %s at %s" % (package, info.source)) plat.undevelop(package) # We just moved to the most recent development version of the component # that got undeveloped. We need to update all components in the platforms # that this component is a member of to make sure all components are # in sync with each other. for platform in platforms: up_opts = argparse.Namespace(package=platform, current_only=False, quiet=ns.quiet, debug=ns.debug) up_command(plat, up_opts)
def versions_command(plat, ns): platforms = plat.get_platform_packages() if ns.package not in platforms: raise platypus.PlatError("Package %s is not a platform package" % ns.package) pkg_info = plat.get_installed_version(ns.package) if not pkg_info: version = plat.get_current_version(ns.package) else: version = pkg_info.version meta = plat.get_package_metadata(ns.package, version) platform = "%s: %s" % (ns.package, meta.get("summary", "")) statusmsg(platform) versions = plat.get_available_versions(ns.package) for version in versions: statusmsg(" " + version)
def develop_command(plat, ns): """FIXME: Refactor in smaller functions to make this digestable. """ if not any((ns.package, ns.location)): errormsg("At least one package or location must be specified.") sys.exit(2) # Only one argument was provided. ns.package could hold a package name # or a path to an existing source check-out. if not ns.location: ns.location = os.path.abspath(ns.package) # If the directory does not exist ns.package must be meant to # specify a package name. Use the non-existing directory as the # default where the package is checked out. # If the directory exists also use it as ns.location. Set ns.package # from the name as per setup.cfg that should live in the directory. setup_fname = os.path.join(ns.location, "setup.cfg") if os.path.isfile(setup_fname): cfg = configparser.ConfigParser() cfg.read(setup_fname) try: ns.package = cfg.get("metadata", "name") except: pass else: # Make sure we use a fully qualified path ns.location = os.path.abspath(ns.location) if not ns.package: errormsg("Unable to determine package name from %s" % ns.location) # Check if the package is already checked-out. pkg_info = plat.get_installed_version(ns.package) if pkg_info and pkg_info.isdevsrc and pkg_info.source != ns.location: warnmsg("Package %s is also checked out at %s" % (ns.package, pkg_info.source)) if not prompt("Continue?"): terminate(rc=0) # Verify that the package is a platform package or a component of a # platform package. platforms = plat.get_platform_packages() platform_pkg = ns.package if ns.package in platforms else None if not platform_pkg: for pkg in platforms: try: deps = plat.get_package_dependencies(pkg) if ns.package in deps: platform_pkg = pkg break except ValueError: pass if not platform_pkg: raise platypus.PlatError( "Package %s is neither a platform package nor a " "component of a platform package" % ns.package) # If the package is a component of a platform package then verify that # the platform package version is at "dev" if platform_pkg != ns.package: plat_info = plat.get_installed_version(platform_pkg) if plat_info and not plat_info.isdev: warnmsg("Package %s is a component of platform package %s which " "is not a dev version." % (ns.package, platform_pkg)) if not prompt("Use dev version of %s?" % platform_pkg): terminate(rc=0) use_opts = argparse.Namespace(package=platform_pkg, version="dev", quiet=ns.quiet, debug=ns.debug) use_command(plat, use_opts) else: up_opts = argparse.Namespace(package=platform_pkg, current_only=False, quiet=ns.quiet, debug=ns.debug) up_command(plat, up_opts) # Check the platform or component package out statusmsg("Develop package %s at %s" % (ns.package, ns.location)) plat.develop(ns.package, ns.location)