Completed
Push — pyup-update-plumbum-1.6.5-to-1... ( 484603 )
by Michael
61:06 queued 60:19
created

mktmpdir()   A

Complexity

Conditions 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1.512

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 7
ccs 1
cts 5
cp 0.2
crap 1.512
rs 9.4285
1 3
import contextlib
2 3
from shutil import rmtree
3 3
import tempfile
4
5
6 3
def extract(dictionary, keys):
7
    """
8
    Extract only the specified keys from a dict
9
10
    :param dictionary: source dictionary
11
    :param keys: list of keys to extract
12
    :return dict: extracted dictionary
13
    """
14 3
    return dict(
15
        (k, dictionary[k]) for k in keys if k in dictionary
16
    )
17
18
19 3
def extract_arguments(arguments, long_keys, key_prefix='--'):
20
    """
21
    :param arguments: dict of command line arguments
22
23
    """
24 3
    long_arguments = extract(
25
        arguments,
26
        long_keys,
27
    )
28 3
    return dict([
29
        (key.replace(key_prefix, ''), value)
30
        for key, value in long_arguments.items()
31
    ])
32
33
34 3
@contextlib.contextmanager
35
def mktmpdir():
36
    tmp_dir = tempfile.mkdtemp()
37
    try:
38
        yield tmp_dir
39
    finally:
40
        rmtree(tmp_dir)
41