-
Notifications
You must be signed in to change notification settings - Fork 0
/
choco.py
138 lines (128 loc) · 4.96 KB
/
choco.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
'''
Home to choco-related things for cAppInstaller
'''
import pathlib
import queue
import shlex
import shutil
from .strings import INSTALL_CHOCO_CMD
from .util import subprocess_call_live_output
CHECKBOXES_PER_ROW = 3
CHOCOLATEY_APPS = {
# Display: Args
'7-Zip' : '7zip',
'8GadgetPack' : '8gadgetpack',
'Adobe Reader' : 'adobereader',
'API Monitor' : 'apimonitor',
'Audacity' : 'audacity',
'Authy' : 'authy-desktop',
'BGInfo' : 'bginfo',
'CPU-Z' : 'cpu-z',
'CrystalDiskInfo' : 'crystaldiskinfo',
'CrystalDiskMark' : 'crystaldiskmark',
'DebugView' : 'dbgview',
'Discord' : 'discord',
'Epic Games Launcher' : 'epicgameslauncher',
'Filezilla' : 'filezilla',
'FurMark' : 'furmark',
'Git' : 'git --params "/NoAutoCrlf"',
'Git Extensions': 'gitextensions',
'Github CLI': 'gh',
'Google Chrome': 'googlechrome',
'GrepWin': 'grepwin',
'GSmartControl': 'gsmartcontrol',
'HWiNFO' : 'hwinfo',
'HxD': 'hxd',
'Intel CPU Diagnostic ': 'intel-ipdt',
'KiTTY' : 'kitty',
'Link Shell Extension': 'linkshellextension',
'Logitech Gaming' : 'logitechgaming',
'Minecraft': 'minecraft',
'Mp3tag' : 'mp3tag',
'Not Another PDF Scanner 2': 'naps2',
'NoMachine': 'nomachine',
'Notepad Plus Plus': 'notepadplusplus',
'OBS Studio': 'obs-studio',
'Open Shell (Classic Shell)': 'open-shell --params "/StartMenu"',
'Postman': 'postman',
'Path Copy Copy': 'path-copy-copy',
'PIA': 'pia',
'Process Explorer': 'procexp',
'PuTTY' : 'putty',
'Python 2': 'python2 /InstallDir "C:/Python27"',
'Python 3.7': 'python --version 3.7.0 --params "/InstallDir:C:/Python37"',
'Python 3.8': 'python --version 3.8.0 --params "/InstallDir:C:/Python38"',
'Python 3.9': 'python --version 3.9.7 --params "/InstallDir:C:/Python39"',
'Python 3.10': 'python3 --version 3.10.7 --override --installarguments "/quiet Include_debug=1 Include_symbols=1 Include_dev=1 InstallAllUsers=1 Include_launcher=1 Include_test=1 InstallAllUsers=1 SimpleInstall=1 TargetDir=C:\Python310 PrependPath=0"',
'Resource Hacker': 'reshack',
'ScreenToGif': 'screentogif',
'Skype': 'skype --version 7.41.0.10101',
'Smartmontools': 'smartmontools',
'Steam': 'steam',
'Sudo': 'sudo',
'Teracopy': 'teracopy',
'Terraform': 'terraform',
'TortoiseHg': 'tortoisehg',
'Transmission': 'transmission',
'VirtualBox' : 'virtualbox',
'Visual Leak Detector' : 'visualleakdetector',
'Visual Studio Code': 'visualstudiocode',
'Visual Studio 2017 Community': 'visualstudio2017community visualstudio2017-workload-nativecrossplat visualstudio2017-workload-nativedesktop visualstudio2017-workload-universal windows-sdk-10.1',
'Visual Studio 2019 Community': 'visualstudio2019community visualstudio2019-workload-nativecrossplat visualstudio2019-workload-nativedesktop visualstudio2019-workload-universal windows-sdk-10.1',
'Visual Studio 2019 Enterprise': 'visualstudio2019enterprise visualstudio2019-workload-nativecrossplat visualstudio2019-workload-nativedesktop visualstudio2019-workload-universal windows-sdk-10.1',
'VLC': 'vlc',
'VNC Viewer': 'vnc-viewer',
'Windows Terminal': 'microsoft-windows-terminal',
'Wget' : 'wget',
'WinDbg': 'windbg',
'WinDirStat': 'windirstat',
'WinMerge': 'winmerge',
'Xming' : 'xming',
}
class Choco:
'''
Class for performing operations via Chocolatey
'''
# Only do this once per gui run.
ALLOW_GLOBAL_CONFIRMATION_SET = False
def __init__(self, display_name: str, output_queue: queue.Queue):
'''
The package is actually the package and args string
The output queue is used to send live output back to the GUI.
'''
self.package = shlex.split(CHOCOLATEY_APPS[display_name])
self.output_queue = output_queue
def install(self):
'''
Attempts to install the given package
'''
if not Choco.ALLOW_GLOBAL_CONFIRMATION_SET:
subprocess_call_live_output(self.output_queue, [
str(self.get_choco()),
'feature',
'enable',
'-n=allowGlobalConfirmation',
'-y'
])
Choco.ALLOW_GLOBAL_CONFIRMATION_SET = True
return subprocess_call_live_output(self.output_queue, [
str(self.get_choco()),
'install',
] + self.package + [
'-y'
])
def get_choco(self):
'''
Attempts to get back the path to choco.exe, if not available install choco
then returns the path to choco.exe
'''
choco = shutil.which('choco')
if not choco:
choco = r"C:\ProgramData\chocolatey\choco.exe"
choco = pathlib.Path(choco)
if choco.is_file():
return choco
else:
self.output_queue.put_nowait(['Installing Choco'])
subprocess_call_live_output(self.output_queue, INSTALL_CHOCO_CMD)
return self.get_choco()