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
0ff7b561
Commit
0ff7b561
authored
5 years ago
by
Konstantin Baierer
Browse files
Options
Downloads
Patches
Plain Diff
CLI for cloning and updating repos
parent
e5f124e5
No related branches found
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
+34
-0
34 additions, 0 deletions
kwalitee/cli.py
kwalitee/repo.py
+11
-1
11 additions, 1 deletion
kwalitee/repo.py
with
45 additions
and
1 deletion
kwalitee/cli.py
+
34
−
0
View file @
0ff7b561
...
@@ -9,6 +9,14 @@ from .repo import Repo
...
@@ -9,6 +9,14 @@ from .repo import Repo
LOG
=
getLogger
(
'
kwalitee.cli
'
)
LOG
=
getLogger
(
'
kwalitee.cli
'
)
def
_check_cloned
(
ctx
):
uncloned
=
[]
for
repo
in
ctx
.
repos
:
if
not
repo
.
is_cloned
():
uncloned
.
append
(
repo
)
if
uncloned
:
raise
Exception
(
"
Some repos not yet cloned: %s
"
%
[
str
(
r
)
for
r
in
uncloned
])
class
CliCtx
():
class
CliCtx
():
def
__init__
(
self
,
config_file
):
def
__init__
(
self
,
config_file
):
with
open
(
config_file
,
'
r
'
)
as
f_config_file
:
with
open
(
config_file
,
'
r
'
)
as
f_config_file
:
...
@@ -23,6 +31,31 @@ pass_ctx = click.make_pass_decorator(CliCtx)
...
@@ -23,6 +31,31 @@ 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
(
'
clone
'
,
help
=
'''
Clone all repos
'''
)
@pass_ctx
def
clone_all
(
ctx
):
for
repo
in
ctx
.
repos
:
if
repo
.
is_cloned
():
LOG
.
info
(
"
Already cloned %s
"
%
repo
)
else
:
LOG
.
info
(
"
Cloning %s
"
%
repo
)
repo
.
clone
()
@cli.command
(
'
pull
'
,
help
=
'''
Pull all repos
'''
)
@pass_ctx
def
pull_all
(
ctx
):
_check_cloned
(
ctx
)
for
repo
in
ctx
.
repos
:
LOG
.
info
(
"
Pulling %s
"
%
repo
)
repo
.
pull
()
@cli.command
(
'
json
'
,
help
=
'''
@cli.command
(
'
json
'
,
help
=
'''
Generate JSON
Generate JSON
...
@@ -38,6 +71,7 @@ def generate_json(ctx, full, **kwargs):
...
@@ -38,6 +71,7 @@ def generate_json(ctx, full, **kwargs):
if
full
:
if
full
:
for
k
in
kwargs
:
for
k
in
kwargs
:
kwargs
[
k
]
=
True
kwargs
[
k
]
=
True
_check_cloned
(
ctx
)
for
repo
in
ctx
.
repos
:
for
repo
in
ctx
.
repos
:
LOG
.
info
(
"
# Assessing %s
"
%
repo
.
name
)
LOG
.
info
(
"
# Assessing %s
"
%
repo
.
name
)
repo
.
clone
()
repo
.
clone
()
...
...
This diff is collapsed.
Click to expand it.
kwalitee/repo.py
+
11
−
1
View file @
0ff7b561
...
@@ -15,8 +15,18 @@ class Repo():
...
@@ -15,8 +15,18 @@ class Repo():
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
)
def
__str__
(
self
):
return
'
<Repo %s @ %s>
'
%
(
self
.
url
,
self
.
path
)
def
is_cloned
(
self
):
return
self
.
path
.
is_dir
()
def
pull
(
self
):
with
pushd_popd
(
self
.
path
):
self
.
_run
(
'
git pull origin master
'
)
def
clone
(
self
):
def
clone
(
self
):
if
self
.
path
.
is_dir
():
if
self
.
is_cloned
():
LOG
.
debug
(
"
Already cloned: %s
"
%
self
.
path
)
LOG
.
debug
(
"
Already cloned: %s
"
%
self
.
path
)
return
return
with
pushd_popd
(
self
.
config
[
'
repodir
'
]):
with
pushd_popd
(
self
.
config
[
'
repodir
'
]):
...
...
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