app.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:pypaperbak 作者: matheusd 项目源码 文件源码
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())
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号