3
0
Fork 0

Compare commits

..

No commits in common. "2fcff6b2a4a1df07ef2e49dfb46cf4502fa58cce" and "ac65ec891b8169d07fc26fd6908e0e12dbd4a27f" have entirely different histories.

20 changed files with 43 additions and 76 deletions

View file

@ -2,8 +2,4 @@
[MESSAGES CONTROL]
disable=all
enable=dangerous-default-value,
inconsistent-return-statements,
redefined-argument-from-local,
unspecified-encoding,
unused-import,
enable=dangerous-default-value

View file

@ -2,7 +2,7 @@
################################################################################
#
# WuttJamaican -- Base package for Wutta Framework
# Copyright © 2023-2025 Lance Edgar
# Copyright © 2023-2024 Lance Edgar
#
# This file is part of Wutta Framework.
#
@ -24,6 +24,7 @@
WuttJamaican - app handler
"""
import datetime
import importlib
import logging
import os
@ -229,7 +230,7 @@ class AppHandler:
If ``obj`` is *not* specified, this behaves a bit differently.
It first will look for a :term:`config setting` named
``wutta.app_dist`` (or similar, depending on :attr:`appname`).
``wutta.app_dist`` (or similar, dpending on :attr:`appname`).
If there is such a config value, it is returned. Otherwise
the "auto-locate" logic described above happens, but using
``self`` instead of ``obj``.
@ -280,7 +281,8 @@ class AppHandler:
return dist
# fall back to configured dist, if obj lookup failed
return self.config.get(f'{self.appname}.app_dist')
if obj is not None:
return self.config.get(f'{self.appname}.app_dist')
def get_version(self, dist=None, obj=None):
"""
@ -300,7 +302,6 @@ class AppHandler:
dist = self.get_distribution(obj=obj)
if dist:
return version(dist)
return None
def get_model(self):
"""
@ -463,7 +464,7 @@ class AppHandler:
"""
output = template.render(**context)
if output_path:
with open(output_path, 'wt', encoding='utf_8') as f:
with open(output_path, 'wt') as f:
f.write(output)
return output

View file

@ -93,7 +93,6 @@ class AuthHandler(GenericHandler):
if user and user.active and user.password:
if self.check_user_password(user, password):
return user
return None
def authenticate_user_token(self, session, token):
"""
@ -123,7 +122,6 @@ class AuthHandler(GenericHandler):
user = token.user
if user.active:
return user
return None
def check_user_password(self, user, password, **kwargs):
"""
@ -160,7 +158,7 @@ class AuthHandler(GenericHandler):
model = self.app.model
if not key:
return None
return
# maybe it is a uuid
if isinstance(key, _uuid.UUID):
@ -190,7 +188,6 @@ class AuthHandler(GenericHandler):
session=session)
if key:
return self.get_role(session, key)
return None
def get_user(self, obj, session=None, **kwargs):
"""
@ -259,7 +256,6 @@ class AuthHandler(GenericHandler):
person = self.app.get_person(obj)
if person:
return person.user
return None
def make_person(self, **kwargs):
"""

View file

