Completed
Push — status ( 924687 )
by Michael
09:41
created

work_in()   A

Complexity

Conditions 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
dl 0
loc 13
rs 9.4285
1
import contextlib
2
import os
3
4
import click
0 ignored issues
show
Configuration introduced by
The import click could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
5
import requests_cache
0 ignored issues
show
Configuration introduced by
The import requests_cache could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
6
7
from . import __version__
8
from changes.commands import init as init_command
9
from changes.commands import status as status_command
10
11
VERSION = 'changes {}'.format(__version__)
12
13
14
@contextlib.contextmanager
15
def work_in(dirname=None):
16
    """
17
    Context manager version of os.chdir. When exited, returns to the working
18
    directory prior to entering.
19
    """
20
    curdir = os.getcwd()
21
    try:
22
        if dirname is not None:
23
            os.chdir(dirname)
24
        yield
25
    finally:
26
        os.chdir(curdir)
27
28
29
def print_version(context, param, value):
30
    if not value or context.resilient_parsing:
31
        return
32
    click.echo(VERSION)
33
    context.exit()
34
35
36
@click.option(
37
    '--dry-run',
38
    help='Prints (instead of executing) the operations to be performed.',
39
    is_flag=True,
40
    default=False,
41
)
42
@click.option(
43
    '--verbose',
44
    help='Enables verbose output.',
45
    is_flag=True,
46
    default=False,
47
)
48
@click.version_option(
49
    __version__,
50
    '-V',
51
    '--version',
52
    message=VERSION
53
)
54
@click.group(
55
    context_settings=dict(
56
        help_option_names=[u'-h', u'--help']
57
    ),
58
)
59
def main(dry_run, verbose):
60
    """Ch-ch-changes"""
61
62
63
@click.command()
64
def init():
65
    """
66
    Detects, prompts and initialises the project.
67
    """
68
    init_command.init()
69
70
main.add_command(init)
71
72
73
@click.command()
74
@click.argument('repo_directory', required=False)
75
def status(repo_directory):
76
    """
77
    Shows current project release status.
78
    """
79
    repo_directory = repo_directory if repo_directory else '.'
80
81
    with work_in(repo_directory):
82
        requests_cache.install_cache(
83
            cache_name='github_cache',
84
            backend='sqlite',
85
            expire_after=180000
86
        )
87
        status_command.status()
88
89
main.add_command(status)