-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathauto-start.py
More file actions
executable file
·79 lines (69 loc) · 2.13 KB
/
auto-start.py
File metadata and controls
executable file
·79 lines (69 loc) · 2.13 KB
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
77
78
79
#!/usr/bin/env python
# coding:utf-8
from __future__ import with_statement
__version__ = '0.1'
import sys
import os
import re
import time
import ctypes
import platform
def addto_startup_linux():
filename = os.path.abspath(__file__)
dirname = os.path.dirname(filename)
scriptname = 'hautclient.py'
DESKTOP_FILE = '''\
[Desktop Entry]
Type=Application
Categories=Network;
Exec=/usr/bin/env python "%s/%s"
Icon=%s/hautclient-logo.png
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name=HautClient
Comment=HautClient Launcher
''' % (dirname , scriptname , dirname)
for dirname in map(os.path.expanduser, ['~/.config/autostart']):
if os.path.isdir(dirname):
filename = os.path.join(dirname, 'hautclient.desktop')
with open(filename, 'w') as fp:
fp.write(DESKTOP_FILE)
def addto_startup_osx():
if os.getuid() != 0:
print 'please use sudo run this script'
sys.exit()
import plistlib
plist = dict(
GroupName = 'wheel',
Label = 'org.hautclient.macos',
ProgramArguments = list([
'/usr/bin/python',
os.path.join(os.path.abspath(os.path.dirname(__file__)), 'hautclient.py')
]),
RunAtLoad = True,
UserName = 'root',
WorkingDirectory = os.path.dirname(__file__),
StandardOutPath = 'var/log/hautclient.log',
StandardErrorPath = 'var/log/hautclient.log',
KeepAlive = dict(
SuccessfulExit = False,
)
)
filename = '/Library/LaunchDaemons/org.hautclient.macos.plist'
print 'write plist to %s' % filename
plistlib.writePlist(plist, filename)
print 'write plist to %s done' % filename
def addto_startup_unknown():
print '*** error: Unknown system'
def main():
addto_startup_funcs = {
'Darwin' : addto_startup_osx,
'Linux' : addto_startup_linux,
}
addto_startup_funcs.get(platform.system(), addto_startup_unknown)()
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
pass