Lines 102-106
class HashMap(object):
Link Here
|
102 |
print header+" (%s) = %s" % (short_file, result) |
102 |
print header+" (%s) = %s" % (short_file, result) |
103 |
return result |
103 |
return result |
104 |
|
104 |
|
105 |
|
105 |
def gen_chksumfile(self, file_, filename, storedir, hash_type, exit_on_error=True): |
106 |
|
106 |
filename = filename+"."+hash_type |
|
|
107 |
modtime = os.path.getmtime(file_) |
108 |
try: |
109 |
with open(os.path.join(storedir,filename), 'w') as chksumfile: |
110 |
chksumfile.write(filename+""+modtime+""+self.calc_hash2(file_, hash_type)) |
111 |
return True |
112 |
except IOError: |
113 |
if exit_on_error: |
114 |
raise CatalystError("Could not generate checksum for " + file_, print_traceback=True) |
115 |
else: |
116 |
return False |
117 |
|
118 |
def evaluate_spec(self, spec, chksumfile, hash_type): |
119 |
with open(chksumfile, 'r') as specfile: |
120 |
lines = specfile.readlines() |
121 |
for line in lines: |
122 |
filename, modtime, chksum = line.split() |
123 |
modtime_n = os.path.getmtime(spec) |
124 |
# First check the modification time to save |
125 |
# resources, if it hasn't been modified, |
126 |
# don't bother generating a second checksum. |
127 |
if not modtime == modtime_n: |
128 |
chksum_n = self.calc_hash2(spec, hash_type) |
129 |
if not chksum == chksum_n: |
130 |
return False |
131 |
else: |
132 |
return True |
133 |
else: |
134 |
return True |
135 |
|
136 |
def check_chksum(self, spec, filename, storedir, hash_type): |
137 |
file_location=os.path.join(storedir,filename+"."+hash_type) |
138 |
if os.path.exists(file_location): |
139 |
return self.evaluate_spec(spec, file_location, hash_type) |
140 |
else |
141 |
# If the checksum doesn't exist, this is the first time |
142 |
# using this spec file, so no need to check against it. |
143 |
return self.gen_chksum(spec, filename, storedir, hash_type) |