Skip to content
Snippets Groups Projects
Commit edb44eb0 authored by Konstantin Baierer's avatar Konstantin Baierer
Browse files

wip

parent 594bc29f
No related branches found
No related tags found
No related merge requests found
<!DOCTYPE html>
<html>
<head>
<title>ocrd kwalitee</title>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Load required Bootstrap and BootstrapVue CSS -->
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap/dist/css/bootstrap.min.css" />
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.min.css" />
<!-- Load polyfills to support older browsers -->
<script src="//polyfill.io/v3/polyfill.min.js?features=es2015%2CIntersectionObserver" crossorigin="anonymous"></script>
<!-- Load Vue followed by BootstrapVue -->
<script src="//unpkg.com/vue@latest/dist/vue.min.js"></script>
<script src="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.min.js"></script>
</head>
<body>
<div id="app">
<b-container>
<button @click="fetchRepoData">Fetch!</button>
</b-container>
<b-container fluid>
<b-row>
<b-card v-for="repo in repos"
:title="repo.org_plus_name"
tag="article"
style="max-width: 20rem;"
class="mb-2"
>
<b-tabs card>
<b-tab title="Git">
<b-card-text>
<b-card-text>
<p>
<a href="`https://pypi.org/project/${ repo.python.name }/`"> <img :src="`https://img.shields.io/pypi/v/${ repo.python.name }.svg`" /> </a>
<a href="`https://travis-ci.org/${ repo.org_plus_name }`"> <img :src="`https://travis-ci.org/${ repo.org_plus_name }.svg?branch=master`" /> </a>
<a href="`https://circleci.com/gh/${ repo.org_plus_name }`"> <img :src="`https://circleci.com/gh/${ repo.org_plus_name }.svg?style=svg`" /> </a>
<a href="`https://hub.docker.com/r/ocrd/core/tags/`"> <img :src="`https://img.shields.io/docker/automated/ocrd/core.svg`" /> </a>
<a href="`https://codecov.io/gh/${ repo.org_plus_name }`"> <img :src="`https://codecov.io/gh/${ repo.org_plus_name }/branch/master/graph/badge.svg`" /> </a>
<a href="`https://scrutinizer-ci.com/g/${ repo.org_plus_name }`"> <img :src="`https://scrutinizer-ci.com/g/${ repo.org_plus_name }/badges/quality-score.png?b=master`" /> </a>
<a href="`https://lgtm.com/projects/g/${ repo.org_plus_name }/alerts/`"> <img :src="`https://img.shields.io/lgtm/alerts/g/${ repo.org_plus_name }.svg?logo=lgtm&amp;logoWidth=18`" /> </a>
</p>
</b-card-text>
<b-table v-if="repo.git" :items="[repo.git]"></b-table>
</b-card-text>
</b-tab>
<b-tab title="Tools">
<b-card-text>
<b-table v-if="repo.ocrd_tool" :items="[repo.ocrd_tool]"></b-table>
</b-card-text>
</b-tab>
<b-tab title="Python">
<b-card-text>
<b-table v-if="repo.python" :items="[repo.python]"></b-table>
</b-card-text>
</b-tab>
</b-tabs>
</b-card>
</b-row>
</b-container>
</div>
<script src="script.js"></script>
</body>
</html>
...@@ -2,6 +2,7 @@ import click ...@@ -2,6 +2,7 @@ import click
from ocrd.decorators import ocrd_loglevel from ocrd.decorators import ocrd_loglevel
from ocrd_utils import getLogger from ocrd_utils import getLogger
from yaml import safe_load from yaml import safe_load
import json
from pkg_resources import resource_filename from pkg_resources import resource_filename
from .repo import Repo from .repo import Repo
...@@ -22,15 +23,24 @@ pass_ctx = click.make_pass_decorator(CliCtx) ...@@ -22,15 +23,24 @@ pass_ctx = click.make_pass_decorator(CliCtx)
def cli(ctx, config_file, **kwargs): # pylint: disable=unused-argument def cli(ctx, config_file, **kwargs): # pylint: disable=unused-argument
ctx.obj = CliCtx(config_file) ctx.obj = CliCtx(config_file)
@cli.command('generate-json', help=''' @cli.command('json', help='''
Generate JSON Generate JSON
''') ''')
@pass_ctx @pass_ctx
def generate_json(ctx): @click.option('-a', '--full', help="Set all flags", is_flag=True, default=False)
@click.option('-g', '--git', help="Git stats", is_flag=True, default=False)
@click.option('-p', '--python', help="Python stats", is_flag=True, default=False)
@click.option('-f', '--files', help="Files", is_flag=True, default=False)
def generate_json(ctx, full, **kwargs):
ret = []
if full:
for k in kwargs:
kwargs[k] = True
for repo in ctx.repos: for repo in ctx.repos:
print("# %s" % repo.name) LOG.info("# Assessing %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() repo.clone()
ret.append(repo.to_json(**kwargs))
# print('%s %s -> %s' % (repo.path.is_dir(), repo.url, repo.path))
print(json.dumps(ret))
from pathlib import Path from pathlib import Path
import json import json
from subprocess import run from subprocess import run, PIPE
from shlex import split as X
from ocrd_utils import pushd_popd, getLogger from ocrd_utils import pushd_popd, getLogger
LOG = getLogger('kwalitee.repo') LOG = getLogger('kwalitee.repo')
class Repo(): class Repo():
def __init__(self, config, url): def __init__(self, config, url):
...@@ -12,7 +14,6 @@ class Repo(): ...@@ -12,7 +14,6 @@ class Repo():
self.config = config self.config = config
self.name = Path(url).name self.name = Path(url).name
self.path = Path(self.config['repodir'], self.name) self.path = Path(self.config['repodir'], self.name)
self.ocrd_tool_path = Path(self.path, 'ocrd-tool.json')
def clone(self): def clone(self):
if self.path.is_dir(): if self.path.is_dir():
...@@ -20,11 +21,53 @@ class Repo(): ...@@ -20,11 +21,53 @@ class Repo():
return return
with pushd_popd(self.config['repodir']): with pushd_popd(self.config['repodir']):
LOG.debug("Cloning %s" % self.url) LOG.debug("Cloning %s" % self.url)
result = run('git clone --depth 1'.split(' ') + [self.url]) result = self._run('git clone --depth 1 "%s"' % self.url)
LOG.debug("Result: %s" % result) LOG.debug("Result: %s" % result)
def has_ocrd_tool_json(self):
return self.ocrd_tool_path.is_file()
def get_ocrd_tool_json(self): def get_git_stats(self):
return json.load(self.ocrd_tool_path) ret = {}
with pushd_popd(self.path):
ret['number_of_commits'] = self._run('git rev-list HEAD --count').stdout
ret['last_commit'] = self._run(r'git log -1 --format=%cd ').stdout
return ret
def get_file_contents(self):
ret = {}
with pushd_popd(self.path):
for path in [Path(x) for x in ['ocrd-tool.json', 'Dockerfile', 'README.md', 'setup.py']]:
if path.is_file():
with path.open() as f:
ret[path.name] = f.read()
else:
ret[path.name] = None
return ret
def get_python_info(self):
ret = {}
with pushd_popd(self.path):
ret['url'] = self._run('python3 setup.py --url').stdout
ret['name'] = self._run('python3 setup.py --name').stdout
ret['author'] = self._run('python3 setup.py --author').stdout
ret['author-email'] = self._run('python3 setup.py --author-email').stdout
return ret
def to_json(self, git=True, python=True, files=True):
desc = {}
desc['url'] = self.url
desc['org_plus_name'] = '/'.join(self.url.split('/')[-2:])
desc['name'] = self.name
if files:
desc['files'] = self.get_file_contents()
desc['ocrd_tool'] = json.loads(desc['files']['ocrd-tool.json']) if desc['files']['ocrd-tool.json'] else None
if git:
desc['git'] = self.get_git_stats()
if python:
desc['python'] = self.get_python_info()
return desc
def _run(self, cmd, **kwargs):
result = run(X(cmd), stdout=PIPE, encoding='utf-8', **kwargs)
if result.stdout:
result.stdout = result.stdout.strip()
return result
This diff is collapsed.
/* global Vue */
window.app = new Vue({
el: '#app',
data: {
repos_raw: []
},
computed: {
repos() {
return this.repos_raw
// return this.repos_raw.map(repo_raw => {
// console.log('xxx', {repo_raw})
// const ret = {}
// Object.entries(repo_raw).forEach(([k, v]) => {
// console.log({k, v})
// if (typeof v == Object) {
// ret = {...ret, ...v}
// } else {
// ret[k] = v
// }
// })
// return ret
// })
}
},
mounted() {
this.fetchRepoData()
},
methods: {
fetchRepoData() {
fetch('/repos.json').then(resp => resp.json()).then(repos => this.repos.push(...repos))
},
}
})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment