diff --git a/kwalitee.py b/kwalitee.py deleted file mode 100644 index e04c58eaca45c25e7647963d72814621ba181b0a..0000000000000000000000000000000000000000 --- a/kwalitee.py +++ /dev/null @@ -1,4 +0,0 @@ -from github import Github - -def analyze_kwalitee(url): - ret = {} diff --git a/kwalitee/cli.py b/kwalitee/cli.py new file mode 100644 index 0000000000000000000000000000000000000000..d373bf10d032a7e05f58ad597156b93bf2b0ffdd --- /dev/null +++ b/kwalitee/cli.py @@ -0,0 +1,36 @@ +import click +from ocrd.decorators import ocrd_loglevel +from ocrd_utils import getLogger +from yaml import safe_load +from pkg_resources import resource_filename + +from .repo import Repo + +LOG = getLogger('kwalitee.cli') + +class CliCtx(): + def __init__(self, config_file): + with open(config_file, 'r') as f_config_file: + self.config = safe_load(f_config_file.read()) + self.repos = [Repo(self.config, url) for url in self.config['repolist']] +pass_ctx = click.make_pass_decorator(CliCtx) + +@click.group() +@click.option('-c', '--config-file', help="", default=resource_filename(__name__, 'config.yml')) +@ocrd_loglevel +@click.pass_context +def cli(ctx, config_file, **kwargs): # pylint: disable=unused-argument + ctx.obj = CliCtx(config_file) + +@cli.command('generate-json', help=''' + + Generate JSON + +''') +@pass_ctx +def generate_json(ctx): + for repo in ctx.repos: + print("# %s" % repo.name) + print("\thas_ocrd_tool_json: %s" % repo.has_ocrd_tool_json()) + # print('%s %s -> %s' % (repo.path.is_dir(), repo.url, repo.path)) + repo.clone() diff --git a/kwalitee/config.yml b/kwalitee/config.yml new file mode 100644 index 0000000000000000000000000000000000000000..002fd0409baebe9ed07836a67319be033386dd77 --- /dev/null +++ b/kwalitee/config.yml @@ -0,0 +1,18 @@ +# Base dir to clone repos to +repodir: /data/monorepo +# repos to clone and process +repolist: + - https://github.com/OCR-D/ocrd_calamari + - https://github.com/OCR-D/ocrd_im6convert + - https://github.com/OCR-D/ocrd_keraslm + - https://github.com/OCR-D/ocrd_kraken + - https://github.com/OCR-D/ocrd_ocropy + - https://github.com/OCR-D/ocrd_olena + - https://github.com/OCR-D/ocrd_segment + - https://github.com/OCR-D/ocrd_tesserocr + - https://github.com/mjenckel/LAYoutERkennung + - https://github.com/ocr-d-modul-2-segmentierung/segmentation-runner + - https://github.com/ASVLeipzig/cor-asv-fst + - https://github.com/ASVLeipzig/cor-asv-ann + - https://github.com/cisocrgroup/ocrd-postcorrection + - https://github.com/seuretm/ocrd_typegroups_classifier diff --git a/kwalitee/kwalitee.py b/kwalitee/kwalitee.py new file mode 100644 index 0000000000000000000000000000000000000000..284b0e7d5d940622ac4867c75f81f85c910d3284 --- /dev/null +++ b/kwalitee/kwalitee.py @@ -0,0 +1,8 @@ +from ocrd_utils import pushd_popd +def assess_kwalitee(repo): + ret = {} + # ocrd-tool.json + with open('ocrd-tool.json') + ret['ocrd-tool'] = + # TODO has docker file? + print("TODO") diff --git a/kwalitee/repo.py b/kwalitee/repo.py new file mode 100644 index 0000000000000000000000000000000000000000..f276e5b0dcf1f2192ee613f5d2a85c46798d4ffc --- /dev/null +++ b/kwalitee/repo.py @@ -0,0 +1,30 @@ +from pathlib import Path +import json +from subprocess import run +from ocrd_utils import pushd_popd, getLogger + +LOG = getLogger('kwalitee.repo') + +class Repo(): + + def __init__(self, config, url): + self.url = url + self.config = config + self.name = Path(url).name + self.path = Path(self.config['repodir'], self.name) + self.ocrd_tool_path = Path(self.path, 'ocrd-tool.json') + + def clone(self): + if self.path.is_dir(): + LOG.debug("Already cloned: %s" % self.path) + return + with pushd_popd(self.config['repodir']): + LOG.debug("Cloning %s" % self.url) + result = run('git clone --depth 1'.split(' ') + [self.url]) + LOG.debug("Result: %s" % result) + + def has_ocrd_tool_json(self): + return self.ocrd_tool_path.is_file() + + def get_ocrd_tool_json(self): + return json.load(self.ocrd_tool_path) diff --git a/requirements.txt b/requirements.txt index 2d0f6650946311c423d6de607a9cdaa95a296fd5..e2ea8074a67f88afaf970acfe9736f1b04e1f129 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ click >=7 +ocrd +pyyaml requests -PyGithub diff --git a/setup.py b/setup.py index 13ce21ea824bcdee07559291ddeafc5c4d13b68c..fa88e698815502ea44f45f2dcd5b878b5dd5d395 100644 --- a/setup.py +++ b/setup.py @@ -13,17 +13,17 @@ setup( long_description_content_type='text/markdown', author='Konstantin Baierer', author_email='unixprog@gmail.com', - url='https://github.com/OCR-D/core', + url='https://github.com/OCR-D/kwalitee', license='Apache License 2.0', packages=find_packages(exclude=('tests', 'docs')), include_package_data=True, install_requires=install_requires, package_data={ - '': ['*.json', '*.yml', '*.yaml', '*.bash', '*.xml'], + '': ['*.json', '*.yml', '*.yaml', '*.list', '*.xml'], }, entry_points={ 'console_scripts': [ - 'ocrd=ocrd.cli:cli', + 'ocrd-kwalitee=kwalitee.cli:cli', ] }, )