From b509495c5fa9bcffc0e8c8c77ea55802e087f9b5 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Mon, 30 Mar 2020 21:43:05 -0400 Subject: [PATCH] Restructure to a more normal module-like structure --- .gitignore | 2 ++ bin/doorUpdater | 5 ++++ bin/events | 5 ++++ bin/sqlExport | 5 ++++ bin/ucsAccounts | 5 ++++ {lib => memberPlumbing}/MembershipWorks.py | 0 memberPlumbing/__init__.py | 0 common.py => memberPlumbing/common.py | 29 +++++++++---------- .../doorUpdater.py | 6 ++-- events.py => memberPlumbing/events.py | 4 +-- {lib => memberPlumbing}/hid/Credential.py | 0 {lib => memberPlumbing}/hid/DoorController.py | 0 memberPlumbing/hid/__init__.py | 0 {lib => memberPlumbing}/mw_models.py | 0 sqlExport.py => memberPlumbing/sqlExport.py | 4 +-- .../ucsAccounts.py | 2 +- pyproject.toml | 1 + systemd/doorUpdater.service | 2 +- systemd/hidEvents.service | 12 ++++++++ systemd/hidEvents.timer | 9 ++++++ systemd/membershipworksSQL.service | 2 +- 21 files changed, 67 insertions(+), 26 deletions(-) create mode 100755 bin/doorUpdater create mode 100755 bin/events create mode 100755 bin/sqlExport create mode 100755 bin/ucsAccounts rename {lib => memberPlumbing}/MembershipWorks.py (100%) create mode 100644 memberPlumbing/__init__.py rename common.py => memberPlumbing/common.py (51%) rename doorUpdater.py => memberPlumbing/doorUpdater.py (98%) rename events.py => memberPlumbing/events.py (97%) rename {lib => memberPlumbing}/hid/Credential.py (100%) rename {lib => memberPlumbing}/hid/DoorController.py (100%) create mode 100644 memberPlumbing/hid/__init__.py rename {lib => memberPlumbing}/mw_models.py (100%) rename sqlExport.py => memberPlumbing/sqlExport.py (95%) rename ucsAccounts.py => memberPlumbing/ucsAccounts.py (98%) create mode 100644 systemd/hidEvents.service create mode 100644 systemd/hidEvents.timer diff --git a/.gitignore b/.gitignore index b31a110..7f57a90 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ __pycache__/ /passwords.py +/passwords.yaml +/venv/ diff --git a/bin/doorUpdater b/bin/doorUpdater new file mode 100755 index 0000000..b186983 --- /dev/null +++ b/bin/doorUpdater @@ -0,0 +1,5 @@ +#!/usr/bin/env python3 + +from memberPlumbing import doorUpdater + +doorUpdater.main() diff --git a/bin/events b/bin/events new file mode 100755 index 0000000..84daf11 --- /dev/null +++ b/bin/events @@ -0,0 +1,5 @@ +#!/usr/bin/env python3 + +from memberPlumbing import events + +events.main() diff --git a/bin/sqlExport b/bin/sqlExport new file mode 100755 index 0000000..3ad0165 --- /dev/null +++ b/bin/sqlExport @@ -0,0 +1,5 @@ +#!/usr/bin/env python3 + +from memberPlumbing import sqlExport + +sqlExport.main() diff --git a/bin/ucsAccounts b/bin/ucsAccounts new file mode 100755 index 0000000..6802f0d --- /dev/null +++ b/bin/ucsAccounts @@ -0,0 +1,5 @@ +#!/usr/bin/env python3 + +from memberPlumbing import ucsAccounts + +ucsAccounts.main() diff --git a/lib/MembershipWorks.py b/memberPlumbing/MembershipWorks.py similarity index 100% rename from lib/MembershipWorks.py rename to memberPlumbing/MembershipWorks.py diff --git a/memberPlumbing/__init__.py b/memberPlumbing/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/common.py b/memberPlumbing/common.py similarity index 51% rename from common.py rename to memberPlumbing/common.py index c9f5d64..c43fc4f 100644 --- a/common.py +++ b/memberPlumbing/common.py @@ -1,22 +1,19 @@ -import os - from ruamel.yaml import YAML -from lib.hid.DoorController import DoorController -from lib.MembershipWorks import MembershipWorks -from passwords import ( - DOOR_PASSWORD, - DOOR_USERNAME, - MEMBERSHIPWORKS_PASSWORD, - MEMBERSHIPWORKS_USERNAME, -) +from .hid.DoorController import DoorController +from .MembershipWorks import MembershipWorks -try: - with open(os.path.dirname(os.path.abspath(__file__)) + "/config.yaml") as f: - config = YAML().load(f) -except NameError: - with open("config.yaml") as f: - config = YAML().load(f) +with open("passwords.yaml") as f: + passwords = YAML().load(f) + +DOOR_USERNAME = passwords["DOOR_USERNAME"] +DOOR_PASSWORD = passwords["DOOR_PASSWORD"] + +MEMBERSHIPWORKS_USERNAME = passwords["MEMBERSHIPWORKS_USERNAME"] +MEMBERSHIPWORKS_PASSWORD = passwords["MEMBERSHIPWORKS_PASSWORD"] + +with open("config.yaml") as f: + config = YAML().load(f) doors = { doorName: DoorController( diff --git a/doorUpdater.py b/memberPlumbing/doorUpdater.py similarity index 98% rename from doorUpdater.py rename to memberPlumbing/doorUpdater.py index e8a19b9..e09af79 100755 --- a/doorUpdater.py +++ b/memberPlumbing/doorUpdater.py @@ -2,9 +2,9 @@ import copy -from common import doors, doorSpecificSchedules, memberLevels, membershipworks -from lib.hid.Credential import Credential -from lib.hid.DoorController import ROOT, E +from .common import doors, doorSpecificSchedules, memberLevels, membershipworks +from .hid.Credential import Credential +from .hid.DoorController import ROOT, E class Member: diff --git a/events.py b/memberPlumbing/events.py similarity index 97% rename from events.py rename to memberPlumbing/events.py index 89accb6..d180a65 100755 --- a/events.py +++ b/memberPlumbing/events.py @@ -5,8 +5,8 @@ import re import requests from lxml import etree -from common import doors -from lib.hid.DoorController import E, E_plain +from .common import doors +from .hid.DoorController import E, E_plain def getStrings(door): diff --git a/lib/hid/Credential.py b/memberPlumbing/hid/Credential.py similarity index 100% rename from lib/hid/Credential.py rename to memberPlumbing/hid/Credential.py diff --git a/lib/hid/DoorController.py b/memberPlumbing/hid/DoorController.py similarity index 100% rename from lib/hid/DoorController.py rename to memberPlumbing/hid/DoorController.py diff --git a/memberPlumbing/hid/__init__.py b/memberPlumbing/hid/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/lib/mw_models.py b/memberPlumbing/mw_models.py similarity index 100% rename from lib/mw_models.py rename to memberPlumbing/mw_models.py diff --git a/sqlExport.py b/memberPlumbing/sqlExport.py similarity index 95% rename from sqlExport.py rename to memberPlumbing/sqlExport.py index 5b45d10..ade47f3 100755 --- a/sqlExport.py +++ b/memberPlumbing/sqlExport.py @@ -2,8 +2,8 @@ from datetime import datetime -from common import membershipworks -from lib.mw_models import Label, Member, MemberLabel, Transaction, database +from .common import membershipworks +from .mw_models import Label, Member, MemberLabel, Transaction, database @database.atomic() diff --git a/ucsAccounts.py b/memberPlumbing/ucsAccounts.py similarity index 98% rename from ucsAccounts.py rename to memberPlumbing/ucsAccounts.py index bbc4db7..84911c2 100755 --- a/ucsAccounts.py +++ b/memberPlumbing/ucsAccounts.py @@ -4,7 +4,7 @@ import re import string import subprocess -from common import membershipworks +from .common import membershipworks LDAP_BASE = "cn=users,dc=sawtooth,dc=claremontmakerspace,dc=org" GROUP_BASE = "cn=groups,dc=sawtooth,dc=claremontmakerspace,dc=org" diff --git a/pyproject.toml b/pyproject.toml index a29c725..bc988c9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,6 +9,7 @@ line_length = 88 [tool.poetry] name = "memberPlumbing" +packages = [{ include = "memberPlumbing" }] version = "0.1.0" description = "" authors = ["Adam Goldsmith "] diff --git a/systemd/doorUpdater.service b/systemd/doorUpdater.service index 7fab175..b2f95a9 100644 --- a/systemd/doorUpdater.service +++ b/systemd/doorUpdater.service @@ -7,4 +7,4 @@ User=adam Type=oneshot TimeoutStartSec=600 WorkingDirectory=/home/adam/memberPlumbing/ -ExecStart=/usr/bin/python3 -u /home/adam/memberPlumbing/doorUpdater.py +ExecStart=/usr/bin/python3 -u /home/adam/.poetry/bin/poetry run /home/adam/memberPlumbing/bin/doorUpdater diff --git a/systemd/hidEvents.service b/systemd/hidEvents.service new file mode 100644 index 0000000..08268cb --- /dev/null +++ b/systemd/hidEvents.service @@ -0,0 +1,12 @@ +[Unit] +Description=Pull events from door controllers into local database +OnFailure=status-email-admin@%n.service +After=mariadb.service +Requires=mariadb.service + +[Service] +User=adam +Type=oneshot +TimeoutStartSec=600 +WorkingDirectory=/home/adam/memberPlumbing/ +ExecStart=/usr/bin/python3 -u /home/adam/.poetry/bin/poetry run /home/adam/memberPlumbing/bin/hidEvents diff --git a/systemd/hidEvents.timer b/systemd/hidEvents.timer new file mode 100644 index 0000000..99212e1 --- /dev/null +++ b/systemd/hidEvents.timer @@ -0,0 +1,9 @@ +[Unit] +Description=Hourly door controller events sync + +[Timer] +OnCalendar=hourly +Persistent=true + +[Install] +WantedBy=timers.target diff --git a/systemd/membershipworksSQL.service b/systemd/membershipworksSQL.service index ff0b003..168b4a9 100644 --- a/systemd/membershipworksSQL.service +++ b/systemd/membershipworksSQL.service @@ -9,4 +9,4 @@ User=adam Type=oneshot TimeoutStartSec=600 WorkingDirectory=/home/adam/memberPlumbing/ -ExecStart=/usr/bin/python3 -u /home/adam/memberPlumbing/sqlExport.py +ExecStart=/usr/bin/python3 -u /home/adam/.poetry/bin/poetry run /home/adam/memberPlumbing/bin/sqlExport