forked from milkypostman/caw
-
Notifications
You must be signed in to change notification settings - Fork 1
/
caw
executable file
·76 lines (65 loc) · 2.38 KB
/
caw
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
71
72
73
74
75
76
#!/usr/bin/python
import os
import sys
import subprocess
_main_environ = "CAW_MAIN"
if __name__ == '__main__':
# try to load default config from the various xdg directories
global_config_dirs = os.path.expandvars('$XDG_CONFIG_DIRS')
if global_config_dirs == '$XDG_CONFIG_DIRS':
global_config_dirs = ["/etc/xdg",]
else:
global_config_dirs = global_config_dirs.split(':')
for dir in global_config_dirs:
default_filename = None
default_filename = os.path.join(dir, "caw", "config.py")
if os.path.isfile(default_filename):
break
#if os.path.isfile(default_filename):
#execfile(default_filename, {}, default_config)
# try to load the user configuration file
home_config_dir = os.path.expandvars('$XDG_CONFIG_HOME')
if home_config_dir == '$XDG_CONFIG_HOME':
home_config_dir = os.path.expanduser("~/.config")
user_filename = os.path.join(home_config_dir, "caw", "config.py")
#user_config = {}
#if os.path.isfile(user_filename):
#execfile(user_filename, {}, user_config)
#if not user_config and not default_config:
# raise Exception("No config file found")
#if user_config:
# config = user_config
# config['config_file']= user_filename
#else:
# config = default_config
# config['config_file']= default_filename
if os.path.isfile(user_filename):
filename = user_filename
elif os.path.isfile(default_filename):
filename = default_filename
else:
raise Exception("No Configuration File Found")
# save our values
# this acts a wrapper so we can restart our server fresh
while 1:
# got this from paster!
args = [sys.executable, filename]
#new_environ = os.environ.copy()
#new_environ[_main_environ] = 'true'
proc = None
try:
#proc = subprocess.Popen(args, env=new_environ)
proc = subprocess.Popen(args)
exit_code = proc.wait()
proc = None
#print "EXIT ON:", exit_code
if exit_code != 5:
break
finally:
# proc has not yet been disconnected
if (proc is not None and hasattr(os, 'kill')):
import signal
try:
os.kill(proc.pid, signal.SIGTERM)
except (OSError, IOError):
pass