Esempio n. 1
0
def init_check():
    FileUtility.check_dirpath_exists(TARGET_DIRPATH)
    parser = argparse.ArgumentParser()
    parser.add_argument("-nc",
                        action="store_true",
                        help="Skip confirm of the script")
    confirm_flag = False if parser.parse_args().nc is True else True
    if confirm_flag is True:
        return NextStep(confirm, {})
    else:
        return NextStep(check_collector_dir, {})
Esempio n. 2
0
def zip_files(staging_dirpath):
    zip_filepath = shutil.make_archive(EXPORT_FILENAME,
                                       format=COMPRESS_FORMAT,
                                       root_dir=staging_dirpath)
    context = dict()
    context["zip_filepath"] = zip_filepath
    return NextStep(move_zip_file_to_dest, context=context)
Esempio n. 3
0
def move_files():
    filepaths = []
    filepaths.extend(FileUtility.get_filepaths(TARGET_DIRPATH,
                                               pattern=PATTERN))
    for filepath in filepaths:
        FileUtility.move_file_to_dirpath(filepath, COLLECTOR_DIRPATH)
    context = {"filepaths": filepaths}
    return NextStep(print_report, context=context)
Esempio n. 4
0
def collect_files(staging_dirpath):
    for task in TASKS:
        basename = os.path.basename(task.src_dirpath)
        shutil.copytree(task.src_dirpath,
                        os.path.join(staging_dirpath, basename),
                        ignore=shutil.ignore_patterns(*task.ignore_patterns),
                        symlinks=True)
    return NextStep(zip_files, {})
Esempio n. 5
0
def create_staging_dir():
    while True:
        hash_id = uuid.uuid1().hex[0:8]
        staging_dirpath = os.path.join(str(Path.home()), f"backup_{hash_id}")
        if os.path.isdir(staging_dirpath) is False:
            os.makedirs(staging_dirpath, exist_ok=False)
            break
    context = dict()
    context["staging_dirpath"] = staging_dirpath
    return NextStep(collect_files, context=context)
Esempio n. 6
0
def print_report(filepaths):
    print(f"{len(filepaths)} screenshots have been collected")
    return NextStep(None, {})
Esempio n. 7
0
def check_collector_dir():
    FileUtility.create_dirpath_if_not_exists(COLLECTOR_DIRPATH)
    return NextStep(move_files, {})
Esempio n. 8
0
def confirm(user_input):
    if user_input.lower().strip() != "y":
        print("ByeBye~")
        return NextStep(None, {})
    else:
        return NextStep(check_collector_dir, {})
Esempio n. 9
0
def remove_staging_files(staging_dirpath):
    shutil.rmtree(staging_dirpath)
    return NextStep(print_report, {})
Esempio n. 10
0
def print_report(des_filepath):
    msg = f"filepath: {des_filepath}"
    print(msg)
    return NextStep(None, {})
Esempio n. 11
0
def move_zip_file_to_dest(zip_filepath):
    des_filepath = os.path.join(DESTINATION_DIRPATH, EXPORT_FILENAME)
    context = dict()
    context["des_filepath"] = des_filepath
    shutil.move(zip_filepath, des_filepath)
    return NextStep(print_report, context=context)
Esempio n. 12
0
def confirm(user_input):
    if user_input.lower().strip() != "y":
        print("ByeBye~")
        return NextStep(None, {})
    else:
        return NextStep(create_staging_dir, {})