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:
4
py/.gitignore
vendored
Normal file
4
py/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*.so
|
||||
.env/
|
3
py/README.md
Normal file
3
py/README.md
Normal file
@ -0,0 +1,3 @@
|
||||
# Python Scwrypts
|
||||
[](https://python.org)
|
||||
<br>
|
0
py/__init__.py
Normal file
0
py/__init__.py
Normal file
7
py/hello_world.py
Executable file
7
py/hello_world.py
Executable 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
1
py/redis/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
|
15
py/redis/client.py
Normal file
15
py/redis/client.py
Normal 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
20
py/redis/interactive.py
Executable 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
2
py/requirements.txt
Normal file
@ -0,0 +1,2 @@
|
||||
redis
|
||||
bpython
|
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