Commit fed70d58 authored by Martin Owens's avatar Martin Owens 🕘
Browse files

Merge branch 'remove-dateutil-dependency' into 'master'

Removed python-dateutil dependency

See merge request !32
parents 456f8b17 07af77f3
Loading
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ ruff:
  stage: lint
  image: registry.gitlab.com/pipeline-components/ruff:latest
  script:
    - ruff --ignore=E402,E731,F401,F821,F841 --line-length=128 --show-source .
    - ruff check --output-format=gitlab .

pytest:
  stage: test
@@ -39,7 +39,7 @@ setup.py_test:
  stage: test
  image: python:latest
  script:  # All pytests fail with ModuleNotFoundError: No module named 'test'
    - pip install pytest
    - pip install pytest setuptools
    - pip install --editable ".[cron-description,cron-schedule]"
    - pip list
    - python setup.py test
@@ -48,7 +48,7 @@ setup.py_test_with_coverage:
  stage: test
  image: python:latest
  script:  # With `&> /dev/null` in `./coverage.sh` everything appears green but...
    - pip install coverage pytest
    - pip install coverage pytest setuptools
    - pip install --editable ".[cron-description,cron-schedule]"
    - ./coverage.sh

+7 −4
Original line number Diff line number Diff line
@@ -21,12 +21,12 @@ Access logs in known locations to find information about them.
import os
import re
import codecs
import platform
from dateutil import parser as dateparse
from datetime import datetime

MATCHER = r'(?P<date>\w+ +\d+ +\d\d:\d\d:\d\d) (?P<host>\w+) ' + \
        r'CRON\[(?P<pid>\d+)\]: \((?P<user>\w+)\) CMD \((?P<cmd>.*)\)'


class LogReader(object):
    """Opens a Log file, reading backwards and watching for changes"""
    def __init__(self, filename, mass=4096):
@@ -82,6 +82,10 @@ class LogReader(object):
                loc -= len(line)


def cron_date_to_datetime(cron_str):
    with_year = f"{cron_str} {datetime.now().year}"
    return datetime.strptime(with_year, "%b %d %H:%M:%S %Y")


class CronLog(LogReader):
    """Use the LogReader to make a Cron specific log reader"""
@@ -98,7 +102,7 @@ class CronLog(LogReader):
            match = re.match(MATCHER, str(line))
            datum = match and match.groupdict()
            if datum and (not self.user or datum['user'] == self.user):
                datum['date'] = dateparse.parse(datum['date'])
                datum['date'] = cron_date_to_datetime(datum['date'])
                yield datum


@@ -112,4 +116,3 @@ class ProgramLog(object):
        for entry in self.log:
            if entry['cmd'] == str(self.command):
                yield entry

pyproject.toml

0 → 100644
+12 −0
Original line number Diff line number Diff line
[tool.ruff]
line-length = 128


[tool.ruff.lint]
ignore = [
    "E402",
    "E731",
    "F401",
    "F821",
    "F841",
]
+0 −1
Original line number Diff line number Diff line
@@ -49,7 +49,6 @@ setup(
    license          = 'LGPLv3',
    py_modules       = ['crontab', 'crontabs', 'cronlog'],
    provides         = ['crontab', 'crontabs', 'cronlog'],
    install_requires = ['python-dateutil'],
    extras_require   = {
        'cron-schedule': ['croniter'],
        'cron-description': ['cron-descriptor'],
+1 −1
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ class Utf8TestCase(unittest.TestCase):

    def test_02_write(self):
        """Write/Read UTF-8 Filename"""
        self.assertEqual(locale.getpreferredencoding(), 'UTF-8')
        self.assertEqual(locale.getpreferredencoding().lower(), 'utf-8')
        self.crontab.write(filename)
        crontab = CronTab(tabfile=filename)
        self.assertTrue(crontab)