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 |
filename = filename |
107 |
modtime = os.path.getmtime(file_) |
108 |
chksum = self.calc_hash2(file_, hash_type) |
109 |
chksum = chksum[:-1] + " " +str(modtime) |
110 |
try: |
111 |
with open(os.path.join(storedir,filename), 'w') as chksumfile: |
112 |
chksumfile.write(chksum) |
113 |
except IOError: |
114 |
if exit_on_error: |
115 |
raise CatalystError("Could not generate checksum for " + file_, print_traceback=True) |
116 |
return False |
117 |
return True |
118 |
|
119 |
def evaluate_spec(self, spec, filename, storedir, hash_type): |
120 |
chksumfile = os.path.join(storedir,filename) |
121 |
with open(chksumfile, 'r') as specfile: |
122 |
lines = specfile.readlines() |
123 |
hash_value = lines[0].split() |
124 |
hash_value = hash_value[1] |
125 |
chksum, filename, modtime = lines[1].split() |
126 |
modtime_n = os.path.getmtime(spec) |
127 |
# First check the modification time to save |
128 |
# resources, if it hasn't been modified, |
129 |
# don't bother generating a second checksum. |
130 |
if not modtime == modtime_n: |
131 |
hash_value_n = self.calc_hash2(spec, hash_type.lower()).split() |
132 |
hash_value_n = hash_value_n[1] |
133 |
chksum_n = self.calc_hash2(spec, hash_type).split() |
134 |
chksum_n = chksum_n[3] |
135 |
# Check the hash value in the file against |
136 |
# the current hash value from the config. |
137 |
if not hash_value == hash_value_n: |
138 |
chksum_n = self.calc_hash2(spec, hash_value.lower()).split() |
139 |
chksum_n = chksum_n[3] |
140 |
|
141 |
if not chksum == chksum_n: |
142 |
return False |
143 |
|
144 |
self.gen_chksumfile(spec, filename, storedir, hash_value_n.lower()) |
145 |
return True |
146 |
|
147 |
def check_chksum(self, spec, filename, storedir, hash_type): |
148 |
file_location=os.path.join(storedir,filename) |
149 |
if os.path.exists(file_location): |
150 |
return self.evaluate_spec(spec, filename, storedir, hash_type) |
151 |
else: |
152 |
# If the checksum doesn't exist, this is the first time |
153 |
# using this spec file, so no need to check against it. |
154 |
return self.gen_chksumfile(spec, filename, storedir, hash_type) |
106 |
|
155 |
|