Lines 3-11
Link Here
|
3 |
# Distributed under the terms of the GNU General Public License v2 |
3 |
# Distributed under the terms of the GNU General Public License v2 |
4 |
# $Header: /var/cvsroot/gentoo-src/portage/pym/portage_contents.py,v 1.3 2004/10/04 14:07:40 vapier Exp $ |
4 |
# $Header: /var/cvsroot/gentoo-src/portage/pym/portage_contents.py,v 1.3 2004/10/04 14:07:40 vapier Exp $ |
5 |
|
5 |
|
6 |
import os,string,types,sys,copy |
6 |
import os,string,types,sys,copy,stat |
7 |
import portage_exception |
7 |
import portage_exception |
8 |
import portage_const |
8 |
import portage_const |
|
|
9 |
import portage_checksum |
9 |
|
10 |
|
10 |
#import gettext |
11 |
#import gettext |
11 |
#gettext_t = gettext.translation('portage.contents', portage_const.LOCALE_DATA_PATH) |
12 |
#gettext_t = gettext.translation('portage.contents', portage_const.LOCALE_DATA_PATH) |
Lines 17-22
Link Here
|
17 |
FILES_KEY = "\0FILES\0" |
18 |
FILES_KEY = "\0FILES\0" |
18 |
OWNER_KEY = "\0OWNER\0" |
19 |
OWNER_KEY = "\0OWNER\0" |
19 |
|
20 |
|
|
|
21 |
class ContentsManager: |
22 |
"""Manage a CONTENTS file.""" |
23 |
def __init__(self,filename): |
24 |
|
25 |
self.contents = [] |
26 |
|
27 |
self.filename = filename |
28 |
self.readFile(filename) |
29 |
|
30 |
def readFile(self,filename): |
31 |
infile = open(filename) |
32 |
|
33 |
mylines = infile.readlines() |
34 |
infile.close() |
35 |
|
36 |
contents = self.contents |
37 |
|
38 |
for line in mylines: |
39 |
if line[-1] == '\n': |
40 |
line = line[:-1] |
41 |
parts = string.split(line) |
42 |
|
43 |
mytype = parts[0] |
44 |
|
45 |
if mytype in ["dir","dev","fif"]: |
46 |
mypath = string.join(parts[1:]) |
47 |
contents.append({'type': mytype, 'path': mypath}) |
48 |
elif mytype == "obj": |
49 |
mypath = string.join(parts[1:-2]) |
50 |
mymd5 = parts[-2] |
51 |
mymtime = parts[-1] |
52 |
contents.append({'type': mytype, 'path': mypath, 'md5': mymd5, 'mtime': mymtime}) |
53 |
elif mytype == "sym": |
54 |
sl = string.join(parts[1:-1]) |
55 |
sl = string.split(sl, " -> ") |
56 |
|
57 |
mypath = sl[0] |
58 |
mytarget = sl[1] |
59 |
mymtime = parts[-1] |
60 |
contents.append({'type': mytype, 'path': mypath, 'target': mytarget, 'mtime': mymtime}) |
61 |
else: |
62 |
print _("Unknown type:"),mytype |
63 |
|
64 |
def writeFile(self,filename=""): |
65 |
contents=self.contents |
66 |
if filename == "": |
67 |
filename = self.filename |
68 |
|
69 |
outfile=open(filename,"w") |
70 |
for x in contents: |
71 |
if x['type'] in ["dir","dev","fif"]: |
72 |
outfile.write(x['type']+"\t"+x['path']+"\n") |
73 |
elif x['type'] == "obj": |
74 |
outfile.write(x['type']+"\t"+x['path']+"\t"+x['md5']+" "+x['mtime']+"\n") |
75 |
elif x['type'] == "sym": |
76 |
outfile.write(x['type']+"\t"+x['path']+"\t->\t"+x['target']+" "+x['mtime']+"\n") |
77 |
outfile.close() |
78 |
return |
79 |
|
80 |
def getMD5(self,filename): |
81 |
contents = self.contents |
82 |
|
83 |
for i in contents: |
84 |
if i['path'] == filename: |
85 |
return i['md5'] |
86 |
|
87 |
def getMtime(self,filename): |
88 |
contents = self.contents |
89 |
|
90 |
for i in contents: |
91 |
if i['path'] == filename: |
92 |
return i['mtime'] |
93 |
|
94 |
def updateAllInfos(self,filename): |
95 |
self.changeMD5(filename) |
96 |
self.changeMtime(filename) |
97 |
|
98 |
def changeMD5(self,filename, newmd5=""): |
99 |
contents = self.contents |
100 |
if newmd5 == "": |
101 |
newmd5=portage_checksum.perform_md5(filename) |
102 |
|
103 |
for i in contents: |
104 |
if i['path'] == filename: |
105 |
i['md5'] = newmd5 |
106 |
|
107 |
def changeMtime(self, filename, newmtime=""): |
108 |
contents = self.contents |
109 |
if newmtime == "": |
110 |
pathstat = os.stat(filename) |
111 |
newmtime = pathstat[stat.ST_MTIME] |
112 |
|
113 |
for i in contents: |
114 |
if i['path'] == filename: |
115 |
i['mtime'] = str(newmtime) |
116 |
|
20 |
|
117 |
|
21 |
def ContentsHandler(filename): |
118 |
def ContentsHandler(filename): |
22 |
infile = open(filename) |
119 |
infile = open(filename) |