def run_restore(self, args):
"""Run the restore operation."""
if os.path.isdir(args.infile):
self.logger.info('Setting up PngDirImporter')
importer = PngDirImporter(args.infile,
args.fnamepattern)
else:
m = magic.Magic(mime=True, uncompress=True)
ftype = m.from_file(args.infile)
if ftype == "image/png":
importer = ImageImporter(args.infile)
else:
raise Exception('Could not detect import type of file %s' % args.infile)
decodefunc = base64.b85decode #FIXME: add arg
with open(args.outfile, "wb") as outfile:
for image in importer:
encdatalist = zbarlight.scan_codes('qrcode', image)
for encdata in encdatalist:
frame = decodefunc(encdata)
bindata, position = self.unframe_data(frame)
outfile.seek(position)
outfile.write(bindata)
self.logger.info('Finished importing')
# Cant calculate during writing because we may be reading pieces
# out of order
if args.sha256:
hashfunc = hashlib.sha256()
with open(args.outfile, "rb") as outfile:
while True:
data = outfile.read()
if not data: break
hashfunc.update(data)
print('SHA-256 of output: %s' % hashfunc.hexdigest())
评论列表
文章目录