-
-
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.
initial stage if adding commit command
- Loading branch information
Showing
13 changed files
with
178 additions
and
7 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/ | ||
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,31 @@ | ||
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. | ||
|
||
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. | ||
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 th 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 | ||
|
||
It will be stored in the following location: | ||
```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 tp change the mongodb connection string, you can do it by running 'dgupdater init' again and providing the new connection string. | ||
|
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,53 @@ | ||
from os import makedirs, getcwd | ||
from json import load, dump, dumps | ||
from .find_files import find_files | ||
|
||
from .create_chunks import create_chunks | ||
|
||
def commit_changes() -> None: | ||
|
||
makedirs('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]) | ||
|
||
|
||
# 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_chunks'] = no_of_chunks | ||
|
||
with open(f'{getcwd()}/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,31 @@ | ||
from json import load, dump | ||
from math import ceil | ||
|
||
|
||
def create_chunks(release_json_str: str, app_name: str) -> int: | ||
|
||
max_chunk_size = 1000000 # 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 | ||
|
||
return no_of_chunks | ||
|
||
|
File renamed without 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,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