File tree Expand file tree Collapse file tree 1 file changed +12
-21
lines changed Expand file tree Collapse file tree 1 file changed +12
-21
lines changed Original file line number Diff line number Diff line change 2
2
import json
3
3
4
4
def pkgs_and_version ():
5
-
6
- lines = os .popen ('dpkg -l | grep "^ii"' ).read ().split ('\n ' )[1 :- 1 ]
7
- i = 0
8
- while len ([l for l in lines [i ].split (' ' ) if l ]) != 4 :
9
- i += 1
10
- offsets = [lines [i ].index (l ) for l in lines [i ].split (' ' ) if len (l )]
5
+ os .system ('dpkg -l | grep "^ii" | cat > versions.txt' )
6
+ fh = open ('versions.txt' )
7
+ lines = []
11
8
pkgs = {}
12
- for line in lines :
13
- parsed = []
14
- for i in range (len (offsets )):
15
- if len (offsets ) == i + 1 :
16
- parsed .append (line [offsets [i ]:].strip ())
17
- else :
18
- parsed .append (line [offsets [i ]:offsets [i + 1 ]].strip ())
19
-
20
- name = parsed [1 ].split ()[0 ]
21
-
22
- version = parsed [1 ].split ()[1 ]
23
-
24
- version = parsed [1 ].split ()[0 ]
25
-
26
- pkgs .update ({name :{'version' :version }})
9
+ while True :
10
+ line = fh .readline ()
11
+ if not line :
12
+ break
13
+ name = line .split ()[1 ]
14
+ version = line .split ()[2 ]
15
+ pkgs [name ] = version
16
+ fh .close ()
17
+ return pkgs
27
18
return pkgs
28
19
29
20
pkgs = pkgs_and_version ()
You can’t perform that action at this time.
0 commit comments