]> git.ipfire.org Git - pakfire.git/blame - python/pakfire/filelist.py
Save capabilities in package metadata and database.
[pakfire.git] / python / pakfire / filelist.py
CommitLineData
862bea4d
MT
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
c2808056
MT
22import tarfile
23
24TYPE_REG = tarfile.REGTYPE # regular file
25TYPE_AREG = tarfile.AREGTYPE # regular file
26TYPE_LNK = tarfile.LNKTYPE # link (inside tarfile)
27TYPE_SYM = tarfile.SYMTYPE # symbolic link
28TYPE_CHR = tarfile.CHRTYPE # character special device
29TYPE_BLK = tarfile.BLKTYPE # block special device
30TYPE_DIR = tarfile.DIRTYPE # directory
31TYPE_FIFO = tarfile.FIFOTYPE # fifo special device
32TYPE_CONT = tarfile.CONTTYPE # contiguous file
33
862bea4d
MT
34class _File(object):
35 def __init__(self, pakfire):
36 self.pakfire = pakfire
37
862bea4d 38 def __cmp__(self, other):
482d1ada
MT
39 ret = cmp(self.name, other.name)
40
482d1ada
MT
41 if not ret:
42 ret = cmp(self.pkg, other.pkg)
43
44 return ret
862bea4d
MT
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
1881477f
MT
56class File(_File):
57 def __init__(self, pakfire):
58 _File.__init__(self, pakfire)
59
60 self.name = ""
c2808056 61 self.config = False
1881477f
MT
62 self.pkg = None
63 self.size = -1
c2808056
MT
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
cabf1fbe 70 self.capabilities = None
c2808056
MT
71
72 def is_config(self):
73 return self.config
1881477f
MT
74
75
862bea4d
MT
76class FileDatabase(_File):
77 def __init__(self, pakfire, db, row_id):
78 _File.__init__(self, pakfire)
79
80 self.db = db
81 self.row_id = row_id
82
83 self.__row = None
84
85 @property
86 def row(self):
87 """
88 Lazy fetching of the database row.
89 """
90 if self.__row is None:
91 c = self.db.cursor()
92 c.execute("SELECT * FROM files WHERE id = ? LIMIT 1", (self.row_id,))
93
94 # Check if we got the same row.
95 #assert c.lastrowid == self.row_id
96
97 for row in c:
98 self.__row = row
99 break
100
101 c.close()
102
103 return self.__row
104
c2808056
MT
105 def is_config(self):
106 return self.row["config"] == 1
107
862bea4d
MT
108 @property
109 def pkg(self):
110 return self.db.get_package_by_id(self.row["pkg"])
111
112 @property
113 def name(self):
114 return self.row["name"]
115
116 @property
117 def size(self):
118 return self.row["size"]
119
120 @property
121 def hash1(self):
122 return self.row["hash1"]
c2808056
MT
123
124 @property
125 def type(self):
126 return self.row["type"]
127
128 @property
129 def mode(self):
130 return self.row["mode"]
131
132 @property
133 def user(self):
134 return self.row["user"]
135
136 @property
137 def group(self):
138 return self.row["group"]
139
140 @property
141 def mtime(self):
142 return self.row["mtime"]
cabf1fbe
MT
143
144 @property
145 def capabilities(self):
146 return self.row["capabilities"]