From ab11346a2a6bddf6ed527426ad285dc78c9c1fbb Mon Sep 17 00:00:00 2001 From: andy Date: Sun, 7 Feb 2021 23:32:46 +0000 Subject: [PATCH] redid command invocation to catch bad return codes --- admin.py | 38 +++++++++++++++++++++----------------- main.py | 6 ++++++ 2 files changed, 27 insertions(+), 17 deletions(-) create mode 100644 main.py diff --git a/admin.py b/admin.py index 969c111..9935cc5 100755 --- a/admin.py +++ b/admin.py @@ -45,26 +45,30 @@ class Admin(Cmd): # ) # os.chdir(stage_dir) - # os.system('gcloud config set project sarsooxyz') + subprocess.check_call(['gcloud', 'config', 'set', 'project', 'sarsooxyz'], shell=True) def prepare_frontend(self): print('>> building css') - os.system(f'sass --style=compressed {scss_rel_path} {css_rel_path}') + print(f'sass --style=compressed {scss_rel_path} {css_rel_path}') + subprocess.check_call(['sass', '--style=compressed', str(scss_rel_path), str(css_rel_path)], shell=True) print('>> building javascript') - os.system('npm run build') + subprocess.check_call(['npm', 'run', 'build'], shell=True) def prepare_main(self, path): print('>> preparing main.py') shutil.copy(f'main.{path}.py', 'main.py') def deploy_function(self, name, timeout: int = 60, region='europe-west2'): - os.system(f'gcloud functions deploy {name} ' - f'--region {region} ' - '--runtime=python38 ' - f'--trigger-topic {name} ' - '--set-env-vars DEPLOY_DESTINATION=PROD ' - f'--timeout={timeout}s') + subprocess.check_call([ + 'gcloud', 'functions', 'deploy', name, + '--region', region, + '--runtime=python38', + '--trigger-topic', name, + '--set-env-vars', 'DEPLOY_DESTINATION=PROD', + f'--timeout={timeout}s' + ], shell=True + ) def do_all(self, args): self.prepare_frontend() @@ -72,7 +76,7 @@ class Admin(Cmd): self.prepare_main('api') print('>> deploying api') - os.system('gcloud app deploy') + subprocess.check_call(['gcloud', 'app', 'deploy'], shell=True) self.prepare_main('update_tag') print('>> deploying tag function') @@ -89,7 +93,7 @@ class Admin(Cmd): self.prepare_main('api') print('>> deploying') - os.system('gcloud app deploy') + subprocess.check_call(['gcloud', 'app', 'deploy'], shell=True) def do_tag(self, args): self.prepare_stage() @@ -145,10 +149,10 @@ class Admin(Cmd): exit(0) def do_sass(self, args): - os.system(f'sass --style=compressed {scss_rel_path} {css_rel_path}') + subprocess.check_call(['sass', '--style=compressed', str(scss_rel_path), str(css_rel_path)], shell=True) def do_watchsass(self, args): - os.system(f'sass --style=compressed --watch {scss_rel_path} {css_rel_path}') + subprocess.check_call(['sass', '--style=compressed', '--watch', str(scss_rel_path), str(css_rel_path)], shell=True) def do_rename(self, args): from music.model.user import User @@ -171,13 +175,13 @@ class Admin(Cmd): playlist.update() def do_depend(self, args): - return os.popen('poetry export -f requirements.txt --output requirements.txt').read() + return subprocess.check_output(['poetry', 'export', '-f', 'requirements.txt', '--output', 'requirements.txt'], shell=True, text=True) def do_filt_depend(self, args): self.export_filtered_dependencies() def export_filtered_dependencies(self): - string = os.popen('poetry export -f requirements.txt --without-hashes').read() + string = subprocess.check_output(['poetry', 'export', '-f', 'requirements.txt', '--without-hashes'], shell=True, text=True) depend = string.split('\n') @@ -191,8 +195,8 @@ class Admin(Cmd): def test(): os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = 'service.json' - subprocess.run( - ['python', '-u', '-m', 'unittest', 'discover', "-s", "tests"] + subprocess.check_call( + ['python', '-u', '-m', 'unittest', 'discover', "-s", "tests"], shell=True ) if __name__ == '__main__': diff --git a/main.py b/main.py new file mode 100644 index 0000000..e0c10a8 --- /dev/null +++ b/main.py @@ -0,0 +1,6 @@ +from music.music import create_app + +app = create_app() + +if __name__ == '__main__': + app.run(host='127.0.0.1', port=8080, debug=True)