Skip to content

Commit

Permalink
[2.2.16] - 2022-12-30
Browse files Browse the repository at this point in the history
## [2.2.16] - 2022-12-30

### Fixed

- Log level is now fixed and should not default to 0
- Docker schedule should now work again

### Changed

- Integrate logging logs to loguru via custom sink
- Simplify docker shell scripts
  • Loading branch information
olofvndrhr committed Dec 30, 2022
2 parents 5bdd54f + b7ff17f commit ece6473
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 99 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

- Add support for more sites

## [2.2.16] - 2022-12-30

### Fixed

- Log level is now fixed and should not default to 0
- Docker schedule should now work again

### Changed

- Integrate logging logs to loguru via custom sink
- Simplify docker shell scripts

## [2.2.15] - 2022-12-29

### Added
Expand Down
3 changes: 1 addition & 2 deletions docker/rootfs/app/schedules/daily.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ python3 /app/manga-dlp.py \
--path /app/downloads \
--read /app/mangas.txt \
--chapters all \
--wait 2 \
--warn
--wait 2
2 changes: 1 addition & 1 deletion docker/rootfs/etc/cont-init.d/20-setenv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
: "${MDLP_FILE_FORMAT:=cbz}"
: "${MDLP_WAIT:=0.5}"
: "${MDLP_FORCEVOL:=false}"
: "${MDLP_LOG_LEVEL:=warn}"
: "${MDLP_LOG_LEVEL:=}"
30 changes: 0 additions & 30 deletions docker/rootfs/etc/cont-init.d/51-fix-schedule.sh

This file was deleted.

49 changes: 21 additions & 28 deletions docker/rootfs/etc/cont-init.d/52-set-schedule.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,45 @@
# source env variables
source /etc/cont-init.d/20-setenv.sh

custom_args=(
--path "${MDLP_PATH}"
--read "${MDLP_READ}"
--language "${MDLP_LANGUAGE}"
--chapters "${MDLP_CHAPTERS}"
--format "${MDLP_FILE_FORMAT}"
--wait "${MDLP_WAIT}"
)

function prepare_vars() {
# set log level
case "${MDLP_LOG_LEVEL}" in
"warn")
MDLP_LOG_LEVEL_FLAG=" --warn"
custom_args+=("--warn")
;;
"debug")
MDLP_LOG_LEVEL_FLAG=" --debug"
custom_args+=("--debug")
;;
*)
MDLP_LOG_LEVEL_FLAG=" --loglevel ${MDLP_LOG_LEVEL}"
if [[ -n "${MDLP_LOG_LEVEL}" ]]; then
custom_args+=("--loglevel" "${MDLP_LOG_LEVEL}")
fi
;;
esac

# check if forcevol should be used
if [[ "${MDLP_FORCEVOL,,}" == "true" ]]; then
# add backslash if log level is also specified
if [[ -n "${MDLP_LOG_LEVEL_FLAG}" ]]; then
MDLP_FORCEVOL_FLAG="\n --forcevol \\"
else
MDLP_FORCEVOL_FLAG="\n --forcevol"
fi
custom_args+=("--forcevol")
fi
}

# set schedule with env variables
function set_vars() {
echo -ne "#!/bin/bash\n
python3 /app/manga-dlp.py \\
--path ${MDLP_PATH} \\
--read ${MDLP_READ} \\
--language ${MDLP_LANGUAGE} \\
--chapters ${MDLP_CHAPTERS} \\
--format ${MDLP_FILE_FORMAT} \\
--wait ${MDLP_WAIT}" \
> /app/schedules/daily.sh

# set forcevol or log level if specified
if [[ -n "${MDLP_FORCEVOL_FLAG}" ]] || [[ -n "${MDLP_LOG_LEVEL_FLAG}" ]]; then
sed -i 's/--wait '"${MDLP_WAIT}"'/--wait '"${MDLP_WAIT}"' \\/g' /app/schedules/daily.sh
echo -e "${MDLP_FORCEVOL_FLAG:-}" >> /app/schedules/daily.sh
echo -e "${MDLP_LOG_LEVEL_FLAG:-}" >> /app/schedules/daily.sh
else
# add final newline of not added before
echo -ne "\n" >> /app/schedules/daily.sh
fi
cat << EOF > "/app/schedules/daily.sh"
#!/bin/bash
python3 /app/manga-dlp.py ${custom_args[@]}
EOF
}

# check if schedule should be generated
Expand Down
22 changes: 11 additions & 11 deletions docs/pages/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ it will not generate it (it will just use the default one).

For more info's about the options, you can look in the main scripts [README.md](../)

