resetting manifest requested domain to floor
[platform/upstream/yum-metadata-parser.git] / sqlitecachec.py
1 # This program is free software; you can redistribute it and/or modify
2 # it under the terms of the GNU General Public License as published by
3 # the Free Software Foundation; either version 2 of the License, or
4 # (at your option) any later version.
5 #
6 # This program is distributed in the hope that it will be useful,
7 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9 # GNU Library General Public License for more details.
10 #
11 # You should have received a copy of the GNU General Public License
12 # along with this program; if not, write to the Free Software
13 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
14
15 try:
16     import sqlite3 as sqlite
17 except ImportError:
18     import sqlite
19 import _sqlitecache
20
21 DBVERSION = _sqlitecache.DBVERSION
22
23 class RepodataParserSqlite:
24     def __init__(self, storedir, repoid, callback=None):
25         self.callback = callback
26         self.repoid = repoid
27
28     def open_database(self, filename):
29         if not filename:
30             return None
31         con = sqlite.connect(filename)
32         con.text_factory = str
33         if sqlite.version_info[0] > 1:
34             con.row_factory = sqlite.Row
35         cur = con.cursor()
36         cur.execute("pragma locking_mode = EXCLUSIVE")
37         del cur
38         return con
39
40     def getPrimary(self, location, checksum):
41         """Load primary.xml.gz from an sqlite cache and update it 
42            if required"""
43         return self.open_database(_sqlitecache.update_primary(location,
44                                                                                                                           checksum,
45                                                               self.callback,
46                                                               self.repoid))
47
48     def getFilelists(self, location, checksum):
49         """Load filelist.xml.gz from an sqlite cache and update it if 
50            required"""
51         return self.open_database(_sqlitecache.update_filelist(location,
52                                                                                                                            checksum,
53                                                                self.callback,
54                                                                self.repoid))
55
56     def getOtherdata(self, location, checksum):
57         """Load other.xml.gz from an sqlite cache and update it if required"""
58         return self.open_database(_sqlitecache.update_other(location,
59                                                                                                                         checksum,
60                                                             self.callback,
61                                                             self.repoid))
62