]>
git.ipfire.org Git - people/ms/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
)
43 for key
in data
.keys():
44 self
._data
[key
] = data
[key
]
47 return "<%s %s>" % (self
.__class
__.__name
__, self
.friendly_name
)
55 id = self
.metadata
.get("id")
63 return self
.metadata
.get("name")
67 return self
.metadata
.get("version")
71 return self
.metadata
.get("release")
75 epoch
= self
.metadata
.get("epoch", 0)
81 return self
.metadata
.get("arch")
85 return self
.metadata
.get("maintainer")
89 return self
.metadata
.get("license")
93 return self
.metadata
.get("summary")
96 def description(self
):
97 return self
.metadata
.get("description")
101 groups
= self
.metadata
.get("groups", "")
104 return groups
.split()
109 def build_date(self
):
110 return self
.metadata
.get("build_date")
113 def build_time(self
):
114 build_time
= self
.metadata
.get("build_time", 0)
117 return int(build_time
)
122 def build_host(self
):
123 return self
.metadata
.get("build_host")
127 return self
.metadata
.get("build_id")
131 return self
.metadata
.get("vendor")
135 return self
.metadata
.get("uuid")
139 return self
.metadata
.get("size", 0)
148 return self
.metadata
.get("provides", "").splitlines()
152 return self
.metadata
.get("requires", "").splitlines()
156 return self
.metadata
.get("conflicts", "").splitlines()
160 return self
.metadata
.get("obsoletes", "").splitlines()
164 return self
.metadata
.get("hash1")
168 return self
.metadata
.get("scriptlet")
172 return self
.metadata
.get("filename") # XXX basename?
179 c
.execute("SELECT id FROM files WHERE pkg = ?", (self
.id,))
182 file = pakfire
.filelist
.FileDatabase(self
.pakfire
, self
.db
, id[0])
183 filelist
.append(file)
188 def configfiles(self
):
191 for file in self
.filelist
:
192 if not file.is_config():
199 def _does_provide_file(self
, requires
):
201 A faster version to find a file in the database.
204 c
.execute("SELECT * FROM files WHERE name GLOB ? AND pkg = ?",
205 (requires
.requires
, self
.id))
216 def download(self
, text
=""):
218 Downloads the package from repository and returns a new instance
222 # XXX a bit hacky, but InstalledRepository has no cache.
223 if self
.repo
.name
== "installed":
226 # Marker, if we need to download the package.
229 # Add shortcut for cache.
230 cache
= self
.repo
.cache
232 cache_filename
= "packages/%s" % os
.path
.basename(self
.filename
)
234 # Check if file already exists in cache.
235 if cache
.exists(cache_filename
):
236 # If the file does already exist, we check if the hash1 matches.
237 if cache
.verify(cache_filename
, self
.hash1
):
238 # We already got the right file. Skip download.
241 # The file in cache has a wrong hash. Remove it and repeat download.
242 cache
.remove(cache_filename
)
245 # Make sure filename is of type string (and not unicode)
246 filename
= str(self
.filename
)
248 # Get a package grabber and add mirror download capabilities to it.
249 grabber
= pakfire
.downloader
.PackageDownloader(
250 text
=text
+ os
.path
.basename(filename
),
252 grabber
= self
.repo
.mirrors
.group(grabber
)
254 i
= grabber
.urlopen(filename
)
256 # Open input and output files and download the file.
257 o
= cache
.open(cache_filename
, "w")
259 buf
= i
.read(BUFFER_SIZE
)
262 buf
= i
.read(BUFFER_SIZE
)
267 # Verify if the download was okay.
268 if not cache
.verify(cache_filename
, self
.hash1
):
269 raise Exception, "XXX this should never happen..."
271 filename
= os
.path
.join(cache
.path
, cache_filename
)
272 return BinaryPackage(self
.pakfire
, self
.repo
, filename
)
274 def cleanup(self
, message
, prefix
):
277 # Get all files, that are in this package and check for all of
278 # them if they need to be removed.
279 files
= self
.filelist
281 # Fetch the whole filelist of the system from the database and create
282 # a diff. Exclude files from this package - of course.
283 c
.execute("SELECT DISTINCT name FROM files WHERE pkg != ?", (self
.id,))
285 installed_files
= set()
287 installed_files
.add(row
["name"])
290 # List with files to be removed.
294 if f
.name
in installed_files
:
297 remove_files
.append(f
)
299 self
._remove
_files
(remove_files
, message
, prefix
)
302 def signatures(self
):
303 # Database packages do not have any signatures.
307 # XXX maybe we can remove this later?
308 class InstalledPackage(DatabasePackage
):