From 44d012b3fd8127164b374d723be7b6ccd62dca33 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Fri, 19 Oct 2018 20:31:49 -0500 Subject: [PATCH 01/51] Update `release` task to use twine for upload --- tasks.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tasks.py b/tasks.py index 09eca73..24f3876 100644 --- a/tasks.py +++ b/tasks.py @@ -26,15 +26,21 @@ Tasks for 'rattail-tempmon' package from __future__ import unicode_literals, absolute_import +import os import shutil from invoke import task +here = os.path.abspath(os.path.dirname(__file__)) +exec(open(os.path.join(here, 'rattail_tempmon', '_version.py')).read()) + + @task def release(ctx): """ Release a new version of `rattail-tempmon` """ shutil.rmtree('rattail_tempmon.egg-info') - ctx.run('python setup.py sdist --formats=gztar upload') + ctx.run('python setup.py sdist --formats=gztar') + ctx.run('twine upload dist/rattail-tempmon-{}.tar.gz'.format(__version__)) From 1f8507508ab182cb079b2fd44f04d8d440c99f5b Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sat, 20 Oct 2018 04:17:42 -0500 Subject: [PATCH 02/51] Make dummy probe use tighter pattern for random readings to make for a more reasonable-looking graph --- rattail_tempmon/client.py | 13 ++++++++++++- rattail_tempmon/db/model.py | 11 +++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/rattail_tempmon/client.py b/rattail_tempmon/client.py index 2b154cb..ffcc721 100644 --- a/rattail_tempmon/client.py +++ b/rattail_tempmon/client.py @@ -181,7 +181,18 @@ class TempmonClient(Daemon): return therm_file.readlines() def random_temp(self, probe): - temp = random.uniform(probe.critical_temp_min - 5, probe.critical_temp_max + 5) + last_reading = probe.last_reading() + if last_reading: + volatility = 2 + # try to keep somewhat of a tight pattern, so graphs look reasonable + last_degrees = float(last_reading.degrees_f) + temp = random.uniform(last_degrees - volatility * 3, last_degrees + volatility * 3) + if temp > (probe.critical_temp_max + volatility * 2): + temp -= volatility + elif temp < (probe.critical_temp_min - volatility * 2): + temp += volatility + else: + temp = random.uniform(probe.critical_temp_min - 5, probe.critical_temp_max + 5) return round(temp, 4) diff --git a/rattail_tempmon/db/model.py b/rattail_tempmon/db/model.py index 4abbd29..181f064 100644 --- a/rattail_tempmon/db/model.py +++ b/rattail_tempmon/db/model.py @@ -297,6 +297,16 @@ class Probe(Base): def __str__(self): return self.description + def last_reading(self): + """ + Returns the reading which was taken most recently for this probe. + """ + session = orm.object_session(self) + return session.query(Reading)\ + .filter(Reading.probe == self)\ + .order_by(Reading.taken.desc())\ + .first() + def start_status(self, status, time): """ Update the "started" timestamp field for the given status. This is @@ -413,6 +423,7 @@ class Reading(Base): """, backref=orm.backref( 'readings', + order_by='Reading.taken', cascade='all, delete-orphan')) taken = sa.Column(sa.DateTime(), nullable=False, default=datetime.datetime.utcnow) From 30f0fe0a84e62a89d2e910b57cdae981c61de9cf Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 23 Oct 2018 10:25:08 -0500 Subject: [PATCH 03/51] Add "default" probe timeout logic for server readings check this way we don't have to set those timeouts on every single probe --- rattail_tempmon/server.py | 15 ++++++- rattail_tempmon/settings.py | 88 +++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 rattail_tempmon/settings.py diff --git a/rattail_tempmon/server.py b/rattail_tempmon/server.py index 4c290bd..f416cee 100644 --- a/rattail_tempmon/server.py +++ b/rattail_tempmon/server.py @@ -229,8 +229,19 @@ class TempmonServerDaemon(Daemon): return # delay even the first email, until configured threshold is reached - timeout = probe.timeout_for_status(status) or 0 - timeout = datetime.timedelta(minutes=timeout) + timeout = probe.timeout_for_status(status) + if timeout is None: + if status == self.enum.TEMPMON_PROBE_STATUS_CRITICAL_HIGH_TEMP: + timeout = self.config.getint('rattail_tempmon', 'probe.default.critical_max_timeout') + elif status == self.enum.TEMPMON_PROBE_STATUS_HIGH_TEMP: + timeout = self.config.getint('rattail_tempmon', 'probe.default.good_max_timeout') + elif status == self.enum.TEMPMON_PROBE_STATUS_LOW_TEMP: + timeout = self.config.getint('rattail_tempmon', 'probe.default.good_min_timeout') + elif status == self.enum.TEMPMON_PROBE_STATUS_CRITICAL_LOW_TEMP: + timeout = self.config.getint('rattail_tempmon', 'probe.default.critical_min_timeout') + elif status == self.enum.TEMPMON_PROBE_STATUS_ERROR: + timeout = self.config.getint('rattail_tempmon', 'probe.default.error_timeout') + timeout = datetime.timedelta(minutes=timeout or 0) started = probe.status_started(status) or probe.status_changed if (self.now - started) <= timeout: return diff --git a/rattail_tempmon/settings.py b/rattail_tempmon/settings.py new file mode 100644 index 0000000..18172bb --- /dev/null +++ b/rattail_tempmon/settings.py @@ -0,0 +1,88 @@ +# -*- coding: utf-8; -*- +################################################################################ +# +# Rattail -- Retail Software Framework +# Copyright © 2010-2018 Lance Edgar +# +# This file is part of Rattail. +# +# Rattail is free software: you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation, either version 3 of the License, or (at your option) any later +# version. +# +# Rattail is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# Rattail. If not, see . +# +################################################################################ +""" +Rattail Tempmon Settings +""" + +from __future__ import unicode_literals, absolute_import + +from rattail.settings import Setting + + +############################## +# TempMon +############################## + +class rattail_tempmon_probe_default_critical_max_timeout(Setting): + """ + Default value to be used as Critical High Timeout value, for any probe + which does not have this timeout defined. + """ + group = "TempMon" + namespace = 'rattail_tempmon' + name = 'probe.default.critical_max_timeout' + data_type = int + + +class rattail_tempmon_probe_default_critical_min_timeout(Setting): + """ + Default value to be used as Critical Low Timeout value, for any probe which + does not have this timeout defined. + """ + group = "TempMon" + namespace = 'rattail_tempmon' + name = 'probe.default.critical_min_timeout' + data_type = int + + +class rattail_tempmon_probe_default_error_timeout(Setting): + """ + Default value to be used as Error Timeout value, for any probe which does + not have this timeout defined. + """ + group = "TempMon" + namespace = 'rattail_tempmon' + name = 'probe.default.error_timeout' + data_type = int + + +class rattail_tempmon_probe_default_good_max_timeout(Setting): + """ + Default value to be used as High Timeout value, for any probe which does + not have this timeout defined. + """ + group = "TempMon" + namespace = 'rattail_tempmon' + name = 'probe.default.good_max_timeout' + data_type = int + + +class rattail_tempmon_probe_default_good_min_timeout(Setting): + """ + Default value to be used as Low Timeout value, for any probe which does not + have this timeout defined. + """ + group = "TempMon" + namespace = 'rattail_tempmon' + name = 'probe.default.good_min_timeout' + data_type = int From b644818eef7ea143ed00db651a463c3d424a6d79 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 23 Oct 2018 17:38:38 -0500 Subject: [PATCH 04/51] Don't mark client as online unless it's also enabled --- rattail_tempmon/client.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rattail_tempmon/client.py b/rattail_tempmon/client.py index ffcc721..9fde68a 100644 --- a/rattail_tempmon/client.py +++ b/rattail_tempmon/client.py @@ -91,11 +91,11 @@ class TempmonClient(Daemon): if client.enabled: for probe in client.enabled_probes(): self.take_reading(session, probe) - session.flush() + session.flush() - # one more thing, make sure our client appears "online" - if not client.online: - client.online = True + # one more thing, make sure our client appears "online" + if not client.online: + client.online = True except Exception as error: log_error = True From 8220082359abc48e3e2008477b8f6002c5c16ae3 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 23 Oct 2018 17:39:18 -0500 Subject: [PATCH 05/51] Add try/catch for client's "read temp" logic this can isolate an error for a certain probe, so that other probes can go ahead and take their readings during each client run. that way only the bad one is marked as "error" status by the server --- rattail_tempmon/client.py | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/rattail_tempmon/client.py b/rattail_tempmon/client.py index 9fde68a..f8694b5 100644 --- a/rattail_tempmon/client.py +++ b/rattail_tempmon/client.py @@ -137,22 +137,28 @@ class TempmonClient(Daemon): Take a single reading and add to Rattail database. """ reading = tempmon.Reading() - reading.degrees_f = self.read_temp(probe) - # a reading of 185.0 °F indicates some sort of power issue. when this - # happens we log an error (which sends basic email) but do not record - # the temperature. that way the server doesn't see the 185.0 reading - # and send out a "false alarm" about the temperature being too high. - # https://www.controlbyweb.com/support/faq/temp-sensor-reading-error.html - if reading.degrees_f == 185.0: - log.error("got reading of 185.0 from probe: %s", probe.description) + try: + reading.degrees_f = self.read_temp(probe) - else: # we have a good reading - reading.client = probe.client - reading.probe = probe - reading.taken = datetime.datetime.utcnow() - session.add(reading) - return reading + except: + log.exception("Failed to read temperature (but will keep trying) for probe: %s", probe) + + else: + # a reading of 185.0 °F indicates some sort of power issue. when this + # happens we log an error (which sends basic email) but do not record + # the temperature. that way the server doesn't see the 185.0 reading + # and send out a "false alarm" about the temperature being too high. + # https://www.controlbyweb.com/support/faq/temp-sensor-reading-error.html + if reading.degrees_f == 185.0: + log.error("got reading of 185.0 from probe: %s", probe.description) + + else: # we have a good reading + reading.client = probe.client + reading.probe = probe + reading.taken = datetime.datetime.utcnow() + session.add(reading) + return reading def read_temp(self, probe): """ From ad3e647160287ae2a9735fb6ff9c83c00ebf1710 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Wed, 24 Oct 2018 19:20:44 -0500 Subject: [PATCH 06/51] Update changelog --- CHANGES.rst | 12 ++++++++++++ rattail_tempmon/_version.py | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 99b430e..f763e4f 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -2,6 +2,18 @@ CHANGELOG ========= +0.2.1 (2018-10-24) +------------------ + +* Make dummy probe use tighter pattern for random readings. + +* Add "default" probe timeout logic for server readings check. + +* Don't mark client as online unless it's also enabled. + +* Add try/catch for client's "read temp" logic. + + 0.2.0 (2018-10-19) ------------------ diff --git a/rattail_tempmon/_version.py b/rattail_tempmon/_version.py index 08b390b..53d3efe 100644 --- a/rattail_tempmon/_version.py +++ b/rattail_tempmon/_version.py @@ -1,3 +1,3 @@ # -*- coding: utf-8; -*- -__version__ = '0.2.0' +__version__ = '0.2.1' From 7212b07504e3b57b0fd5f4d91fdd9965167ae693 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Thu, 25 Oct 2018 09:00:17 -0500 Subject: [PATCH 07/51] Fix bug when sending certain emails while checking probe readings use common method to add more context for email template --- rattail_tempmon/server.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rattail_tempmon/server.py b/rattail_tempmon/server.py index f416cee..af4039e 100644 --- a/rattail_tempmon/server.py +++ b/rattail_tempmon/server.py @@ -208,13 +208,13 @@ class TempmonServerDaemon(Daemon): and prev_status in (self.enum.TEMPMON_PROBE_STATUS_CRITICAL_HIGH_TEMP, self.enum.TEMPMON_PROBE_STATUS_CRITICAL_TEMP) and prev_alert_sent): - send_email(self.config, 'tempmon_high_temp', data) + self.send_email(status, 'tempmon_high_temp', data) probe.status_alert_sent = self.now return # send email when things go back to normal (i.e. from any other status) if status == self.enum.TEMPMON_PROBE_STATUS_GOOD_TEMP and prev_alert_sent: - send_email(self.config, 'tempmon_good_temp', data) + self.send_email(status, 'tempmon_good_temp', data) probe.status_alert_sent = self.now return From 3b14a0b28855a80d36f55f01057f403d47757436 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Thu, 25 Oct 2018 09:01:19 -0500 Subject: [PATCH 08/51] Update changelog --- CHANGES.rst | 6 ++++++ rattail_tempmon/_version.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index f763e4f..aecca68 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -2,6 +2,12 @@ CHANGELOG ========= +0.2.2 (2018-10-25) +------------------ + +* Fix bug when sending certain emails while checking probe readings. + + 0.2.1 (2018-10-24) ------------------ diff --git a/rattail_tempmon/_version.py b/rattail_tempmon/_version.py index 53d3efe..a5342bb 100644 --- a/rattail_tempmon/_version.py +++ b/rattail_tempmon/_version.py @@ -1,3 +1,3 @@ # -*- coding: utf-8; -*- -__version__ = '0.2.1' +__version__ = '0.2.2' From c45baaed5e009117aaab18d8872b2e60b1e0bcac Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Wed, 31 Oct 2018 17:20:35 -0500 Subject: [PATCH 09/51] Add more template context for email previews just to keep things from breaking outright..although this hasn't been given much attention still, numbers may not make total sense --- rattail_tempmon/emails.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/rattail_tempmon/emails.py b/rattail_tempmon/emails.py index 11256c8..6a18dca 100644 --- a/rattail_tempmon/emails.py +++ b/rattail_tempmon/emails.py @@ -40,17 +40,22 @@ class TempmonBase(object): def sample_data(self, request): now = localtime(self.config) - client = model.TempmonClient(config_key='testclient', hostname='testclient') - probe = model.TempmonProbe(config_key='testprobe', description="Test Probe") + client = tempmon.Client(config_key='testclient', hostname='testclient') + probe = tempmon.Probe(config_key='testprobe', description="Test Probe", + good_max_timeout=45) client.probes.append(probe) return { 'client': client, 'probe': probe, + 'probe_url': '#', 'status': self.enum.TEMPMON_PROBE_STATUS[self.enum.TEMPMON_PROBE_STATUS_ERROR], - 'reading': model.TempmonReading(), + 'reading': tempmon.Reading(), 'taken': now, 'now': now, - 'probe_url': '#', + 'status_since': now.strftime('%I:%M %p'), + 'status_since_delta': 'now', + 'recent_minutes': 90, + 'recent_readings': [], } From f31a0c4c22cd7116913c1906b1f958d2c31d9b12 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Fri, 25 Jan 2019 19:33:49 -0600 Subject: [PATCH 10/51] Convert `enabled` for Client, Probe to use datetime instead of boolean value is null if disabled, else timestamp of when it was last enabled --- .../fd1df160539a_make_enabled_datetime.py | 80 +++++++++++++++++++ rattail_tempmon/db/model.py | 18 +++-- rattail_tempmon/problems.py | 6 +- rattail_tempmon/server.py | 2 +- 4 files changed, 96 insertions(+), 10 deletions(-) create mode 100644 rattail_tempmon/db/alembic/versions/fd1df160539a_make_enabled_datetime.py diff --git a/rattail_tempmon/db/alembic/versions/fd1df160539a_make_enabled_datetime.py b/rattail_tempmon/db/alembic/versions/fd1df160539a_make_enabled_datetime.py new file mode 100644 index 0000000..1a327f9 --- /dev/null +++ b/rattail_tempmon/db/alembic/versions/fd1df160539a_make_enabled_datetime.py @@ -0,0 +1,80 @@ +# -*- coding: utf-8; -*- +"""make enabled datetime + +Revision ID: fd1df160539a +Revises: a2676d3dfc1e +Create Date: 2019-01-25 18:41:01.652823 + +""" + +from __future__ import unicode_literals, absolute_import + +# revision identifiers, used by Alembic. +revision = 'fd1df160539a' +down_revision = 'a2676d3dfc1e' +branch_labels = None +depends_on = None + +import datetime +from alembic import op +import sqlalchemy as sa +import rattail.db.types + + + +def upgrade(): + + now = datetime.datetime.utcnow() + + # client + op.add_column('client', sa.Column('new_enabled', sa.DateTime(), nullable=True)) + client = sa.sql.table('client', + sa.sql.column('enabled'), + sa.sql.column('new_enabled')) + op.execute(client.update()\ + .where(client.c.enabled == True)\ + .values({'new_enabled': now})) + op.drop_column('client', 'enabled') + op.alter_column('client', 'new_enabled', new_column_name='enabled') + + # probe + op.add_column('probe', sa.Column('new_enabled', sa.DateTime(), nullable=True)) + probe = sa.sql.table('probe', + sa.sql.column('enabled'), + sa.sql.column('new_enabled')) + op.execute(probe.update()\ + .where(probe.c.enabled == True)\ + .values({'new_enabled': now})) + op.drop_column('probe', 'enabled') + op.alter_column('probe', 'new_enabled', new_column_name='enabled') + + +def downgrade(): + + # probe + op.add_column('probe', sa.Column('old_enabled', sa.Boolean(), nullable=True)) + probe = sa.sql.table('probe', + sa.sql.column('enabled'), + sa.sql.column('old_enabled')) + op.execute(probe.update()\ + .where(probe.c.enabled != None)\ + .values({'old_enabled': True})) + op.execute(probe.update()\ + .where(probe.c.enabled == None)\ + .values({'old_enabled': False})) + op.drop_column('probe', 'enabled') + op.alter_column('probe', 'old_enabled', new_column_name='enabled', nullable=False) + + # client + op.add_column('client', sa.Column('old_enabled', sa.Boolean(), nullable=True)) + client = sa.sql.table('client', + sa.sql.column('enabled'), + sa.sql.column('old_enabled')) + op.execute(client.update()\ + .where(client.c.enabled != None)\ + .values({'old_enabled': True})) + op.execute(client.update()\ + .where(client.c.enabled == None)\ + .values({'old_enabled': False})) + op.drop_column('client', 'enabled') + op.alter_column('client', 'old_enabled', new_column_name='enabled', nullable=False) diff --git a/rattail_tempmon/db/model.py b/rattail_tempmon/db/model.py index 181f064..985de17 100644 --- a/rattail_tempmon/db/model.py +++ b/rattail_tempmon/db/model.py @@ -111,11 +111,11 @@ class Client(Base): Any arbitrary notes for the client. """) - enabled = sa.Column(sa.Boolean(), nullable=False, default=False, doc=""" - Whether the client should be considered enabled (active). If set, the - client will be expected to take readings (but only for "enabled" probes) - and the server will monitor them to ensure they are within the expected - range etc. + enabled = sa.Column(sa.DateTime(), nullable=True, doc=""" + This will either be the date/time when the client was most recently + enabled, or null if it is not currently enabled. If set, the client will + be expected to take readings (but only for "enabled" probes) and the server + will monitor them to ensure they are within the expected range etc. """) online = sa.Column(sa.Boolean(), nullable=False, default=False, doc=""" @@ -191,7 +191,13 @@ class Probe(Base): """) device_path = sa.Column(sa.String(length=255), nullable=True) - enabled = sa.Column(sa.Boolean(), nullable=False, default=True) + + enabled = sa.Column(sa.DateTime(), nullable=True, doc=""" + This will either be the date/time when the probe was most recently enabled, + or null if it is not currently enabled. If set, the client will be + expected to take readings for this probe, and the server will monitor them + to ensure they are within the expected range etc. + """) critical_temp_max = sa.Column(sa.Integer(), nullable=False, doc=""" Maximum high temperature; when a reading is greater than or equal to this diff --git a/rattail_tempmon/problems.py b/rattail_tempmon/problems.py index edb28af..087ceb1 100644 --- a/rattail_tempmon/problems.py +++ b/rattail_tempmon/problems.py @@ -37,13 +37,13 @@ def disabled_probes(config, progress=None): tempmon_session = TempmonSession() clients = tempmon_session.query(tempmon.Client)\ .filter(tempmon.Client.archived == False)\ - .filter(tempmon.Client.enabled == False)\ + .filter(tempmon.Client.enabled == None)\ .all() probes = tempmon_session.query(tempmon.Probe)\ .join(tempmon.Client)\ .filter(tempmon.Client.archived == False)\ - .filter(tempmon.Client.enabled == True)\ - .filter(tempmon.Probe.enabled == False)\ + .filter(tempmon.Client.enabled != None)\ + .filter(tempmon.Probe.enabled == None)\ .all() if clients or probes: send_email(config, 'tempmon_disabled_probes', { diff --git a/rattail_tempmon/server.py b/rattail_tempmon/server.py index af4039e..c63ed39 100644 --- a/rattail_tempmon/server.py +++ b/rattail_tempmon/server.py @@ -71,7 +71,7 @@ class TempmonServerDaemon(Daemon): try: clients = session.query(tempmon.Client)\ - .filter(tempmon.Client.enabled == True)\ + .filter(tempmon.Client.enabled != None)\ .filter(tempmon.Client.archived == False) for client in clients: self.check_readings_for_client(session, client) From cf27af81d4d89dda539124de66d9eb4d90879d07 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Fri, 25 Jan 2019 19:49:46 -0600 Subject: [PATCH 11/51] Modify tempmon server logic to take "unfair" time windows into account when a client or probe first are (re-)enabled, we can't expect to have readings within the time window we'd normally be checking. previously we'd get false alarms about "probe error status" etc. when this happened; hopefully no longer! --- rattail_tempmon/server.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/rattail_tempmon/server.py b/rattail_tempmon/server.py index c63ed39..1968782 100644 --- a/rattail_tempmon/server.py +++ b/rattail_tempmon/server.py @@ -122,10 +122,24 @@ class TempmonServerDaemon(Daemon): # the client to be (possibly) offline. delay = client.delay or 60 cutoff = self.now - datetime.timedelta(seconds=delay + 60) + + # but if client was "just now" enabled, cutoff may not be quite fair. + # in this case we'll just skip checks until cutoff does seem fair. + if cutoff < client.enabled: + return + + # we make similar checks for each probe; if cutoff "is not fair" for + # any of them, we'll skip that probe check, and avoid marking client + # offline for this round, just to be safe online = False + cutoff_unfair = False for probe in client.enabled_probes(): - if self.check_readings_for_probe(session, probe, cutoff): + if cutoff < probe.enabled: + cutoff_unfair = True + elif self.check_readings_for_probe(session, probe, cutoff): online = True + if cutoff_unfair: + return # if client was previously marked online, but we have no "new" # readings, then let's look closer to see if it's been long enough to From 8187c9532f94e6f731a4d81726403b5f88d1c347 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Mon, 28 Jan 2019 15:48:57 -0600 Subject: [PATCH 12/51] Update changelog --- CHANGES.rst | 10 ++++++++++ rattail_tempmon/_version.py | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index aecca68..1a04e32 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -2,6 +2,16 @@ CHANGELOG ========= +0.2.3 (2019-01-28) +------------------ + +* Add more template context for email previews. + +* Convert ``enabled`` for Client, Probe to use datetime instead of boolean. + +* Modify tempmon server logic to take "unfair" time windows into account. + + 0.2.2 (2018-10-25) ------------------ diff --git a/rattail_tempmon/_version.py b/rattail_tempmon/_version.py index a5342bb..aed15ca 100644 --- a/rattail_tempmon/_version.py +++ b/rattail_tempmon/_version.py @@ -1,3 +1,3 @@ # -*- coding: utf-8; -*- -__version__ = '0.2.2' +__version__ = '0.2.3' From 353abcc1726cbd920fd4661ae4d390f4c573315c Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 9 Apr 2019 12:43:00 -0500 Subject: [PATCH 13/51] Make sure we use zero as fallback/default timeout values --- rattail_tempmon/server.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/rattail_tempmon/server.py b/rattail_tempmon/server.py index 1968782..f5ef640 100644 --- a/rattail_tempmon/server.py +++ b/rattail_tempmon/server.py @@ -246,15 +246,20 @@ class TempmonServerDaemon(Daemon): timeout = probe.timeout_for_status(status) if timeout is None: if status == self.enum.TEMPMON_PROBE_STATUS_CRITICAL_HIGH_TEMP: - timeout = self.config.getint('rattail_tempmon', 'probe.default.critical_max_timeout') + timeout = self.config.getint('rattail_tempmon', 'probe.default.critical_max_timeout', + default=0) elif status == self.enum.TEMPMON_PROBE_STATUS_HIGH_TEMP: - timeout = self.config.getint('rattail_tempmon', 'probe.default.good_max_timeout') + timeout = self.config.getint('rattail_tempmon', 'probe.default.good_max_timeout', + default=0) elif status == self.enum.TEMPMON_PROBE_STATUS_LOW_TEMP: - timeout = self.config.getint('rattail_tempmon', 'probe.default.good_min_timeout') + timeout = self.config.getint('rattail_tempmon', 'probe.default.good_min_timeout', + default=0) elif status == self.enum.TEMPMON_PROBE_STATUS_CRITICAL_LOW_TEMP: - timeout = self.config.getint('rattail_tempmon', 'probe.default.critical_min_timeout') + timeout = self.config.getint('rattail_tempmon', 'probe.default.critical_min_timeout', + default=0) elif status == self.enum.TEMPMON_PROBE_STATUS_ERROR: - timeout = self.config.getint('rattail_tempmon', 'probe.default.error_timeout') + timeout = self.config.getint('rattail_tempmon', 'probe.default.error_timeout', + default=0) timeout = datetime.timedelta(minutes=timeout or 0) started = probe.status_started(status) or probe.status_changed if (self.now - started) <= timeout: From 873cd3def93cec458a822db1fbe4a239854dfbaf Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 23 Apr 2019 22:22:07 -0500 Subject: [PATCH 14/51] Update changelog --- CHANGES.rst | 6 ++++++ rattail_tempmon/_version.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 1a04e32..a8ec67c 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -2,6 +2,12 @@ CHANGELOG ========= +0.2.4 (2019-04-23) +------------------ + +* Make sure we use zero as fallback/default timeout values. + + 0.2.3 (2019-01-28) ------------------ diff --git a/rattail_tempmon/_version.py b/rattail_tempmon/_version.py index aed15ca..be44554 100644 --- a/rattail_tempmon/_version.py +++ b/rattail_tempmon/_version.py @@ -1,3 +1,3 @@ # -*- coding: utf-8; -*- -__version__ = '0.2.3' +__version__ = '0.2.4' From 1b03841c7f57bebf4b07b37d671732da4caf3c0f Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Thu, 13 Jun 2019 12:06:49 -0500 Subject: [PATCH 15/51] Remove config for deprecated 'tempmon_critical_temp' email we now have critical_high and critical_low as separate emails --- rattail_tempmon/emails.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/rattail_tempmon/emails.py b/rattail_tempmon/emails.py index 6a18dca..4a3b5cf 100644 --- a/rattail_tempmon/emails.py +++ b/rattail_tempmon/emails.py @@ -83,19 +83,6 @@ class tempmon_critical_low_temp(TempmonBase, Email): return data -class tempmon_critical_temp(TempmonBase, Email): - """ - Sent when a tempmon probe takes a reading which is "critical" in either the - high or low sense. - """ - default_subject = "Critical temperature detected" - - def sample_data(self, request): - data = super(tempmon_critical_temp, self).sample_data(request) - data['status'] = self.enum.TEMPMON_PROBE_STATUS[self.enum.TEMPMON_PROBE_STATUS_CRITICAL_TEMP] - return data - - class tempmon_error(TempmonBase, Email): """ Sent when a tempmon probe is noticed to have some error, i.e. no current readings. From 4eebd454d547e8b01f72e90e271a7e3bdcde49a1 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sat, 4 Apr 2020 19:30:37 -0500 Subject: [PATCH 16/51] Declare sort order for `Appliance.probes` relationship --- rattail_tempmon/db/model.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rattail_tempmon/db/model.py b/rattail_tempmon/db/model.py index 985de17..160de00 100644 --- a/rattail_tempmon/db/model.py +++ b/rattail_tempmon/db/model.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2018 Lance Edgar +# Copyright © 2010-2020 Lance Edgar # # This file is part of Rattail. # @@ -178,6 +178,7 @@ class Probe(Base): """, backref=orm.backref( 'probes', + order_by='Probe.description', doc=""" List of probes which monitor this appliance. """)) From 28ecdda0e6f3e3d16e80690434135e184068430b Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 22 Sep 2020 19:56:10 -0500 Subject: [PATCH 17/51] Update changelog --- CHANGES.rst | 8 ++++++++ rattail_tempmon/_version.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index a8ec67c..9eb10a3 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -2,6 +2,14 @@ CHANGELOG ========= +0.2.5 (2020-09-22) +------------------ + +* Remove config for deprecated 'tempmon_critical_temp' email. + +* Declare sort order for ``Appliance.probes`` relationship. + + 0.2.4 (2019-04-23) ------------------ diff --git a/rattail_tempmon/_version.py b/rattail_tempmon/_version.py index be44554..85dddb5 100644 --- a/rattail_tempmon/_version.py +++ b/rattail_tempmon/_version.py @@ -1,3 +1,3 @@ # -*- coding: utf-8; -*- -__version__ = '0.2.4' +__version__ = '0.2.5' From 1ddeb8a0307fca76f6785ca99856b0c53484cebb Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sat, 6 Aug 2022 21:09:27 -0500 Subject: [PATCH 18/51] Register email profiles provided by this pkg --- setup.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 2c7d7cf..c7ea5aa 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2017 Lance Edgar +# Copyright © 2010-2022 Lance Edgar # # This file is part of Rattail. # @@ -97,6 +97,7 @@ setup( include_package_data = True, entry_points = { + 'rattail.commands': [ 'export-hotcooler = rattail_tempmon.commands:ExportHotCooler', 'purge-tempmon = rattail_tempmon.commands:PurgeTempmon', @@ -104,8 +105,13 @@ setup( 'tempmon-problems = rattail_tempmon.commands:TempmonProblems', 'tempmon-server = rattail_tempmon.commands:TempmonServer', ], + 'rattail.config.extensions': [ 'tempmon = rattail_tempmon.config:TempmonConfigExtension', ], + + 'rattail.emails': [ + 'rattail_tempmon = rattail_tempmon.emails', + ], }, ) From 1efdd9debd7739bde67539501b708c2e43581a91 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sat, 6 Aug 2022 21:10:11 -0500 Subject: [PATCH 19/51] Update changelog --- CHANGES.rst | 6 ++++++ rattail_tempmon/_version.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 9eb10a3..d10076d 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -2,6 +2,12 @@ CHANGELOG ========= +0.2.6 (2022-08-06) +------------------ + +* Register email profiles provided by this pkg. + + 0.2.5 (2020-09-22) ------------------ diff --git a/rattail_tempmon/_version.py b/rattail_tempmon/_version.py index 85dddb5..90676aa 100644 --- a/rattail_tempmon/_version.py +++ b/rattail_tempmon/_version.py @@ -1,3 +1,3 @@ # -*- coding: utf-8; -*- -__version__ = '0.2.5' +__version__ = '0.2.6' From a45a0b44d5eb3eaa901d4bbeead2441dfb95e47e Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sat, 6 Aug 2022 21:10:57 -0500 Subject: [PATCH 20/51] Use `build` module instead of invoking `setup.py` for release --- tasks.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tasks.py b/tasks.py index 24f3876..971888f 100644 --- a/tasks.py +++ b/tasks.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2018 Lance Edgar +# Copyright © 2010-2022 Lance Edgar # # This file is part of Rattail. # @@ -42,5 +42,5 @@ def release(ctx): Release a new version of `rattail-tempmon` """ shutil.rmtree('rattail_tempmon.egg-info') - ctx.run('python setup.py sdist --formats=gztar') + ctx.run('python -m build --sdist') ctx.run('twine upload dist/rattail-tempmon-{}.tar.gz'.format(__version__)) From fea643145a0345a0e893f80b2b35cde3ddfc780f Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Wed, 8 Feb 2023 10:53:27 -0600 Subject: [PATCH 21/51] Officially drop support for python2 --- setup.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index c7ea5aa..8e06bce 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2022 Lance Edgar +# Copyright © 2010-2023 Lance Edgar # # This file is part of Rattail. # @@ -24,8 +24,6 @@ setup script for rattail-tempmon """ -from __future__ import unicode_literals, absolute_import - import os from setuptools import setup, find_packages @@ -87,7 +85,7 @@ setup( 'Natural Language :: English', 'Operating System :: OS Independent', 'Programming Language :: Python', - 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3', 'Topic :: Office/Business', 'Topic :: Software Development :: Libraries :: Python Modules', ], From 304cec9dd5b3b428577ad200f3caba4d00bf4d3f Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Wed, 8 Feb 2023 10:57:04 -0600 Subject: [PATCH 22/51] Address a warning from SQLAlchemy for `declarative_base` as of 1.4 that has moved --- rattail_tempmon/db/model.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/rattail_tempmon/db/model.py b/rattail_tempmon/db/model.py index 160de00..6fda2aa 100644 --- a/rattail_tempmon/db/model.py +++ b/rattail_tempmon/db/model.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2020 Lance Edgar +# Copyright © 2010-2023 Lance Edgar # # This file is part of Rattail. # @@ -24,14 +24,14 @@ Data models for tempmon """ -from __future__ import unicode_literals, absolute_import - import datetime -import six import sqlalchemy as sa from sqlalchemy import orm -from sqlalchemy.ext.declarative import declarative_base +try: + from sqlalchemy.orm import declarative_base +except ImportError: + from sqlalchemy.ext.declarative import declarative_base from rattail import enum from rattail.db.model import uuid_column @@ -41,7 +41,6 @@ from rattail.db.model.core import ModelBase Base = declarative_base(cls=ModelBase) -@six.python_2_unicode_compatible class Appliance(Base): """ Represents an appliance which is monitored by tempmon. @@ -81,7 +80,6 @@ class Appliance(Base): return self.name -@six.python_2_unicode_compatible class Client(Base): """ Represents a tempmon client. @@ -139,7 +137,6 @@ class Client(Base): return [probe for probe in self.probes if probe.enabled] -@six.python_2_unicode_compatible class Probe(Base): """ Represents a probe connected to a tempmon client. @@ -399,7 +396,6 @@ class Probe(Base): return self.error_timeout -@six.python_2_unicode_compatible class Reading(Base): """ Represents a single temperature reading from a tempmon probe. From acfc7f7d80f9c5f3a3cfa3dcae62f135d0746fea Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Fri, 10 Feb 2023 21:09:51 -0600 Subject: [PATCH 23/51] Update changelog --- CHANGES.rst | 8 ++++++++ rattail_tempmon/_version.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index d10076d..2938e45 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -2,6 +2,14 @@ CHANGELOG ========= +0.2.7 (2023-02-10) +------------------ + +* Officially drop support for python2. + +* Address a warning from SQLAlchemy for ``declarative_base``. + + 0.2.6 (2022-08-06) ------------------ diff --git a/rattail_tempmon/_version.py b/rattail_tempmon/_version.py index 90676aa..71a46aa 100644 --- a/rattail_tempmon/_version.py +++ b/rattail_tempmon/_version.py @@ -1,3 +1,3 @@ # -*- coding: utf-8; -*- -__version__ = '0.2.6' +__version__ = '0.2.7' From f7f60eff85f8c6a9d4e8fc1142ea675afc9ab9b7 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Fri, 10 Feb 2023 21:12:57 -0600 Subject: [PATCH 24/51] Avoid error when re-running release task --- tasks.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/tasks.py b/tasks.py index 971888f..4fec2d2 100644 --- a/tasks.py +++ b/tasks.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2022 Lance Edgar +# Copyright © 2010-2023 Lance Edgar # # This file is part of Rattail. # @@ -24,8 +24,6 @@ Tasks for 'rattail-tempmon' package """ -from __future__ import unicode_literals, absolute_import - import os import shutil @@ -37,10 +35,11 @@ exec(open(os.path.join(here, 'rattail_tempmon', '_version.py')).read()) @task -def release(ctx): +def release(c): """ Release a new version of `rattail-tempmon` """ - shutil.rmtree('rattail_tempmon.egg-info') - ctx.run('python -m build --sdist') - ctx.run('twine upload dist/rattail-tempmon-{}.tar.gz'.format(__version__)) + if os.path.exists('rattail_tempmon.egg-info'): + shutil.rmtree('rattail_tempmon.egg-info') + c.run('python -m build --sdist') + c.run('twine upload dist/rattail-tempmon-{}.tar.gz'.format(__version__)) From 995e0dde0acaf7d00cbad8b4d55fb500fc8fd88f Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sat, 11 Feb 2023 22:24:56 -0600 Subject: [PATCH 25/51] Refactor `Query.get()` => `Session.get()` per SQLAlchemy 1.4 --- rattail_tempmon/client.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/rattail_tempmon/client.py b/rattail_tempmon/client.py index f8694b5..5173c67 100644 --- a/rattail_tempmon/client.py +++ b/rattail_tempmon/client.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2018 Lance Edgar +# Copyright © 2010-2023 Lance Edgar # # This file is part of Rattail. # @@ -24,15 +24,12 @@ TempMon client daemon """ -from __future__ import unicode_literals, absolute_import - import time import datetime import random import socket import logging -import six from sqlalchemy.exc import OperationalError from sqlalchemy.orm.exc import NoResultFound @@ -86,7 +83,7 @@ class TempmonClient(Daemon): session = Session() try: - client = session.query(tempmon.Client).get(client_uuid) + client = session.get(tempmon.Client, client_uuid) self.delay = client.delay or 60 if client.enabled: for probe in client.enabled_probes(): @@ -111,7 +108,7 @@ class TempmonClient(Daemon): # first time after DB stop. but in the case of DB stop, # subsequent errors will instead match the second test if error.connection_invalidated or ( - 'could not connect to server: Connection refused' in six.text_type(error)): + 'could not connect to server: Connection refused' in str(error)): # only suppress logging for 3 failures, after that we let them go # TODO: should make the max attempts configurable @@ -119,7 +116,7 @@ class TempmonClient(Daemon): log_error = False log.debug("database connection failure #%s: %s", self.failed_checks, - six.text_type(error)) + str(error)) # send error email unless we're suppressing it for now if log_error: From b887875f80dbe80e927f3e78ea3770b91e417b8f Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sun, 12 Feb 2023 11:22:06 -0600 Subject: [PATCH 26/51] Update changelog --- CHANGES.rst | 6 ++++++ rattail_tempmon/_version.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 2938e45..3dfc98e 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -2,6 +2,12 @@ CHANGELOG ========= +0.2.8 (2023-02-12) +------------------ + +* Refactor ``Query.get()`` => ``Session.get()`` per SQLAlchemy 1.4. + + 0.2.7 (2023-02-10) ------------------ diff --git a/rattail_tempmon/_version.py b/rattail_tempmon/_version.py index 71a46aa..90d50a1 100644 --- a/rattail_tempmon/_version.py +++ b/rattail_tempmon/_version.py @@ -1,3 +1,3 @@ # -*- coding: utf-8; -*- -__version__ = '0.2.7' +__version__ = '0.2.8' From a16f2ba718a5637d28e2571bca88f30a6fb328c5 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 16 May 2023 13:21:26 -0500 Subject: [PATCH 27/51] Replace `setup.py` contents with `setup.cfg` --- setup.cfg | 47 +++++++++++++++++++++++++++++ setup.py | 90 ++----------------------------------------------------- 2 files changed, 49 insertions(+), 88 deletions(-) create mode 100644 setup.cfg diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..a11350b --- /dev/null +++ b/setup.cfg @@ -0,0 +1,47 @@ +# -*- coding: utf-8; -*- + +[metadata] +name = rattail-tempmon +version = attr: rattail_tempmon.__version__ +author = Lance Edgar +author_email = lance@edbob.org +url = https://rattailproject.org/ +license = GNU GPL v3 +description = Retail Software Framework - Temperature monitoring add-on +long_description = file: README.rst +classifiers = + Development Status :: 3 - Alpha + Intended Audience :: Developers + License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+) + Natural Language :: English + Operating System :: OS Independent + Programming Language :: Python + Programming Language :: Python :: 3 + Topic :: Office/Business + Topic :: Software Development :: Libraries :: Python Modules + + +[options] +install_requires = + rattail[db] + six + sqlsoup + +packages = find: +include_package_data = True + + +[options.entry_points] + +rattail.commands = + export-hotcooler = rattail_tempmon.commands:ExportHotCooler + purge-tempmon = rattail_tempmon.commands:PurgeTempmon + tempmon-client = rattail_tempmon.commands:TempmonClient + tempmon-problems = rattail_tempmon.commands:TempmonProblems + tempmon-server = rattail_tempmon.commands:TempmonServer + +rattail.config.extensions = + tempmon = rattail_tempmon.config:TempmonConfigExtension + +rattail.emails = + rattail_tempmon = rattail_tempmon.emails diff --git a/setup.py b/setup.py index 8e06bce..d3afc65 100644 --- a/setup.py +++ b/setup.py @@ -24,92 +24,6 @@ setup script for rattail-tempmon """ -import os -from setuptools import setup, find_packages +from setuptools import setup - -here = os.path.abspath(os.path.dirname(__file__)) -exec(open(os.path.join(here, 'rattail_tempmon', '_version.py')).read()) -README = open(os.path.join(here, 'README.rst')).read() - - -requires = [ - # - # Version numbers within comments below have specific meanings. - # Basically the 'low' value is a "soft low," and 'high' a "soft high." - # In other words: - # - # If either a 'low' or 'high' value exists, the primary point to be - # made about the value is that it represents the most current (stable) - # version available for the package (assuming typical public access - # methods) whenever this project was started and/or documented. - # Therefore: - # - # If a 'low' version is present, you should know that attempts to use - # versions of the package significantly older than the 'low' version - # may not yield happy results. (A "hard" high limit may or may not be - # indicated by a true version requirement.) - # - # Similarly, if a 'high' version is present, and especially if this - # project has laid dormant for a while, you may need to refactor a bit - # when attempting to support a more recent version of the package. (A - # "hard" low limit should be indicated by a true version requirement - # when a 'high' version is present.) - # - # In any case, developers and other users are encouraged to play - # outside the lines with regard to these soft limits. If bugs are - # encountered then they should be filed as such. - # - # package # low high - - 'rattail[db]', # 0.7.46 - 'six', # 1.10.0 - 'sqlsoup', # 0.9.1 -] - - -setup( - name = "rattail-tempmon", - version = __version__, - author = "Lance Edgar", - author_email = "lance@edbob.org", - url = "https://rattailproject.org/", - license = "GNU GPL v3", - description = "Retail Software Framework - Temperature monitoring add-on", - long_description = README, - - classifiers = [ - 'Development Status :: 3 - Alpha', - 'Intended Audience :: Developers', - 'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)', - 'Natural Language :: English', - 'Operating System :: OS Independent', - 'Programming Language :: Python', - 'Programming Language :: Python :: 3', - 'Topic :: Office/Business', - 'Topic :: Software Development :: Libraries :: Python Modules', - ], - - install_requires = requires, - packages = find_packages(), - include_package_data = True, - - entry_points = { - - 'rattail.commands': [ - 'export-hotcooler = rattail_tempmon.commands:ExportHotCooler', - 'purge-tempmon = rattail_tempmon.commands:PurgeTempmon', - 'tempmon-client = rattail_tempmon.commands:TempmonClient', - 'tempmon-problems = rattail_tempmon.commands:TempmonProblems', - 'tempmon-server = rattail_tempmon.commands:TempmonServer', - ], - - 'rattail.config.extensions': [ - 'tempmon = rattail_tempmon.config:TempmonConfigExtension', - ], - - 'rattail.emails': [ - 'rattail_tempmon = rattail_tempmon.emails', - ], - }, -) +setup() From e82e7144171d272983399bfe3a6fcee9d87cd42b Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 16 May 2023 17:40:36 -0500 Subject: [PATCH 28/51] Update changelog --- CHANGES.rst | 6 ++++++ rattail_tempmon/_version.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 3dfc98e..e4e27ce 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -2,6 +2,12 @@ CHANGELOG ========= +0.2.9 (2023-05-16) +------------------ + +* Replace ``setup.py`` contents with ``setup.cfg``. + + 0.2.8 (2023-02-12) ------------------ diff --git a/rattail_tempmon/_version.py b/rattail_tempmon/_version.py index 90d50a1..33bef45 100644 --- a/rattail_tempmon/_version.py +++ b/rattail_tempmon/_version.py @@ -1,3 +1,3 @@ # -*- coding: utf-8; -*- -__version__ = '0.2.8' +__version__ = '0.2.9' From 7a11ee7ad7c03a93ff91481d4d222310ccb42578 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Wed, 22 Nov 2023 18:05:58 -0600 Subject: [PATCH 29/51] Update subcommand entry point group names, per wuttjamaican --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index a11350b..e2043dc 100644 --- a/setup.cfg +++ b/setup.cfg @@ -33,7 +33,7 @@ include_package_data = True [options.entry_points] -rattail.commands = +rattail.subcommands = export-hotcooler = rattail_tempmon.commands:ExportHotCooler purge-tempmon = rattail_tempmon.commands:PurgeTempmon tempmon-client = rattail_tempmon.commands:TempmonClient From d8b865da716ae88da47136c87620e716307b1f15 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Thu, 30 Nov 2023 22:24:15 -0600 Subject: [PATCH 30/51] Update changelog --- CHANGES.rst | 6 ++++++ rattail_tempmon/_version.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index e4e27ce..38c8c02 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -2,6 +2,12 @@ CHANGELOG ========= +0.2.10 (2023-11-30) +------------------- + +* Update subcommand entry point group names, per wuttjamaican. + + 0.2.9 (2023-05-16) ------------------ diff --git a/rattail_tempmon/_version.py b/rattail_tempmon/_version.py index 33bef45..ff14503 100644 --- a/rattail_tempmon/_version.py +++ b/rattail_tempmon/_version.py @@ -1,3 +1,3 @@ # -*- coding: utf-8; -*- -__version__ = '0.2.9' +__version__ = '0.2.10' From 9a39db4546d5a6e6d4e4ca6af332b042ed8e89eb Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Thu, 16 May 2024 20:55:42 -0500 Subject: [PATCH 31/51] Add typer equivalents for `rattail` commands --- rattail_tempmon/commands.py | 190 +++++++++++++++++++++++++++++------- setup.cfg | 3 + 2 files changed, 158 insertions(+), 35 deletions(-) diff --git a/rattail_tempmon/commands.py b/rattail_tempmon/commands.py index 312c4d3..e06ecca 100644 --- a/rattail_tempmon/commands.py +++ b/rattail_tempmon/commands.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2017 Lance Edgar +# Copyright © 2010-2024 Lance Edgar # # This file is part of Rattail. # @@ -24,19 +24,139 @@ Tempmon commands """ -from __future__ import unicode_literals, absolute_import - import datetime import logging +from enum import Enum +from pathlib import Path -from rattail import commands -from rattail.time import localtime, make_utc +import typer +from typing_extensions import Annotated + +from rattail.commands import rattail_typer, Subcommand, ImportSubcommand +from rattail.commands.typer import importer_command, typer_get_runas_user +from rattail.commands.importing import ImportCommandHandler log = logging.getLogger(__name__) -class ExportHotCooler(commands.ImportSubcommand): +class ServiceAction(str, Enum): + start = 'start' + stop = 'stop' + + +@rattail_typer.command() +@importer_command +def export_hotcooler( + ctx: typer.Context, + **kwargs +): + """ + Export data from Rattail-Tempmon to HotCooler + """ + config = ctx.parent.rattail_config + progress = ctx.parent.rattail_progress + handler = ImportCommandHandler( + config, + import_handler_spec='rattail_tempmon.hotcooler.importing.tempmon:FromTempmonToHotCooler') + kwargs['user'] = typer_get_runas_user(ctx) + handler.run(kwargs, progress=progress) + + +@rattail_typer.command() +def purge_tempmon( + ctx: typer.Context, + keep_days: Annotated[ + int, + typer.Option('--keep', + help="Number of days for which data should be kept.")] = ..., + dry_run: Annotated[ + bool, + typer.Option('--dry-run', + help="Go through the full motions and allow logging etc. to " + "occur, but rollback (abort) the transaction at the end.")] = False, +): + """ + Purge stale data from Tempmon database + """ + config = ctx.parent.rattail_config + progress = ctx.parent.rattail_progress + do_purge(config, keep_days, dry_run=dry_run, progress=progress) + + +@rattail_typer.command() +def tempmon_client( + ctx: typer.Context, + action: Annotated[ + ServiceAction, + typer.Argument(help="Action to perform for the service.")] = ..., + pid_file: Annotated[ + Path, + typer.Option('--pidfile', '-p', + help="Path to PID file.")] = None, + # TODO: deprecate / remove this + daemonize: Annotated[ + bool, + typer.Option('--daemonize', + help="Daemonize when starting.")] = False, +): + """ + Manage the tempmon-client daemon + """ + from rattail_tempmon.client import make_daemon + + config = ctx.parent.rattail_config + daemon = make_daemon(config, pidfile) + if action == 'start': + daemon.start(daemonize) + elif action == 'stop': + daemon.stop() + + +@rattail_typer.command() +def tempmon_problems( + ctx: typer.Context, +): + """ + Email report(s) of various Tempmon data problems + """ + from rattail_tempmon import problems + + config = ctx.parent.rattail_config + progress = ctx.parent.rattail_progress + problems.disabled_probes(config, progress=progress) + + +@rattail_typer.command() +def tempmon_server( + ctx: typer.Context, + action: Annotated[ + ServiceAction, + typer.Argument(help="Action to perform for the service.")] = ..., + pid_file: Annotated[ + Path, + typer.Option('--pidfile', '-p', + help="Path to PID file.")] = None, + # TODO: deprecate / remove this + daemonize: Annotated[ + bool, + typer.Option('--daemonize', + help="Daemonize when starting.")] = False, +): + """ + Manage the tempmon-server daemon + """ + from rattail_tempmon.server import make_daemon + + config = ctx.parent.rattail_config + daemon = make_daemon(config, pidfile) + if action == 'start': + daemon.start(daemonize) + elif action == 'stop': + daemon.stop() + + +class ExportHotCooler(ImportSubcommand): """ Export data from Rattail-Tempmon to HotCooler """ @@ -45,7 +165,7 @@ class ExportHotCooler(commands.ImportSubcommand): handler_spec = 'rattail_tempmon.hotcooler.importing.tempmon:FromTempmonToHotCooler' -class PurgeTempmon(commands.Subcommand): +class PurgeTempmon(Subcommand): """ Purge stale data from Tempmon database """ @@ -60,34 +180,34 @@ class PurgeTempmon(commands.Subcommand): "occur, but rollback (abort) the transaction at the end.") def run(self, args): - from rattail_tempmon.db import Session as TempmonSession, model as tempmon - - cutoff = localtime(self.config).date() - datetime.timedelta(days=args.keep) - cutoff = localtime(self.config, datetime.datetime.combine(cutoff, datetime.time(0))) - session = TempmonSession() - - readings = session.query(tempmon.Reading)\ - .filter(tempmon.Reading.taken < make_utc(cutoff)) - count = readings.count() - - def purge(reading, i): - session.delete(reading) - if i % 200 == 0: - session.flush() - - self.progress_loop(purge, readings, count=count, message="Purging stale readings") - log.info("deleted {} stale readings".format(count)) - - if args.dry_run: - session.rollback() - log.info("dry run, so transaction was rolled back") - else: - session.commit() - log.info("transaction was committed") - session.close() + do_purge(self.config, args.keep, dry_run=args.dry_run, progress=self.progress) -class TempmonClient(commands.Subcommand): +def do_purge(self, config, keep_days, dry_run=False, progress=None): + from rattail_tempmon.db import Session, model + from rattail.db.util import finalize_session + + app = config.get_app() + cutoff = app.today() - datetime.timedelta(days=keep_days) + cutoff = app.localtime(datetime.datetime.combine(cutoff, datetime.time(0))) + session = Session() + + readings = session.query(model.Reading)\ + .filter(model.Reading.taken < app.make_utc(cutoff))\ + .all() + + def purge(reading, i): + session.delete(reading) + if i % 200 == 0: + session.flush() + + app.progress_loop(purge, readings, progress, + message="Purging stale readings") + log.info("deleted %s stale readings", len(readings)) + finalize_session(session, dry_run=dry_run) + + +class TempmonClient(Subcommand): """ Manage the tempmon-client daemon """ @@ -117,7 +237,7 @@ class TempmonClient(commands.Subcommand): daemon.stop() -class TempmonServer(commands.Subcommand): +class TempmonServer(Subcommand): """ Manage the tempmon-server daemon """ @@ -147,7 +267,7 @@ class TempmonServer(commands.Subcommand): daemon.stop() -class TempmonProblems(commands.Subcommand): +class TempmonProblems(Subcommand): """ Email report(s) of various Tempmon data problems """ diff --git a/setup.cfg b/setup.cfg index e2043dc..ecfe3f6 100644 --- a/setup.cfg +++ b/setup.cfg @@ -40,6 +40,9 @@ rattail.subcommands = tempmon-problems = rattail_tempmon.commands:TempmonProblems tempmon-server = rattail_tempmon.commands:TempmonServer +rattail.typer_imports = + rattail_tempmon = rattail_tempmon.commands + rattail.config.extensions = tempmon = rattail_tempmon.config:TempmonConfigExtension From 3f46ee6a309445e7baf4a29865352892f410d368 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Fri, 17 May 2024 09:38:55 -0500 Subject: [PATCH 32/51] Fix typo for purge command --- rattail_tempmon/commands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rattail_tempmon/commands.py b/rattail_tempmon/commands.py index e06ecca..7e6b8e8 100644 --- a/rattail_tempmon/commands.py +++ b/rattail_tempmon/commands.py @@ -183,7 +183,7 @@ class PurgeTempmon(Subcommand): do_purge(self.config, args.keep, dry_run=args.dry_run, progress=self.progress) -def do_purge(self, config, keep_days, dry_run=False, progress=None): +def do_purge(config, keep_days, dry_run=False, progress=None): from rattail_tempmon.db import Session, model from rattail.db.util import finalize_session From 3fde33ac848383d4b050d0ed571c810cd73c9fb7 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Wed, 29 May 2024 07:27:22 -0500 Subject: [PATCH 33/51] Fix pidfile args in typer commands --- rattail_tempmon/commands.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rattail_tempmon/commands.py b/rattail_tempmon/commands.py index 7e6b8e8..fd7227b 100644 --- a/rattail_tempmon/commands.py +++ b/rattail_tempmon/commands.py @@ -90,7 +90,7 @@ def tempmon_client( action: Annotated[ ServiceAction, typer.Argument(help="Action to perform for the service.")] = ..., - pid_file: Annotated[ + pidfile: Annotated[ Path, typer.Option('--pidfile', '-p', help="Path to PID file.")] = None, @@ -133,7 +133,7 @@ def tempmon_server( action: Annotated[ ServiceAction, typer.Argument(help="Action to perform for the service.")] = ..., - pid_file: Annotated[ + pidfile: Annotated[ Path, typer.Option('--pidfile', '-p', help="Path to PID file.")] = None, From f01faaf2f9c8793edd79b0778ac0b1091a39ba23 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Thu, 30 May 2024 11:14:16 -0500 Subject: [PATCH 34/51] Update changelog --- CHANGES.rst | 6 ++++++ rattail_tempmon/_version.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 38c8c02..eba4936 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -2,6 +2,12 @@ CHANGELOG ========= +0.3.0 (2024-05-30) +------------------ + +* Migrate all commands to use ``typer``. + + 0.2.10 (2023-11-30) ------------------- diff --git a/rattail_tempmon/_version.py b/rattail_tempmon/_version.py index ff14503..2f2de2d 100644 --- a/rattail_tempmon/_version.py +++ b/rattail_tempmon/_version.py @@ -1,3 +1,3 @@ # -*- coding: utf-8; -*- -__version__ = '0.2.10' +__version__ = '0.3.0' From 784f75ac3f6927e2b860d661870cab545a8c3baa Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Thu, 30 May 2024 11:15:07 -0500 Subject: [PATCH 35/51] Fix default dist filename for release task not sure why this fix was needed, did setuptools behavior change? --- tasks.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tasks.py b/tasks.py index 4fec2d2..1c9413e 100644 --- a/tasks.py +++ b/tasks.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2023 Lance Edgar +# Copyright © 2010-2024 Lance Edgar # # This file is part of Rattail. # @@ -42,4 +42,4 @@ def release(c): if os.path.exists('rattail_tempmon.egg-info'): shutil.rmtree('rattail_tempmon.egg-info') c.run('python -m build --sdist') - c.run('twine upload dist/rattail-tempmon-{}.tar.gz'.format(__version__)) + c.run(f'twine upload dist/rattail_tempmon-{__version__}.tar.gz') From 6b4280a6aa02cdfa76b44fa48582f4e5e91c3145 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Mon, 10 Jun 2024 21:21:19 -0500 Subject: [PATCH 36/51] feat: switch from setup.cfg to pyproject.toml + hatchling --- .gitignore | 3 ++ pyproject.toml | 61 +++++++++++++++++++++++++++++++++++++ rattail_tempmon/_version.py | 5 ++- setup.cfg | 50 ------------------------------ setup.py | 29 ------------------ tasks.py | 8 ++--- 6 files changed, 71 insertions(+), 85 deletions(-) create mode 100644 pyproject.toml delete mode 100644 setup.cfg delete mode 100644 setup.py diff --git a/.gitignore b/.gitignore index b2c6123..8b9f408 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ +*~ +*.pyc +dist/ rattail_tempmon.egg-info/ diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..b5920ba --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,61 @@ + +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + + +[project] +name = "rattail-tempmon" +version = "0.3.0" +description = "Retail Software Framework - Temperature monitoring add-on" +readme = "README.rst" +authors = [{name = "Lance Edgar", email = "lance@edbob.org"}] +license = {text = "GNU GPL v3+"} +classifiers = [ + "Development Status :: 3 - Alpha", + "Intended Audience :: Developers", + "License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)", + "Natural Language :: English", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Topic :: Office/Business", + "Topic :: Software Development :: Libraries :: Python Modules", +] +dependencies = [ + "rattail[db]", + "six", + "sqlsoup", +] + + +[project.urls] +Homepage = "https://rattailproject.org" +Repository = "https://kallithea.rattailproject.org/rattail-project/rattail-tempmon" +Changelog = "https://kallithea.rattailproject.org/rattail-project/rattail-tempmon/files/master/CHANGES.rst" + + +[project.entry-points."rattail.config.extensions"] +tempmon = "rattail_tempmon.config:TempmonConfigExtension" + + +[project.entry-points."rattail.subcommands"] +export-hotcooler = "rattail_tempmon.commands:ExportHotCooler" +purge-tempmon = "rattail_tempmon.commands:PurgeTempmon" +tempmon-client = "rattail_tempmon.commands:TempmonClient" +tempmon-problems = "rattail_tempmon.commands:TempmonProblems" +tempmon-server = "rattail_tempmon.commands:TempmonServer" + + +[project.entry-points."rattail.typer_imports"] +rattail_tempmon = "rattail_tempmon.commands" + + +[project.entry-points."rattail.emails"] +rattail_tempmon = "rattail_tempmon.emails" + + +[tool.commitizen] +version_provider = "pep621" +tag_format = "v$version" +update_changelog_on_bump = true diff --git a/rattail_tempmon/_version.py b/rattail_tempmon/_version.py index 2f2de2d..71aa2b6 100644 --- a/rattail_tempmon/_version.py +++ b/rattail_tempmon/_version.py @@ -1,3 +1,6 @@ # -*- coding: utf-8; -*- -__version__ = '0.3.0' +from importlib.metadata import version + + +__version__ = version('rattail-tempmon') diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index ecfe3f6..0000000 --- a/setup.cfg +++ /dev/null @@ -1,50 +0,0 @@ -# -*- coding: utf-8; -*- - -[metadata] -name = rattail-tempmon -version = attr: rattail_tempmon.__version__ -author = Lance Edgar -author_email = lance@edbob.org -url = https://rattailproject.org/ -license = GNU GPL v3 -description = Retail Software Framework - Temperature monitoring add-on -long_description = file: README.rst -classifiers = - Development Status :: 3 - Alpha - Intended Audience :: Developers - License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+) - Natural Language :: English - Operating System :: OS Independent - Programming Language :: Python - Programming Language :: Python :: 3 - Topic :: Office/Business - Topic :: Software Development :: Libraries :: Python Modules - - -[options] -install_requires = - rattail[db] - six - sqlsoup - -packages = find: -include_package_data = True - - -[options.entry_points] - -rattail.subcommands = - export-hotcooler = rattail_tempmon.commands:ExportHotCooler - purge-tempmon = rattail_tempmon.commands:PurgeTempmon - tempmon-client = rattail_tempmon.commands:TempmonClient - tempmon-problems = rattail_tempmon.commands:TempmonProblems - tempmon-server = rattail_tempmon.commands:TempmonServer - -rattail.typer_imports = - rattail_tempmon = rattail_tempmon.commands - -rattail.config.extensions = - tempmon = rattail_tempmon.config:TempmonConfigExtension - -rattail.emails = - rattail_tempmon = rattail_tempmon.emails diff --git a/setup.py b/setup.py deleted file mode 100644 index d3afc65..0000000 --- a/setup.py +++ /dev/null @@ -1,29 +0,0 @@ -# -*- coding: utf-8; -*- -################################################################################ -# -# Rattail -- Retail Software Framework -# Copyright © 2010-2023 Lance Edgar -# -# This file is part of Rattail. -# -# Rattail is free software: you can redistribute it and/or modify it under the -# terms of the GNU General Public License as published by the Free Software -# Foundation, either version 3 of the License, or (at your option) any later -# version. -# -# Rattail is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -# details. -# -# You should have received a copy of the GNU General Public License along with -# Rattail. If not, see . -# -################################################################################ -""" -setup script for rattail-tempmon -""" - -from setuptools import setup - -setup() diff --git a/tasks.py b/tasks.py index 1c9413e..497f721 100644 --- a/tasks.py +++ b/tasks.py @@ -30,16 +30,14 @@ import shutil from invoke import task -here = os.path.abspath(os.path.dirname(__file__)) -exec(open(os.path.join(here, 'rattail_tempmon', '_version.py')).read()) - - @task def release(c): """ Release a new version of `rattail-tempmon` """ + if os.path.exists('dist'): + shutil.rmtree('dist') if os.path.exists('rattail_tempmon.egg-info'): shutil.rmtree('rattail_tempmon.egg-info') c.run('python -m build --sdist') - c.run(f'twine upload dist/rattail_tempmon-{__version__}.tar.gz') + c.run('twine upload dist/*') From eb8962003ce8e17a6a6ab23a174545dab3183914 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Mon, 10 Jun 2024 21:21:30 -0500 Subject: [PATCH 37/51] =?UTF-8?q?bump:=20version=200.3.0=20=E2=86=92=200.4?= =?UTF-8?q?.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 17 +++++++++++++++++ CHANGES.rst => docs/OLDCHANGES.rst | 4 ++++ pyproject.toml | 2 +- 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 CHANGELOG.md rename CHANGES.rst => docs/OLDCHANGES.rst (97%) diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..12f84c2 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,17 @@ + +# Changelog +All notable changes to rattail-tempmon will be documented in this file. + +The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) +and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). + +## v0.4.0 (2024-06-10) + +### Feat + +- switch from setup.cfg to pyproject.toml + hatchling + + +## Older Releases + +Please see `docs/OLDCHANGES.rst` for older release notes. diff --git a/CHANGES.rst b/docs/OLDCHANGES.rst similarity index 97% rename from CHANGES.rst rename to docs/OLDCHANGES.rst index eba4936..8727078 100644 --- a/CHANGES.rst +++ b/docs/OLDCHANGES.rst @@ -2,6 +2,10 @@ CHANGELOG ========= +NB. this file contains "old" release notes only. for newer releases +see the `CHANGELOG.md` file in the source root folder. + + 0.3.0 (2024-05-30) ------------------ diff --git a/pyproject.toml b/pyproject.toml index b5920ba..a0d9937 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "hatchling.build" [project] name = "rattail-tempmon" -version = "0.3.0" +version = "0.4.0" description = "Retail Software Framework - Temperature monitoring add-on" readme = "README.rst" authors = [{name = "Lance Edgar", email = "lance@edbob.org"}] From f4682c9070a7f0b4a0dbc27c315432c94aeb39dd Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Fri, 14 Jun 2024 17:35:23 -0500 Subject: [PATCH 38/51] fix: fallback to `importlib_metadata` on older python --- rattail_tempmon/_version.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/rattail_tempmon/_version.py b/rattail_tempmon/_version.py index 71aa2b6..7135faa 100644 --- a/rattail_tempmon/_version.py +++ b/rattail_tempmon/_version.py @@ -1,6 +1,9 @@ # -*- coding: utf-8; -*- -from importlib.metadata import version +try: + from importlib.metadata import version +except ImportError: + from importlib_metadata import version __version__ = version('rattail-tempmon') From be4d6bfe4dd69eaaac63b7911235501ca94e5f69 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Fri, 14 Jun 2024 17:37:04 -0500 Subject: [PATCH 39/51] =?UTF-8?q?bump:=20version=200.4.0=20=E2=86=92=200.4?= =?UTF-8?q?.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 6 ++++++ pyproject.toml | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12f84c2..8c1a4a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to rattail-tempmon will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## v0.4.1 (2024-06-14) + +### Fix + +- fallback to `importlib_metadata` on older python + ## v0.4.0 (2024-06-10) ### Feat diff --git a/pyproject.toml b/pyproject.toml index a0d9937..30161b3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "hatchling.build" [project] name = "rattail-tempmon" -version = "0.4.0" +version = "0.4.1" description = "Retail Software Framework - Temperature monitoring add-on" readme = "README.rst" authors = [{name = "Lance Edgar", email = "lance@edbob.org"}] From 625736253451683d13d132a6874a3d98cccf4a07 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Mon, 1 Jul 2024 12:20:48 -0500 Subject: [PATCH 40/51] fix: remove legacy command definitions --- pyproject.toml | 8 --- rattail_tempmon/commands.py | 102 +----------------------------------- 2 files changed, 1 insertion(+), 109 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 30161b3..1d08843 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,14 +39,6 @@ Changelog = "https://kallithea.rattailproject.org/rattail-project/rattail-tempmo tempmon = "rattail_tempmon.config:TempmonConfigExtension" -[project.entry-points."rattail.subcommands"] -export-hotcooler = "rattail_tempmon.commands:ExportHotCooler" -purge-tempmon = "rattail_tempmon.commands:PurgeTempmon" -tempmon-client = "rattail_tempmon.commands:TempmonClient" -tempmon-problems = "rattail_tempmon.commands:TempmonProblems" -tempmon-server = "rattail_tempmon.commands:TempmonServer" - - [project.entry-points."rattail.typer_imports"] rattail_tempmon = "rattail_tempmon.commands" diff --git a/rattail_tempmon/commands.py b/rattail_tempmon/commands.py index fd7227b..29291f1 100644 --- a/rattail_tempmon/commands.py +++ b/rattail_tempmon/commands.py @@ -32,7 +32,7 @@ from pathlib import Path import typer from typing_extensions import Annotated -from rattail.commands import rattail_typer, Subcommand, ImportSubcommand +from rattail.commands import rattail_typer from rattail.commands.typer import importer_command, typer_get_runas_user from rattail.commands.importing import ImportCommandHandler @@ -156,33 +156,6 @@ def tempmon_server( daemon.stop() -class ExportHotCooler(ImportSubcommand): - """ - Export data from Rattail-Tempmon to HotCooler - """ - name = 'export-hotcooler' - description = __doc__.strip() - handler_spec = 'rattail_tempmon.hotcooler.importing.tempmon:FromTempmonToHotCooler' - - -class PurgeTempmon(Subcommand): - """ - Purge stale data from Tempmon database - """ - name = 'purge-tempmon' - description = __doc__.strip() - - def add_parser_args(self, parser): - parser.add_argument('--keep', metavar='DAYS', required=True, type=int, - help="Number of days for which data should be kept.") - parser.add_argument('--dry-run', action='store_true', - help="Go through the full motions and allow logging etc. to " - "occur, but rollback (abort) the transaction at the end.") - - def run(self, args): - do_purge(self.config, args.keep, dry_run=args.dry_run, progress=self.progress) - - def do_purge(config, keep_days, dry_run=False, progress=None): from rattail_tempmon.db import Session, model from rattail.db.util import finalize_session @@ -205,76 +178,3 @@ def do_purge(config, keep_days, dry_run=False, progress=None): message="Purging stale readings") log.info("deleted %s stale readings", len(readings)) finalize_session(session, dry_run=dry_run) - - -class TempmonClient(Subcommand): - """ - Manage the tempmon-client daemon - """ - name = 'tempmon-client' - description = __doc__.strip() - - def add_parser_args(self, parser): - subparsers = parser.add_subparsers(title='subcommands') - - start = subparsers.add_parser('start', help="Start daemon") - start.set_defaults(subcommand='start') - stop = subparsers.add_parser('stop', help="Stop daemon") - stop.set_defaults(subcommand='stop') - - parser.add_argument('-p', '--pidfile', - help="Path to PID file.", metavar='PATH') - parser.add_argument('-D', '--daemonize', action='store_true', - help="Daemonize when starting.") - - def run(self, args): - from rattail_tempmon.client import make_daemon - - daemon = make_daemon(self.config, args.pidfile) - if args.subcommand == 'start': - daemon.start(args.daemonize) - elif args.subcommand == 'stop': - daemon.stop() - - -class TempmonServer(Subcommand): - """ - Manage the tempmon-server daemon - """ - name = 'tempmon-server' - description = __doc__.strip() - - def add_parser_args(self, parser): - subparsers = parser.add_subparsers(title='subcommands') - - start = subparsers.add_parser('start', help="Start daemon") - start.set_defaults(subcommand='start') - stop = subparsers.add_parser('stop', help="Stop daemon") - stop.set_defaults(subcommand='stop') - - parser.add_argument('-p', '--pidfile', - help="Path to PID file.", metavar='PATH') - parser.add_argument('-D', '--daemonize', action='store_true', - help="Daemonize when starting.") - - def run(self, args): - from rattail_tempmon.server import make_daemon - - daemon = make_daemon(self.config, args.pidfile) - if args.subcommand == 'start': - daemon.start(args.daemonize) - elif args.subcommand == 'stop': - daemon.stop() - - -class TempmonProblems(Subcommand): - """ - Email report(s) of various Tempmon data problems - """ - name = 'tempmon-problems' - description = __doc__.strip() - - def run(self, args): - from rattail_tempmon import problems - - problems.disabled_probes(self.config, progress=self.progress) From ff0af6732a77b1e78a32d537954d265a93f7abb1 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Mon, 1 Jul 2024 14:11:57 -0500 Subject: [PATCH 41/51] =?UTF-8?q?bump:=20version=200.4.1=20=E2=86=92=200.4?= =?UTF-8?q?.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 6 ++++++ pyproject.toml | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c1a4a7..9b9a381 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to rattail-tempmon will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## v0.4.2 (2024-07-01) + +### Fix + +- remove legacy command definitions + ## v0.4.1 (2024-06-14) ### Fix diff --git a/pyproject.toml b/pyproject.toml index 1d08843..68af181 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "hatchling.build" [project] name = "rattail-tempmon" -version = "0.4.1" +version = "0.4.2" description = "Retail Software Framework - Temperature monitoring add-on" readme = "README.rst" authors = [{name = "Lance Edgar", email = "lance@edbob.org"}] From f36759dc48f73ca9d0dc94afa9ce56da99388a16 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Mon, 1 Jul 2024 16:40:46 -0500 Subject: [PATCH 42/51] fix: remove references, dependency for `six` package --- pyproject.toml | 1 - rattail_tempmon/server.py | 9 +++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 68af181..3965cc5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,7 +24,6 @@ classifiers = [ ] dependencies = [ "rattail[db]", - "six", "sqlsoup", ] diff --git a/rattail_tempmon/server.py b/rattail_tempmon/server.py index f5ef640..a54614a 100644 --- a/rattail_tempmon/server.py +++ b/rattail_tempmon/server.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2018 Lance Edgar +# Copyright © 2010-2024 Lance Edgar # # This file is part of Rattail. # @@ -24,13 +24,10 @@ Tempmon server daemon """ -from __future__ import unicode_literals, absolute_import - import time import datetime import logging -import six import humanize from sqlalchemy import orm from sqlalchemy.exc import OperationalError @@ -91,7 +88,7 @@ class TempmonServerDaemon(Daemon): # first time after DB stop. but in the case of DB stop, # subsequent errors will instead match the second test if error.connection_invalidated or ( - 'could not connect to server: Connection refused' in six.text_type(error)): + 'could not connect to server: Connection refused' in str(error)): # only suppress logging for 3 failures, after that we let them go # TODO: should make the max attempts configurable @@ -99,7 +96,7 @@ class TempmonServerDaemon(Daemon): log_error = False log.debug("database connection failure #%s: %s", self.failed_checks, - six.text_type(error)) + str(error)) # send error email unless we're suppressing it for now if log_error: From fe0840d3e02abe6d12ddb4117f249b49df8c65cf Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Mon, 1 Jul 2024 23:22:07 -0500 Subject: [PATCH 43/51] =?UTF-8?q?bump:=20version=200.4.2=20=E2=86=92=200.4?= =?UTF-8?q?.3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 6 ++++++ pyproject.toml | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b9a381..2b8e853 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to rattail-tempmon will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## v0.4.3 (2024-07-01) + +### Fix + +- remove references, dependency for `six` package + ## v0.4.2 (2024-07-01) ### Fix diff --git a/pyproject.toml b/pyproject.toml index 3965cc5..715f355 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "hatchling.build" [project] name = "rattail-tempmon" -version = "0.4.2" +version = "0.4.3" description = "Retail Software Framework - Temperature monitoring add-on" readme = "README.rst" authors = [{name = "Lance Edgar", email = "lance@edbob.org"}] From 56d7a48e45190f579ab996f41e8cf18bf7594ce6 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 2 Jul 2024 00:27:59 -0500 Subject: [PATCH 44/51] fix: avoid deprecated function for engine config --- rattail_tempmon/config.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/rattail_tempmon/config.py b/rattail_tempmon/config.py index 1c30d30..17034fc 100644 --- a/rattail_tempmon/config.py +++ b/rattail_tempmon/config.py @@ -1,8 +1,8 @@ -# -*- coding: utf-8 -*- +# -*- coding: utf-8; -*- ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2017 Lance Edgar +# Copyright © 2010-2024 Lance Edgar # # This file is part of Rattail. # @@ -24,10 +24,9 @@ Tempmon config extension """ -from __future__ import unicode_literals, absolute_import +from wuttjamaican.db import get_engines from rattail.config import ConfigExtension -from rattail.db.config import get_engines from rattail_tempmon.db import Session From 55c84c6efeeace82d2b5b603da0eeac8c83e2a7b Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 2 Jul 2024 00:28:18 -0500 Subject: [PATCH 45/51] =?UTF-8?q?bump:=20version=200.4.3=20=E2=86=92=200.4?= =?UTF-8?q?.4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 6 ++++++ pyproject.toml | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b8e853..a885e10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to rattail-tempmon will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## v0.4.4 (2024-07-02) + +### Fix + +- avoid deprecated function for engine config + ## v0.4.3 (2024-07-01) ### Fix diff --git a/pyproject.toml b/pyproject.toml index 715f355..1b2f077 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "hatchling.build" [project] name = "rattail-tempmon" -version = "0.4.3" +version = "0.4.4" description = "Retail Software Framework - Temperature monitoring add-on" readme = "README.rst" authors = [{name = "Lance Edgar", email = "lance@edbob.org"}] From 8021ac818eed3457818e2f7762f926b4b086dc76 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 2 Jul 2024 01:22:37 -0500 Subject: [PATCH 46/51] fix: fix signature for calls to `get_engines()` --- rattail_tempmon/config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rattail_tempmon/config.py b/rattail_tempmon/config.py index 17034fc..32ef48f 100644 --- a/rattail_tempmon/config.py +++ b/rattail_tempmon/config.py @@ -52,10 +52,10 @@ class TempmonConfigExtension(ConfigExtension): def configure(self, config): # tempmon - config.tempmon_engines = get_engines(config, section='rattail_tempmon.db') + config.tempmon_engines = get_engines(config, 'rattail_tempmon.db') config.tempmon_engine = config.tempmon_engines.get('default') Session.configure(bind=config.tempmon_engine) # hotcooler - config.hotcooler_engines = get_engines(config, section='hotcooler.db') + config.hotcooler_engines = get_engines(config, 'hotcooler.db') config.hotcooler_engine = config.hotcooler_engines.get('default') From 7fe5e9aea636d444c4cf45e7c3e595027b45e71a Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 2 Jul 2024 01:23:02 -0500 Subject: [PATCH 47/51] =?UTF-8?q?bump:=20version=200.4.4=20=E2=86=92=200.4?= =?UTF-8?q?.5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 6 ++++++ pyproject.toml | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a885e10..09ca81c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to rattail-tempmon will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## v0.4.5 (2024-07-02) + +### Fix + +- fix signature for calls to `get_engines()` + ## v0.4.4 (2024-07-02) ### Fix diff --git a/pyproject.toml b/pyproject.toml index 1b2f077..2728bb2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "hatchling.build" [project] name = "rattail-tempmon" -version = "0.4.4" +version = "0.4.5" description = "Retail Software Framework - Temperature monitoring add-on" readme = "README.rst" authors = [{name = "Lance Edgar", email = "lance@edbob.org"}] From fa4cb5dc9a62ee2e2d71a6ec8d8067583b6fb5bb Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Fri, 16 Aug 2024 10:10:13 -0500 Subject: [PATCH 48/51] fix: avoid deprecated base class for config extension --- rattail_tempmon/config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rattail_tempmon/config.py b/rattail_tempmon/config.py index 32ef48f..a5f1333 100644 --- a/rattail_tempmon/config.py +++ b/rattail_tempmon/config.py @@ -25,12 +25,12 @@ Tempmon config extension """ from wuttjamaican.db import get_engines +from wuttjamaican.conf import WuttaConfigExtension -from rattail.config import ConfigExtension from rattail_tempmon.db import Session -class TempmonConfigExtension(ConfigExtension): +class TempmonConfigExtension(WuttaConfigExtension): """ Config extension for tempmon; adds tempmon DB engine/Session etc. Expects something like this in your config: From 949c9ee5a1f6b75d4bfdf828c449e3bd51ae55e0 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Mon, 19 Aug 2024 08:44:10 -0500 Subject: [PATCH 49/51] =?UTF-8?q?bump:=20version=200.4.5=20=E2=86=92=200.4?= =?UTF-8?q?.6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 6 ++++++ pyproject.toml | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 09ca81c..a249452 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to rattail-tempmon will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## v0.4.6 (2024-08-19) + +### Fix + +- avoid deprecated base class for config extension + ## v0.4.5 (2024-07-02) ### Fix diff --git a/pyproject.toml b/pyproject.toml index 2728bb2..3914b4d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "hatchling.build" [project] name = "rattail-tempmon" -version = "0.4.5" +version = "0.4.6" description = "Retail Software Framework - Temperature monitoring add-on" readme = "README.rst" authors = [{name = "Lance Edgar", email = "lance@edbob.org"}] From 07dda66bae075a8a4d5551d2413ace3ef7a514f0 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Fri, 13 Sep 2024 18:22:48 -0500 Subject: [PATCH 50/51] docs: use markdown for readme file --- README.rst => README.md | 8 +++----- pyproject.toml | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) rename README.rst => README.md (64%) diff --git a/README.rst b/README.md similarity index 64% rename from README.rst rename to README.md index 39651c1..979c915 100644 --- a/README.rst +++ b/README.md @@ -1,6 +1,5 @@ -rattail-tempmon -=============== +# rattail-tempmon Rattail is a retail software framework, released under the GNU General Public License. @@ -8,6 +7,5 @@ License. This is the ``rattail-tempmon`` package, which provides a database schema, and client/server daemons for recording and processing temperature data. -Please see Rattail's `home page`_ for more information. - -.. _home page: https://rattailproject.org/ +Please see Rattail's [home page](https://rattailproject.org/) for more +information. diff --git a/pyproject.toml b/pyproject.toml index 3914b4d..21cd013 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,7 +8,7 @@ build-backend = "hatchling.build" name = "rattail-tempmon" version = "0.4.6" description = "Retail Software Framework - Temperature monitoring add-on" -readme = "README.rst" +readme = "README.md" authors = [{name = "Lance Edgar", email = "lance@edbob.org"}] license = {text = "GNU GPL v3+"} classifiers = [ From f56cb41e6914b97f999fc2505065e8f04f379f60 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sat, 14 Sep 2024 12:12:40 -0500 Subject: [PATCH 51/51] docs: update project links, kallithea -> forgejo --- pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 21cd013..0e694fa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,8 +30,8 @@ dependencies = [ [project.urls] Homepage = "https://rattailproject.org" -Repository = "https://kallithea.rattailproject.org/rattail-project/rattail-tempmon" -Changelog = "https://kallithea.rattailproject.org/rattail-project/rattail-tempmon/files/master/CHANGES.rst" +Repository = "https://forgejo.wuttaproject.org/rattail/rattail-tempmon" +Changelog = "https://forgejo.wuttaproject.org/rattail/rattail-tempmon/src/branch/master/CHANGELOG.md" [project.entry-points."rattail.config.extensions"]