From 006c010907a64e33c556f141dde1bc79b57cbab8 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Tue, 29 Aug 2023 23:00:03 +0200 Subject: [PATCH] `scripts` -> `subcommands`, add logic to `lib` --- dibbler/{ => lib}/barcode_helpers.py | 0 dibbler/{ => lib}/helpers.py | 2 +- dibbler/{ => lib}/printer_helpers.py | 0 dibbler/{ => lib}/statistikkHelpers.py | 4 ++-- dibbler/main.py | 8 ++++---- dibbler/menus/__init__.py | 9 --------- dibbler/menus/helpermenus.py | 12 +++++------- dibbler/menus/mainmenu.py | 3 ++- dibbler/menus/miscmenus.py | 2 +- dibbler/menus/printermenu.py | 2 +- dibbler/menus/stats.py | 4 ++-- dibbler/{scripts => subcommands}/__init__.py | 0 dibbler/{text_based.py => subcommands/loop.py} | 6 +++--- dibbler/{scripts => subcommands}/makedb.py | 0 dibbler/{scripts => subcommands}/slabbedasker.py | 0 dibbler/{scripts => subcommands}/statistikk.py | 2 +- 16 files changed, 22 insertions(+), 32 deletions(-) rename dibbler/{ => lib}/barcode_helpers.py (100%) rename dibbler/{ => lib}/helpers.py (99%) rename dibbler/{ => lib}/printer_helpers.py (100%) rename dibbler/{ => lib}/statistikkHelpers.py (99%) rename dibbler/{scripts => subcommands}/__init__.py (100%) rename dibbler/{text_based.py => subcommands/loop.py} (96%) rename dibbler/{scripts => subcommands}/makedb.py (100%) rename dibbler/{scripts => subcommands}/slabbedasker.py (100%) rename dibbler/{scripts => subcommands}/statistikk.py (99%) diff --git a/dibbler/barcode_helpers.py b/dibbler/lib/barcode_helpers.py similarity index 100% rename from dibbler/barcode_helpers.py rename to dibbler/lib/barcode_helpers.py diff --git a/dibbler/helpers.py b/dibbler/lib/helpers.py similarity index 99% rename from dibbler/helpers.py rename to dibbler/lib/helpers.py index 2d581c0..de21bdf 100644 --- a/dibbler/helpers.py +++ b/dibbler/lib/helpers.py @@ -5,7 +5,7 @@ import signal from sqlalchemy import or_, and_ -from .models import User, Product +from ..models import User, Product def search_user(string, session, ignorethisflag=None): string = string.lower() diff --git a/dibbler/printer_helpers.py b/dibbler/lib/printer_helpers.py similarity index 100% rename from dibbler/printer_helpers.py rename to dibbler/lib/printer_helpers.py diff --git a/dibbler/statistikkHelpers.py b/dibbler/lib/statistikkHelpers.py similarity index 99% rename from dibbler/statistikkHelpers.py rename to dibbler/lib/statistikkHelpers.py index eb2c731..1d5811c 100644 --- a/dibbler/statistikkHelpers.py +++ b/dibbler/lib/statistikkHelpers.py @@ -5,8 +5,8 @@ import datetime from collections import defaultdict from .helpers import * -from .models import Transaction -from .db import Session +from ..models import Transaction +from ..db import Session def getUser(): while 1: diff --git a/dibbler/main.py b/dibbler/main.py index 105550b..69c098e 100644 --- a/dibbler/main.py +++ b/dibbler/main.py @@ -35,15 +35,15 @@ def main(): config.read(args.config) if args.subcommand == 'loop': - import dibbler.text_based as text_based - text_based.main() + import dibbler.subcommands.loop as loop + loop.main() elif args.subcommand == 'create-db': - import dibbler.scripts.makedb as makedb + import dibbler.subcommands.makedb as makedb makedb.main() elif args.subcommand == 'slabbedasker': - import dibbler.scripts.slabbedasker as slabbedasker + import dibbler.subcommands.slabbedasker as slabbedasker slabbedasker.main() diff --git a/dibbler/menus/__init__.py b/dibbler/menus/__init__.py index 20b884c..6926815 100644 --- a/dibbler/menus/__init__.py +++ b/dibbler/menus/__init__.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from .addstock import AddStockMenu from .buymenu import BuyMenu from .editing import ( @@ -28,10 +26,3 @@ from .stats import ( BalanceMenu, LoggedStatisticsMenu ) - -exit_commands = ['exit', 'abort', 'quit', 'bye', 'eat flaming death', 'q'] -help_commands = ['help', '?'] -context_commands = ['what', '??'] -local_help_commands = ['help!', '???'] -faq_commands = ['faq'] -restart_commands = ['restart'] \ No newline at end of file diff --git a/dibbler/menus/helpermenus.py b/dibbler/menus/helpermenus.py index 4e793f9..15ba17e 100644 --- a/dibbler/menus/helpermenus.py +++ b/dibbler/menus/helpermenus.py @@ -7,19 +7,17 @@ from select import select from dibbler.db import Session from dibbler.models import User -from dibbler.helpers import ( +from dibbler.lib.helpers import ( search_user, search_product, guess_data_type, argmax, ) -from . import ( - context_commands, - local_help_commands, - help_commands, - exit_commands, -) +exit_commands = ['exit', 'abort', 'quit', 'bye', 'eat flaming death', 'q'] +help_commands = ['help', '?'] +context_commands = ['what', '??'] +local_help_commands = ['help!', '???'] class ExitMenu(Exception): diff --git a/dibbler/menus/mainmenu.py b/dibbler/menus/mainmenu.py index f6181bf..e658e16 100644 --- a/dibbler/menus/mainmenu.py +++ b/dibbler/menus/mainmenu.py @@ -6,11 +6,12 @@ import sys from dibbler.db import Session -from . import faq_commands, restart_commands from .buymenu import BuyMenu from .faq import FAQMenu from .helpermenus import Menu +faq_commands = ['faq'] +restart_commands = ['restart'] def restart(): # Does not work if the script is not executable, or if it was diff --git a/dibbler/menus/miscmenus.py b/dibbler/menus/miscmenus.py index 67a0f89..60d5a31 100644 --- a/dibbler/menus/miscmenus.py +++ b/dibbler/menus/miscmenus.py @@ -2,7 +2,7 @@ import sqlalchemy from dibbler.conf import config from dibbler.models import Transaction, Product, User -from dibbler.helpers import less +from dibbler.lib.helpers import less from .helpermenus import Menu, Selector diff --git a/dibbler/menus/printermenu.py b/dibbler/menus/printermenu.py index 225aebb..d5ec4c2 100644 --- a/dibbler/menus/printermenu.py +++ b/dibbler/menus/printermenu.py @@ -2,7 +2,7 @@ import re from dibbler.conf import config from dibbler.models import Product, User -from dibbler.printer_helpers import print_bar_code, print_name_label +from dibbler.lib.printer_helpers import print_bar_code, print_name_label from .helpermenus import Menu diff --git a/dibbler/menus/stats.py b/dibbler/menus/stats.py index 9ca6526..7548079 100644 --- a/dibbler/menus/stats.py +++ b/dibbler/menus/stats.py @@ -1,8 +1,8 @@ from sqlalchemy import desc, func -from dibbler.helpers import less +from dibbler.lib.helpers import less from dibbler.models import PurchaseEntry, Product, User -from dibbler.statistikkHelpers import statisticsTextOnly +from dibbler.lib.statistikkHelpers import statisticsTextOnly from .helpermenus import Menu diff --git a/dibbler/scripts/__init__.py b/dibbler/subcommands/__init__.py similarity index 100% rename from dibbler/scripts/__init__.py rename to dibbler/subcommands/__init__.py diff --git a/dibbler/text_based.py b/dibbler/subcommands/loop.py similarity index 96% rename from dibbler/text_based.py rename to dibbler/subcommands/loop.py index b0d5099..68deeb7 100755 --- a/dibbler/text_based.py +++ b/dibbler/subcommands/loop.py @@ -5,9 +5,9 @@ import random import sys import traceback -from .conf import config -from .helpers import * -from .menus import * +from ..conf import config +from ..lib.helpers import * +from ..menus import * random.seed() diff --git a/dibbler/scripts/makedb.py b/dibbler/subcommands/makedb.py similarity index 100% rename from dibbler/scripts/makedb.py rename to dibbler/subcommands/makedb.py diff --git a/dibbler/scripts/slabbedasker.py b/dibbler/subcommands/slabbedasker.py similarity index 100% rename from dibbler/scripts/slabbedasker.py rename to dibbler/subcommands/slabbedasker.py diff --git a/dibbler/scripts/statistikk.py b/dibbler/subcommands/statistikk.py similarity index 99% rename from dibbler/scripts/statistikk.py rename to dibbler/subcommands/statistikk.py index f593ead..aaaf429 100644 --- a/dibbler/scripts/statistikk.py +++ b/dibbler/subcommands/statistikk.py @@ -4,7 +4,7 @@ import matplotlib.pyplot as plt import matplotlib.dates as mdates -from dibbler.statistikkHelpers import * +from dibbler.lib.statistikkHelpers import * def getInputType(): inp = 0