Ejemplo n.º 1
0
def test_get_file_info():
    s = '\n'

    path = util.get_relative_path(__file__, 'a.txt')
    s += 'get_file_info(\'' + path + '\') = ' + util.to_json(
        util.get_file_info(path)) + '\n'

    s += '\n'
    path = util.get_relative_path(__file__, 'dir1')
    s += 'get_file_info(\'' + path + '\') = ' + util.to_json(
        util.get_file_info(path)) + '\n'

    s += '\n'
    path = util.get_relative_path(__file__, 'dir2')
    s += 'get_file_info(\'' + path + '\') = ' + util.to_json(
        util.get_file_info(path)) + '\n'

    s += '\n'
    path = util.get_relative_path(__file__, 'dir2/')
    s += 'get_file_info(\'' + path + '\') = ' + util.to_json(
        util.get_file_info(path)) + '\n'

    #path = util.get_relative_path(__file__, 'notexist')
    #s += 'get_file_info(\'' + path + '\') = ' + util.to_json(util.get_file_info(path)) + '\n'

    return s
Ejemplo n.º 2
0
def change_match_file(file_name, edited_res):
    """Replace the file name of a resource"""
    dir_name, res_name, file_ext = u.get_file_info(file_name)
    if dict(edited_res)[res_name] is not None:
        res_crypt_name = crypt_identifier(res_name)
        new_file_name = dir_name + res_crypt_name + file_ext  # Append the string
        u.rename(file_name, new_file_name)  # Rename the file
Ejemplo n.º 3
0
def change_match_file(file_name, edited_res):
    """Replace the file name of a resource"""
    dir_name, res_name, file_ext = u.get_file_info(file_name)
    if dict(edited_res)[res_name] is not None:
        res_crypt_name = crypt_identifier(res_name)
        new_file_name = dir_name + res_crypt_name + file_ext  # Append the string
        u.rename(file_name, new_file_name)  # Rename the file
Ejemplo n.º 4
0
def change_match_file(file_name):
    """Rename a class file appending the string"""
    dir_name, res_name, file_ext = u.get_file_info(file_name)
    new_res_name = '!' + res_name + file_ext + '!'
    new_file_name = dir_name + new_res_name
    for class_crypt in re.findall(r'(\![^\!]*?\!)', new_file_name):
        new_file_name = new_file_name.replace(class_crypt, apply_crypt(class_crypt[:-1][1:]))
    u.rename(file_name, new_file_name)
Ejemplo n.º 5
0
def change_match_file(file_name):
    """Rename a class file appending the string"""
    dir_name, res_name, file_ext = u.get_file_info(file_name)
    new_res_name = '!' + res_name + file_ext + '!'
    new_file_name = dir_name + new_res_name
    for class_crypt in re.findall(r'(\![^\!]*?\!)', new_file_name):
        new_file_name = new_file_name.replace(
            class_crypt, apply_crypt(class_crypt[:-1][1:]))
    u.rename(file_name, new_file_name)
Ejemplo n.º 6
0
def main():
    # parse CLI args
    args = get_args()

    # setup logging
    log = util.init_logger(args.log_level)

    # Get module file info
    log.debug(f"Command Line Args: {args}")
    file_info = util.get_file_info(args.module)
    log.debug(f"Module info: {file_info}")

    # validate module
    if not file_info.exists:
        sys.exit(util.err(f"Python module argument `{args.module}` does not exist"))
    if file_info.isdir or not file_info.isfile:
        sys.exit(util.err(f"Python module argument `{args.module}` is not a file"))
    if file_info.extension != ".py":
        sys.exit(util.err(f"Python module argument `{args.module}` is not a `.py` file"))

    # compress module to .zip file
    zip_path = os.path.join(BUILD_DIR, file_info.leaf_name + ".zip")
    with zipfile.ZipFile(zip_path, "w") as zf:
        # NOTE: This is using arcname to remove any uneeded parent directories; however,
        # for a module with imports/dependancies this wont work
        zf.write(file_info.abspath, arcname=file_info.leaf)

    # Run subprocess call to AWS cli
    zip_file_info = util.get_file_info(zip_path)
    logging.debug(f"Zip file info: {zip_file_info}")
    zip_path = "fileb://" + zip_file_info.abspath
    cmd = [
        "aws",
        "lambda",
        "update-function-code",
        "--function-name",
        args.fname,
        "--zip-file",
        zip_path,
    ]
    log.debug(f"AWS subprocess command: `{' '.join(cmd)}`")

    if not args.dry_run:
        subprocess.run(cmd)
Ejemplo n.º 7
0
def change_match_file(file_name):
    """Rename a class file appending the string"""
    dir_name, res_name, file_ext = u.get_file_info(file_name)
    res_name = fix_invalid_file(res_name)
    new_res_name = '!' + res_name + '!'
    new_res_name = new_res_name.replace('$', '!$!')
    new_file_name = dir_name + new_res_name + file_ext
    new_file_name = defix_invalid_file(new_file_name)
    for class_crypt in re.findall(r'(\![^\!]*?\!)', new_file_name):
        new_file_name = new_file_name.replace(
            class_crypt, crypt_identifier(class_crypt[:-1][1:]))
    u.rename(file_name, new_file_name)
Ejemplo n.º 8
0
def change_match_file(file_name):
    """Rename a class file appending the string"""
    dir_name, res_name, file_ext = u.get_file_info(file_name)
    u.rename(file_name, dir_name + 'lib' + crypt_identifier(res_name + file_ext) + file_ext)
Ejemplo n.º 9
0
def change_match_dir(dir_name):
    """Rename a class dir appending the string"""
    old_dir_name, res_name, file_ext = u.get_file_info(dir_name)
    new_res_name = apply_crypt(res_name)
    u.rename_dir(dir_name, old_dir_name + new_res_name)
Ejemplo n.º 10
0
def change_match_dir(dir_name):
    """Rename a class dir appending the string"""
    old_dir_name, res_name, file_ext = u.get_file_info(dir_name)
    new_res_name = apply_crypt(res_name)
    u.rename_dir(dir_name, old_dir_name + new_res_name)