@ -2,7 +2,7 @@
################################################################################
#
# WuttJamaican -- Base package for Wutta Framework
# Copyright © 2023-2025 Lance Edgar
# Copyright © 2023-2024 Lance Edgar
#
# This file is part of Wutta Framework.
#
@ -25,6 +25,7 @@ WuttJamaican - app configuration
"""
import configparser
import importlib
import logging
import logging.config
import os
@ -273,7 +274,7 @@ class WuttaConfig:
# re-write as temp file with "final" values
fd, temp_path = tempfile.mkstemp(suffix='.ini')
os.close(fd)
with open(temp_path, 'wt', encoding='utf_8') as f:
with open(temp_path, 'wt') as f:
temp_config.write(f)
# and finally, load that into our main config
@ -285,14 +286,14 @@ class WuttaConfig:
# bring in any "required" files
requires = config.get(f'{self.appname}.config.require')
if requires:
for p in self.parse_list(requires):
self._load_ini_configs(p, configs, require=True)
for path in self.parse_list(requires):
self._load_ini_configs(path, configs, require=True)
# bring in any "included" files
includes = config.get(f'{self.appname}.config.include')
if includes:
for p in self.parse_list(includes):
self._load_ini_configs(p, configs, require=False)
for path in self.parse_list(includes):
self._load_ini_configs(path, configs, require=False)
def get_prioritized_files(self):
"""
@ -466,8 +467,6 @@ class WuttaConfig:
if default is not UNSPECIFIED:
return default
return None
def get_from_db(self, key, session=None, **kwargs):
"""
Retrieve a config value from database settings table.
@ -512,7 +511,6 @@ class WuttaConfig:
value = self.get(*args, **kwargs)
if value is not None:
return int(value)
return None
def get_list(self, *args, **kwargs):
"""
@ -527,7 +525,6 @@ class WuttaConfig:
value = self.get(*args, **kwargs)
if value is not None:
return self.parse_list(value)
return None
def get_dict(self, prefix):
"""
@ -614,7 +611,7 @@ class WuttaConfig:
# write INI file and return path
fd, path = tempfile.mkstemp(suffix='.conf')
os.close(fd)
with open(path, 'wt', encoding='utf_8') as f:
with open(path, 'wt') as f:
parser.write(f)
return path

View file

@ -45,7 +45,7 @@ import sqlalchemy as sa
from sqlalchemy import orm
from sqlalchemy.ext.associationproxy import association_proxy
from . import Base, uuid_column, uuid_fk_column
from .base import Base, uuid_column, uuid_fk_column
class Role(Base):

View file

@ -2,7 +2,7 @@
################################################################################
#
# WuttJamaican -- Base package for Wutta Framework
# Copyright © 2023-2025 Lance Edgar
# Copyright © 2023-2024 Lance Edgar
#
# This file is part of Wutta Framework.
#
@ -36,7 +36,8 @@ import sqlalchemy as sa
from sqlalchemy import orm
from sqlalchemy.ext.associationproxy import association_proxy
from wuttjamaican.db.util import naming_convention, ModelBase, uuid_column
from wuttjamaican.db.util import (naming_convention, ModelBase,
uuid_column, uuid_fk_column)
class WuttaModelBase(ModelBase):
@ -214,4 +215,3 @@ class Person(Base):
if self.users:
return self.users[0]
return None

View file

@ -2,7 +2,7 @@
################################################################################
#
# WuttJamaican -- Base package for Wutta Framework
# Copyright © 2023-2025 Lance Edgar
# Copyright © 2023-2024 Lance Edgar
#
# This file is part of Wutta Framework.
#
@ -31,7 +31,7 @@ from sqlalchemy import orm
from sqlalchemy.ext.declarative import declared_attr
from sqlalchemy.ext.orderinglist import ordering_list
from wuttjamaican.db.model import uuid_column, User
from wuttjamaican.db.model import uuid_column, uuid_fk_column, User
from wuttjamaican.db.util import UUID
@ -263,7 +263,6 @@ class BatchMixin:
"""
if self.id:
return f'{self.id:08d}'
return None
class BatchRowMixin:

View file

@ -2,7 +2,7 @@
################################################################################
#
# WuttJamaican -- Base package for Wutta Framework
# Copyright © 2023-2025 Lance Edgar
# Copyright © 2023-2024 Lance Edgar
#
# This file is part of Wutta Framework.
#
@ -29,7 +29,7 @@ import datetime
import sqlalchemy as sa
from sqlalchemy import orm
from . import Base, uuid_column, uuid_fk_column
from .base import Base, uuid_column, uuid_fk_column
from wuttjamaican.enum import UpgradeStatus
from wuttjamaican.db.util import UUID
from wuttjamaican.util import make_true_uuid

View file

@ -2,7 +2,7 @@
################################################################################
#
# WuttJamaican -- Base package for Wutta Framework
# Copyright © 2023-2025 Lance Edgar
# Copyright © 2023-2024 Lance Edgar
#
# This file is part of Wutta Framework.
#
@ -66,7 +66,6 @@ class ModelBase:
state = sa.inspect(self)
if hasattr(state.attrs, key):
return getattr(self, key)
raise KeyError(f"model instance has no attr with key: {key}")
class UUID(sa.types.TypeDecorator):

View file

@ -2,7 +2,7 @@
################################################################################
#
# WuttJamaican -- Base package for Wutta Framework
# Copyright © 2023-2025 Lance Edgar
# Copyright © 2023-2024 Lance Edgar
#
# This file is part of Wutta Framework.
#
@ -358,7 +358,6 @@ class EmailHandler(GenericHandler):
if instance:
setting = setting(self.config)
return setting
return None
def make_message(self, **kwargs):
"""
@ -574,7 +573,6 @@ class EmailHandler(GenericHandler):
if template:
context = context or {}
return template.render(**context)
return None
def get_auto_html_body(self, key, context=None):
"""
@ -587,7 +585,6 @@ class EmailHandler(GenericHandler):
if template:
context = context or {}
return template.render(**context)
return None
def get_auto_body_template(self, key, mode):
""" """
@ -604,7 +601,6 @@ class EmailHandler(GenericHandler):
return templates.get_template(f'{key}.{mode}.mako')
except TopLevelLookupException:
pass
return None
def get_notes(self, key):
"""
@ -656,8 +652,8 @@ class EmailHandler(GenericHandler):
:returns: True if this email type is enabled, otherwise false.
"""
for k in set([key, 'default']):
enabled = self.config.get_bool(f'{self.config.appname}.email.{k}.enabled')
for key in set([key, 'default']):
enabled = self.config.get_bool(f'{self.config.appname}.email.{key}.enabled')
if enabled is not None:
return enabled
return True

View file

