Exemplo n.º 1
0
    with open(_MYPARENT.parent / "Resources" / "logging.yml",
              encoding=UTF8) as stream:
        log_config = yaml.load(stream, Loader=yaml.FullLoader)
    logging.config.dictConfig(log_config)

    # ----- Miscellaneous objects.
    arguments = parser.parse_args()
    genres = dict(get_genres())  # type: Mapping[str, int]
    countries = dict(get_countries())  # type: Mapping[str, int]
    languages = dict(get_languages())  # type: Mapping[str, int]
    providers = dict(get_providers())  # type: Mapping[str, int]

    # ----- Templating environment.
    ENVIRONMENT = TemplatingEnvironment(_MYPARENT / "Templates")
    ENVIRONMENT.set_environment(filters={
        "rjustify": rjustify,
        "stringify": stringify
    })

    # ----- Get tracks collection.
    collection = arguments.klass(arguments.db,
                                 *arguments.path,
                                 countries=countries,
                                 genres=genres,
                                 languages=languages,
                                 providers=providers)  # type: Any

    # ----- Print raised exceptions.
    print(
        ENVIRONMENT.get_template("T02").render(
            collection=collection.exceptions))
# Arguments parser.
# =================
parser = argparse.ArgumentParser()
parser.add_argument("path")
arguments = parser.parse_args()

# ==========
# Variables.
# ==========
dirs, empty_dirs = [], []

# =========
# Template.
# =========
template = TemplatingEnvironment(path=that_file.parents[0] / "Templates", keep_trailing_newline=False)
template.set_environment(filters={"rjustify": rjustify})
template.set_template(template="T01")

# ===============
# Main algorithm.
# ===============
for root, directories, files in os.walk(str(PureWindowsPath(arguments.path))):
    dirs.extend(PureWindowsPath(root) / PureWindowsPath(file) for file in files)
    if not any([directories, files]):
        empty_dirs.extend(PureWindowsPath(root) / PureWindowsPath(directory) for directory in directories)
dirs = sorted(sorted(sorted(dirs, key=byname), key=byextension), key=byparents)
it1, it2 = tee(dirs)
extensions = filter(None, sorted([(key[1:], value) for key, value in count_justify(*Counter(file.suffix for file in it1).items())], key=itemgetter(0)))
directories = filter(None, sorted([(str(key), value) for key, value in count_justify(*Counter(file.parents[0] for file in it2).items())], key=itemgetter(0)))
print(getattr(template, "template").render(root=arguments.path, dirs=dirs, extensions=extensions, directories=directories, empty_directories=empty_dirs))
Exemplo n.º 3
0
# Arguments parser.
# =================
parser = argparse.ArgumentParser()
parser.add_argument("collection", type=argparse.FileType(encoding=UTF8))
arguments = parser.parse_args()

# ================
# Local functions.
# ================
rjustify = partial(rjustify_index, width=4)

# =======================
# Templating environment.
# =======================
template = TemplatingEnvironment(_MYPARENT / "Templates")
template.set_environment(filters={"rjustify": rjustify})

# ============
# Main script.
# ============
stream = csv.reader(arguments.collection, CustomDialect())
collection = [(Path(image),
               format_date(LOCAL.localize(parse(datetime.replace(":", '-',
                                                                 2))),
                           template=TEMPLATE2),
               int(parse(datetime.replace(":", '-', 2)).timestamp()))
              for image, datetime in stream]  # type: Any
collection = sorted(collection, key=itemgetter(2))
collection = sorted(collection, key=itemgetter_(0)(attrgetter("parent")))
collection = enumerate(collection, start=1)
collection = [((index, ), tuple(compress(file, [1, 1, 0])))
Exemplo n.º 4
0
            yield file, ts


# =================
# Arguments parser.
# =================
parser = argparse.ArgumentParser()
parser.add_argument("files", type=argparse.FileType(encoding="ISO-8859-1"))
parser.add_argument("pattern", action=CompilePattern)
parser.add_argument("--pprint", action="store_true")

# =======================
# Templating environment.
# =======================
environment = TemplatingEnvironment(_MYPARENT)
environment.set_environment(filters={"format_": format_index_})

# ===========
# Main logic.
# ===========

# Initialize variables.
master_collection, level = [], 100  # type: List[Any], int

# Get arguments.
arguments = parser.parse_args()

# Run script.
for target, group in groupby(csv.reader(arguments.files, CustomDialect()),
                             key=itemgetter(0)):
    collection = []  # type: List[Any]