Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: 3.6
python-version: 3.11
- name: Checkout code
uses: actions/checkout@v2
- name: Run Unit Tests
Expand All @@ -33,7 +33,7 @@ jobs:
pip3 install wheel
./run.sh -b
working-directory: ./
- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v4
with:
name: wheel
path: dist/shellwrap-*-py3-none-any.whl
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ lib


#application
.python-*-history
.python-*-history
__pycache__
33 changes: 28 additions & 5 deletions run.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
#!/bin/bash

run_init()
{
pip3 install build
}

run_clean()
{
rm -rf build dist shellwrap.egg-info
}

run_build()
{
python3 setup.py sdist bdist_wheel
#python3 setup.py sdist bdist_wheel
python3 -m build # the new way
}

run_install()
{
pip3 install shellwrap-0.0.1-py3-none-any.whl
pip3 install dist/shellwrap-0.0.3-py3-none-any.whl
}

run_test()
{
python3 -m unittest discover -s ./ -p '*test.py'
#python3 -m unittest discover -s ./test -p 'test*.py'
python3 -m unittest discover
}

run_lint()
Expand All @@ -30,20 +37,36 @@ run_lint()
# --ignore-patterns=".*\.md,.*\.sh,.*\.html,pylintrc,LICENSE,build,dist,tags,shellwrap.egg-info"
}

run_help()
{
fmt="%4s %s\\n"
printf "$fmt" flag meaning
printf "$fmt" -h help
printf "$fmt" -c clean
printf "$fmt" -b build
printf "$fmt" -I init
printf "$fmt" -i install
printf "$fmt" -t test
printf "$fmt" -l lint
printf "$fmt" -u uninstall
printf "$fmt" -v "set version"
}

# Process the command line arguments
while getopts "hcbitlu" opt
while getopts "hcbIitlu" opt
do
case ${opt} in
h) run_help ;;
c) run_clean ;;
b) run_build ;;
I) run_init ;;
i) run_install ;;
t) run_test ;;
l) run_lint ;;

u) pip3 uninstall shellwrap ;;
v) set_version $OPTARG ;;
*) help ; exit ;;
*) run_help ; exit ;;
esac
done

Expand Down
89 changes: 80 additions & 9 deletions example.py → scripts/example.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from shellwrap import color
from shellwrap import file
from shellwrap import datetools
from shellwrap import interactive
from shellwrap import unix
from shellwrap import file
from shellwrap import net
import argparse

# ######################################
Expand All @@ -26,9 +28,9 @@ def initialize_enviornment(args):
if args.color_off:
environment["color"] = False
if args.verbose:
environment["verbose"]=VMode.WARN
environment["verbose"]=1
if args.very_verbose:
environment["verbose"]=VMode.INFO
environment["verbose"]=3
return environment

# ######################################
Expand Down Expand Up @@ -57,6 +59,37 @@ def process_actions(action=None, env:dict=None):
some_task(action, env)
return True

@color.print_red
@color.print_green
def log_this(item):
return item

@color.bold
@color.green
def color_this(foo):
return foo

@color.bold
@color.black_green
@color.underline
def blueit(text):
return text

@color.green
@color.underline
def headline(text):
return text

@unix.str_to_json
@unix.wrap_call
@unix.wrap_curl
def curl_test(url, what, proj):
return [url + what + proj, "-H", "Client-Id: test"]

@net.str_to_json
def other_test(url):
return net.read(url)["text"]

# ######################################
#mark - Main

Expand All @@ -69,22 +102,60 @@ def main():
world['do_action'] = do_action
world['process_actions'] = process_actions

color.cprint(color.tcode.green, "Starting script", env)
print("This will go away")
color.cmd_clear_screen()

color.cprint(color.tcode.green, "Starting script")

if args.interactive:
interactive.interactive(env, g=globals())
if args.user:
interactive.user_commands(handler=process_actions, environment=env, g=globals())

print(headline("Unix tests"))
result = unix.pipe(['echo', 'one', 'two', 'three'], ['wc', '-m'])
print(f"pipe result={result}.")
print(unix.ccurl('-H', 'Header: Value', 'https://github.com/jceaser/shellwrap.git'))

presult = unix.pipe(['echo', 'one', 'two', 'three'], ['wc', '-m'])
print(presult)
#print(headline("\nUnix Decorator tests"))
#print(curl_test('http://thomascherry.name/',
# '/cgi-bin/go.cgi',
# '?user=thomas&name=main&group=public'))

print(unix.ccurl('-H', 'Header: Value', 'https://github.com/jceaser/shellwrap.git'))
#color.cprint(color.tcode.red, "ending", env)

print(headline("\nFile tests"))
print(file.read('.editorconfig'))

print(headline("\nDecorator tests"))
print("Normal: %s" % log_this('hi, this is the decorator'))
print(color_this("some text"))
print(blueit("Make this blue and bold."))
print(color.link("https://apple.com/", "apple.com"))

#print(headline("\nURL tests"))
#url = 'http://thomascherry.name/cgi-bin/go.cgi?user=thomas&name=main&group=public'
#print(net.read(url)["text"])

#print(other_test(url))
#print(net.rread(url).text)

print(headline("Colorize tests"))
print(color.colorize(":rocket: This is my :red:red:end: text and this is my :green:green:end: text."))

color.cprint([color.tcode.green, color.tcode.underline], "my list text")

print(' ; '.join(f"{i}={color.emoji[i]}" for i in color.emoji))

color.cprint(color.tcode.red, "ending", env)
print(headline("Date tests"))
start: int = datetools.unix()
print("Now: ", datetools.now())
print("Unix: ", datetools.unix())
print("Today: ", datetools.today())
print("Internal: ", datetools.now_internal())
print("Durration: ", datetools.unix_difference(start))

print(file.read_file('.editorconfig'))
print(color.colorize(":warn::blink::red: This is the end of the script :end:"))

if __name__ == "__main__":
main()
20 changes: 20 additions & 0 deletions scripts/show.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env python3

for i in range(30, 37 + 1):
print("\033[%dm%d\t\t\033[%dm%d" % (i, i, i + 60, i + 60))

print("\033[39m\\033[49m - Reset color")
print("\\033[2K - Clear Line")
print("\\033[<L>;<C>H or \\033[<L>;<C>f - Put the cursor at line L and column C.")
print("\\033[<N>A - Move the cursor up N lines")
print("\\033[<N>B - Move the cursor down N lines")
print("\\033[<N>C - Move the cursor forward N columns")
print("\\033[<N>D - Move the cursor backward N columns\n")
print("\\033[2J - Clear the screen, move to (0,0)")
print("\\033[K - Erase to end of line")
print("\\033[s - Save cursor position")
print("\\033[u - Restore cursor position\n")
print("\\033[4m - Underline on")
print("\\033[24m - Underline off\n")
print("\\033[1m - Bold on")
print("\\033[21m - Bold off")
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup, find_packages

VERSION = '0.0.1'
VERSION = '0.0.3'
DESCRIPTION = 'Scripting Tools'
LONG_DESCRIPTION = 'A set of tools to make it easy to write unix scripts'

Expand Down
Loading
Loading