forked from esitarski/RaceDB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreateShortcut.py
47 lines (41 loc) · 1.26 KB
/
CreateShortcut.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
import sys, os
import tempfile
import subprocess
vbTemplate = '''
Set oWS = WScript.CreateObject("WScript.Shell")
strDesktop = oWS.SpecialFolders("Desktop")
Set oLink = oWS.CreateShortcut(strDesktop + "\{name}.lnk")
oLink.TargetPath = "{targetPath}"
oLink.WorkingDirectory = "{workingDirectory}"
oLink.Arguments = "{arguments}"
oLink.Description = "{description}"
oLink.IconLocation = "{icon}"
oLink.WindowStyle = 4
oLink.Save
'''
def CreateShortcut( cmd="launch" ):
'''
Create a desktop shortcut on Windows without win32shell module.
Write a visual basic script, then run it with CScript.
'''
current_folder = os.path.dirname(os.path.realpath(__file__))
vbStr = vbTemplate.format(
name ='RaceDB Launch',
targetPath =sys.executable,
arguments =' '.join( ("manage.py", cmd) ),
description ="RaceDB Launch",
icon ='{},{}'.format(os.path.join(current_folder, 'core', 'static', 'images', 'RaceDB.ico'), 0),
workingDirectory=current_folder,
)
fd, fname = tempfile.mkstemp( suffix='.vbs' )
with os.fdopen( fd, 'w' ) as f:
f.write( vbStr )
try:
subprocess.call( ['cscript.exe', '//Nologo', fname], shell=True )
except Exception as e:
print ( 'Failed: {}'.format(e) )
finally:
os.remove( fname )
pass
if __name__ == '__main__':
CreateShortcut()