-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from Ashif4354/v0.2.0
v0.3.0
- Loading branch information
Showing
16 changed files
with
225 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,23 @@ | ||
# misc | ||
plan.txt | ||
notes.txt | ||
.dgupdaterignore | ||
.env | ||
*.exe | ||
|
||
# Virtual Environments | ||
venv/ | ||
|
||
# Tests | ||
tests/ | ||
main.py | ||
dgupdater.py | ||
dgupdaterconf.json | ||
|
||
# Builds | ||
# Builds & release | ||
dgupdater.egg-info/ | ||
dist/ | ||
build/ | ||
dgupdater_release/ | ||
|
||
# Pycache | ||
*.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,61 @@ | ||
You need to have a mongodb database preferrably on cloud. You can use mongodb atlas for the same, MongoDB have a serverless db cluster which is very cheap (0.1$ / 1M reads). they also have a good free tier. After configuring, get the connection url and save it. | ||
# DGUPDATER | ||
|
||
You need to get two connection string from mongo db, one with write access and one with read access. | ||
the one with write access will be used by the developer to write data to the database and the one with read access will be used by the client to read data from the database. both the connection string should have access to the same cluser and databases. | ||
## Requirements for using dgupdater | ||
|
||
* You need to have a mongodb database preferrably on cloud. You can use mongodb atlas for the same, MongoDB has a serverless db cluster which is very cheap (0.1$ / 1M reads). they also have a good free tier. | ||
After configuring, get the connection string and save it. | ||
|
||
* You need to create two database users in the database, one with only read access and one with only write access. | ||
The user with write access will be used by the developer to write data to the database and the user with read access will be used by the client to read data from the database. | ||
|
||
* When initializing the application will ask two connection strings, one with write access and one with read access. | ||
So replace the username and password in the connection string with the username and password of the user with write and read access respectively. | ||
|
||
<!-- You need to get two connection string from mongo db, one with write access and one with read access. | ||
the one with write access will be used by the developer to write data to the database and the one with read access will be used by the client to read data from the database. both the connection string should have access to the same cluser and databases. --> | ||
|
||
|
||
## Initialization | ||
You have open a terminal and navigate into the directory which you want to initialize for auto updation. Then run the following command: | ||
|
||
```bash | ||
dgupdater init | ||
``` | ||
|
||
* This will ask you for the application name, application version, mongodb connection string with read access, mongodb connection string with write access. After providing the required information, it will create a file named 'dgupdaterconf.json' in the current directory. This file will be used to store the configuration of the application. | ||
|
||
* The mongodbconnection string with write access will be stored in a different place as follows | ||
```bash | ||
Windows: C:/Users/<username>/AppData/local/DarkGlance/dgupdater/dgupdaterconf.json | ||
Linux: /home/<username>/.config/DarkGlance/dgupdater/dgupdaterconf.json | ||
Mac: Users/<username>/Library/Application Support/DarkGlance/dgupdater/dgupdaterconf.json | ||
``` | ||
|
||
* Then it will check if the application is already registered in the database or not. If it is not registered, it will register the application in the database. or it will ask to overwrite the application details. | ||
|
||
* It will also create a file named .dgupdaterignore in the current directory. | ||
this file works just like the .gitignore file. you can add the files and directories which you want to ignore while updating the application. | ||
|
||
* If you want to change the mongodb connection string, you can do it by running 'dgupdater init' again and providing the new connection string. | ||
|
||
* After initializing the application, you can continue building the application and when you are ready to update the application, you can commit the changes. | ||
|
||
## Commiting the changes | ||
|
||
* After making the changes in the application, you can commit the changes by running the following command: | ||
|
||
```bash | ||
dgupdater commit | ||
``` | ||
|
||
* This will ask for the new versio number of the application. | ||
* After providing the version number, it will ask confirmation to commit the changes. If you confirm, it will commit the changes. | ||
|
||
* In this process the following things will happen: | ||
|
||
1. The files and directories mentioned in the .dgupdaterignore file will be ignored. | ||
2. It will create a folder named 'dgupdater_release' in the directory | ||
3. It will create another folder named 'chunks' in the dgupdater_release folder. | ||
4. It will then create a new dgupdaterconf.json file in the dgupdater_release folder with the updated data. | ||
5. It will then divide the files into smaller chunks and save them in the chunks folder. | ||
6. The commiting process is complete. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from click import command, option, prompt, echo | ||
|
||
from .func.check_configuration_files_exists import check_configuration_files_exists | ||
from .func.update_version import update_version | ||
from .func.commit_changes import commit_changes | ||
|
||
@command() | ||
@option('--version', '-v', required = True, prompt = 'New version number', help='New version number of the application') | ||
def commit(version: str) -> None: | ||
|
||
check_configuration_files_exists() | ||
|
||
if prompt("Are you sure you want to commit the changes? (y/n): ").lower() in ["y", "yes"]: | ||
echo("Committing...") | ||
|
||
update_version(version) | ||
commit_changes() | ||
|
||
echo("Committed successfully.") | ||
return | ||
|
||
echo("Commit aborted.") | ||
|
Empty file.
21 changes: 21 additions & 0 deletions
21
dgupdater/cli_commands/commit/func/check_configuration_files_exists.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from os.path import exists | ||
from click import echo | ||
from json import load | ||
from ...init.init import dgupdaterconf_json | ||
|
||
|
||
def check_configuration_files_exists() -> bool: | ||
if not exists('dgupdaterconf.json'): | ||
echo("\ndgupdaterconf.json not found. Run 'dgupdater init' first. \nAlso check if you are in the correct directory.") | ||
return False | ||
|
||
with open('dgupdaterconf.json') as f: | ||
dgupdaterconf_json_ = load(f) | ||
|
||
if (dgupdaterconf_json_.keys() != dgupdaterconf_json.keys()): | ||
echo("dgupdaterconf.json is not valid. \nTry 'dgupdater init' again.") | ||
return False | ||
|
||
return True | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from os import makedirs, getcwd | ||
from json import load, dump, dumps | ||
from shutil import rmtree | ||
|
||
from .find_files import find_files | ||
from .create_chunks import create_chunks | ||
|
||
def commit_changes() -> None: | ||
|
||
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 = {} | ||
|
||
release_files = find_files() | ||
# print(release_files) | ||
|
||
for file in release_files: | ||
|
||
file_path = f'{getcwd()}{file}' | ||
try: | ||
with open(file_path, 'r') as f: | ||
# print(file_path) | ||
release_json[file] = f.read() | ||
except UnicodeDecodeError as _: | ||
with open(file_path, 'rb') as f: | ||
content = str(f.read()) | ||
release_json[file] = content | ||
# print(content[:10]) | ||
|
||
release_json_str = dumps(release_json) | ||
|
||
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['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()}/dgupdater_release/dgupdaterconf.json', 'w') as f: | ||
dump(dgupdaterconf_json, f, indent = 4) | ||
|
||
|
||
if __name__ == "__main__": | ||
commit_changes() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
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 = 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 | ||
|
||
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 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from json import load, dump | ||
|
||
def update_version(version: str) -> None: | ||
with open('dgupdaterconf.json') as f: | ||
dgupdaterconf_json = load(f) | ||
|
||
dgupdaterconf_json['version'] = version | ||
|
||
with open('dgupdaterconf.json', 'w') as f: | ||
dump(dgupdaterconf_json, f, indent = 4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
|
||
setup( | ||
name="dgupdater", | ||
version="0.2.5", | ||
version="0.3.0", | ||
author="DarkGlance", | ||
author_email="[email protected]", | ||
description="A CLI based auto updation assistant tool for python applications", | ||
|
@@ -16,7 +16,7 @@ | |
'Development Status :: 2 - Pre-Alpha', | ||
"Programming Language :: Python :: 3.12", | ||
"License :: OSI Approved :: MIT License", | ||
"Operating System :: Microsoft :: Windows", | ||
"Operating System :: Platform Independent", | ||
'Topic :: Utilities' | ||
], | ||
python_requires='>=3.6', | ||
|