Esempio n. 1
0
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])))
              for index, file in collection]
collection = [tuple(chain.from_iterable(item)) for item in collection]
print(template.get_template("T01").render(collection=collection))
Esempio n. 2
0
    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))

    # ----- Dump tracks collection.
    coll1, coll2 = tee(collection)
    coll1 = list(coll1)
    coll1.insert(
        0,
        pytz.timezone("UTC").localize(datetime.datetime.utcnow()).astimezone(
            pytz.timezone(DFTTIMEZONE)).isoformat())
    with open(TEMP / "digitaldiscs.yml", mode=WRITE, encoding=UTF8) as stream:
        yaml.dump(coll1, stream)

    # ----- Insert tracks collection into database.
    if arguments.skip:
        sys.exit(0)
    sys.exit(insert_discs(*coll2))
Esempio n. 3
0
    (file, Path(REGEX1.sub(sub_, str(path)))) for file, path in collection
]  # (file1.m4a, file1.ape), (file1.m4a, file1.dsf), (file1.m4a, file1.flac), ...
collection = [
    (file, path.exists()) for file, path in collection
]  # (file1.m4a, False), (file1.m4a, False), (file1.m4a, True), ...
collection = sorted(collection, key=itemgetter(1))
collection = sorted(collection, key=itemgetter(0))
collection = groupby(
    collection, key=itemgetter(0)
)  # (file1.m4a, ((file1.m4a, False), (file1.m4a, False), (file1.m4a, True))), ...
collection = [
    (key, [exist for _, exist in group]) for key, group in collection
]  # (file1.m4a, [False, False, True]), (file2.m4a, [False, False, False]), ...
collection = [
    Path(file).parent.parent for file, exist in collection if not any(exist)
]  # file2.m4a, ...
collection = chain(*[[(path.parent,
                       Path(path.name) / "*" / "*?" / f"*.{extension}",
                       TEMPDIR / "/".join(path.parts[1:]))
                      for extension in ["m4a", "mp3"]]
                     for path in set(collection)])
collection = sorted(collection, key=itemgetter(1))
collection = sorted(collection, key=itemgetter(0))
collection = groupby(collection, key=itemgetter(0))

# -----
environment = TemplatingEnvironment(_MYPARENT.parent / "AudioCD" / "Templates")
arguments.commands.write(
    environment.get_template("T00c").render(collection=collection,
                                            tempdir=TEMPDIR))
Esempio n. 4
0
                    (workspace, uid, name, source, destination, regexes))

    # Sort targets collection.
    collection = sorted(collection, key=itemgetter_(1)(int))
    collection = sorted(collection, key=itemgetter(2))
    collection = sorted(collection, key=itemgetter(0))

    # Dump targets configuration into a JSON file.
    json.dump([
        dict([("workspace", workspace), ("description", name),
              ("target", uid)]) for workspace, uid, name, _, _, _ in collection
    ],
              json_file,
              ensure_ascii=False,
              indent=4)

    # Dump targets configuration into a TXT file.
    main_content = [
    ]  # type: List[Tuple[str, str, str, List[List[Tuple[str, ...]]]]]
    for workspace, uid, name, source, destination, regexes in collection:
        if regexes:
            content = []  # type: List[List[Tuple[str, ...]]]
            separator = "-" * (len(name) + 1)  # type: str
            for regex in regexes:
                content.append([(uid, "PRODUCTION", source, regex),
                                (uid, "BACKUP", destination)])
            main_content.append((separator, f"{name}.", separator, content))
    txt_file.write(
        environment.get_template("targets.tpl").render(
            content=iter(main_content)))
Esempio n. 5
0
parser.add_argument("--collection",
                    default=TEMP / "tmp1n53chv0" / "tmplpg2af5i",
                    nargs="?",
                    action=GetPath)
parser.add_argument("--encoding", default=UTF8, nargs="?")
arguments = parser.parse_args()

