dirutility.view   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 25
rs 10
c 0
b 0
f 0
wmc 5

2 Functions

Rating   Name   Duplication   Size   Complexity  
A desktop() 0 6 2
A open_window() 0 9 3
1
# View directories and files in a window
2
import os
3
from pathlib import Path
4
from subprocess import call, Popen
5
from sys import modules
6
7
8
def open_window(path):
9
    """Open path in finder or explorer window"""
10
    if 'pathlib' in modules:
11
        try:
12
            call(["open", "-R", str(Path(str(path)))])
13
        except FileNotFoundError:
14
            Popen(r'explorer /select,' + str(Path(str(path))))
15
    else:
16
        print('pathlib module must be installed to execute open_window function')
17
18
19
def desktop():
20
    try:
21
        home = os.environ['HOMEPATH']
22
    except KeyError:
23
        home = os.environ['HOME']
24
    return os.path.join(home, 'Desktop')
25