def update_license(ctx: click.Context, conf: PkgitConf): local_conf = conf.get_local_conf() lice = local_conf.get('license') if not lice: return lice_path = fsoopify.Path( __file__).dirname.dirname / 'data' / 'licenses' / f'{lice}.txt' lice_temp = fsoopify.FileInfo(lice_path).read_text() author = conf.proxy_get('author') lice_cont = lice_temp.format_map({ 'year': str(datetime.datetime.now().year), 'author': author, }) fsoopify.FileInfo('LICENSE').write_text(lice_cont, append=False)
def run(conf_path: str): conf_file = fsoopify.FileInfo(conf_path) if not conf_file.is_file(): return print('%s is not a file', conf_path) try: conf: dict = conf_file.load() except fsoopify.SerializeError: return print('unable load conf file: %s', conf_path) # `device` device = conf.get('device') if not isinstance(device, str): return print('`device` is not a str') match = re.search(r'^(?P<host>.+):(?P<port>\d+)$', device, re.I) if match: host, port = match.group('host'), int(match.group('port')) else: host, port = device, None # `remotes` remotes: List[str] = conf.get('remotes', []) if isinstance(remotes, str): remotes = [remotes] elif not isinstance(remotes, list) or any(not isinstance(x, str) for x in remotes): return print('`remotes` is not a str list') # `root` root = conf.get('root', os.path.dirname(conf_path)) if not isinstance(root, str): return print('`root` is not a str') # `filesuffix` file_suffix: str = conf.get('file_suffix', '.placeholder') if not isinstance(file_suffix, str): return print('`file_suffix` is not a str') if host.startswith('ftp://'): dirtrees = _get_dirtrees_from_ftp(host[6:], port, remotes) else: dirtrees = _get_dirtrees_from_fs(host, port, remotes) root_path = pathlib.Path(root) for remote in remotes: dirtree = dirtrees[remote] assert isinstance(dirtree, dict) base_dir: pathlib.Path = root_path / remote.replace(':', '') base_dir.mkdir(parents=True, exist_ok=True) _update_dirtree(base_dir, dirtree, file_suffix=file_suffix)
def main(argv=None): if argv is None: argv = sys.argv try: opt = docopt.docopt(__doc__) conf = load_conf(opt) srcs = [] for k, v in conf.get('web', {}).items(): srcs.append(WebServerSource(k, v)) for k, v in conf.get('user', {}).items(): srcs.append(UserServerSource(k, v)) filter = ServerUrlFilter(opt, srcs) result = '\n'.join(filter.get_list()) fsoopify.FileInfo(opt['DEST']).write_text(result, append=False) except Exception: # pylint: disable=W0703 traceback.print_exc()
def load_conf(opt): file = fsoopify.FileInfo(opt['CONF']) if not file.is_exists(): print('') exit() return file.load()
# -*- coding: utf-8 -*- # # Copyright (c) 2019~2999 - Cologler <*****@*****.**> # ---------- # # ---------- import re import fsoopify from setupmeta_builder import get_setup_attrs install_requires = fsoopify.FileInfo( 'requirements.txt').read_text().strip().splitlines() install_requires.sort() def test_attrs_for_setupmeta_builder(): setup_attrs = get_setup_attrs() with open('README.md', encoding='utf-8') as fp: assert setup_attrs['long_description'] == fp.read() setup_attrs.pop('long_description') assert re.match(r'^\d+\.\d+\.\d+$', setup_attrs.pop('version')) classifiers = setup_attrs.pop('classifiers') assert isinstance(classifiers, list) assert 'Development Status :: 5 - Production/Stable' in classifiers assert 'License :: OSI Approved :: MIT License' in classifiers assert 'Programming Language :: Python :: 3.7' in classifiers assert 'Programming Language :: Python :: 3.8' in classifiers
def get_fileinfo(self, relpath: str) -> fsoopify.FileInfo: '''get `FileInfo`.''' return fsoopify.FileInfo(str(self._root_path / relpath))
def _get_gitignore_file(self): return fsoopify.FileInfo(pkgit_ioc['cwd'] / '.gitignore')