diff --git a/.gitignore b/.gitignore index b87a251..8422016 100644 --- a/.gitignore +++ b/.gitignore @@ -17,7 +17,7 @@ dgupdaterconf.json dgupdater.egg-info/ dist/ build/ -release/ +dgupdater_release/ # Pycache *.pyc diff --git a/dgupdater/cli_commands/commit/func/commit_changes.py b/dgupdater/cli_commands/commit/func/commit_changes.py index f7725a1..56e1d6f 100644 --- a/dgupdater/cli_commands/commit/func/commit_changes.py +++ b/dgupdater/cli_commands/commit/func/commit_changes.py @@ -1,12 +1,18 @@ from os import makedirs, getcwd from json import load, dump, dumps -from .find_files import find_files +from shutil import rmtree +from .find_files import find_files from .create_chunks import create_chunks def commit_changes() -> None: - makedirs('release/chunks', exist_ok = True) + try: + rmtree('dgupdater_release/chunks') # Removing the chunks directory and its contents if it exists + except FileNotFoundError as _: + pass + + makedirs('dgupdater_release/chunks', exist_ok = True) release_json = {} @@ -26,26 +32,19 @@ def commit_changes() -> None: release_json[file] = content # print(content[:10]) - - # with open('release/release.json', 'w') as f: - # dump(release_json, f, indent = 4) - release_json_str = dumps(release_json) - # with open('release/testrelease.json', 'w') as f: - # dump({'release': release_json_str}, f, indent = 4) - - # print(len(release_json_str)) - with open('dgupdaterconf.json') as f: dgupdaterconf_json = load(f) no_of_chunks = create_chunks(release_json_str, dgupdaterconf_json['app_name']) #creating chunks as well as getting the number of chunks - dgupdaterconf_json['files_in_latest_version'] = release_files + dgupdaterconf_json['no_of_files'] = len(release_files) + dgupdaterconf_json['update_ready'] = False dgupdaterconf_json['no_of_chunks'] = no_of_chunks + dgupdaterconf_json['files_in_latest_version'] = release_files - with open(f'{getcwd()}/release/dgupdaterconf.json', 'w') as f: + with open(f'{getcwd()}/dgupdater_release/dgupdaterconf.json', 'w') as f: dump(dgupdaterconf_json, f, indent = 4) diff --git a/dgupdater/cli_commands/commit/func/create_chunks.py b/dgupdater/cli_commands/commit/func/create_chunks.py index b3605a7..27f954b 100644 --- a/dgupdater/cli_commands/commit/func/create_chunks.py +++ b/dgupdater/cli_commands/commit/func/create_chunks.py @@ -1,30 +1,36 @@ -from json import load, dump +from json import dump from math import ceil +from tqdm import tqdm def create_chunks(release_json_str: str, app_name: str) -> int: - max_chunk_size = 1000000 # 10 Lakh (or) 1 Million + max_chunk_size = 1_000_000 # 10 Lakh (or) 1 Million release_json_size = len(release_json_str) no_of_chunks = ceil(release_json_size / max_chunk_size) start = 0 - for i in range(no_of_chunks): - chunk_part = i + 1 - chunk_name = f'{app_name}_part{chunk_part}' - - chunk = release_json_str[start:start + max_chunk_size] - chunk = { - '_id': chunk_name, - 'chunk_data': chunk - } - - with open(f'release/chunks/{chunk_name}.json', 'w') as f: - dump(chunk, f, indent = 4) - - start += max_chunk_size + + with tqdm(total = no_of_chunks, desc = "Creating Chunks", ncols = 110, unit='chunks') as pbar: + + for i in range(no_of_chunks): + chunk_part = i + 1 + chunk_name = f'{app_name}_part{chunk_part}' + + chunk = release_json_str[start:start + max_chunk_size] + chunk = { + 'obj_type': 'chunk', + '_id': chunk_name, + 'chunk_data': chunk + } + + with open(f'dgupdater_release/chunks/{chunk_name}.json', 'w') as f: + dump(chunk, f, indent = 4) + + start += max_chunk_size + pbar.update(1) return no_of_chunks diff --git a/dgupdater/cli_commands/commit/func/find_files.py b/dgupdater/cli_commands/commit/func/find_files.py index 0984c51..12a8442 100644 --- a/dgupdater/cli_commands/commit/func/find_files.py +++ b/dgupdater/cli_commands/commit/func/find_files.py @@ -39,7 +39,7 @@ def get_ignore_list() -> list: try: with open('.dgupdaterignore', 'r') as file: return [line.split('\n')[0] for line in file.readlines()] - except FileNotFoundError: + except FileNotFoundError as _: return [] if __name__ == "__main__": diff --git a/dgupdater/cli_commands/init/func/check_app_exists.py b/dgupdater/cli_commands/init/func/check_app_exists.py index f8bbb85..67386a4 100644 --- a/dgupdater/cli_commands/init/func/check_app_exists.py +++ b/dgupdater/cli_commands/init/func/check_app_exists.py @@ -7,7 +7,7 @@ def check_app_exists(name: str, mongostr: str) -> bool: with MongoClient(mongostr) as client: db = client['DGUPDATER'] collections = [collection.lower() for collection in db.list_collection_names()] - except Exception as e: + except Exception as _: echo("Some error occured. Please try again.") if name.lower() in collections: diff --git a/dgupdater/cli_commands/init/func/check_mongo_string.py b/dgupdater/cli_commands/init/func/check_mongo_string.py index b90c88a..4eb29f8 100644 --- a/dgupdater/cli_commands/init/func/check_mongo_string.py +++ b/dgupdater/cli_commands/init/func/check_mongo_string.py @@ -18,7 +18,7 @@ def check_mongo_string(ctx, param, value: str) -> str|None: echo("Verified !!\n") return value + '*VERIFIEDONCE*' # *VERIFIEDONCE* is added to the end of the string to detect second execution of callback of click.options() - except ConnectionFailure as e: + except ConnectionFailure as _: print() raise BadParameter("Enter a Valid MongoDB Connection String") except Exception as e: diff --git a/dgupdater/cli_commands/init/func/create_configuration_files.py b/dgupdater/cli_commands/init/func/create_configuration_files.py index f96cfef..adbc8a6 100644 --- a/dgupdater/cli_commands/init/func/create_configuration_files.py +++ b/dgupdater/cli_commands/init/func/create_configuration_files.py @@ -21,7 +21,7 @@ def create_configuration_files(data: dict, app_name: str, mongodbstrd: str) -> N if exists(file): with open(file, 'r') as f: dgupdaterconf_json = load(f) - except JSONDecodeError as e: + except JSONDecodeError as _: pass dgupdaterconf_json['mongodbstrds'][app_name] = mongodbstrd diff --git a/dgupdater/cli_commands/init/func/create_entry_in_mongodb.py b/dgupdater/cli_commands/init/func/create_entry_in_mongodb.py index 2ed8a26..f6c7121 100644 --- a/dgupdater/cli_commands/init/func/create_entry_in_mongodb.py +++ b/dgupdater/cli_commands/init/func/create_entry_in_mongodb.py @@ -13,7 +13,7 @@ def create_entry_in_mongodb(dgupdaterconf_json: dict[str:any], mongodbstrd: str, collection.insert_one(dgupdaterconf_json) - except Exception as e: + except Exception as _: raise UsageError("Error while creating entry in MongoDB: ") diff --git a/dgupdater/cli_commands/init/init.py b/dgupdater/cli_commands/init/init.py index dee5ee6..561511a 100644 --- a/dgupdater/cli_commands/init/init.py +++ b/dgupdater/cli_commands/init/init.py @@ -26,6 +26,7 @@ #template dgupdaterconf_json = { + "obj_type": "config", "_id": "", "app_name": "", "version": "", @@ -35,11 +36,10 @@ @command() -@option("--name", "-n", required = True, prompt = arguments["name"]["prompt"], help = arguments["name"]["help"]) -@option("--version", "-v", required = True, prompt = arguments["version"]["prompt"], help = arguments["version"]["help"]) +@option("--name", "-n", required = True, prompt = arguments["name"]["prompt"], help = arguments["name"]["help"]) @option("--mongodbstrd", "-md", callback = check_mongo_string, required = True, prompt = arguments["mongodb_connection_string_write"]["prompt"], help = arguments["mongodb_connection_string_write"]["help"]) @option("--mongodbstrc", "-mc", callback = check_mongo_string, required = True, prompt = arguments["mongodb_connection_string_read"]["prompt"], help = arguments["mongodb_connection_string_read"]["help"]) -def init(name: str, version: str, mongodbstrd: str, mongodbstrc: str) -> None: +def init(name: str, mongodbstrd: str, mongodbstrc: str) -> None: # print(name, version, mongodbstrd, mongodbstrc) echo("\nInitializing this directory for autoupdation...") @@ -54,7 +54,7 @@ def init(name: str, version: str, mongodbstrd: str, mongodbstrc: str) -> None: dgupdaterconf_json["_id"] = name + '_config' dgupdaterconf_json["app_name"] = name - dgupdaterconf_json["version"] = version + dgupdaterconf_json["version"] = "Version will be updated after publishing the changes." dgupdaterconf_json["mongodb_connection_string_client"] = mongodbstrc dgupdaterconf_json["files_in_latest_version"] = 'Files will be listed after publishing the changes.'