Skip to content
Snippets Groups Projects
Commit f6cf88c9 authored by André Anjos's avatar André Anjos :speech_balloon:
Browse files

[scripts] Add preliminary color support

parent 35f13db1
No related branches found
No related tags found
1 merge request!17Terminal colors
Pipeline #26967 passed
#!/usr/bin/env python #!/usr/bin/env python
import os import os
import logging
logger = logging.getLogger(__name__)
import click import click
import gitlab
from . import bdt from . import bdt
from ..log import verbosity_option
from ..changelog import get_last_tag, parse_date from ..changelog import get_last_tag, parse_date
from ..release import get_gitlab_instance from ..release import get_gitlab_instance
from ..log import verbosity_option, get_logger, echo_normal, echo_warning
logger = get_logger(__name__)
@click.command(epilog=''' @click.command(epilog='''
Examples: Examples:
...@@ -38,11 +39,16 @@ def lasttag(package): ...@@ -38,11 +39,16 @@ def lasttag(package):
gl = get_gitlab_instance() gl = get_gitlab_instance()
# we lookup the gitlab package once # we lookup the gitlab package once
use_package = gl.projects.get(package) try:
logger.info('Found gitlab project %s (id=%d)', use_package = gl.projects.get(package)
use_package.attributes['path_with_namespace'], use_package.id) logger.info('Found gitlab project %s (id=%d)',
use_package.attributes['path_with_namespace'], use_package.id)
tag = get_last_tag(use_package)
date = parse_date(tag.commit['committed_date']) tag = get_last_tag(use_package)
click.echo('Lastest tag for %s is %s (%s)' % \ date = parse_date(tag.commit['committed_date'])
(package, tag.name, date.strftime('%Y-%m-%d %H:%M:%S'))) echo_normal('%s: %s (%s)' % \
(package, tag.name, date.strftime('%Y-%m-%d %H:%M:%S')))
except gitlab.GitlabGetError as e:
logger.warn('Gitlab access error - package %s does not exist?',
package)
echo_warning('%s: unknown' % (package,))
...@@ -6,13 +6,12 @@ import sys ...@@ -6,13 +6,12 @@ import sys
import click import click
import gitlab import gitlab
import logging
logger = logging.getLogger(__name__)
from . import bdt from . import bdt
from ..log import verbosity_option
from ..release import get_gitlab_instance from ..release import get_gitlab_instance
from ..log import verbosity_option, get_logger, echo_normal, echo_warning
logger = get_logger(__name__)
@click.command(epilog=''' @click.command(epilog='''
Examples: Examples:
...@@ -48,12 +47,12 @@ def visibility(target, group): ...@@ -48,12 +47,12 @@ def visibility(target, group):
# reads package list or considers name to be a package name # reads package list or considers name to be a package name
if os.path.exists(target) and os.path.isfile(target): if os.path.exists(target) and os.path.isfile(target):
logger.info('Reading package names from file %s...', target) logger.debug('Reading package names from file %s...', target)
with open(target, 'rt') as f: with open(target, 'rt') as f:
packages = [k.strip() for k in f.readlines() if k.strip() and not \ packages = [k.strip() for k in f.readlines() if k.strip() and not \
k.strip().startswith('#')] k.strip().startswith('#')]
else: else:
logger.info('Assuming %s is a package name (file does not ' \ logger.debug('Assuming %s is a package name (file does not ' \
'exist)...', target) 'exist)...', target)
packages = [target] packages = [target]
...@@ -66,11 +65,11 @@ def visibility(target, group): ...@@ -66,11 +65,11 @@ def visibility(target, group):
# retrieves the gitlab package object # retrieves the gitlab package object
try: try:
use_package = gl.projects.get(package) use_package = gl.projects.get(package)
logger.info('Found gitlab project %s (id=%d)', logger.debug('Found gitlab project %s (id=%d)',
use_package.attributes['path_with_namespace'], use_package.id) use_package.attributes['path_with_namespace'], use_package.id)
click.echo('%s: %s' % (package, echo_normal('%s: %s' % (package,
use_package.attributes['visibility'].lower())) use_package.attributes['visibility'].lower()))
except gitlab.GitlabGetError as e: except gitlab.GitlabGetError as e:
logger.warn('Gitlab access error - package %s does not exist?', logger.warn('Gitlab access error - package %s does not exist?',
package) package)
click.echo('%s: unknown' % (package,)) echo_warning('%s: unknown' % (package,))
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