mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-03 20:13:02 +00:00
use try ... finally in build arg handler to revert configs
This commit is contained in:
+10
-10
@@ -35,15 +35,13 @@ class HandleArgs:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
if settings.IS_BUILD:
|
if settings.IS_BUILD:
|
||||||
log.error("ERROR: You can't build here!")
|
print("Catch me if you can! 😆💬")
|
||||||
return
|
sys.exit(0)
|
||||||
|
|
||||||
# get last.fm api key from env
|
lastfm_key = settings.Keys.LASTFM_API
|
||||||
last_fm_key = settings.Keys.LASTFM_API
|
|
||||||
posthog_key = settings.Keys.POSTHOG_API_KEY
|
posthog_key = settings.Keys.POSTHOG_API_KEY
|
||||||
|
|
||||||
# if the key is not in env, exit
|
if not lastfm_key:
|
||||||
if not last_fm_key:
|
|
||||||
log.error("ERROR: LASTFM_API_KEY not set in environment")
|
log.error("ERROR: LASTFM_API_KEY not set in environment")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
@@ -52,9 +50,10 @@ class HandleArgs:
|
|||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
if ALLARGS.build in ARGS:
|
if ALLARGS.build in ARGS:
|
||||||
|
try:
|
||||||
with open("./app/configs.py", "w", encoding="utf-8") as file:
|
with open("./app/configs.py", "w", encoding="utf-8") as file:
|
||||||
# copy the api key to the config file
|
# copy the api keys to the config file
|
||||||
line1 = f'LASTFM_API_KEY = "{last_fm_key}"\n'
|
line1 = f'LASTFM_API_KEY = "{lastfm_key}"\n'
|
||||||
line2 = f'POSTHOG_API_KEY = "{posthog_key}"\n'
|
line2 = f'POSTHOG_API_KEY = "{posthog_key}"\n'
|
||||||
file.write(line1)
|
file.write(line1)
|
||||||
file.write(line2)
|
file.write(line2)
|
||||||
@@ -72,8 +71,8 @@ class HandleArgs:
|
|||||||
"-y",
|
"-y",
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
finally:
|
||||||
# revert build to False and remove the api key for dev mode
|
# revert and remove the api keys for dev mode
|
||||||
with open("./app/configs.py", "w", encoding="utf-8") as file:
|
with open("./app/configs.py", "w", encoding="utf-8") as file:
|
||||||
line1 = "LASTFM_API_KEY = ''\n"
|
line1 = "LASTFM_API_KEY = ''\n"
|
||||||
line2 = "POSTHOG_API_KEY = ''\n"
|
line2 = "POSTHOG_API_KEY = ''\n"
|
||||||
@@ -174,3 +173,4 @@ class HandleArgs:
|
|||||||
if any((a in ARGS for a in ALLARGS.version)):
|
if any((a in ARGS for a in ALLARGS.version)):
|
||||||
print(settings.Release.APP_VERSION)
|
print(settings.Release.APP_VERSION)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user