@ -2,7 +2,7 @@
################################################################################
#
# WuttJamaican -- Base package for Wutta Framework
# Copyright © 2023-2025 Lance Edgar
# Copyright © 2023-2024 Lance Edgar
#
# This file is part of Wutta Framework.
#
@ -25,6 +25,7 @@ Install Handler
"""
import os
import shutil
import stat
import subprocess
import sys
@ -254,7 +255,6 @@ class InstallHandler(GenericHandler):
sa.inspect(engine).has_table('whatever')
except Exception as error:
return str(error)
return None
def make_template_context(self, dbinfo, **kwargs):
"""

View file

@ -2,7 +2,7 @@
################################################################################
#
# WuttJamaican -- Base package for Wutta Framework
# Copyright © 2023-2025 Lance Edgar
# Copyright © 2023-2024 Lance Edgar
#
# This file is part of Wutta Framework.
#
@ -88,5 +88,3 @@ class PeopleHandler(GenericHandler):
user = obj
if user.person:
return user.person
return None

View file

@ -308,14 +308,14 @@ class ProblemHandler(GenericHandler):
if not self.is_enabled(check):
log.debug("problem check is not enabled: %s", key)
if not force:
return None
return
weekday = datetime.date.today().weekday()
if not self.should_run_for_weekday(check, weekday):
log.debug("problem check is not scheduled for %s: %s",
calendar.day_name[weekday], key)
if not force:
return None
return
check_instance = check(self.config)
problems = self.find_problems(check_instance)

View file

@ -2,7 +2,7 @@
################################################################################
#
# WuttJamaican -- Base package for Wutta Framework
# Copyright © 2023-2025 Lance Edgar
# Copyright © 2023-2024 Lance Edgar
#
# This file is part of Wutta Framework.
#
@ -196,7 +196,6 @@ class ReportHandler(GenericHandler):
if instance:
report = report(self.config)
return report
return None
def make_report_data(self, report, params=None, progress=None, **kwargs):
"""

View file

@ -95,7 +95,7 @@ class FileTestCase(TestCase):
myconf = self.write_file('my.conf', '<file contents>')
"""
path = os.path.join(self.tempdir, filename)
with open(path, 'wt', encoding='utf_8') as f:
with open(path, 'wt') as f:
f.write(content)
return path

View file

@ -2,7 +2,7 @@
################################################################################
#
# WuttJamaican -- Base package for Wutta Framework
# Copyright © 2023-2025 Lance Edgar
# Copyright © 2023-2024 Lance Edgar
#
# This file is part of Wutta Framework.
#
@ -256,11 +256,11 @@ def parse_list(value):
parser.whitespace += ','
parser.whitespace_split = True
values = list(parser)
for i, val in enumerate(values):
if val.startswith('"') and val.endswith('"'):
values[i] = val[1:-1]
elif val.startswith("'") and val.endswith("'"):
values[i] = val[1:-1]
for i, value in enumerate(values):
if value.startswith('"') and value.endswith('"'):
values[i] = value[1:-1]
elif value.startswith("'") and value.endswith("'"):
values[i] = value[1:-1]
return values
@ -354,8 +354,8 @@ def resource_path(path):
package, filename = path.split(':')
ref = files(package) / filename
with as_file(ref) as p:
return str(p)
with as_file(ref) as path:
return str(path)
return path

View file

@ -27,10 +27,6 @@ else:
batch = MyBatch(id=42, uuid=_uuid.UUID('0675cdac-ffc9-7690-8000-6023de1c8cfd'))
self.assertEqual(repr(batch), "MyBatch(uuid=UUID('0675cdac-ffc9-7690-8000-6023de1c8cfd'))")
self.assertEqual(str(batch), "00000042")
self.assertEqual(batch.id_str, "00000042")
batch2 = MyBatch()
self.assertIsNone(batch2.id_str)
class TestBatchRowMixin(DataTestCase):

View file

@ -22,11 +22,9 @@ else:
def test_dict_behavior(self):
setting = Setting()
self.assertEqual(list(iter(setting)), [('name', None), ('value', None)])
self.assertIsNone(setting.name)
self.assertIsNone(setting['name'])
setting.name = 'foo'
self.assertEqual(setting['name'], 'foo')
self.assertRaises(KeyError, lambda: setting['notfound'])
class TestUUID(TestCase):

View file

@ -375,10 +375,6 @@ app_title = WuttaTest
ver = self.app.get_version(obj=query)
self.assertEqual(ver, version('SQLAlchemy'))
# random object will not yield a dist nor version
ver = self.app.get_version(obj=42)
self.assertIsNone(ver)
# can override dist via config
self.config.setdefault('wuttatest.app_dist', 'python-configuration')
ver = self.app.get_version()

View file

@ -94,10 +94,6 @@ class TestReportHandler(ConfigTestCase):
self.assertTrue(issubclass(report, mod.Report))
self.assertIs(report, MockFooReport)
# not found
report = handler.get_report('unknown')
self.assertIsNone(report)
def test_make_report_data(self):
providers = {
'wuttatest': MagicMock(report_modules=['tests.test_reports']),