Skip to content

Commit

Permalink
删除 fs_util.delete_dir()
Browse files Browse the repository at this point in the history
  • Loading branch information
TakWolf committed Jul 3, 2024
1 parent 027e24e commit ccde7d4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
8 changes: 3 additions & 5 deletions tools/build.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import itertools
import shutil

from tools import configs
from tools.configs import path_define
Expand All @@ -7,14 +8,11 @@
from tools.configs.font import FontConfig
from tools.services import update_service, dump_service, publish_service, info_service, template_service, image_service
from tools.services.font_service import DesignContext, FontContext
from tools.utils import fs_util


def main():
fs_util.delete_dir(path_define.dump_dir)
fs_util.delete_dir(path_define.fallback_glyphs_dir)
fs_util.delete_dir(path_define.outputs_dir)
fs_util.delete_dir(path_define.releases_dir)
if path_define.build_dir.exists():
shutil.rmtree(path_define.build_dir)

update_service.setup_ark_pixel_glyphs()

Expand Down
18 changes: 12 additions & 6 deletions tools/services/update_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,14 @@ def setup_ark_pixel_glyphs():
logger.info("Already downloaded: '%s'", source_file_path)

source_unzip_dir = downloads_dir.joinpath(f'ark-pixel-font-{sha}')
fs_util.delete_dir(source_unzip_dir)
if source_unzip_dir.exists():
shutil.rmtree(source_unzip_dir)
with zipfile.ZipFile(source_file_path) as file:
file.extractall(downloads_dir)
logger.info("Unzip: '%s'", source_unzip_dir)

fs_util.delete_dir(path_define.ark_pixel_glyphs_dir)
if path_define.ark_pixel_glyphs_dir.exists():
shutil.rmtree(path_define.ark_pixel_glyphs_dir)
path_define.ark_pixel_glyphs_dir.mkdir(parents=True)
for font_size in configs.font_sizes:
source_glyphs_dir_from = source_unzip_dir.joinpath('assets', 'glyphs', str(font_size))
Expand All @@ -95,7 +97,8 @@ def setup_ark_pixel_glyphs():
license_path_to = font_ark_pixel_dir.joinpath('LICENSE.txt')
shutil.copyfile(license_path_from, license_path_to)

fs_util.delete_dir(source_unzip_dir)
if source_unzip_dir.exists():
shutil.rmtree(source_unzip_dir)
fs_util.write_json(version_info, cache_version_file_path)
logger.info("Update glyphs: '%s'", sha)

Expand All @@ -120,7 +123,8 @@ def update_fonts(update_config: UpdateConfig):
downloads_dir = path_define.downloads_dir.joinpath(update_config.repository_name, tag_name)
downloads_dir.mkdir(parents=True, exist_ok=True)

fs_util.delete_dir(fonts_dir)
if fonts_dir.exists():
shutil.rmtree(fonts_dir)
fonts_dir.mkdir(parents=True)

for asset_config in update_config.asset_configs:
Expand All @@ -138,7 +142,8 @@ def update_fonts(update_config: UpdateConfig):
logger.info("Already downloaded: '%s'", asset_file_path)

asset_unzip_dir = asset_file_path.with_suffix('')
fs_util.delete_dir(asset_unzip_dir)
if asset_unzip_dir.exists():
shutil.rmtree(asset_unzip_dir)
with zipfile.ZipFile(asset_file_path) as file:
file.extractall(asset_unzip_dir)
logger.info("Unzip: '%s'", asset_unzip_dir)
Expand All @@ -148,7 +153,8 @@ def update_fonts(update_config: UpdateConfig):
to_path = fonts_dir.joinpath(copy_info[1].format(version=version))
shutil.copyfile(from_path, to_path)
logger.info("Copy from '%s' to '%s'", from_path, to_path)
fs_util.delete_dir(asset_unzip_dir)
if asset_unzip_dir.exists():
shutil.rmtree(asset_unzip_dir)

version_info = {
'repository_url': repository_url,
Expand Down
6 changes: 0 additions & 6 deletions tools/utils/fs_util.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import json
import shutil
from pathlib import Path
from typing import Any

import yaml


def delete_dir(path: Path):
if path.exists():
shutil.rmtree(path)


def is_empty_dir(path: Path) -> bool:
for item_path in path.iterdir():
if item_path.name == '.DS_Store':
Expand Down

0 comments on commit ccde7d4

Please sign in to comment.