v2.0.0
===================================================================== Subscwrypts + Environment Inheritance --- Release Notes ------------------------ - added support for environment inheritance - added support for arbitrarily nested scripts (subscwrypts) - added support for CI mode - improved modularity of zsh/utils module - refactored to move some data from ~/.config/scwrypts to ~/.local/share/scwrypts - refactored various scripts to use new subscwrypt api --- New Scripts -------------------------- zsh ) - db/interactive/postgres - aws/rds/interactive-login
This commit is contained in:
1
py/.gitignore
vendored
1
py/.gitignore
vendored
@ -1,4 +1,3 @@
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*.so
|
||||
.env/
|
||||
|
@ -1,16 +1,15 @@
|
||||
#!/usr/bin/env python
|
||||
from os import getenv
|
||||
|
||||
from py.redis.client import Client
|
||||
from py.scwrypts import interactive
|
||||
from py.scwrypts import interactive, getenv
|
||||
|
||||
|
||||
@interactive
|
||||
def main():
|
||||
r = Client
|
||||
|
||||
print('''
|
||||
r = StrictRedis("{getenv("REDIS_HOST")}")
|
||||
print(f'''
|
||||
>>> r = StrictRedis({getenv("REDIS_HOST")}:{getenv("REDIS_PORT")})
|
||||
''')
|
||||
|
||||
return locals()
|
||||
|
@ -1,2 +1,3 @@
|
||||
from py.scwrypts.getenv import getenv
|
||||
from py.scwrypts.interactive import interactive
|
||||
from py.scwrypts.run import run
|
||||
|
@ -1,23 +1,16 @@
|
||||
from os import getenv as os_getenv
|
||||
from pathlib import Path
|
||||
from subprocess import run
|
||||
|
||||
from py.scwrypts.exceptions import MissingVariableError
|
||||
from py.scwrypts.run import run
|
||||
|
||||
|
||||
def getenv(name, required=True):
|
||||
value = os_getenv(name, None)
|
||||
|
||||
if value == None:
|
||||
ZSH_COMMAND = Path(__file__).parents[2] / 'zsh/scwrypts/environment/stage-variables'
|
||||
run('zsh/scwrypts/environment/stage-variables', name)
|
||||
|
||||
run(
|
||||
f'{ZSH_COMMAND} {name}',
|
||||
shell=True,
|
||||
executable='/bin/zsh',
|
||||
)
|
||||
|
||||
if required:
|
||||
raise MissingVariableError(name)
|
||||
if required and not value:
|
||||
raise MissingVariableError(name)
|
||||
|
||||
return value
|
||||
|
@ -3,7 +3,9 @@ from bpython import embed
|
||||
|
||||
def interactive(function):
|
||||
def main(*args, **kwargs):
|
||||
print('preparing interactive environment...')
|
||||
local_vars = function(*args, **kwargs)
|
||||
print('environment ready; user, GO! :)')
|
||||
embed(local_vars)
|
||||
|
||||
return main
|
||||
|
17
py/scwrypts/run.py
Normal file
17
py/scwrypts/run.py
Normal file
@ -0,0 +1,17 @@
|
||||
from os import getenv
|
||||
from pathlib import Path
|
||||
from subprocess import run as subprocess_run
|
||||
|
||||
|
||||
def run(scwrypt_name, *args):
|
||||
DEPTH = int(getenv('SUBSCWRYPT', '0'))
|
||||
DEPTH += 1
|
||||
|
||||
print(f'\n {"--"*DEPTH} ({DEPTH}) BEGIN SUBSCWRYPT : {Path(scwrypt_name).name}')
|
||||
subprocess_run(
|
||||
f'SUBSCWRYPT={DEPTH} {Path(__file__).parents[2] / "scwrypts"} {scwrypt_name} -- {" ".join([str(x) for x in args])}',
|
||||
shell=True,
|
||||
executable='/bin/zsh',
|
||||
)
|
||||
|
||||
print(f' {"--"*DEPTH} ({DEPTH}) END SUBSCWRYPT : {Path(scwrypt_name).name}\n')
|
Reference in New Issue
Block a user