]>
git.ipfire.org Git - pakfire.git/blob - python/pakfire/packages/installed.py
2 ###############################################################################
4 # Pakfire - The IPFire package management system #
5 # Copyright (C) 2011 Pakfire development team #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
24 import pakfire
.downloader
25 import pakfire
.filelist
27 from base
import Package
28 from file import BinaryPackage
30 import pakfire
.util
as util
31 from pakfire
.constants
import *
33 class DatabasePackage(Package
):
36 def __init__(self
, pakfire
, repo
, db
, data
):
37 Package
.__init
__(self
, pakfire
, repo
)
44 for key
in data
.keys():
45 self
._data
[key
] = data
[key
]
48 return "<%s %s>" % (self
.__class
__.__name
__, self
.friendly_name
)
56 id = self
.metadata
.get("id")
64 return self
.metadata
.get("name")
68 return self
.metadata
.get("version")
72 return self
.metadata
.get("release")
76 epoch
= self
.metadata
.get("epoch", 0)
82 return self
.metadata
.get("arch")
86 return self
.metadata
.get("maintainer")
90 return self
.metadata
.get("license")
94 return self
.metadata
.get("summary")
97 def description(self
):
98 return self
.metadata
.get("description")
102 groups
= self
.metadata
.get("groups", "")
105 return groups
.split()
110 def build_date(self
):
111 return self
.metadata
.get("build_date")
114 def build_time(self
):
115 build_time
= self
.metadata
.get("build_time", 0)
118 return int(build_time
)
123 def build_host(self
):
124 return self
.metadata
.get("build_host")
128 return self
.metadata
.get("build_id")
132 return self
.metadata
.get("vendor")
136 return self
.metadata
.get("uuid")
140 return self
.metadata
.get("size", 0)
144 inst_size
= self
.metadata
.get("inst_size", None)
146 # As install size has not always been saved in the database
147 # use the package size instead.
148 if inst_size
is None:
155 return self
.metadata
.get("provides", "").splitlines()
159 return self
.metadata
.get("requires", "").splitlines()
163 return self
.metadata
.get("conflicts", "").splitlines()
167 return self
.metadata
.get("obsoletes", "").splitlines()
170 def recommends(self
):
171 recommends
= self
.metadata
.get("recommends", None)
174 return recommends
.splitlines()
180 suggests
= self
.metadata
.get("suggests", None)
183 return suggests
.splitlines()
189 return self
.metadata
.get("hash1")
193 return self
.metadata
.get("scriptlet")
197 return self
.metadata
.get("filename")
201 if self
._filelist
is None:
205 c
.execute("SELECT * FROM files WHERE pkg = ?", (self
.id,))
207 for row
in c
.fetchall():
208 file = pakfire
.filelist
.FileDatabase(self
.pakfire
, self
.db
, row
["id"], row
)
209 self
._filelist
.append(file)
211 return self
._filelist
214 def configfiles(self
):
217 for file in self
.filelist
:
218 if not file.is_config():
229 for file in self
.filelist
:
230 if not file.is_datafile():
237 def _does_provide_file(self
, requires
):
239 A faster version to find a file in the database.
242 c
.execute("SELECT * FROM files WHERE name GLOB ? AND pkg = ?",
243 (requires
.requires
, self
.id))
254 def download(self
, text
=""):
256 Downloads the package from repository and returns a new instance
260 # XXX a bit hacky, but InstalledRepository has no cache.
261 if self
.repo
.name
== "installed":
264 # Marker, if we need to download the package.
267 # Add shortcut for cache.
268 cache
= self
.repo
.cache
270 cache_filename
= "packages/%s" % os
.path
.basename(self
.filename
)
272 # Check if file already exists in cache.
273 if cache
.exists(cache_filename
):
274 # If the file does already exist, we check if the hash1 matches.
275 if cache
.verify(cache_filename
, self
.hash1
):
276 # We already got the right file. Skip download.
279 # The file in cache has a wrong hash. Remove it and repeat download.
280 cache
.remove(cache_filename
)
283 # Make sure filename is of type string (and not unicode)
284 filename
= str(self
.filename
)
286 # Get a package grabber and add mirror download capabilities to it.
287 grabber
= pakfire
.downloader
.PackageDownloader(
288 text
=text
+ os
.path
.basename(filename
),
290 grabber
= self
.repo
.mirrors
.group(grabber
)
292 i
= grabber
.urlopen(filename
)
294 # Open input and output files and download the file.
295 o
= cache
.open(cache_filename
, "w")
297 buf
= i
.read(BUFFER_SIZE
)
300 buf
= i
.read(BUFFER_SIZE
)
305 # Verify if the download was okay.
306 if not cache
.verify(cache_filename
, self
.hash1
):
307 raise Exception, "XXX this should never happen..."
309 filename
= os
.path
.join(cache
.path
, cache_filename
)
310 return BinaryPackage(self
.pakfire
, self
.repo
, filename
)
312 def cleanup(self
, message
, prefix
):
315 # Get all files, that are in this package and check for all of
316 # them if they need to be removed.
317 files
= self
.filelist
319 # Fetch the whole filelist of the system from the database and create
320 # a diff. Exclude files from this package - of course.
321 c
.execute("SELECT DISTINCT name FROM files WHERE pkg != ?", (self
.id,))
323 installed_files
= set()
325 installed_files
.add(row
["name"])
328 # List with files to be removed.
332 if f
.name
in installed_files
:
335 remove_files
.append(f
)
337 self
._remove
_files
(remove_files
, message
, prefix
)
340 def signatures(self
):
341 # Database packages do not have any signatures.
345 # XXX maybe we can remove this later?
346 class InstalledPackage(DatabasePackage
):