summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-10-29 16:47:26 +0000
committerGerrit Code Review <review@openstack.org>2018-10-29 16:47:26 +0000
commit420f7ae281557cbe5cdd426b86a8e6647a52fff3 (patch)
tree7001c206dcb21cd0363d91d65495b9b733557632
parent25ec5f76be341da13692a0d06efb58191430d7f9 (diff)
parent0fcca0bcdb276afad8e893c42583fef510e67d37 (diff)
Merge "refactor: Add convenient callback for processing site repos"
-rw-r--r--pegleg/cli.py31
-rw-r--r--pegleg/engine/util/git.py1
2 files changed, 21 insertions, 11 deletions
diff --git a/pegleg/cli.py b/pegleg/cli.py
index 8c4d3b2..cd15660 100644
--- a/pegleg/cli.py
+++ b/pegleg/cli.py
@@ -29,6 +29,18 @@ CONTEXT_SETTINGS = {
29 'help_option_names': ['-h', '--help'], 29 'help_option_names': ['-h', '--help'],
30} 30}
31 31
32
33def _process_repositories_callback(ctx, param, value):
34 """Convenient callback for ``@click.argument(site_name)``.
35
36 Automatically processes repository information for the specified site. This
37 entails cloning all requires repositories and checking out specified
38 references for each repository.
39 """
40 engine.repository.process_repositories(value)
41 return value
42
43
32MAIN_REPOSITORY_OPTION = click.option( 44MAIN_REPOSITORY_OPTION = click.option(
33 '-r', 45 '-r',
34 '--site-repository', 46 '--site-repository',
@@ -103,6 +115,9 @@ WARN_LINT_OPTION = click.option(
103 multiple=True, 115 multiple=True,
104 help='Warn if linting check fails. -w takes priority over -x.') 116 help='Warn if linting check fails. -w takes priority over -x.')
105 117
118SITE_REPOSITORY_ARGUMENT = click.argument(
119 'site_name', callback=_process_repositories_callback)
120
106 121
107@click.group(context_settings=CONTEXT_SETTINGS) 122@click.group(context_settings=CONTEXT_SETTINGS)
108@click.option( 123@click.option(
@@ -234,7 +249,7 @@ def site(*, site_repository, clone_path, extra_repositories, repo_key,
234 'warn_lint', 249 'warn_lint',
235 multiple=True, 250 multiple=True,
236 help='Warn if linting check fails. -w takes priority over -x.') 251 help='Warn if linting check fails. -w takes priority over -x.')
237@click.argument('site_name') 252@SITE_REPOSITORY_ARGUMENT
238def collect(*, save_location, validate, exclude_lint, warn_lint, site_name): 253def collect(*, save_location, validate, exclude_lint, warn_lint, site_name):
239 """Collects documents into a single site-definition.yaml file, which 254 """Collects documents into a single site-definition.yaml file, which
240 defines the entire site definition and contains all documents required 255 defines the entire site definition and contains all documents required
@@ -246,9 +261,6 @@ def collect(*, save_location, validate, exclude_lint, warn_lint, site_name):
246 Collect can lint documents prior to collection if the ``--validate`` 261 Collect can lint documents prior to collection if the ``--validate``
247 flag is optionally included. 262 flag is optionally included.
248 """ 263 """
249
250 engine.repository.process_repositories(site_name)
251
252 if validate: 264 if validate:
253 # Lint the primary repo prior to document collection. 265 # Lint the primary repo prior to document collection.
254 _lint_helper( 266 _lint_helper(
@@ -267,7 +279,7 @@ def collect(*, save_location, validate, exclude_lint, warn_lint, site_name):
267 type=click.File(mode='w'), 279 type=click.File(mode='w'),
268 default=sys.stdout, 280 default=sys.stdout,
269 help='Where to output. Defaults to sys.stdout.') 281 help='Where to output. Defaults to sys.stdout.')
270def list_(*, output_stream): 282def list_sites(*, output_stream):
271 engine.repository.process_site_repository(update_config=True) 283 engine.repository.process_site_repository(update_config=True)
272 engine.site.list_(output_stream) 284 engine.site.list_(output_stream)
273 285
@@ -280,9 +292,8 @@ def list_(*, output_stream):
280 type=click.File(mode='w'), 292 type=click.File(mode='w'),
281 default=sys.stdout, 293 default=sys.stdout,
282 help='Where to output. Defaults to sys.stdout.') 294 help='Where to output. Defaults to sys.stdout.')
283@click.argument('site_name') 295@SITE_REPOSITORY_ARGUMENT
284def show(*, output_stream, site_name): 296def show(*, output_stream, site_name):
285 engine.repository.process_repositories(site_name)
286 engine.site.show(site_name, output_stream) 297 engine.site.show(site_name, output_stream)
287 298
288 299
@@ -294,9 +305,8 @@ def show(*, output_stream, site_name):
294 type=click.File(mode='w'), 305 type=click.File(mode='w'),
295 default=sys.stdout, 306 default=sys.stdout,
296 help='Where to output. Defaults to sys.stdout.') 307 help='Where to output. Defaults to sys.stdout.')
297@click.argument('site_name') 308@SITE_REPOSITORY_ARGUMENT
298def render(*, output_stream, site_name): 309def render(*, output_stream, site_name):
299 engine.repository.process_repositories(site_name)
300 engine.site.render(site_name, output_stream) 310 engine.site.render(site_name, output_stream)
301 311
302 312
@@ -304,12 +314,11 @@ def render(*, output_stream, site_name):
304@ALLOW_MISSING_SUBSTITUTIONS_OPTION 314@ALLOW_MISSING_SUBSTITUTIONS_OPTION
305@EXCLUDE_LINT_OPTION 315@EXCLUDE_LINT_OPTION
306@WARN_LINT_OPTION 316@WARN_LINT_OPTION
307@click.argument('site_name') 317@SITE_REPOSITORY_ARGUMENT
308def lint_site(*, fail_on_missing_sub_src, exclude_lint, warn_lint, site_name): 318def lint_site(*, fail_on_missing_sub_src, exclude_lint, warn_lint, site_name):
309 """Lint a given site using checks defined in 319 """Lint a given site using checks defined in
310 :mod:`pegleg.engine.errorcodes`. 320 :mod:`pegleg.engine.errorcodes`.
311 """ 321 """
312 engine.repository.process_repositories(site_name)
313 _lint_helper( 322 _lint_helper(
314 site_name=site_name, 323 site_name=site_name,
315 fail_on_missing_sub_src=fail_on_missing_sub_src, 324 fail_on_missing_sub_src=fail_on_missing_sub_src,
diff --git a/pegleg/engine/util/git.py b/pegleg/engine/util/git.py
index d2e1feb..dce3f96 100644
--- a/pegleg/engine/util/git.py
+++ b/pegleg/engine/util/git.py
@@ -169,6 +169,7 @@ def _try_git_clone(repo_url,
169 # and ensure we handle url/foo.git/ cases. prefix is 'tmp' by default. 169 # and ensure we handle url/foo.git/ cases. prefix is 'tmp' by default.
170 repo_name = repo_url.rstrip('/').split('/')[-1] 170 repo_name = repo_url.rstrip('/').split('/')[-1]
171 temp_dir = os.path.join(clone_path, repo_name) 171 temp_dir = os.path.join(clone_path, repo_name)
172
172 try: 173 try:
173 os.makedirs(temp_dir) 174 os.makedirs(temp_dir)
174 except FileExistsError: 175 except FileExistsError: