Skip to content

Commit

Permalink
Fix-deploy (#40)
Browse files Browse the repository at this point in the history
* cli logging update

passing -v now enables console logging
pass -debug to increase verbosity

* ignore case in regexexpressions
  • Loading branch information
niro1987 authored Oct 16, 2024
1 parent e94b621 commit d9b6917
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
29 changes: 22 additions & 7 deletions src/sapcommissions/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ def convert(self, value, param, ctx):
return value


def setup_logging(logfile: Path | None = None, verbose: bool = False) -> None:
"""Set up logging and add filehandler if logfile is provided."""
def setup_logging(
filename: Path | None = None,
verbose: bool = False,
debug: bool = False,
) -> None:
"""Set up logging."""
config = {
"version": 1,
"formatters": {
Expand All @@ -48,16 +52,21 @@ def setup_logging(logfile: Path | None = None, verbose: bool = False) -> None:
},
}
handlers = {}
if logfile:
if verbose:
handlers["console"] = {
"class": "logging.StreamHandler",
"formatter": "standard",
}
if filename:
handlers["file"] = {
"class": "logging.FileHandler",
"formatter": "standard",
"filename": str(str(logfile)),
"filename": str(str(filename)),
}
loggers = {
__package__: {
"handlers": list(handlers.keys()),
"level": "DEBUG" if verbose else "INFO",
"level": "DEBUG" if debug else "INFO",
},
}
config["handlers"] = handlers
Expand Down Expand Up @@ -231,7 +240,12 @@ async def async_load_resource(
@click.option(
"-v",
is_flag=True,
help="Increase logging verbosity.",
help="Verbose logging.",
)
@click.option(
"-debug",
is_flag=True,
help="Enable DEBUG logging.",
)
def cli( # noqa: PLR0913
ctx: click.Context,
Expand All @@ -241,6 +255,7 @@ def cli( # noqa: PLR0913
no_ssl: bool = False,
logfile: Path | None = None,
v: bool = False,
debug: bool = False,
) -> None:
"""Command-line interface for Python SAP Commissions.
Expand All @@ -258,7 +273,7 @@ def cli( # noqa: PLR0913
ctx.obj["PASSWORD"] = password
ctx.obj["SSL"] = not no_ssl

setup_logging(logfile, v)
setup_logging(logfile, v, debug)
LOGGER.info("Tenant: '%s', Username: '%s', Ssl: '%s'", tenant, username, not no_ssl)


Expand Down
21 changes: 14 additions & 7 deletions src/sapcommissions/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,32 @@
LOGGER: logging.Logger = logging.getLogger(__name__)

RE_CREDIT_TYPE: Final[re.Pattern] = re.compile(
r"^[a-zA-Z0-9_.\- ]*(Credit Type)\.txt$",
r"^[a-z0-9_.\- ]*(Credit Type)\.txt$",
flags=re.IGNORECASE,
)
RE_EARNING_CODE: Final[re.Pattern] = re.compile(
r"^[a-zA-Z0-9_.\- ]*(Earning Code)\.txt$",
r"^[a-z0-9_.\- ]*(Earning Code)\.txt$",
flags=re.IGNORECASE,
)
RE_EARNING_GROUP: Final[re.Pattern] = re.compile(
r"^[a-zA-Z0-9_.\- ]*(Earning Group)\.txt$",
r"^[a-z0-9_.\- ]*(Earning Group)\.txt$",
flags=re.IGNORECASE,
)
RE_EVENT_TYPE: Final[re.Pattern] = re.compile(
r"^[a-zA-Z0-9_.\- ]*(Event Type)\.txt$",
r"^[a-z0-9_.\- ]*(Event Type)\.txt$",
flags=re.IGNORECASE,
)
RE_FIXED_VALUE_TYPE: Final[re.Pattern] = re.compile(
r"^[a-zA-Z0-9_.\- ]*(Fixed Value Type)\.txt$",
r"^[a-z0-9_.\- ]*(Fixed Value Type)\.txt$",
flags=re.IGNORECASE,
)
RE_REASON_CODE: Final[re.Pattern] = re.compile(
r"^[a-zA-Z0-9_.\- ]*(Reason Code)\.txt$",
r"^[a-z0-9_.\- ]*(Reason Code)\.txt$",
flags=re.IGNORECASE,
)
RE_XML: Final[re.Pattern] = re.compile(
r"^[a-zA-Z0-9_.\- ]*[a-zA-Z0-9_.\- ]+\.xml$",
r"^[a-z0-9_.\- ]*[a-z0-9_.\- ]+\.xml$",
flags=re.IGNORECASE,
)


Expand Down

0 comments on commit d9b6917

Please sign in to comment.