def gen_unique_id(self): ''' Generate an unique id = sha256(apk hash + script name) ''' try: return sha256(self.res.apk.hash + self.name) except AttributeError: log.warn('Could not calculate unique id for %s', self) raise
def get_hash(self): ''' Get the sha256 message digest of the file and store it. Returns ------- str sha256 message digest as hexstring None If path is None Raises ------ OSError If the file could no be opened ''' if self._get_hash() is None: if self.path is None: # cannot calculate message digest from file return None else: with open(self.path, "rb") as apkf: self.hash = sha256(apkf.read()) log.debug("Calculated hash for %s by reading file %s", self, self.path) return self._get_hash()