v1.0.0
===================================================================== Finally decided to port personal scripts into a standalone library. --- Release Notes ------------------------ - added support for python, zsh, and zx scripts - added support for "interactive" scripts which drop the user to a REPL - added support for passing arguments to commands - added support for python/node virtualenv management through scwrypts - added contributing and usage docs - updated zsh plugin to write commands to history - licensed under GPLv3 --- New Scripts -------------------------- zsh/scwrypts ) - configure - environment/copy - environment/delete - environment/edit - environment/synchronize - logs/clear - logs/view zsh ) - aws/ecr/login - aws/efs/mount - aws/efs/unmount - aws/route53/backup - aws/s3/media-sync/pull - aws/s3/media-sync/push python ) - redis/interactive
This commit is contained in:
2
py/scwrypts/__init__.py
Normal file
2
py/scwrypts/__init__.py
Normal file
@ -0,0 +1,2 @@
|
||||
from py.scwrypts.getenv import getenv
|
||||
from py.scwrypts.interactive import interactive
|
3
py/scwrypts/exceptions.py
Normal file
3
py/scwrypts/exceptions.py
Normal file
@ -0,0 +1,3 @@
|
||||
class MissingVariableError(Exception):
|
||||
def init(self, name):
|
||||
super().__init__(f'Missing required environment variable "{name}"')
|
23
py/scwrypts/getenv.py
Normal file
23
py/scwrypts/getenv.py
Normal file
@ -0,0 +1,23 @@
|
||||
from os import getenv as os_getenv
|
||||
from pathlib import Path
|
||||
from subprocess import run
|
||||
|
||||
from py.scwrypts.exceptions import MissingVariableError
|
||||
|
||||
|
||||
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(
|
||||
f'{ZSH_COMMAND} {name}',
|
||||
shell=True,
|
||||
executable='/bin/zsh',
|
||||
)
|
||||
|
||||
if required:
|
||||
raise MissingVariableError(name)
|
||||
|
||||
return value
|
9
py/scwrypts/interactive.py
Normal file
9
py/scwrypts/interactive.py
Normal file
@ -0,0 +1,9 @@
|
||||
from bpython import embed
|
||||
|
||||
|
||||
def interactive(function):
|
||||
def main(*args, **kwargs):
|
||||
local_vars = function(*args, **kwargs)
|
||||
embed(local_vars)
|
||||
|
||||
return main
|
Reference in New Issue
Block a user