fix: make semantic changes to commands

* add missing __main__ call to commands.py
* remove unnecessary imports
* fix backup WITH_FILES logic
* follow python semantics (?)

Signed-off-by: Chinmay D. Pai <chinmaydpai@gmail.com>
This commit is contained in:
Chinmay D. Pai
2020-04-29 01:45:59 +05:30
parent 5a5a79f206
commit 884a82d814
11 changed files with 103 additions and 55 deletions

View File

@@ -9,10 +9,12 @@ from check_connection import get_config
APP_VERSIONS_JSON_FILE = 'app_versions.json'
APPS_TXT_FILE = 'apps.txt'
def save_version_file(versions):
with open(APP_VERSIONS_JSON_FILE, 'w') as f:
return json.dump(versions, f, indent=1, sort_keys=True)
def get_apps():
apps = []
try:
@@ -24,40 +26,43 @@ def get_apps():
except FileNotFoundError as exception:
print(exception)
exit(1)
except:
except Exception:
print(APPS_TXT_FILE+" is not valid")
exit(1)
return apps
def get_container_versions(apps):
versions = {}
for app in apps:
try:
version = __import__(app).__version__
versions.update({app:version})
except:
versions.update({app: version})
except Exception:
pass
try:
path = os.path.join('..','apps', app)
path = os.path.join('..', 'apps', app)
repo = git.Repo(path)
commit_hash = repo.head.object.hexsha
versions.update({app+'_git_hash':commit_hash})
except:
versions.update({app+'_git_hash': commit_hash})
except Exception:
pass
return versions
def get_version_file():
versions = None
try:
with open(APP_VERSIONS_JSON_FILE) as versions_file:
versions = json.load(versions_file)
except:
except Exception:
pass
return versions
def main():
is_ready = False
apps = get_apps()
@@ -76,7 +81,7 @@ def main():
version_file_hash = None
container_hash = None
repo = git.Repo(os.path.join('..','apps',app))
repo = git.Repo(os.path.join('..', 'apps', app))
branch = repo.active_branch.name
if branch == 'develop':
@@ -105,5 +110,6 @@ def main():
version_file = container_versions
save_version_file(version_file)
if __name__ == "__main__":
main()