-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall_script.py
30 lines (29 loc) · 1.32 KB
/
install_script.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
import sys
import os
from setuptools.command.install import install
#修改project_name即可打包,其他地方不用修改
project_name = "kdFileFinder"
class install_cmd(install):
def run(self):
install.run(self)
try :
if sys.platform =="win32" :
script_file = os.path.join(self._get_desktop_folder(),project_name + '.bat')
with open(script_file, "w") as f:
f.write("@echo off\r\nstart " + project_name+ ".exe")
elif sys.platform == "linux":
import stat
script_file = os.path.join(self._get_desktop_folder(),project_name + '.sh')
with open(script_file, "w") as f:
f.write("#!/bin/sh\n" + project_name)
st = os.stat(script_file)
os.chmod(script_file, st.st_mode | stat.S_IEXEC)
except Exception as e:
print("can not create start script." + str(e))
def _get_desktop_folder(self):
import subprocess
try:
return subprocess.check_output(['xdg-user-dir',
'DESKTOP']).decode('utf-8').strip()
except Exception:
return os.path.join(os.path.expanduser('~'), 'Desktop')