Add Makefile and refactor package structure
- Replace shell script with Makefile for build/install tasks - Move main logic into main() function for proper packaging - Configure package entrypoint in pyproject.toml
This commit is contained in:
parent
4ab46ee2fc
commit
b23ca49a83
25
Makefile
Normal file
25
Makefile
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
.PHONY: default venv build install clean
|
||||||
|
|
||||||
|
default: install
|
||||||
|
|
||||||
|
venv:
|
||||||
|
@[ ! -d ./venv ] && python3 -m venv venv && bash -c \
|
||||||
|
"source venv/bin/activate && \
|
||||||
|
pip install --upgrade pip && \
|
||||||
|
pip install -r requirements.txt" || true
|
||||||
|
|
||||||
|
build: venv
|
||||||
|
@if [ -n "$$(git status --porcelain)" ]; then \
|
||||||
|
echo "[ERROR]: There are uncommitted changes or untracked files."; \
|
||||||
|
exit 1; \
|
||||||
|
fi
|
||||||
|
@bash -c \
|
||||||
|
"source venv/bin/activate && \
|
||||||
|
pip install build twine && \
|
||||||
|
python -m build"
|
||||||
|
|
||||||
|
install: venv
|
||||||
|
@bash -c "source venv/bin/activate && pip install -e ."
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf venv dist tarc.egg-info
|
@ -1,4 +1,7 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "tarc"
|
name = "tarc"
|
||||||
version = "0.0.1dev2"
|
version = "0.0.1dev3"
|
||||||
description = "Manage BT archives"
|
description = "Manage BT archives"
|
||||||
|
|
||||||
|
[project.scripts]
|
||||||
|
tarc = "tarc:main"
|
||||||
|
20
tarc.sh
20
tarc.sh
@ -1,20 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# Create a virtual environment if it does not exist
|
|
||||||
if [ ! -d "venv" ]; then
|
|
||||||
# shellcheck disable=SC1091
|
|
||||||
python3 -m venv venv && \
|
|
||||||
source venv/bin/activate && \
|
|
||||||
pip install -r requirements.txt && \
|
|
||||||
deactivate
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Activate the virtual environment
|
|
||||||
# shellcheck disable=SC1091
|
|
||||||
source venv/bin/activate
|
|
||||||
|
|
||||||
# Run the Python script
|
|
||||||
python tarc/main.py "$@"
|
|
||||||
|
|
||||||
# Deactivate the virtual environment
|
|
||||||
deactivate
|
|
@ -0,0 +1,5 @@
|
|||||||
|
"""
|
||||||
|
tarc - Manage BT archives
|
||||||
|
"""
|
||||||
|
|
||||||
|
from .main import main
|
45
tarc/main.py
45
tarc/main.py
@ -154,27 +154,32 @@ def list_clients(conn):
|
|||||||
return rows
|
return rows
|
||||||
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description="Manage BT archives", prog="tarc")
|
def main():
|
||||||
subparsers = parser.add_subparsers(
|
"""
|
||||||
|
Entrypoint of the program.
|
||||||
|
"""
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(description="Manage BT archives", prog="tarc")
|
||||||
|
subparsers = parser.add_subparsers(
|
||||||
dest="command", required=True, help="Available commands"
|
dest="command", required=True, help="Available commands"
|
||||||
)
|
)
|
||||||
|
|
||||||
scan_parser = subparsers.add_parser("scan", help="Scan command")
|
scan_parser = subparsers.add_parser("scan", help="Scan command")
|
||||||
scan_parser.add_argument("--debug", action="store_true", help="Enable debug mode")
|
scan_parser.add_argument("--debug", action="store_true", help="Enable debug mode")
|
||||||
scan_parser.add_argument(
|
scan_parser.add_argument(
|
||||||
"--confirm-add", action="store_true", help="Confirm adding a new client"
|
"--confirm-add", action="store_true", help="Confirm adding a new client"
|
||||||
)
|
)
|
||||||
scan_parser.add_argument("-n", "--name", help="Name of client")
|
scan_parser.add_argument("-n", "--name", help="Name of client")
|
||||||
scan_parser.add_argument("-d", "--directory", help="Directory to scan")
|
scan_parser.add_argument("-d", "--directory", help="Directory to scan")
|
||||||
scan_parser.add_argument("-t", "--type", help="Scan type")
|
scan_parser.add_argument("-t", "--type", help="Scan type")
|
||||||
scan_parser.add_argument("-e", "--endpoint", help="Endpoint URL")
|
scan_parser.add_argument("-e", "--endpoint", help="Endpoint URL")
|
||||||
scan_parser.add_argument("-u", "--username", help="Username")
|
scan_parser.add_argument("-u", "--username", help="Username")
|
||||||
scan_parser.add_argument("-p", "--password", help="Password")
|
scan_parser.add_argument("-p", "--password", help="Password")
|
||||||
scan_parser.add_argument("-s", "--storage", help="Path of sqlite3 database")
|
scan_parser.add_argument("-s", "--storage", help="Path of sqlite3 database")
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if args.command == "scan":
|
if args.command == "scan":
|
||||||
if args.storage is None:
|
if args.storage is None:
|
||||||
STORAGE = os.path.expanduser("~/.tarch.db")
|
STORAGE = os.path.expanduser("~/.tarch.db")
|
||||||
else:
|
else:
|
||||||
@ -255,8 +260,14 @@ if args.command == "scan":
|
|||||||
print(f"[DEBUG]: Tracker {repr(elem)}")
|
print(f"[DEBUG]: Tracker {repr(elem)}")
|
||||||
print("\n", end="")
|
print("\n", end="")
|
||||||
else:
|
else:
|
||||||
print(f'[ERROR]: Multiple clients ({len(clients)}) using "{args.endpoint}"')
|
print(
|
||||||
|
f'[ERROR]: Multiple clients ({len(clients)}) using "{args.endpoint}"'
|
||||||
|
)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
print("[ERROR]: Must specify directory OR client endpoint")
|
print("[ERROR]: Must specify directory OR client endpoint")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
Loading…
Reference in New Issue
Block a user