load_backup_locally.py 文件源码

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

项目:dancedeets-monorepo 作者: mikelambert 项目源码 文件源码
def run():
    # Set your downloaded folder's path here (must be readable by dev_appserver)
    mypath = '/Users/lambert/Dropbox/dancedeets/data/datastore_backup_datastore_backup_2016_11_19_DBEvent/15700286559371541387849311E815D'
    # Se the class of the objects here
    cls = DBEvent
    # Set your app's name here
    appname = "dev~None"

    # Do the harlem shake
    onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]

    for file in onlyfiles:
        i = 0
        try:
            raw = open(mypath + "/" + file, 'r')
            reader = records.RecordsReader(raw)
            to_put = list()
            for record in reader:
                entity_proto = entity_pb.EntityProto(contents=record)
                entity_proto.key_.app_ = appname
                obj = cls._from_pb(entity_proto)

                to_put.append(obj)
                i += 1
                if i % 100 == 0:
                    print "Saved %d %ss" % (i, '')  #entity.kind())
                    ndb.put_multi(to_put)  # use_memcache=False)
                    to_put = list()

            ndb.put_multi(to_put)  # use_memcache=False)
            to_put = list()
            print "Saved %d" % i

        except ProtocolBufferDecodeError:
            """ All good """
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号