-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase.py
70 lines (48 loc) · 1.43 KB
/
base.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from subprocess import check_output, CalledProcessError, STDOUT
from shlex import split
from os.path import join
__all__ = (
"repos",
"cmd",
"notify",
"debug",
"home"
)
home = join("/home", "istvan")
progs = join(home, "progs")
utils = join(progs, "utils")
icons = join(utils, "icons")
repos = {
"insar_meteo": join(progs, "insar_meteo"),
"geodynamics": join(progs, "geodynamics"),
"utils": join(progs, "utils"),
"texfiles": join(home, "Dokumentumok", "texfiles"),
"pygamma": join(progs, "gamma")
}
def cmd(*args, **kwargs):
debug = kwargs.pop("debug", False)
Cmd = " ".join(args)
if debug:
print(Cmd)
return
try:
proc = check_output(split(Cmd), stderr=STDOUT)
except CalledProcessError as e:
print("\nNon zero returncode from command: \n'{}'\n"
"\nOUTPUT OF THE COMMAND: \n\n{}\nRETURNCODE was: {}"
.format(Cmd, e.output.decode(), e.returncode))
exit(1)
return proc.decode()
def notify(msg, header=None, icon=None, time=None):
if header is not None:
txt = '"%s" "%s"' % (header, msg)
else:
txt = msg
if icon is not None:
txt = '%s -i "%s"' % (txt, join(icons, icon))
if time is not None:
txt = "%s -t %s" % (txt, time)
txt = "notify-send %s" % txt
cmd(txt)
def debug(msg):
notify(msg, header="Debug", icon="debug.png")