コード例 #1
0
ファイル: commits.py プロジェクト: karlicoss/HPI
# experiment to make it lazy?
# would be nice to have a nicer syntax for it... maybe make_config could return a 'lazy' object
def config() -> commits_cfg:
    res = make_config(commits_cfg)
    if res.emails is None and res.names is None:
        # todo error policy? throw/warn/ignore
        high("Set either 'emails' or 'names', otherwise you'll get no commits")
    return res


##########################

import git  # type: ignore
from git.repo.fun import is_git_dir  # type: ignore

log = LazyLogger(__name__, level='info')


def by_me(c: git.objects.commit.Commit) -> bool:
    actor = c.author
    if actor.email in (config().emails or ()):
        return True
    if actor.name in (config().names or ()):
        return True
    return False


@dataclass
class Commit:
    committed_dt: datetime
    authored_dt: datetime
コード例 #2
0
# todo most of it belongs to DAL... but considering so few people use it I didn't bother for now
from datetime import datetime, timedelta
from pathlib import Path
import re
import sqlite3
from typing import Iterable, Sequence, Set, Optional

from my.core import get_files, LazyLogger, dataclass, Res
from my.core.sqlite import sqlite_connect_immutable

from my.config import bluemaestro as config


# todo control level via env variable?
# i.e. HPI_LOGGING_MY_BLUEMAESTRO_LEVEL=debug
logger = LazyLogger(__name__, level='debug')


def inputs() -> Sequence[Path]:
    return get_files(config.export_path)


Celsius = float
Percent = float
mBar    = float

@dataclass
class Measurement:
    dt: datetime # todo aware/naive
    temp    : Celsius
    humidity: Percent
コード例 #3
0
from mailparser.exceptions import MailParserReceivedParsingError  # type: ignore[import]
from more_itertools import unique_everseen

from my.core import LazyLogger

REQUIRES = ["mail-parser", "dateparser"]

# silence all mailparser logs
# https://stackoverflow.com/a/55396144
mlog = logging.getLogger("mailparser")
for handler in mlog.handlers.copy():
    mlog.removeHandler(handler)
mlog.addHandler(logging.NullHandler())
mlog.propagate = False

logger = LazyLogger(__name__)


class Email(MailParser):
    """
    subclass of the mailparser which
    supports serialization by my.core.serialize
    along with a few other convenience functions
    """

    # note: The 'message' property on this class
    # is the stdlib email.Message class:
    # https://docs.python.org/3/library/email.message.html#module-email.message
    def __init__(self, message: Message) -> None:
        super().__init__(message=message)
        self.filepath: Optional[Path] = None
コード例 #4
0
ファイル: zsh.py プロジェクト: tg-z/hpi
    # path to current zsh history (i.e. the live file)
    live_file: Optional[PathIsh]


from pathlib import Path
from typing import Sequence
from functools import lru_cache

from my.core import get_files, warn_if_empty, Stats, LazyLogger
from my.core.common import mcachew
from my.core.warnings import low
from .utils.time import parse_datetime_sec
from .utils.common import InputSource


logger = LazyLogger(__name__, level="warning")


def backup_inputs() -> Sequence[Path]:
    return list(get_files(config.export_path))


@lru_cache(1)
def _live_file() -> Optional[Path]:
    if config.live_file is not None:
        p: Path = Path(config.live_file).expanduser().absolute()
        if p.exists():
            return p
        else:
            low(f"'live_file' provided {config.live_file} but that file doesn't exist.")
            return None