Completed
Push — master ( 187618...022db0 )
by Jace
01:32
created

dtb._default_top()   A

Complexity

Conditions 3

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3
Metric Value
cc 3
dl 0
loc 12
ccs 6
cts 6
cp 1
crap 3
rs 9.4286
1
"""Classes and functions to interact with sharing services."""
2
3 1
import os
4 1
import logging
5
6
7 1
SERVICES = (
8
    'Dropbox',
9
    'Dropbox (Personal)',
10
)
11 1
SHARE = 'DropTheBeat'
12 1
SHARE_DEPTH = 3  # number of levels to search for share directory
13
14
15 1
def find(home=None):
16
    """Return the path to a sharing location."""
17
18 1
    home = home or os.path.expanduser("~")
19
20 1
    logging.debug("looking for service in {}...".format(home))
21 1
    for directory in os.listdir(home):
22 1
        if directory in SERVICES:
23 1
            service = os.path.join(home, directory)
24 1
            logging.debug("found service: {}".format(service))
25 1
            logging.debug("looking for '{}' in {}...".format(SHARE, service))
26 1
            for dirpath, dirnames, _, in os.walk(service):
27 1
                depth = dirpath.count(os.path.sep) - service.count(os.path.sep)
28 1
                if depth >= SHARE_DEPTH:
29 1
                    del dirnames[:]
30 1
                    continue
31 1
                path = os.path.join(dirpath, SHARE)
32 1
                if os.path.isdir(path) and \
33
                        not os.path.isfile(os.path.join(path, 'setup.py')):
34 1
                    logging.info("found share: {}".format(path))
35 1
                    return path
36
37
    raise EnvironmentError("no '{}' folder found".format(SHARE))
38