This repository has been archived by the owner on Dec 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
winmin_yml_install.py
executable file
·62 lines (49 loc) · 2.09 KB
/
winmin_yml_install.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
#!/usr/bin/python3
import yaml
import os,sys,subprocess
import argparse
import urllib.request
def installdesk(data):
home=os.environ['HOME']
for program in data["Programs"]:
name = program["Name"]
shortname = "winmin-"+str.lower(name).replace(" ","-")
if program["Icon"]["Link"]:
iconurl = program["Icon"]["Location"]
iconname = "winmin-"+str.lower(iconurl.split("/")[-1]).replace(" ","-")
urllib.request.urlretrieve(iconurl, '{}/.local/share/pixmaps/{}'.format(home,iconname))
icon = "{}/.local/share/pixmaps/{}".format(home,iconname)
else:
icon = program["Icon"]["Location"]
print("shortname: {}".format(shortname))
template = open("/usr/share/winmin/template.desktop","rt")
out = open("{}/.local/share/applications/{}.desktop".format(home,shortname), 'wt')
for line in template:
out.write(line.replace("{{NAME}}",name).replace("{{PROGRAM}}",name).replace("{{VM}}","winmin-"+data["Id"]).replace("{{ICON}}",icon))
def main():
parser = argparse.ArgumentParser(description='Install application to WinMin using a yaml file.')
parser.add_argument('input', help='input yaml file path')
args = parser.parse_args()
file=args.input
if not os.path.isfile(file):
print("File not found")
exit()
if os.path.exists("/tmp/winmin-tmp"):
os.system("rm -r /tmp/winmin-tmp")
with open(file) as f:
data = yaml.load(f, Loader=yaml.FullLoader)
print(data)
os.mkdir("/tmp/winmin-tmp")
shortname = data["Id"]
url = data["Installer"]["Url"]
filename = url.split("/")[-1]
if data["Installer"]["InstallerType"] == "web":
subprocess.call("winmin-install \"{}\" \"{}\" --web".format(url,shortname),shell=True)
else: #TODO, specify if executing exe, and if user input is necessary (see winget repo for ideas)
urllib.request.urlretrieve(url, '/tmp/winmin-tmp/{}'.format(filename))
installfile="/tmp/winmin-tmp/{}".format(filename)
subprocess.call("winmin-install \"{}\" \"{}\"".format(installfile,shortname),shell=True)
installdesk(data)
#os.system("rm -r /tmp/winmin-tmp")
if __name__ == "__main__":
main();