-
Notifications
You must be signed in to change notification settings - Fork 5
/
install_windows.py
55 lines (48 loc) · 1.83 KB
/
install_windows.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
import os, sys, argparse, shutil
# Dependencies
dependencies_script = 'pip install pyinstaller winshell pywin32'
try:
import pyinstaller, winshell
from win32com.client import Dispatch
except:
os.system(dependencies_script)
import winshell
from win32com.client import Dispatch
# Uninstall
parser = argparse.ArgumentParser(description='Install Simon Stålenhag wallpaper for Windows')
parser.add_argument('-u', '--uninstall', help='Remove installation', action='store_true')
def remove(path):
try:
shutil.rmtree(path)
except Exception as e:
return
if parser.parse_args().uninstall:
print('Uninstalling Stålenhag Wallpaper Application')
remove(os.path.expanduser('~|Pictures|Stålenhag|'.replace('|', os.sep)))
remove(os.path.expanduser('~|.stalenhag|'.replace('|', os.sep)))
desktop = winshell.desktop()
shortcutpath = os.path.join(desktop, "Stalenhag.lnk")
os.remove(shortcutpath)
quit()
# Install
print('Installing Stålenhag Wallpaper Application')
install_loc = os.path.expanduser(f'~{os.sep}.stalenhag/install')
install_script = f'pyinstaller --noconfirm --onedir --console --distpath="{install_loc}" --add-data="./tftf_front.ico;." --icon="./tftf_front.ico" "./stalenhag.py"'
# note: --icon "path/asd.ico"
os.system(install_script)
print(f'SUCCESS ---------------------------')
print(f'Executable install in {install_loc}')
# clean
os.remove('stalenhag.spec')
remove('./build')
# Add Shortcut
desktop = winshell.desktop()
path = os.path.join(desktop, "Stalenhag.lnk")
target = f"{install_loc}{os.sep}stalenhag{os.sep}stalenhag.exe"
wDir = f"{install_loc}"
shell = Dispatch('WScript.Shell')
shortcut = shell.CreateShortCut(path)
shortcut.Targetpath = target
shortcut.WorkingDirectory = wDir
shortcut.IconLocation = f"{install_loc}{os.sep}stalenhag{os.sep}tftf_front.ico"
shortcut.save()