1
0
Fork 0

Build scripts replaced by Makefile. Minor update for setup.cfg. Added main.py

(to be written) that will replace current CLI realisation.
This commit is contained in:
Alexander Andreev 2020-05-19 02:13:36 +04:00
parent d9dbf0fb8d
commit 92443d59a9
5 changed files with 82 additions and 9 deletions

9
Makefile Normal file
View File

@ -0,0 +1,9 @@
build: piggybank
python setup.py sdist bdist_wheel
install:
python -m pip install --upgrade dist/piggybank-1.0.0-py3-none-any.whl
uninstall:
python -m pip uninstall piggybank
clean:
rm -rf piggybank/__pycache__ piggybank/cli/__pycache__ \
build dist piggybank.egg-info

4
bi.cmd
View File

@ -1,4 +0,0 @@
@echo off
python setup.py sdist bdist_wheel
python -m pip install --user --upgrade dist/piggybank-1.0.0-py3-none-any.whl
pause

3
bi.sh
View File

@ -1,3 +0,0 @@
#!/usr/bin/sh
python setup.py sdist bdist_wheel
python -m pip install --upgrade dist/piggybank-1.0.0-py3-none-any.whl

70
piggybank/cli/main.py Normal file
View File

@ -0,0 +1,70 @@
from re import match
from sys import argv
from piggybank import print_program_version
from piggybank.currencies import print_supported_currencies
USAGE_PUT = "Usage: piggybank put [-r|--reversed] COINS in FILE of CURRENCY\n" \
"Put a set of coins in a piggybank. Set a currency of a new one.\n\n" \
"-r, --reversed -- use reversed order of COINS (from greater to least);\n" \
"COINS -- array of comma or whitespace separated coins;\n" \
"in FILE -- .pb file name of your piggybank;\n" \
"of CURRENCY -- set a currency for a new piggybank.\n"
USAGE_TAKE = "Take a set of coins from a piggybank.\n" \
"Usage: piggybank take [-r|--reversed] COINS from FILE\n\n" \
"-r, --reversed -- use reversed order of COINS (from greater to least);\n" \
"COINS -- array of comma or whitespace separated coins;\n" \
"from FILE -- .pb file of your piggybank.\n" \
USAGE_SHOW = "Show statistics about a piggybank.\n" \
"Usage: piggybank show FILE [with t,transactions]\n\n" \
"FILE -- .pb file name of your piggybank;\n" \
"with t,transaction -- list all transactions.\n"
HELP = "Usage: piggybank [put | take | show] [-v | --version] " \
"[-h | --help] [-L | --list-currencies]\n\n" \
f"{USAGE_PUT}\n" \
f"{USAGE_TAKE}\n" \
f"{USAGE_SHOW}\n\n" \
"-L,--list-currencies -- list all supported currencies and a default one;" \
"-v,--version -- print version of a program;\n" \
"-h,--help -- print this help.\n"
def put(args):
r = r"^put(?P<reversed> -r| --reversed)? (?P<coins>[\d ,]+) in (?P<file>\S+)(?= of (?P<currency>\w+))?"
def take(args):
r = r"^take(?P<reversed> -r| --reversed)? (?P<coins>[\d ,]+) from (?P<file>\S+)"
def show(args):
r = r"^show (?P<file>\S+)(?= with (?P<transactions>t|transactions))?"
def common(args):
r = r"(?P<version>-v|--version)?(?P<help>-h|--help)?(?P<list_currencies>-L|--list-currencies)?"
argd = match(r, args).groupdict()
if not argd["version"] is None:
print_program_version()
exit()
elif not argd["help"] is None:
print(HELP)
elif not argd["list_currencies"] is None:
print_supported_currencies()
def main():
command = argv[1]
args_str = " ".join(argv[1:])
if command == "put":
put(args_str)
elif command == "take":
take(args_str)
elif command == "show":
show(args_str)
else:
common(args_str)
if __name__ == "__main__":
main()

View File

@ -8,7 +8,7 @@ long_description = file: README.md
long_description_content_type = text/markdown
author = attr: piggybank.__author__
author_email = attr: piggybank.__email__
url = https://aravs.ru
url = https://arav.top
keywords =
coins
piggy bank
@ -16,6 +16,7 @@ keywords =
savings
license = WTFPL 2.0
license_file = COPYING
platforms=OS Independent
classifiers =
Development Status :: 5 - Production/Stable
Environment :: Console
@ -28,7 +29,7 @@ classifiers =
[options]
zip_safe = False
python_requires = >=3.7
python_requires = >=3.6
include_package_data = True
packages = find: