Completed
Push — master ( 2617b3...8e8154 )
by russianidiot
01:57
created

_scripts()   B

Complexity

Conditions 6

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
c 1
b 0
f 0
dl 0
loc 11
rs 8
1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
import os
4
from __init__ import REPO
5
6
__all__ = ["scripts"]
7
8
9
def valid_script_name(name):
10
    if name[0] == ".":  # skip .hidden files
11
        return False
12
    if " " in name:  # skip filename with ' ' space
13
        return False
14
    if ".txt" in name:  # skip .txt files
15
        return False
16
    return True
17
18
19
def _scripts(path):
20
    listdir = os.listdir(path)
21
    for l in listdir:
22
        if not valid_script_name(l):
23
            continue
24
        dst = os.path.join("/usr/local/bin/%s" % l)
25
        if os.path.exists(dst) and not os.path.isfile(dst):
26
            raise OSError("ERROR: %s EXISTS and NOT FILE" % dst)
27
        fullpath = os.path.join(path, l)
28
        if os.path.isfile(fullpath):
29
            yield os.path.join(folder, l)
30
31
folder = "bin"
32
path = os.path.join(REPO, folder)
33
if os.path.exists(path) and os.path.isdir(path):
34
    scripts = list(_scripts(path))
35
else:
36
    if __name__ == "__main__":
37
        print("SKIP: %s/ NOT EXISTS" % path)
38
39
if __name__ == "__main__":
40
    for k in __all__:
41
        if k in globals():
42
            print("%s: %s" % (k, globals()[k]))
43