=====================================================================

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:
2022-04-28 16:09:23 -06:00
commit bffd64051c
63 changed files with 2131 additions and 0 deletions

4
py/.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
__pycache__/
*.py[cod]
*.so
.env/

3
py/README.md Normal file
View File

@ -0,0 +1,3 @@
# Python Scwrypts
[![Generic Badge](https://img.shields.io/badge/python->=3.9-informational.svg)](https://python.org)
<br>

0
py/__init__.py Normal file
View File

7
py/hello_world.py Executable file
View File

@ -0,0 +1,7 @@
#!/usr/bin/env python
def main():
print('HELLO WORLD')
if __name__ == '__main__':
main()

1
py/redis/__init__.py Normal file
View File

@ -0,0 +1 @@

15
py/redis/client.py Normal file
View File

@ -0,0 +1,15 @@
from redis import StrictRedis
from py.scwrypts import getenv
class RedisClient(StrictRedis):
def __init__(self):
super().__init__(
host = getenv('REDIS_HOST'),
port = getenv('REDIS_PORT'),
password = getenv('REDIS_AUTH'),
decode_responses = True,
)
Client = RedisClient()

20
py/redis/interactive.py Executable file
View File

@ -0,0 +1,20 @@
#!/usr/bin/env python
from os import getenv
from py.redis.client import Client
from py.scwrypts import interactive
@interactive
def main():
r = Client
print('''
r = StrictRedis("{getenv("REDIS_HOST")}")
''')
return locals()
if __name__ == '__main__':
main()

2
py/requirements.txt Normal file
View File

@ -0,0 +1,2 @@
redis
bpython

2
py/scwrypts/__init__.py Normal file
View File

@ -0,0 +1,2 @@
from py.scwrypts.getenv import getenv
from py.scwrypts.interactive import interactive

View 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
View 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

View 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