]>
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
26 from base
import Package
27 from file import BinaryPackage
29 import pakfire
.util
as util
30 from pakfire
.constants
import *
32 class DatabasePackage(Package
):
35 def __init__(self
, pakfire
, repo
, db
, data
):
36 Package
.__init
__(self
, pakfire
, repo
)
42 for key
in data
.keys():
43 self
._data
[key
] = data
[key
]
46 return "<%s %s>" % (self
.__class
__.__name
__, self
.friendly_name
)
54 id = self
.metadata
.get("id")
62 return self
.metadata
.get("name")
66 return self
.metadata
.get("version")
70 return self
.metadata
.get("release")
74 epoch
= self
.metadata
.get("epoch", 0)
80 return self
.metadata
.get("arch")
84 return self
.metadata
.get("maintainer")
88 return self
.metadata
.get("license")
92 return self
.metadata
.get("summary")
95 def description(self
):
96 return self
.metadata
.get("description")
100 groups
= self
.metadata
.get("groups", "")
103 return groups
.split()
108 def build_date(self
):
109 return self
.metadata
.get("build_date")
112 def build_time(self
):
113 build_time
= self
.metadata
.get("build_time", 0)
116 return int(build_time
)
121 def build_host(self
):
122 return self
.metadata
.get("build_host")
126 return self
.metadata
.get("build_id")
130 return self
.metadata
.get("uuid")
134 return self
.metadata
.get("size", 0)
143 return self
.metadata
.get("provides", "").split()
147 return self
.metadata
.get("requires", "").split()
151 return self
.metadata
.get("conflicts", "").split()
155 return self
.metadata
.get("obsoletes", "").split()
159 return self
.metadata
.get("hash1")
163 return self
.metadata
.get("scriptlet")
167 return self
.metadata
.get("filename") # XXX basename?
173 c
.execute("SELECT name FROM files WHERE pkg = ?", (self
.id,))
175 return [f
["name"] for f
in c
]
180 def configfiles(self
):
181 return [] # XXX to be done
183 def _does_provide_file(self
, requires
):
185 A faster version to find a file in the database.
188 c
.execute("SELECT * FROM files WHERE name GLOB ? AND pkg = ?",
189 (requires
.requires
, self
.id))
200 def download(self
, text
=""):
202 Downloads the package from repository and returns a new instance
206 # XXX a bit hacky, but InstalledRepository has no cache.
207 if self
.repo
.name
== "installed":
210 # Marker, if we need to download the package.
213 # Add shortcut for cache.
214 cache
= self
.repo
.cache
216 cache_filename
= "packages/%s" % os
.path
.basename(self
.filename
)
218 # Check if file already exists in cache.
219 if cache
.exists(cache_filename
):
220 # If the file does already exist, we check if the hash1 matches.
221 if cache
.verify(cache_filename
, self
.hash1
):
222 # We already got the right file. Skip download.
225 # The file in cache has a wrong hash. Remove it and repeat download.
226 cache
.remove(cache_filename
)
229 # Make sure filename is of type string (and not unicode)
230 filename
= str(self
.filename
)
232 # Get a package grabber and add mirror download capabilities to it.
233 grabber
= pakfire
.downloader
.PackageDownloader(
234 text
=text
+ os
.path
.basename(filename
),
236 grabber
= self
.repo
.mirrors
.group(grabber
)
238 i
= grabber
.urlopen(filename
)
240 # Open input and output files and download the file.
241 o
= cache
.open(cache_filename
, "w")
243 buf
= i
.read(BUFFER_SIZE
)
246 buf
= i
.read(BUFFER_SIZE
)
251 # Verify if the download was okay.
252 if not cache
.verify(cache_filename
, self
.hash1
):
253 raise Exception, "XXX this should never happen..."
255 filename
= os
.path
.join(cache
.path
, cache_filename
)
256 return BinaryPackage(self
.pakfire
, self
.repo
, filename
)
258 def cleanup(self
, message
, prefix
):
261 # Get all files, that are in this package and check for all of
262 # them if they need to be removed.
263 files
= self
.filelist
265 # Fetch the whole filelist of the system from the database and create
266 # a diff. Exclude files from this package - of course.
267 c
.execute("SELECT name FROM files WHERE pkg != ?", (self
.id,))
270 # Check if file in filelist.
271 if row
["name"] in files
:
272 files
.remove(row
["name"])
276 self
._remove
_files
(files
, message
, prefix
)
279 # XXX maybe we can remove this later?
280 class InstalledPackage(DatabasePackage
):