def __call__(self, filename): if isinstance(filename, base_data_source): if filename.path is not None: filename = filename.path if isinstance(filename, basestring) and fchksum is not None: return long(fchksum.fmd5t(filename)[0], 16) return chksum_loop_over_file(filename, md5.new)[0]
def compute_hashes(self): self.files_tuples = [] self.hashes = [] for entry in self.files: md5d = fchksum.fmd5t(entry) self.hashes.append(md5d[0]) self.files_tuples.append((entry, md5d[0], md5d[1]))
def index(directory,trim,excludedirs,excludefiles): stack = [directory] files = [] while stack: directory = stack.pop() directory = os.path.abspath(directory) for file in os.listdir(directory): fullname = os.path.join(directory, file) truncname = fullname[trim:] if truncname not in excludedirs and truncname not in excludefiles: if os.path.isfile(fullname) and not os.path.islink(fullname): mode = getStat(fullname) files.append([truncname,fchksum.fmd5t(fullname)[0],oct(mode[0]),str(mode[1]),str(mode[2])]) if os.path.isfile(fullname) and os.path.islink(fullname): mode = getStat(fullname) files.append([truncname,"symlink to file",oct(mode[0]),str(mode[1]),str(mode[2])]) if os.path.isdir(fullname) and os.path.islink(fullname): mode = getStat(fullname) files.append([truncname,"symlink to directory",oct(mode[0]),str(mode[1]),str(mode[2])]) if os.path.isdir(fullname) and not os.path.islink(fullname) and os.listdir(fullname) == []: mode = getStat(fullname) files.append([truncname,"empty dir",oct(mode[0]),str(mode[1]),str(mode[2])]) if os.path.isdir(fullname) and not os.path.islink(fullname): stack.append(fullname) else: print "excluding", fullname return files
def verify_md5_sig (self): if not os.path.exists (self.path): raise prog.ProgPayloadNotFound if self.size: size = os.lstat (self.path)[stat.ST_SIZE] if self.size != size: raise prog.ProgPayloadInvalidSize (size) if self.checksum: checksum = fchksum.fmd5t (self.path)[0] if self.checksum != checksum: raise prog.ProgPayloadInvalidChecksum (checksum)
def verify_app(self, url=None, down_link=None): """ url: detail页面链接 down_link: 下载链接 chsksum: 校验和 """ is_right = False #如果没有传入down_link,就需要向detail页面发送请求 if not down_link and url: etree = self.send_request(url=url) down_link = etree.xpath(self.down_xpath) if down_link: down_link = down_link[0] down_link = self.normalize_url(url, down_link) if down_link: storage = self.download_app(down_link) md5sum = fchksum.fmd5t(storage)[0] if md5sum == self.chksum: is_right = True os.unlink(storage) return is_right
def local_uptodate (self, file): """Check if file in local depot equivalent to that in remote depot.""" if not self.verify_checksum: raise depot.DepotChecksumsOff (file) local_file = os.path.join (self.local_path, file) # if file in local depot matches checksum of version in # remote repository, do not download if os.path.exists (local_file): try: self.fetch (file + '.md5') except depot.DepotFileNotFoundError: return False md5_checksum = fchksum.fmd5t (local_file)[0] fh = open (local_file + '.md5') sum = fh.readline ().rstrip () fh.close () if str (sum) == str (md5_checksum): return True return False
def md5hash(filename): return fchksum.fmd5t(filename)
def md5hash(filename, chksum): return fchksum.fmd5t(filename)[0] == chksum