Beispiel #1
0
 def win_callback(self,params):
     start_time = params['start_time']
     end_time = iso8601()
     img_in = params['img_in']
     tmp_out = params['img_out'] # temporary output file
     img_out = params['final_out'] # final output file
     process_id = gen_id()
     if not os.path.exists(tmp_out):
         self.log('FAIL temporary output file does not exist: %s' % tmp_out)
         return FAIL
     in_md5 = md5_file(img_in)
     out_md5 = md5_file(tmp_out)
     in_length = os.stat(img_in).st_size
     out_length = os.stat(tmp_out).st_size
     used = {
         'process_id': process_id,
         'algorithm_id': '201203_ic', # FIXME uncontrolled
         'direction': 'used', # FIXME local id
         'pathname': img_in, # FIXME local pathname
         'no_earlier_than': start_time,
         'no_later_than': end_time,
         'fixity_md5': in_md5,
         'fixity_length': in_length
         }
     generated_by = {
         'process_id': process_id,
         'algorithm_id': '201203_ic', # FIXME uncontrolled
         'direction': 'generated by', # FIXME local id
         'pathname': img_out, # FIXME local pathname
         'no_earlier_than': start_time,
         'no_later_than': end_time,
         'fixity_md5': out_md5,
         'fixity_length': out_length
         }
     # FIXME emit provenance record
     prov_qname = '%s_prov' % self.qname
     try:
         self.enqueue(json.dumps(used), prov_qname)
         self.enqueue(json.dumps(generated_by), prov_qname)
     except:
         raise JobExit('Failed to enqueue provenance records', FAIL)
     try:
         os.rename(tmp_out, img_out)
     except:
         raise JobExit('Cannot move temporary file into place: %s -> %s' % (tmp_out, img_out), FAIL)
     return WIN
Beispiel #2
0
 def fix(self):
     """compute fixity based on pathname"""
     now = secs2utcdatetime()
     stat = os.stat(self.pathname)
     self.length = stat.st_size
     self.fix_time = now
     self.create_time = secs2utcdatetime(stat.st_ctime)
     self.mod_time = secs2utcdatetime(stat.st_mtime)
     if self.checksum_type=='md5':
         self.checksum = md5_file(self.pathname)
     elif self.checksum_type=='sha1':
         self.checksum = sha1_file(self.pathname)
Beispiel #3
0
 def check(self):
     """check fixity against current state of pathname.
     failure modes include missing file, non-matching length and checksum."""
     if not os.path.exists(self.pathname):
         raise FixityException("file not found at location specified in fixity record")
     stat = os.stat(self.pathname)
     if stat.st_size != self.length:
         raise FixityException("file size differs from fixity record")
     if self.checksum_type=='md5':
         if self.checksum != md5_file(self.pathname):
             raise FixityException("md5 checksum does not match fixity record")
     elif self.checksum_type=='sha1':
         if self.checksum != sha15_file(self.pathname):
             raise FixityException("sha-1 checksum does not match fixity record")