Beispiel #1
0
def fix_spkg(instance_name, pkn, action, package_factory):
    """A user is requesting to take a package that is currently flagged
    as 'broken' and set it to be 'installed'. Perhaps they have manually
    fixed the package on the system."""
    progress_file = get_progress_path(instance_name)
    status_data = open(progress_file, 'r').read()
    try:
        status = json.loads(status_data)
    except ValueError:
        Logger.error("Data in %s is not parsable by json" % progress_file)
        return FAIL
    if status.get("install-progress") == None:
        status["install-progress"] = {}
        Logger.warning( "Status file is empty." )
    now = time.asctime()
    if action == FIX:
        fix_name = []
        base_names = re.compile("(\s+)\-\d+").findall(pkn)
        if base_names:
            base_name = base_names[0]
        else:
            base_name = pkn
        for possible_pkn in status["install-progress"]:
            if base_name in possible_pkn:
                fix_name.append(possible_pkn)
        if len(fix_name) > 1:
            msg = "Package name %s is ambigious. (possible %s)"
            msg = msg % (pkn, ' '.join(fix_name))
            Logger.error(msg)
            return FAIL
        elif len(fix_name) == 1:
            pkn = fix_name[0]
        elif len(fix_name) == 0:
            new_package = package_factory.get_me_one(pkn)
            pkn = new_package.full_name
            Logger.info("Selecting previously UNINSTALLED package: %s" % pkn)
        status["install-progress"]["%s" % pkn] = {"INSTALLED": now,
                                                  "UNINSTALLED": "NA",
                                                  "VERIFIED": now}
        Logger.info("==OUTPUT==:%s has been set to INSTALLED." % pkn )
    elif action == PURGE:
        if status["install-progress"].get(pkn):
            del status["install-progress"][pkn]
            msg = "==OUTPUT==:%s has been removed from %s status"
            msg = msg % (pkn, instance_name)
            Logger.info(msg)
        else:
            Logger.info("==OUTPUT==:%s is not in the status file" % pkn)
            pkns = status["install-progress"]
            possible_names = [x for x in pkns if pkn in x]
            msg = "==OUTPUT==:Maybe you want one of these: %s"
            msg = msg % str(possible_names)
            Logger.info(msg)
            return FAIL
    open(get_progress_path(instance_name), 'w').write(json.dumps(status))
    return OK
Beispiel #2
0
def find_likely_pkn(instance_name, pkn):
    """Sometimes an ambiguous package name is requested.
    This attempts to help a guy out."""
    progress_file = get_progress_path(instance_name)
    try:
        status_yml = json.loads(open(progress_file).read())
    except ValueError:
        Logger.error("Progress data in %s is not parsable." % progress_file)
        raise
    pkns = []
    status_packages = status_yml['install-progress']
    for name in status_packages:
        if status_packages[name]['INSTALLED'] in [ 'NA', 'BROKEN' ]:
            continue
        if pkn.lower() in name.lower():
            pkns.append(name)
    if len(pkns) > 1:
        msg = 'Ambiguous package name: %s could be any of %s' % (pkn, str(pkns))
        Logger.error( msg )
        exit_with_return_code(FAIL)
    if len(pkns) == 0:
        Logger.error( 'Package not found: %s' %pkn )
        exit_with_return_code(FAIL)
    else:
        pkn = '-'.join(pkns[0].split('-')[:-1])
        Logger.info( 'Using %s' %pkn)
        return pkn
Beispiel #3
0
def instance_setup(instance_name):
    "When Bombardier is first getting set up, this method is called."
    progress_path = get_progress_path(instance_name)
    status_dict = None
    if os.path.isfile(progress_path):
        try:
            status_dict = json.loads(open(progress_path).read())
        except:
            msg = "Unable to load existing json from %s" % progress_path
            Logger.warning(msg)
    if type(status_dict) != type({}):
        status_dict = {"install-progress": {}}
    status_dict["client_version"] = CLIENT_VERSION
    status_dict["core_version"] = CORE_VERSION
    status_dict["clientVersion"] = CLIENT_VERSION
    status_dict["coreVersion"] = CORE_VERSION
    pkg_dir = make_path(get_spkg_path(), instance_name, "packages")
    repos_dir = make_path(get_spkg_path(), "repos")
    tmp_dir = make_path(get_spkg_path(), "tmp")
    if not os.path.isdir(pkg_dir):
        os.makedirs(pkg_dir)
    if not os.path.isdir(repos_dir):
        os.makedirs(repos_dir)
    if not os.path.isdir(tmp_dir):
        os.makedirs(tmp_dir)
    open(progress_path, 'w').write(json.dumps(status_dict))