def download_data(cls): data_dir = cls.user_data_dir() _get_logger().debug(f'Downloading CkipTagger data to {data_dir} ...') cls._download_data(data_dir) _get_logger().debug( f'Downloading CkipTagger data to {data_dir} ... done') return data_dir
def install_data(cls, src_dir, *, copy=False): data_dir = cls.user_data_dir() if _os.path.isdir(data_dir): _get_logger().warning(f'{data_dir} already exists!') else: _os.makedirs(_os.path.dirname(data_dir), exist_ok=True) if not copy: _get_logger().debug( f'Linking CkipTagger data from {src_dir} to {data_dir} ...' ) _os.symlink(src_dir, data_dir) _get_logger().debug( f'Linking CkipTagger data from {src_dir} to {data_dir} ... done' ) else: _get_logger().debug( f'Copying CkipTagger data from {src_dir} to {data_dir} ...' ) _shutil.copytree(src_dir, data_dir) _get_logger().debug( f'Copying CkipTagger data from {src_dir} to {data_dir} ... done' ) return data_dir
def get_data(cls): for data_dir in ( cls.env_data_dir(), cls.user_data_dir(), cls.site_data_dir(), *cls.extra_dirs, ): if data_dir and _os.path.isdir(data_dir): break else: _get_logger().warning(f'No existing data for {cls.fullname}. Download data from remote ...') data_dir = cls.download_data() return data_dir
def get(driver_type, driver_family): # pylint: disable=missing-docstring if driver_family is None: return DummyDriver assert driver_type is None or isinstance(driver_type, DriverType), f'{driver_type} is not a DriverType' assert driver_family is None or isinstance(driver_family, DriverFamily), f'{driver_family} is not a DriverFamily' driver = DriverRegister._DRIVERS.get((driver_type, driver_family,)) if not driver: raise KeyError(f'{driver_type.name} is not implemented for type {driver_family.name}') if not driver.is_dummy: _get_logger().debug(f'Use {driver.__name__} ...') return driver
def get(driver_type, driver_family): # pylint: disable=missing-docstring if driver_family is None: return DummyDriver driver = DriverRegister._DRIVERS.get(( driver_type, driver_family, )) if not driver: raise KeyError( f'{driver_type} is not implemented for type {driver_family}') if not driver.is_dummy: _get_logger().debug(f'Use {driver.__name__} ...') return driver
def init(self): # pylint: disable=missing-docstring if self._inited: return _get_logger().info(f'Initializing {self.__class__.__name__} ...') self._init() self._inited = True