cleaned up pip and pkg listers

This commit is contained in:
Joshua Harlow 2012-03-05 21:26:13 -08:00
parent 252899d69d
commit 1415f0d973
4 changed files with 40 additions and 107 deletions

View File

@ -51,12 +51,12 @@ BASE_LINK_DIR = "/etc"
class ComponentBase(object):
def __init__(self, component_name, **kargs):
self.component_name = component_name
self.cfg = kargs.get("config")
self.packager = kargs.get("packager")
self.distro = kargs.get("distro")
self.component_name = component_name
self.instances = kargs.get("instances", set())
self.component_opts = kargs.get('opts', list())
self.instances = kargs.get("instances")
self.component_opts = kargs.get('opts')
self.root = kargs.get("root")
self.component_root = sh.joinpths(self.root, component_name)
self.tracedir = sh.joinpths(self.component_root, settings.COMPONENT_TRACE_DIR)

View File

@ -166,7 +166,7 @@ class ActionRunner(object):
adjusted_components = dict(components)
if self.ignore_deps:
return (adjusted_components, list(components.keys()))
all_components = common.get_components_deps(self.action, components, self.distro, self.directory)
all_components = common.get_components_deps(self.action, components, self.directory, self.distro)
component_diff = set(all_components.keys()).difference(components.keys())
if component_diff:
LOG.info("Having to activate dependent components: [%s]" % (", ".join(sorted(component_diff))))

View File

@ -137,7 +137,7 @@ def format_secs_taken(secs):
return output
def get_action_cls(action_name, component_name, distro):
def get_action_cls(action_name, component_name, distro=None):
action_cls_map = ACTION_CLASSES.get(action_name)
if not action_cls_map:
raise excp.StackException("Action %s has no component to class mapping" % (action_name))
@ -155,14 +155,15 @@ def get_packager(distro, keep_packages):
return cls(distro, keep_packages)
def get_config():
cfg_fn = sh.canon_path(settings.STACK_CONFIG_LOCATION)
def get_config(cfg_fn=None):
if not cfg_fn:
cfg_fn = sh.canon_path(settings.STACK_CONFIG_LOCATION)
config_instance = cfg.StackConfigParser()
config_instance.read(cfg_fn)
return config_instance
def get_components_deps(action_name, base_components, distro, root_dir):
def get_components_deps(action_name, base_components, root_dir=None, distro=None):
all_components = dict()
active_names = list(base_components)
if not root_dir:

View File

@ -1,110 +1,42 @@
import json
import os
import sys
import tempfile
#useful for running like the following
#find conf/ | grep ".json\$" | xargs python tools/list_pkgs.py "rhel-6"
possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), os.pardir, os.pardir))
sys.path.insert(0, possible_topdir)
VER_LEN = 10
MAX_SUB_SEGMENTS = 2
from devstack import utils
from devstack import settings
from devstack import component
from devstack.progs import common
def clean_file(name):
with open(name, "r") as f:
contents = f.read()
lines = contents.splitlines()
cleaned_up = list()
for line in lines:
if line.lstrip().startswith('#'):
continue
else:
cleaned_up.append(line)
cleaned_lines = os.linesep.join(cleaned_up)
data = json.loads(cleaned_lines)
return data
def versionize(ver):
real_digits = list()
for i in range(VER_LEN):
if i < len(ver):
digit = ver[i].strip().strip("*")
if not len(digit):
real_digits.append("0" * MAX_SUB_SEGMENTS)
else:
for j in range(MAX_SUB_SEGMENTS):
if j < len(digit):
real_digits.append(digit[j])
else:
real_digits.append("0")
else:
real_digits.append("0" * MAX_SUB_SEGMENTS)
ver_str = "".join(real_digits)
return int(ver_str)
def pick_version(old_ver, new_ver):
if new_ver is None:
return old_ver
if old_ver is None:
return new_ver
try:
old_v = versionize(old_ver.strip("*").split("."))
new_v = versionize(new_ver.strip("*").split("."))
if old_v < new_v:
return new_ver
else:
return old_ver
except ValueError:
return old_ver
def get_pips(c, distro):
cls = common.get_action_cls(settings.INSTALL, c)
dummy_config = common.get_config()
dummy_root = tempfile.gettempdir()
instance = cls(instances=set(), distro=distro,
packager=None, config=dummy_config,
root=dummy_root, opts=list(),
keep_old=False)
if not isinstance(instance, component.PkgInstallComponent):
return None
else:
return instance._get_pkgs_expanded()
if __name__ == "__main__":
ME = os.path.basename(sys.argv[0])
if len(sys.argv) == 1:
print("%s distro filename filename filename..." % (ME))
sys.exit(0)
distro = sys.argv[1]
fns = sys.argv[2:len(sys.argv)]
pkgs = dict()
pips = dict()
for fn in fns:
data = clean_file(fn)
is_pip = False
if fn.find("pip") != -1:
#TODO this isn't that great
is_pip = True
if distro in data:
for (name, info) in data[distro].items():
if is_pip:
if name in pips:
my_ver = info.get("version")
old_ver = pips[name]
pips[name] = pick_version(old_ver, my_ver)
else:
pips[name] = info.get("version")
else:
if name in pkgs:
my_ver = info.get("version")
old_ver = pkgs[name]
pkgs[name] = pick_version(old_ver, my_ver)
else:
pkgs[name] = info.get("version")
print("+Pips (%s) for distro: %s" % (len(pips), distro))
for name in sorted(pips.keys()):
version = pips.get(name)
if version is None:
version = "???"
for c in sorted(settings.COMPONENT_NAMES):
print("Packages for %s:" % (utils.color_text(c, 'green')))
pips = get_pips(c, distro)
if pips is None or not pips:
print("\t- %s" % (utils.color_text('N/A', 'red')))
else:
version = str(version)
print("[%s] with version [%s]" % (name, version))
print("")
print("+Packages (%s) for distro: %s" % (len(pkgs), distro))
for name in sorted(pkgs.keys()):
version = pkgs.get(name)
if version is None:
version = "???"
else:
version = str(version)
print("[%s] with version [%s]" % (name, version))
names = sorted(pips.keys())
for name in names:
real_name = name
info = pips.get(name) or dict()
if 'version' in info:
real_name = "%s (%s)" % (name, utils.color_text(str(info.get('version')), 'blue', bold=True))
print("\t- %s" % real_name)