Exemplo n.º 1
0
def identify(files):
    markers = {
        "insights_archive.txt": SerializedArchiveContext,
        "insights_commands": HostArchiveContext,
        "sos_commands": SosArchiveContext,
        "JBOSS_HOME": JDRContext
    }

    for f, m in product(files, markers):
        if m in f:
            i = f.find(m)
            common_path = os.path.dirname(f[:i])
            ctx = markers[m]
            return common_path, ctx

    common_path = os.path.dirname(os.path.commonprefix(files))
    if not common_path:
        raise archives.InvalidArchive("Unable to determine common path")

    if any(
            f.endswith(archives.COMPRESSION_TYPES)
            for f in os.listdir(common_path)):
        return common_path, ClusterArchiveContext

    return common_path, HostArchiveContext
Exemplo n.º 2
0
def create_context(path, context=None):
    all_files = get_all_files(path)
    if not all_files:
        raise archives.InvalidArchive("No files in archive")

    common_path, ctx = identify(all_files)
    context = context or ctx
    return context(common_path, all_files=all_files)
Exemplo n.º 3
0
def identify(files):
    common_path, ctx = ExecutionContextMeta.identify(files)
    if ctx:
        return common_path, ctx

    common_path = os.path.dirname(os.path.commonprefix(files))
    if not common_path:
        raise archives.InvalidArchive("Unable to determine common path")

    return common_path, HostArchiveContext
Exemplo n.º 4
0
def create_context(path, context=None):
    top = os.listdir(path)
    arc = [os.path.join(path, f) for f in top if f.endswith(archives.COMPRESSION_TYPES)]
    if arc:
        return ClusterArchiveContext(path, all_files=arc)

    all_files = get_all_files(path)
    if not all_files:
        raise archives.InvalidArchive("No files in archive")

    common_path, ctx = identify(all_files)
    context = context or ctx
    return context(common_path, all_files=all_files)