| ENV Variable | Default | manga-dlp option | Info |
|:-----------------------|:----------------|:------------------------------|--------------------------------------------------------------------------|
| MDLP_GENERATE_SCHEDULE | false | none | Has to be set to "true" to generate the config via environment variables |
| MDLP_PATH | /app/downloads | --path | |
| MDLP_READ | /app/mangas.txt | --read | |
| MDLP_LANGUAGE | en | --language | |
| MDLP_CHAPTERS | all | --chapter | |
| MDLP_FILE_FORMAT | cbz | --format | |
| MDLP_WAIT | 0.5 | --wait | |
| MDLP_FORCEVOL | false | --forcevol | |
| MDLP_LOG_LEVEL | lean | --warn / --debug / --loglevel | Can either be set to: warn, debug or a custom loglevel integer |
| ENV Variable | Default | manga-dlp option | Info |
|:-----------------------|:----------------|:------------------------------------|--------------------------------------------------------------------------|
| MDLP_GENERATE_SCHEDULE | false | none | Has to be set to "true" to generate the config via environment variables |
| MDLP_PATH | /app/downloads | --path | |
| MDLP_READ | /app/mangas.txt | --read | |
| MDLP_LANGUAGE | en | --language | |
| MDLP_CHAPTERS | all | --chapter | |
| MDLP_FILE_FORMAT | cbz | --format | |
| MDLP_WAIT | 0.5 | --wait | |
| MDLP_FORCEVOL | false | --forcevol | |
| MDLP_LOG_LEVEL | <none> | --warn / --debug / --loglevel <INT> | Can either be set to: warn, debug or a custom loglevel integer |

## Run commands in container

Expand Down
2 changes: 1 addition & 1 deletion mangadlp/__about__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.1.15"
__version__ = "2.1.16"
18 changes: 11 additions & 7 deletions mangadlp/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def readin_list(_, __, value) -> list:

# filter empty lines and remove them
filtered_list = list(filter(len, url_list))
log.info(f"Mangas from list: {filtered_list}")
click.echo(f"Mangas from list: {filtered_list}")

return filtered_list

Expand Down Expand Up @@ -64,24 +64,24 @@ def readin_list(_, __, value) -> list:
"--loglevel",
"verbosity",
type=int,
default=20,
default=None,
show_default=True,
help="Custom log level",
)
@optgroup.option(
"--warn",
"verbosity",
flag_value=25,
default=20,
show_default=False,
flag_value=30,
default=None,
show_default=True,
help="Only log warnings and higher",
)
@optgroup.option(
"--debug",
"verbosity",
flag_value=10,
default=20,
show_default=False,
default=None,
show_default=True,
help="Debug logging. Log EVERYTHING",
)
# other options
Expand Down Expand Up @@ -212,6 +212,10 @@ def main(
"""

# set log level to INFO if not set
if not verbosity:
verbosity = 20

# set loglevel and log format
prepare_logger(verbosity)

Expand Down
44 changes: 28 additions & 16 deletions mangadlp/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,45 @@

from loguru import logger

LOGGING_FMT: str = (
"%(asctime)s | (D) [%(levelname)-7s] [%(name)-10s] [%(funcName)-20s]: %(message)s"
)
LOGURU_FMT: str = "{time:%Y-%m-%dT%H:%M:%S%z} | (C) <level>[{level: <7}]</level> [{name: <10}] [{function: <20}]: {message}"
LOGURU_FMT = "{time:%Y-%m-%dT%H:%M:%S%z} | <level>[{level: <7}]</level> [{name: <10}] [{function: <20}]: {message}"


def enable_default_logger(loglevel: int) -> None:
logging.root.handlers = []
# from loguru docs
class InterceptHandler(logging.Handler):
"""
Intercept python logging messages and log them via loguru.logger
"""

logging.basicConfig(
format=LOGGING_FMT,
datefmt="%Y-%m-%dT%H:%M:%S%z",
level=loglevel,
handlers=[logging.StreamHandler()],
)
def emit(self, record):
# Get corresponding Loguru level if it exists
try:
level = logger.level(record.levelname).name
except ValueError:
level = record.levelno

# Find caller from where originated the logged message
frame, depth = logging.currentframe(), 2
while frame.f_code.co_filename == logging.__file__:
frame = frame.f_back
depth += 1

logger.opt(depth=depth, exception=record.exc_info).log(
level, record.getMessage()
)


# init logger with format and log level
def prepare_logger(loglevel: int = 20) -> None:

# create config for a normal stderr logger
def prepare_logger(loglevel: int) -> None:
config: dict = {
"handlers": [
{
"sink": sys.stdout,
"level": loglevel,
"format": LOGURU_FMT,
},
}
],
}

logging.basicConfig(handlers=[InterceptHandler()], level=loglevel)
logger.configure(**config)
enable_default_logger(loglevel)
9 changes: 6 additions & 3 deletions mangadlp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,17 @@ def get_filename(


def progress_bar(progress: float, total: float) -> None:
time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
time = datetime.now().strftime("%Y-%m-%dT%H:%M:%S")
percent = int(progress / (int(total) / 100))
bar_length = 50
bar_progress = int(progress / (int(total) / bar_length))
bar_texture = "■" * bar_progress
whitespace_texture = " " * (bar_length - bar_progress)
if progress == total:
full_bar = "■" * bar_length
print(f"\r{time} |{full_bar}❙ 100%", end="\n")
print(f"\r{time}{' '*6}| [BAR ]{full_bar}❙ 100%", end="\n")
else:
print(f"\r{time} | ❙{bar_texture}{whitespace_texture}{percent}%", end="\r")
print(
f"\r{time}{' '*6}| [BAR ] ❙{bar_texture}{whitespace_texture}{percent}%",
end="\r",
)

0 comments on commit ece6473

Please sign in to comment.