merged commands into single strings while using shell=True

This commit is contained in:
andy 2021-02-08 00:56:11 +00:00
parent 9ce7c3049e
commit 14c28ca21b

View File

@ -45,28 +45,27 @@ class Admin(Cmd):
# ) # )
# os.chdir(stage_dir) # os.chdir(stage_dir)
subprocess.check_call(['gcloud', 'config', 'set', 'project', 'sarsooxyz'], shell=True) subprocess.check_call('gcloud config set project sarsooxyz', shell=True)
def prepare_frontend(self): def prepare_frontend(self):
print('>> building css') print('>> building css')
subprocess.check_call(['sass', '--style=compressed', str(scss_rel_path), str(css_rel_path)], shell=True) subprocess.check_call(f'sass --style=compressed {str(scss_rel_path)} {str(css_rel_path)}', shell=True)
print('>> building javascript') print('>> building javascript')
subprocess.check_call(['npm', 'run', 'build'], shell=True) subprocess.check_call('npm run build', shell=True)
def prepare_main(self, path): def prepare_main(self, path):
print('>> preparing main.py') print('>> preparing main.py')
shutil.copy(f'main.{path}.py', 'main.py') shutil.copy(f'main.{path}.py', 'main.py')
def deploy_function(self, name, timeout: int = 60, region='europe-west2'): def deploy_function(self, name, timeout: int = 60, region='europe-west2'):
subprocess.check_call([ subprocess.check_call(
'gcloud', 'functions', 'deploy', name, f'gcloud functions deploy {name} '
'--region', region, f'--region {region} '
'--runtime=python38', '--runtime=python38 '
'--trigger-topic', name, f'--trigger-topic {name} '
'--set-env-vars', 'DEPLOY_DESTINATION=PROD', '--set-env-vars DEPLOY_DESTINATION=PROD '
f'--timeout={timeout}s' f'--timeout={timeout}s', shell=True
], shell=True
) )
def do_all(self, args): def do_all(self, args):
@ -75,7 +74,7 @@ class Admin(Cmd):
self.prepare_main('api') self.prepare_main('api')
print('>> deploying api') print('>> deploying api')
subprocess.check_call(['gcloud', 'app', 'deploy'], shell=True) subprocess.check_call('gcloud app deploy', shell=True)
self.prepare_main('update_tag') self.prepare_main('update_tag')
print('>> deploying tag function') print('>> deploying tag function')
@ -92,7 +91,7 @@ class Admin(Cmd):
self.prepare_main('api') self.prepare_main('api')
print('>> deploying') print('>> deploying')
subprocess.check_call(['gcloud', 'app', 'deploy'], shell=True) subprocess.check_call('gcloud app deploy', shell=True)
def do_tag(self, args): def do_tag(self, args):
self.prepare_stage() self.prepare_stage()
@ -148,10 +147,10 @@ class Admin(Cmd):
exit(0) exit(0)
def do_sass(self, args): def do_sass(self, args):
subprocess.check_call(['sass', '--style=compressed', str(scss_rel_path), str(css_rel_path)], shell=True) subprocess.check_call(f'sass --style=compressed {str(scss_rel_path)} {str(css_rel_path)}', shell=True)
def do_watchsass(self, args): def do_watchsass(self, args):
subprocess.check_call(['sass', '--style=compressed', '--watch', str(scss_rel_path), str(css_rel_path)], shell=True) subprocess.check_call(f'sass --style=compressed --watch {str(scss_rel_path)} {str(css_rel_path)}', shell=True)
def do_rename(self, args): def do_rename(self, args):
from music.model.user import User from music.model.user import User
@ -174,13 +173,13 @@ class Admin(Cmd):
playlist.update() playlist.update()
def do_depend(self, args): def do_depend(self, args):
return subprocess.check_output(['poetry', 'export', '-f', 'requirements.txt', '--output', 'requirements.txt'], shell=True, text=True) return subprocess.check_output('poetry export -f requirements.txt --output requirements.txt', shell=True, text=True)
def do_filt_depend(self, args): def do_filt_depend(self, args):
self.export_filtered_dependencies() self.export_filtered_dependencies()
def export_filtered_dependencies(self): def export_filtered_dependencies(self):
string = subprocess.check_output(['poetry', 'export', '-f', 'requirements.txt', '--without-hashes'], shell=True, text=True) string = subprocess.check_output('poetry export -f requirements.txt --without-hashes', shell=True, text=True)
depend = string.split('\n') depend = string.split('\n')
@ -194,9 +193,7 @@ class Admin(Cmd):
def test(): def test():
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = 'service.json' os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = 'service.json'
subprocess.check_call( subprocess.check_call("python -u -m unittest discover -s tests", shell=True)
['python', '-u', '-m', 'unittest', 'discover', "-s", "tests"], shell=True
)
if __name__ == '__main__': if __name__ == '__main__':
console = Admin() console = Admin()