def getFileHash(baseDir, fname): fullpath = os.path.join(baseDir, fn) with open(fullpath, 'rb') as fdata: return binary_to_hex(sha256(fdata.read()))
fname, fid = line.strip().split() inputPath = os.path.join(srcAnnounce, fname) outputPath = os.path.join(dstAnnounce, fname) # If we're using a modified DL file if fname == 'dllinks.txt': inputPath = newDLFile if fname.endswith('.txt'): doSignFile(inputPath, outputPath) else: shutil.copy(inputPath, outputPath) fdata = open(outputPath, 'rb').read() fhash = binary_to_hex(sha256(fdata)) fileMappings[fname] = [fid, fhash] longestID = max(longestID, len(fid)) longestURL = max(longestURL, len(bucketAnnounce + fname)) print 'Creating digest file...' digestFile = open(announcePath, 'w') ### for fname, vals in fileMappings.iteritems(): fid = vals[0].ljust(longestID + 3) url = (bucketAnnounce + fname).ljust(longestURL + 3) fhash = vals[1] digestFile.write('%s %s %s\n' % (fid, url, fhash)) digestFile.close()
fname, fid = line.strip().split() inputPath = os.path.join(srcAnnounce, fname) outputPath = os.path.join(dstAnnounce, fname) # If we're using a modified DL file if fname=='dllinks.txt': inputPath = newDLFile if fname.endswith('.txt'): doSignFile(inputPath, outputPath) else: shutil.copy(inputPath, outputPath) fdata = open(outputPath, 'rb').read() fhash = binary_to_hex(sha256(fdata)) fileMappings[fname] = [fid, fhash] longestID = max(longestID, len(fid)) longestURL = max(longestURL, len(bucketAnnounce + fname)) print 'Creating digest file...' digestFile = open(announcePath, 'w') ### for fname,vals in fileMappings.iteritems(): fid = vals[0].ljust(longestID + 3) url = (bucketAnnounce + fname).ljust(longestURL + 3) fhash = vals[1] digestFile.write('%s %s %s\n' % (fid, url, fhash))