Exemplo n.º 1
0
def print_package_ids() -> None:
    """Print all the packages out."""
    id_len = max(len(pack.id) for pack in PACKAGES.values())
    row_count = 128 // (id_len + 2)
    for i, pack in enumerate(sorted(pack.id for pack in PACKAGES.values()), start=1):
        print(' {0:<{1}} '.format(pack, id_len), end='')
        if i % row_count == 0:
            print()
    print()
Exemplo n.º 2
0
def check_file(file: Path, portal2: Path, packages: Path) -> None:
    """Check for the location this file is in, and copy it to the other place."""
    try:
        relative = file.relative_to(portal2)
    except ValueError:
        # Not in Portal 2, in the packages.
        # Find the first 'resources/' folder, and copy to Portal 2.
        try:
            relative = file.relative_to(packages)
        except ValueError:
            # Not in either.
            LOGGER.warning('File "{!s}" not in packages or Portal 2!', file)
            return
        part = relative.parts
        try:
            res_path = Path(*part[part.index('resources')+1:])
        except IndexError:
            LOGGER.warning('File "{!s} not a resource!', file)
            return

        if res_path.parts[0] == 'instances':
            dest = (
                portal2 /
                'sdk_content/maps/instances/bee2' /
                res_path.relative_to('instances')
            )
        elif res_path.parts[0] == 'bee2':
            LOGGER.warning('File "{!s}" not for copying!', file)
            return
        else:
            if (portal2 / 'bee2_dev').exists():
                dest = portal2 / 'bee2_dev' / res_path
            else:
                dest = portal2 / 'bee2' / res_path
        LOGGER.info('"{}" -> "{}"', file, dest)
        os.makedirs(str(dest.parent), exist_ok=True)
        shutil.copy(str(file), str(dest))
    else:
        # In Portal 2, copy to each matching package.
        try:
            rel_loc = Path('resources', 'instances') / relative.relative_to(
                'sdk_content/maps/instances/bee2'
            )
        except ValueError:
            rel_loc = Path('resources') / relative.relative_to(
                'bee2_dev' if (portal2 / 'bee2_dev').exists() else 'bee2'
            )

        target_systems = []

        for package in PACKAGES.values():
            if not isinstance(package.fsys, RawFileSystem):
                # In a zip or the like.
                continue
            if str(rel_loc) in package.fsys:
                target_systems.append(package.fsys)

        if not target_systems:
            # This file is totally new.
            try:
                target_systems.append(get_package(rel_loc))
            except KeyboardInterrupt:
                return

        for fsys in target_systems:
            full_loc = fsys.path / rel_loc
            LOGGER.info('"{}" -> "{}"', file, full_loc)
            os.makedirs(str(full_loc.parent), exist_ok=True)
            shutil.copy(str(file), str(full_loc))