# ============
# Main script.
# ============
with open(arguments.collection, encoding=arguments.encoding, newline="") as fr:
    collection = csv.reader(fr, dialect=CustomDialect())  # type: Iterable[Any]
    collection = sorted(collection, key=get_name)
    collection = sorted(collection, key=get_parent)
    collection = sorted(collection, key=itemgetter(1))
    collection = sorted(collection, key=itemgetter(0))
    for key, group in groupby(collection, key=itemgetter(0)):
        environment = TemplatingEnvironment(key)
        for sub_key, sub_group in groupby(group, key=itemgetter(1)):
            with open(TEMP / "tmp1n53chv0" / f"batch{sub_key}.cmd",
                      mode=WRITE,
                      encoding="ISO-8859-1") as fw:
                files = [
                    tuple(compress(item, TEMPLATES.get((Path(key), sub_key))))
                    for item in sub_group
                ]  # type: Iterable[Any]
                files = [tuple(break_(file)) for file in files]
                files = groupby(files, key=itemgetter(0))
                fw.write(
                    environment.get_template(sub_key).render(collection=files))
Esempio n. 6
0
directories = list(
    filter(
        None,
        sorted([
            f"{str(key)}: {value}" for key, value in pprint_count(*Counter(
                str(file.parent) for file in collection).items())
        ],
               key=itemgetter(0))))
if directories:
    index += 1
    content.append(
        ("   ============", f"{LETTERS.get(index, 'Z')}. Directories.",
         iter(directories)))

# Empty directories.
if empty:
    index += 1
    content.append(
        ("   ==================",
         f"{LETTERS.get(index, 'Z')}. Empty directories.", iter(empty)))

# Store results.
if arguments.output:
    for file in collection:
        arguments.output.write(f"{file}\n")

# Display results.
print(
    environment.get_template("T06").render(root=str(arguments.path),
                                           content=iter(content)))
Esempio n. 7
0
    # Parse input arguments.
    parser = argparse.ArgumentParser()
    parser.add_argument("outfile",
                        type=argparse.FileType("w", encoding="ISO-8859-1"),
                        nargs="?",
                        default=os.path.join(os.path.expandvars("%TEMP%"),
                                             "xxcopy.cmd"),
                        help="XXCOPY commands file")
    arguments = parser.parse_args()

    # Load configuration.
    with open(_THATFILE.parents[1] / "Resources" /
              "audio_config.yml") as stream:
        configuration = yaml.load(stream, Loader=yaml.FullLoader)

    # Run interface.
    app = wx.App()
    interface = MainFrame(None, **configuration)
    interface.Show()
    app.MainLoop()
    if interface.copy_audiofiles:
        arguments.outfile.write(
            template.get_template("T01").render(
                collection1=iter(interface.collection1),
                collection2=iter(interface.collection2)))
        if not interface.test_mode:
            level = 0

    # Exit script.
    sys.exit(level)
Esempio n. 8
0
            collection.extend(
                ["No new file appeared since the last backup.", None])
        if len(new_files) > 0:
            level = 0
            collection.extend([None, iter(new_files)])

        # Get existing modified files.
        exi_files = [
            Path(production[item][1]) / item
            for item in sorted(set(production).intersection(backup))
            if production[item][0] > backup[item]
        ]
        if len(exi_files) == 0:
            collection.extend(
                ["No existing file was modified since the last backup.", None])
        if len(exi_files) > 0:
            level = 0
            collection.extend([None, iter(exi_files)])

        # Append selected files to master collection.
        master_collection.append(tuple(collection))

# Output results.
if arguments.pprint:
    print(
        environment.get_template("check.tpl").render(
            contents=master_collection))

# Exit script.
sys.exit(level)
Esempio n. 9
0
# -----
collection = zip_longest(
    collection1, collection2, fillvalue=(None, None, None)
)  # ((target1, 1, 1234), (target3, 3, 9012)), ((target2, 2, 5678), (None, None, None)), ...
collection = list(
    chain.from_iterable(collection)
)  # (target1, 1, 1234), (target3, 3, 9012), (target2, 2, 5678), (None, None, None), ...
collection.extend([("Exit", 99, 99), (None, None, None)])

# -----
codes = {str(number): code
         for _, number, code in collection}  # type: Mapping[str, int]

# -----
menu = environment.get_template("T04").render(
    collection=list(shared.format_menu(*collection, group=2)))
while True:
    run("CLS", shell=True)
    print(menu)
    choice = input("\t\tPlease enter task: ".expandtabs(4))
    if choice:
        if not shared.REGEX.match(choice):
            continue
        if choice not in codes:
            continue
        break

# ============
# Exit script.
# ============
sys.exit(codes[choice])