]> git.ipfire.org Git - pakfire.git/blob - python/pakfire/filelist.py
Add proper handling of configuration files.
[pakfire.git] / python / pakfire / filelist.py
1 #!/usr/bin/python
2 ###############################################################################
3 # #
4 # Pakfire - The IPFire package management system #
5 # Copyright (C) 2011 Pakfire development team #
6 # #
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. #
11 # #
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. #
16 # #
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/>. #
19 # #
20 ###############################################################################
21
22 import tarfile
23
24 TYPE_REG = tarfile.REGTYPE # regular file
25 TYPE_AREG = tarfile.AREGTYPE # regular file
26 TYPE_LNK = tarfile.LNKTYPE # link (inside tarfile)
27 TYPE_SYM = tarfile.SYMTYPE # symbolic link
28 TYPE_CHR = tarfile.CHRTYPE # character special device
29 TYPE_BLK = tarfile.BLKTYPE # block special device
30 TYPE_DIR = tarfile.DIRTYPE # directory
31 TYPE_FIFO = tarfile.FIFOTYPE # fifo special device
32 TYPE_CONT = tarfile.CONTTYPE # contiguous file
33
34 class _File(object):
35 def __init__(self, pakfire):
36 self.pakfire = pakfire
37
38 def __cmp__(self, other):
39 ret = cmp(self.name, other.name)
40
41 if not ret:
42 ret = cmp(self.pkg, other.pkg)
43
44 return ret
45
46 def is_dir(self):
47 # XXX TODO
48 # VERY POOR CHECK
49 return self.name.endswith("/")
50
51 def is_config(self):
52 # XXX TODO
53 return False
54
55
56 class File(_File):
57 def __init__(self, pakfire):
58 _File.__init__(self, pakfire)
59
60 self.name = ""
61 self.config = False
62 self.pkg = None
63 self.size = -1
64 self.hash1 = None
65 self.type = TYPE_REG
66 self.mode = 0
67 self.user = 0
68 self.group = 0
69 self.mtime = 0
70
71 def is_config(self):
72 return self.config
73
74
75 class FileDatabase(_File):
76 def __init__(self, pakfire, db, row_id):
77 _File.__init__(self, pakfire)
78
79 self.db = db
80 self.row_id = row_id
81
82 self.__row = None
83
84 @property
85 def row(self):
86 """
87 Lazy fetching of the database row.
88 """
89 if self.__row is None:
90 c = self.db.cursor()
91 c.execute("SELECT * FROM files WHERE id = ? LIMIT 1", (self.row_id,))
92
93 # Check if we got the same row.
94 #assert c.lastrowid == self.row_id
95
96 for row in c:
97 self.__row = row
98 break
99
100 c.close()
101
102 return self.__row
103
104 def is_config(self):
105 return self.row["config"] == 1
106
107 @property
108 def pkg(self):
109 return self.db.get_package_by_id(self.row["pkg"])
110
111 @property
112 def name(self):
113 return self.row["name"]
114
115 @property
116 def size(self):
117 return self.row["size"]
118
119 @property
120 def hash1(self):
121 return self.row["hash1"]
122
123 @property
124 def type(self):
125 return self.row["type"]
126
127 @property
128 def mode(self):
129 return self.row["mode"]
130
131 @property
132 def user(self):
133 return self.row["user"]
134
135 @property
136 def group(self):
137 return self.row["group"]
138
139 @property
140 def mtime(self):
141 return self.row["mtime"]