Skip to content

Commit

Permalink
更换 logger 库
Browse files Browse the repository at this point in the history
  • Loading branch information
TakWolf committed Jul 20, 2024
1 parent 2c5a87a commit a870d1a
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 27 deletions.
3 changes: 0 additions & 3 deletions tools/build.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import logging
import shutil

from tools import configs
from tools.configs import path_define
from tools.services import dump_service, font_service, image_service

logging.basicConfig(level=logging.DEBUG)


def main():
if path_define.build_dir.exists():
Expand Down
6 changes: 2 additions & 4 deletions tools/services/dump_service.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import logging
from typing import IO

from character_encoding_utils import gb2312
from character_encoding_utils.gb2312 import GB2312Exception
from loguru import logger

from tools.configs import DumpConfig
from tools.utils import glyph_util

logger = logging.getLogger('dump-service')


def _dump_glyph(dump_config: DumpConfig, c: str, glyph_bytes: bytes):
glyph_data = []
Expand All @@ -25,7 +23,7 @@ def _dump_glyph(dump_config: DumpConfig, c: str, glyph_bytes: bytes):
hex_name = f'{ord(c): 04X}'
file_path = dump_config.dump_dir.joinpath(f'{hex_name}.png')
glyph_util.save_glyph_data_to_png(glyph_data, file_path)
logger.info('Dump %s %d*%d %s - %s', dump_config.font_name, dump_config.glyph_width, dump_config.glyph_height, c if c.isprintable() else ' ', hex_name)
logger.info('Dump {} {}*{} {} - {}', dump_config.font_name, dump_config.glyph_width, dump_config.glyph_height, c if c.isprintable() else ' ', hex_name)


def _dump_font_ascii(dump_config: DumpConfig, file: IO, num_start: int, num_end: int):
Expand Down
12 changes: 5 additions & 7 deletions tools/services/font_service.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import logging
import math

from loguru import logger
from pixel_font_builder import FontBuilder, WeightName, SerifStyle, SlantStyle, WidthStyle, Glyph
from pixel_font_builder.opentype import Flavor

from tools.configs import FontConfig
from tools.configs import path_define
from tools.utils import glyph_util

logger = logging.getLogger('font-service')


def collect_glyph_files(font_config: FontConfig) -> tuple[dict[int, str], list[tuple[str, str]]]:
root_dirs = [path_define.glyphs_dir.joinpath(str(font_config.size))]
Expand Down Expand Up @@ -84,16 +82,16 @@ def make_font_files(font_config: FontConfig, character_mapping: dict[int, str],

otf_file_path = path_define.outputs_dir.joinpath(f'{font_config.outputs_name}.otf')
builder.save_otf(otf_file_path)
logger.info("Make font file: '%s'", otf_file_path)
logger.info("Make font file: '{}'", otf_file_path)

woff2_file_path = path_define.outputs_dir.joinpath(f'{font_config.outputs_name}.woff2')
builder.save_otf(woff2_file_path, flavor=Flavor.WOFF2)
logger.info("Make font file: '%s'", woff2_file_path)
logger.info("Make font file: '{}'", woff2_file_path)

ttf_file_path = path_define.outputs_dir.joinpath(f'{font_config.outputs_name}.ttf')
builder.save_ttf(ttf_file_path)
logger.info("Make font file: '%s'", ttf_file_path)
logger.info("Make font file: '{}'", ttf_file_path)

bdf_file_path = path_define.outputs_dir.joinpath(f'{font_config.outputs_name}.bdf')
builder.save_bdf(bdf_file_path)
logger.info("Make font file: '%s'", bdf_file_path)
logger.info("Make font file: '{}'", bdf_file_path)
7 changes: 2 additions & 5 deletions tools/services/image_service.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import logging

from PIL import Image, ImageFont, ImageDraw
from loguru import logger

from tools.configs import FontConfig
from tools.configs import path_define

logger = logging.getLogger('image-service')


def make_preview_image_file(font_config: FontConfig):
font = ImageFont.truetype(path_define.outputs_dir.joinpath(f'{font_config.outputs_name}.woff2'), font_config.size)
Expand All @@ -24,4 +21,4 @@ def make_preview_image_file(font_config: FontConfig):
path_define.outputs_dir.mkdir(parents=True, exist_ok=True)
file_path = path_define.outputs_dir.joinpath(font_config.preview_image_file_name)
image.save(file_path)
logger.info("Make preview image file: '%s'", file_path)
logger.info("Make preview image file: '{}'", file_path)
7 changes: 3 additions & 4 deletions tools/services/publish_service.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import logging
import shutil
from pathlib import Path

from loguru import logger

from tools import configs
from tools.configs import path_define

logger = logging.getLogger('publish-service')


def _copy_file(file_name: str, from_dir: Path, to_dir: Path):
from_path = from_dir.joinpath(file_name)
to_path = to_dir.joinpath(file_name)
shutil.copyfile(from_path, to_path)
logger.info("Copy from '%s' to '%s'", from_path, to_path)
logger.info("Copy from '{}' to '{}'", from_path, to_path)


def update_docs():
Expand Down
4 changes: 0 additions & 4 deletions tools/update_docs.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import logging

from tools.services import publish_service

logging.basicConfig(level=logging.DEBUG)


def main():
publish_service.update_docs()
Expand Down

0 comments on commit a870d1a

Please sign in to comment.