-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.py
41 lines (29 loc) · 893 Bytes
/
index.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
from subprocess import run, PIPE
def isNumber(s):
return any(char.isdigit() for char in s)
def command(cmdString):
return cmdString.split()
def deleteFileContent(filename):
file = open(filename, mode='w')
file.write('')
file.close()
def writeFile(filename, cmdOutput):
file = open(filename, mode='a')
file.write(
'<?xml version="1.0" encoding="utf-8"?>\n'+
'<packages>\n'
)
for text in cmdOutput:
if (text.__contains__('package')):
break
if ( isNumber(text) == False ):
file.write('<package id="'+text+'" />\n')
file.write(
'</packages>'
)
file.close()
print(filename + ' file created')
filename = 'packages.config'
cmdOutput = run(command('choco list -lo'), stdout=PIPE).stdout.decode('utf-8')
deleteFileContent(filename)
writeFile(filename, cmdOutput.split())