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
139
140
141
|
# -*- python -*-
'''
xpybar – xmobar replacement written in python
Copyright © 2014, 2015, 2016, 2017, 2018, 2019 Mattias Andrée (m@maandreese)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''
from util import *
class Pacman:
'''
Retrieve package information using Arch Linux's pacman
Unique variables for installed:
@variable required:list<str> Packages that require this package
@variable optrequired:list<str> Packages that this package is optional for
@variable install_date:str The date and time the package was installed
@variable installed_explicitly:bool Whether the package was installed explicitly
@variable install_script:bool Whether the package contains and install script
Unique variables for not installed:
@variable repository:str The repository the package is located in
@variable download_size:float The download size of the package in kilobytes
Common variables:
@variable name:str The name of the package
@variable version:str The version of the package
@variable description:str The description of the package
@variable architecture:str The microprocessor architecture of the package
@variable url:str The home URL of the project
@variable licenses:list<str> The licenses used by the package
@variable groups:list<str> Package groups the package is a member of
@variable provides:list<str> Packages the package provides
@variable depends:list<str> Packages the package depends on
@variable optdepends:list<(str, str?, bool)> Optional packages for this package, stored as a tuple of:
The name of the package, the reason for using it,
and whether or not it is installed.
@variable conflicts:list<str> Packages the package conflicts with
@variable replaces:list<str> Packages the package replaces
@variable installed_size:float The installed size of the package in kilobytes
@variable packager:str? The packager of the package, `None` if unknown
@variable build_date:str The date and time the package was built
@variable validated_by:list<str> Methods used to validate the package's integrity
'''
def __init__(self, package, installed):
'''
Constructor
@param package:str The name of the package, can be %repo/%name
@param installed:bool Whether it is information about the installed version that should be fetched
'''
verb = '-Qi' if installed else '-Si' # -Sii and -Qii, while a bit different, would get us more info.
info = spawn_read('env', 'LOCALE=C', 'pacman', verb, package).split('\n')
if len(info) == 1:
raise Exception('Package `%s\' is not installed' % package)
last_field = None
fields = {}
for line in info:
continued = line.startswith(' ')
line = list(filter(lambda cell : not cell == '', line.split(' ')))
colon = -1
if not continued:
for i in range(len(line)):
if line[i] == ':':
colon = i
break
field = last_field
if colon >= 0:
last_field = field = ' '.join(line[:colon])
line = line[colon + 1:]
if field not in fields:
fields[field] = []
fields[field].append(line)
word = lambda x : fields[x][0][0]
text = lambda x : ' '.join(fields[x][0])
plur = lambda x : list(filter(lambda w : not w == 'None', fields[x][0]))
if installed:
self.required = plur('Required By')
self.optrequired = plur('Optional For')
self.install_date = text('Install Date')
self.installed_explicitly = text('Install Reason') == 'Explicitly installed'
self.install_script = text('Install Script') == 'Yes'
if not installed:
self.repository = word('Name')
self.download_size = float(word('Download Size'))
self.name = word('Name')
self.version = word('Version')
self.description = text('Description')
self.architecture = word('Architecture')
self.url = text('URL')
self.licenses = plur('Licences')
self.groups = plur('Groups')
self.provides = plur('Provides')
self.depends = plur('Depends On')
self.optdepends = []
optdepends_ = [' '.join(x) for x in fields['Optional Deps']]
for deps in optdepends_:
inst = deps.endswith(' [installed]')
if installed:
deps = deps[:-len(' [installed]')]
if ': ' in deps:
deps = deps.split(': ')
name = deps[0]
deps = ': '.join(deps[1:])
self.optdepends.append((name, deps, inst))
else:
self.optdepends.append((deps, None, inst))
self.conflicts = plur('Conflicts With')
self.replaces = plur('Replaces')
self.installed_size = float(word('Installed Size'))
self.packager = text('Packager')
if self.packager == 'Unknown Packager':
self.packager = None
self.build_date = text('Build Date')
self.validated_by = list(filter(lambda x : not x == 'Sum', plur('Validated By')))
|