Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
quiver-frontend-local
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Monitor
Service Desk
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
subugoe
OCR-D
quiver-frontend-local
Commits
f3e8b695
Commit
f3e8b695
authored
4 years ago
by
Konstantin Baierer
Browse files
Options
Downloads
Patches
Plain Diff
add command ocrd-tool to generate one big ocrd-tool json list
parent
8e0ac7e7
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
kwalitee/cli.py
+22
-6
22 additions, 6 deletions
kwalitee/cli.py
kwalitee/repo.py
+11
-9
11 additions, 9 deletions
kwalitee/repo.py
with
33 additions
and
15 deletions
kwalitee/cli.py
+
22
−
6
View file @
f3e8b695
...
@@ -8,8 +8,6 @@ from pkg_resources import resource_filename
...
@@ -8,8 +8,6 @@ from pkg_resources import resource_filename
from
.repo
import
Repo
from
.repo
import
Repo
LOG
=
getLogger
(
'
kwalitee.cli
'
)
def
_check_cloned
(
ctx
):
def
_check_cloned
(
ctx
):
uncloned
=
[]
uncloned
=
[]
for
repo
in
ctx
.
repos
:
for
repo
in
ctx
.
repos
:
...
@@ -20,6 +18,7 @@ def _check_cloned(ctx):
...
@@ -20,6 +18,7 @@ def _check_cloned(ctx):
class
CliCtx
():
class
CliCtx
():
def
__init__
(
self
,
config_file
):
def
__init__
(
self
,
config_file
):
self
.
log
=
getLogger
(
'
ocrd.kwalitee
'
)
with
open
(
config_file
,
'
r
'
)
as
f_config_file
:
with
open
(
config_file
,
'
r
'
)
as
f_config_file
:
self
.
config
=
safe_load
(
f_config_file
.
read
())
self
.
config
=
safe_load
(
f_config_file
.
read
())
self
.
repos
=
[]
self
.
repos
=
[]
...
@@ -45,9 +44,9 @@ def cli(ctx, config_file, **kwargs): # pylint: disable=unused-argument
...
@@ -45,9 +44,9 @@ def cli(ctx, config_file, **kwargs): # pylint: disable=unused-argument
def
clone_all
(
ctx
):
def
clone_all
(
ctx
):
for
repo
in
ctx
.
repos
:
for
repo
in
ctx
.
repos
:
if
repo
.
is_cloned
():
if
repo
.
is_cloned
():
LOG
.
info
(
"
Already cloned %s
"
%
repo
)
ctx
.
log
.
info
(
"
Already cloned %s
"
%
repo
)
else
:
else
:
LOG
.
info
(
"
Cloning %s
"
%
repo
)
ctx
.
log
.
info
(
"
Cloning %s
"
%
repo
)
repo
.
clone
()
repo
.
clone
()
@cli.command
(
'
pull
'
,
help
=
'''
@cli.command
(
'
pull
'
,
help
=
'''
...
@@ -58,7 +57,7 @@ def clone_all(ctx):
...
@@ -58,7 +57,7 @@ def clone_all(ctx):
def
pull_all
(
ctx
):
def
pull_all
(
ctx
):
_check_cloned
(
ctx
)
_check_cloned
(
ctx
)
for
repo
in
ctx
.
repos
:
for
repo
in
ctx
.
repos
:
LOG
.
info
(
"
Pulling %s
"
%
repo
)
ctx
.
log
.
info
(
"
Pulling %s
"
%
repo
)
repo
.
pull
()
repo
.
pull
()
...
@@ -73,7 +72,7 @@ def generate_json(ctx, output=None):
...
@@ -73,7 +72,7 @@ def generate_json(ctx, output=None):
ret
=
[]
ret
=
[]
_check_cloned
(
ctx
)
_check_cloned
(
ctx
)
for
repo
in
ctx
.
repos
:
for
repo
in
ctx
.
repos
:
LOG
.
info
(
"
# Assessing %s
"
%
repo
.
name
)
ctx
.
log
.
info
(
"
# Assessing %s
"
%
repo
.
name
)
repo
.
clone
()
repo
.
clone
()
ret
.
append
(
repo
.
to_json
())
ret
.
append
(
repo
.
to_json
())
# print('%s %s -> %s' % (repo.path.is_dir(), repo.url, repo.path))
# print('%s %s -> %s' % (repo.path.is_dir(), repo.url, repo.path))
...
@@ -82,3 +81,20 @@ def generate_json(ctx, output=None):
...
@@ -82,3 +81,20 @@ def generate_json(ctx, output=None):
Path
(
output
).
write_text
(
json_str
)
Path
(
output
).
write_text
(
json_str
)
else
:
else
:
print
(
json_str
)
print
(
json_str
)
@cli.command
(
'
ocrd-tool
'
)
@click.option
(
'
-o
'
,
'
--output
'
,
help
=
"
Output file. Omit to print to STDOUT
"
)
@pass_ctx
def
generate_tool_json
(
ctx
,
output
=
None
):
'''
Return one big list of ocrd tools
'''
ret
=
{}
_check_cloned
(
ctx
)
for
repo
in
ctx
.
repos
:
ret
=
{
**
ret
,
**
repo
.
get_ocrd_tools
()}
json_str
=
json
.
dumps
(
ret
,
indent
=
4
,
sort_keys
=
True
)
if
output
:
Path
(
output
).
write_text
(
json_str
)
else
:
print
(
json_str
)
This diff is collapsed.
Click to expand it.
kwalitee/repo.py
+
11
−
9
View file @
f3e8b695
...
@@ -5,12 +5,10 @@ from shlex import split as X
...
@@ -5,12 +5,10 @@ from shlex import split as X
from
ocrd_utils
import
pushd_popd
,
getLogger
from
ocrd_utils
import
pushd_popd
,
getLogger
import
requests
as
R
import
requests
as
R
LOG
=
getLogger
(
'
kwalitee.repo
'
)
class
Repo
():
class
Repo
():
def
__init__
(
self
,
config
,
url
,
official
=
False
,
compliant_cli
=
False
):
def
__init__
(
self
,
config
,
url
,
official
=
False
,
compliant_cli
=
False
):
self
.
log
=
getLogger
(
'
kwalitee.repo
'
)
self
.
url
=
url
self
.
url
=
url
self
.
config
=
config
self
.
config
=
config
self
.
name
=
Path
(
url
).
name
self
.
name
=
Path
(
url
).
name
...
@@ -30,17 +28,17 @@ class Repo():
...
@@ -30,17 +28,17 @@ class Repo():
def
clone
(
self
):
def
clone
(
self
):
if
self
.
is_cloned
():
if
self
.
is_cloned
():
LOG
.
debug
(
"
Already cloned: %s
"
%
self
.
path
)
self
.
log
.
debug
(
"
Already cloned: %s
"
%
self
.
path
)
return
return
with
pushd_popd
(
self
.
config
[
'
repodir
'
]):
with
pushd_popd
(
self
.
config
[
'
repodir
'
]):
LOG
.
debug
(
"
Cloning %s
"
%
self
.
url
)
self
.
log
.
debug
(
"
Cloning %s
"
%
self
.
url
)
result
=
self
.
_run
(
'
git clone --depth 1
"
%s
"'
%
self
.
url
)
result
=
self
.
_run
(
'
git clone --depth 1
"
%s
"'
%
self
.
url
)
LOG
.
debug
(
"
Result: %s
"
%
result
)
self
.
log
.
debug
(
"
Result: %s
"
%
result
)
def
get_git_stats
(
self
):
def
get_git_stats
(
self
):
ret
=
{}
ret
=
{}
LOG
.
info
(
"
Fetching git info
"
)
self
.
log
.
info
(
"
Fetching git info
"
)
with
pushd_popd
(
self
.
path
):
with
pushd_popd
(
self
.
path
):
ret
[
'
number_of_commits
'
]
=
self
.
_run
(
'
git rev-list HEAD --count
'
).
stdout
ret
[
'
number_of_commits
'
]
=
self
.
_run
(
'
git rev-list HEAD --count
'
).
stdout
ret
[
'
last_commit
'
]
=
self
.
_run
(
r
'
git log -1 --format=%cd
'
).
stdout
ret
[
'
last_commit
'
]
=
self
.
_run
(
r
'
git log -1 --format=%cd
'
).
stdout
...
@@ -50,7 +48,7 @@ class Repo():
...
@@ -50,7 +48,7 @@ class Repo():
def
get_file_contents
(
self
):
def
get_file_contents
(
self
):
ret
=
{}
ret
=
{}
LOG
.
info
(
"
Getting file contents
"
)
self
.
log
.
info
(
"
%s
Getting file contents
"
%
self
.
url
)
with
pushd_popd
(
self
.
path
):
with
pushd_popd
(
self
.
path
):
for
path
in
[
Path
(
x
)
for
x
in
[
'
ocrd-tool.json
'
,
'
Dockerfile
'
,
'
README.md
'
,
'
setup.py
'
]]:
for
path
in
[
Path
(
x
)
for
x
in
[
'
ocrd-tool.json
'
,
'
Dockerfile
'
,
'
README.md
'
,
'
setup.py
'
]]:
if
path
.
is_file
():
if
path
.
is_file
():
...
@@ -67,11 +65,15 @@ class Repo():
...
@@ -67,11 +65,15 @@ class Repo():
ret
[
'
name
'
]
=
self
.
_run
(
'
python3 setup.py --name
'
).
stdout
ret
[
'
name
'
]
=
self
.
_run
(
'
python3 setup.py --name
'
).
stdout
ret
[
'
author
'
]
=
self
.
_run
(
'
python3 setup.py --author
'
).
stdout
ret
[
'
author
'
]
=
self
.
_run
(
'
python3 setup.py --author
'
).
stdout
ret
[
'
author-email
'
]
=
self
.
_run
(
'
python3 setup.py --author-email
'
).
stdout
ret
[
'
author-email
'
]
=
self
.
_run
(
'
python3 setup.py --author-email
'
).
stdout
LOG
.
info
(
"
Fetching pypi info
"
)
self
.
log
.
info
(
"
Fetching pypi info
"
)
response
=
R
.
get
(
'
https://pypi.python.org/pypi/%s/json
'
%
ret
[
'
name
'
])
response
=
R
.
get
(
'
https://pypi.python.org/pypi/%s/json
'
%
ret
[
'
name
'
])
ret
[
'
pypi
'
]
=
json
.
loads
(
response
.
text
)
if
response
.
status_code
==
200
else
None
ret
[
'
pypi
'
]
=
json
.
loads
(
response
.
text
)
if
response
.
status_code
==
200
else
None
return
ret
return
ret
def
get_ocrd_tools
(
self
):
ot
=
json
.
loads
(
self
.
get_file_contents
()[
'
ocrd-tool.json
'
])
return
ot
[
'
tools
'
]
def
to_json
(
self
):
def
to_json
(
self
):
desc
=
{}
desc
=
{}
desc
[
'
url
'
]
=
self
.
url
desc
[
'
url
'
]
=
self
.
url
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment