<commit_before>
import os
import shutil

from geekcms.protocal import BasePlugin
from geekcms.protocal import PluginController as pcl
from geekcms.utils import PathResolver, ShareData

from .assets import (Page, ArticlePage, TimeLinePage,
                     ArchivePage, AboutPage, IndexPage,
                     StaticFile)


class OutputCleaner(BasePlugin):

    plugin = 'clean'

    def run(self, resources):
        for name in os.listdir(PathResolver.outputs()):
            if name.startswith('.'):
                continue

            path = os.path.join(
                PathResolver.outputs(),
                name,
            )
            if os.path.isfile(path):
                os.remove(path)
            elif os.path.isdir(path):
                os.removedirs(path)


class _TargetAbsPath:

    def _get_tgt_abs_path(self, tgt_rel_path):
        path = os.path.join(
            PathResolver.outputs(),
            tgt_rel_path,
        )
        return path

    def _make_sure_dir_exist(self, tgt_abs_path):
        dir_path, _ = os.path.split(tgt_abs_path)
        if not os.path.exists(dir_path):
            os.makedirs(dir_path)


class StaticWriter(BasePlugin, _TargetAbsPath):
<commit_msg>Fixed stupid bugs on removing non-empty directory<commit_after>
import os
import shutil

from geekcms.protocal import BasePlugin
from geekcms.protocal import PluginController as pcl
from geekcms.utils import PathResolver, ShareData

from .assets import (Page, ArticlePage, TimeLinePage,
                     ArchivePage, AboutPage, IndexPage,
                     StaticFile)


class OutputCleaner(BasePlugin):

    plugin = 'clean'

    def run(self, resources):
        for name in os.listdir(PathResolver.outputs()):
            if name.startswith('.'):
                continue

            path = os.path.join(
                PathResolver.outputs(),
                name,
            )
            if os.path.isfile(path):
                os.remove(path)
            elif os.path.isdir(path):
                shutil.rmtree(path)


class _TargetAbsPath:

    def _get_tgt_abs_path(self, tgt_rel_path):
        path = os.path.join(
            PathResolver.outputs(),
            tgt_rel_path,
        )
        return path

    def _make_sure_dir_exist(self, tgt_abs_path):
        dir_path, _ = os.path.split(tgt_abs_path)
        if not os.path.exists(dir_path):
            os.makedirs(dir_path)


class StaticWriter(BasePlugin, _TargetAbsPath):

{'fraction_non_alphanumeric': 0.08373786407766991, 'fraction_numerical': 0.0, 'mean_word_length': 2.030637254901961, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7195066', 'n_tokens_mistral': 760, 'n_tokens_neox': 716, 'n_words': 160}