]> git.ipfire.org Git - people/stevee/pakfire.git/blob - src/pakfire/filelist.py
Use autotools.
[people/stevee/pakfire.git] / src / 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 TYPE_DIR_INT = int(TYPE_DIR)
35
36 class _File(object):
37 def __init__(self, pakfire):
38 self.pakfire = pakfire
39
40 def __cmp__(self, other):
41 ret = cmp(self.name, other.name)
42
43 if not ret:
44 ret = cmp(self.pkg, other.pkg)
45
46 return ret
47
48 def is_dir(self):
49 # XXX TODO
50 # VERY POOR CHECK
51 return self.name.endswith("/")
52
53 def is_config(self):
54 # XXX TODO
55 return False
56
57 def is_datafile(self):
58 return False
59
60
61 class File(_File):
62 def __init__(self, pakfire):
63 _File.__init__(self, pakfire)
64
65 self.name = ""
66 self.config = False
67 self.pkg = None
68 self.size = -1
69 self.hash1 = None
70 self.type = TYPE_REG
71 self.mode = 0
72 self.user = 0
73 self.group = 0
74 self.mtime = 0
75 self.capabilities = None
76 self.datafile = False
77
78 def is_dir(self):
79 return self.type == TYPE_DIR_INT \
80 or self.name.endswith("/")
81
82 def is_config(self):
83 return self.config
84
85 def is_datafile(self):
86 return self.datafile
87
88
89 class FileDatabase(_File):
90 def __init__(self, pakfire, db, row_id, row=None):
91 _File.__init__(self, pakfire)
92
93 self.db = db
94 self.row_id = row_id
95 self.__row = row
96
97 @property
98 def row(self):
99 """
100 Lazy fetching of the database row.
101 """
102 if self.__row is None:
103 c = self.db.cursor()
104 c.execute("SELECT * FROM files WHERE id = ? LIMIT 1", (self.row_id,))
105
106 self.__row = c.fetchone()
107 c.close()
108
109 return self.__row
110
111 def is_dir(self):
112 return self.type == TYPE_DIR_INT \
113 or self.name.endswith("/")
114
115 def is_config(self):
116 return self.row["config"] == 1
117
118 def is_datafile(self):
119 return self.row["datafile"] == 1
120
121 @property
122 def pkg(self):
123 return self.db.get_package_by_id(self.row["pkg"])
124
125 @property
126 def name(self):
127 return self.row["name"]
128
129 @property
130 def size(self):
131 return self.row["size"]
132
133 @property
134 def hash1(self):
135 return self.row["hash1"]
136
137 @property
138 def type(self):
139 return self.row["type"]
140
141 @property
142 def mode(self):
143 return self.row["mode"]
144
145 @property
146 def user(self):
147 return self.row["user"]
148
149 @property
150 def group(self):
151 return self.row["group"]
152
153 @property
154 def mtime(self):
155 return self.row["mtime"]
156
157 @property
158 def capabilities(self):
159 return self.row["capabilities"]