当前位置: 首页>>代码示例>>Python>>正文


Python SavedBasicExport.save方法代码示例

本文整理汇总了Python中couchexport.models.SavedBasicExport.save方法的典型用法代码示例。如果您正苦于以下问题:Python SavedBasicExport.save方法的具体用法?Python SavedBasicExport.save怎么用?Python SavedBasicExport.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在couchexport.models.SavedBasicExport的用法示例。


在下文中一共展示了SavedBasicExport.save方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_file_save_and_load

# 需要导入模块: from couchexport.models import SavedBasicExport [as 别名]
# 或者: from couchexport.models.SavedBasicExport import save [as 别名]
 def test_file_save_and_load(self):
     payload = 'something small and simple'
     for name in ['normal', u'हिंदी', None]:
         saved = SavedBasicExport(configuration=_mk_config(name))
         saved.save()
         saved.set_payload(payload)
         self.assertEqual(payload, saved.get_payload())
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:9,代码来源:test_saved.py

示例2: test_get_by_index

# 需要导入模块: from couchexport.models import SavedBasicExport [as 别名]
# 或者: from couchexport.models.SavedBasicExport import save [as 别名]
 def test_get_by_index(self):
     index = ['some', 'index']
     saved_export = SavedBasicExport(configuration=_mk_config(index=index))
     saved_export.save()
     back = SavedBasicExport.by_index(index)
     self.assertEqual(1, len(back))
     self.assertEqual(saved_export._id, back[0]._id)
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:9,代码来源:test_saved.py

示例3: rebuild_export

# 需要导入模块: from couchexport.models import SavedBasicExport [as 别名]
# 或者: from couchexport.models.SavedBasicExport import save [as 别名]
def rebuild_export(config, schema, output_dir, last_access_cutoff=None, filter=None):
    if output_dir == "couch":
        saved = get_saved_export_and_delete_copies(config.index)
        if last_access_cutoff and saved and saved.last_accessed and \
                saved.last_accessed < last_access_cutoff:
            # ignore exports that haven't been accessed since last_access_cutoff
            return

    try:
        files = schema.get_export_files(format=config.format, filter=filter)
    except SchemaMismatchException:
        # fire off a delayed force update to prevent this from happening again
        rebuild_schemas.delay(config.index)
        raise ExportRebuildError(u'Schema mismatch for {}. Rebuilding tables...'.format(config.filename))

    with files:
        payload = files.file.payload
        if output_dir == "couch":
            if not saved:
                saved = SavedBasicExport(configuration=config)
            else:
                saved.configuration = config

            if saved.last_accessed is None:
                saved.last_accessed = datetime.utcnow()
            saved.last_updated = datetime.utcnow()
            saved.save()
            saved.set_payload(payload)
        else:
            with open(os.path.join(output_dir, config.filename), "wb") as f:
                f.write(payload)
开发者ID:dimagi,项目名称:couchexport,代码行数:33,代码来源:groupexports.py

示例4: export_for_group

# 需要导入模块: from couchexport.models import SavedBasicExport [as 别名]
# 或者: from couchexport.models.SavedBasicExport import save [as 别名]
def export_for_group(export_id_or_group, output_dir):
    if isinstance(export_id_or_group, basestring):
        try:
            config = GroupExportConfiguration.get(export_id_or_group)
        except ResourceNotFound:
            raise Exception("Couldn't find an export with id %s" % export_id_or_group)
    else:
        config = export_id_or_group

    for config, schema in config.all_exports:
        try:
            tmp, _ = schema.get_export_files(format=config.format)
        except SchemaMismatchException, e:
            # fire off a delayed force update to prevent this from happening again
            rebuild_schemas.delay(config.index)
            continue

        payload = Temp(tmp).payload
        if output_dir == "couch":
            saved = SavedBasicExport.view("couchexport/saved_exports", 
                                          key=json.dumps(config.index),
                                          include_docs=True,
                                          reduce=False).one()
            if not saved: 
                saved = SavedBasicExport(configuration=config)
            else:
                saved.configuration = config
            saved.last_updated = datetime.utcnow()
            saved.save()
            saved.set_payload(payload)

        else:
            with open(os.path.join(output_dir, config.filename), "wb") as f:
                f.write(payload)
开发者ID:kennknowles,项目名称:couchexport,代码行数:36,代码来源:groupexports.py

示例5: handle

# 需要导入模块: from couchexport.models import SavedBasicExport [as 别名]
# 或者: from couchexport.models.SavedBasicExport import save [as 别名]
 def handle(self, *args, **options):
     if len(args) < 2: raise CommandError('Please specify %s.' % self.label)
         
     export_id = args[0]
     output_dir = args[1]
     try:
         config = GroupExportConfiguration.get(export_id)
     except ResourceNotFound:
         raise CommandError("Couldn't find an export with id %s" % export_id)
     
     for export_config in config.full_exports:
         print "exporting %s to %s" % (export_config.name, output_dir)
         # special case couch storage
         if output_dir == "couch":
             fd, path = tempfile.mkstemp()
             with os.fdopen(fd, 'wb') as f:
                 export(export_config.index, f, format=export_config.format)
             # got the file, now rewrite it to couch
             saved = SavedBasicExport.view("couchexport/saved_exports", 
                                           key=json.dumps(export_config.index),
                                           include_docs=True,
                                           reduce=False).one()
             if not saved: 
                 saved = SavedBasicExport(configuration=export_config)
                 saved.save()
             with open(path, "rb") as f:
                 saved.put_attachment(f.read(), export_config.filename)
                 saved.last_updated = datetime.utcnow()
                 saved.save()
             os.remove(path)
         else:
             with open(os.path.join(output_dir, export_config.filename), "wb") as f:
                 export(export_config.index, f, format=export_config.format)
开发者ID:wbnigeria,项目名称:couchexport,代码行数:35,代码来源:couchexport_data.py

示例6: testFileSaveAndLoad

# 需要导入模块: from couchexport.models import SavedBasicExport [as 别名]
# 或者: from couchexport.models.SavedBasicExport import save [as 别名]
    def testFileSaveAndLoad(self):
        def _mk_config(name):
            return ExportConfiguration(index="dummy_index", name=name, format="xlsx")

        payload = "something small and simple"
        for name in ["normal", u"हिंदी", None]:
            saved = SavedBasicExport(configuration=_mk_config(name))
            saved.save()
            saved.set_payload(payload)
            self.assertEqual(payload, saved.get_payload())
开发者ID:kennknowles,项目名称:couchexport,代码行数:12,代码来源:test_saved.py

示例7: test_save_basic_export_to_blobdb

# 需要导入模块: from couchexport.models import SavedBasicExport [as 别名]
# 或者: from couchexport.models.SavedBasicExport import save [as 别名]
 def test_save_basic_export_to_blobdb(self):
     index = ['single']
     saved_export = SavedBasicExport(configuration=_mk_config(index=index))
     saved_export.save()
     saved_export.set_payload("content")
     name = saved_export.get_attachment_name()
     self.assertTrue(saved_export.has_file())
     self.assertIn(name, saved_export.external_blobs)
     self.assertEqual(saved_export.size, 7)
     with saved_export.get_payload(stream=True) as fh:
         self.assertEqual(fh.read(), "content")
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:13,代码来源:test_saved.py

示例8: test_get_saved_and_delete_copies_multiple

# 需要导入模块: from couchexport.models import SavedBasicExport [as 别名]
# 或者: from couchexport.models.SavedBasicExport import save [as 别名]
    def test_get_saved_and_delete_copies_multiple(self):
        index = ['multiple']
        # make three exports with the last one being the most recently updated
        timestamp = datetime.datetime.utcnow()
        for i in range(3):
            saved_export = SavedBasicExport(configuration=_mk_config(index=index),
                                            last_updated=timestamp + datetime.timedelta(days=i))
            saved_export.save()

        self.assertEqual(3, len(SavedBasicExport.by_index(index)))
        chosen_one = get_saved_export_and_delete_copies(index)
        # this relies on the variable being set last in the loop which is a bit unintuitive
        self.assertEqual(saved_export._id, chosen_one._id)
        saved_after_deletion = SavedBasicExport.by_index(index)
        self.assertEqual(1, len(saved_after_deletion))
        self.assertEqual(chosen_one._id, saved_after_deletion[0]._id)
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:18,代码来源:test_saved.py

示例9: _save_export_payload

# 需要导入模块: from couchexport.models import SavedBasicExport [as 别名]
# 或者: from couchexport.models.SavedBasicExport import save [as 别名]
def _save_export_payload(files, saved_export, config, is_safe=False):
    payload = files.file.payload
    if not saved_export:
        saved_export = SavedBasicExport(configuration=config)
    else:
        saved_export.configuration = config
    saved_export.is_safe = is_safe

    if saved_export.last_accessed is None:
        saved_export.last_accessed = datetime.utcnow()
    saved_export.last_updated = datetime.utcnow()
    try:
        saved_export.save()
    except ResourceConflict:
        # task was executed concurrently, so let first to finish win and abort the rest
        pass
    else:
        saved_export.set_payload(payload)
开发者ID:kkrampa,项目名称:commcare-hq,代码行数:20,代码来源:groupexports.py

示例10: test_migrate_with_concurrent_modification

# 需要导入模块: from couchexport.models import SavedBasicExport [as 别名]
# 或者: from couchexport.models.SavedBasicExport import save [as 别名]
    def test_migrate_with_concurrent_modification(self):
        # setup data
        saved = SavedBasicExport(configuration=_mk_config())
        saved.save()
        name = saved.get_attachment_name()
        new_payload = 'something new'
        old_payload = 'something old'
        super(BlobMixin, saved).put_attachment(old_payload, name)
        super(BlobMixin, saved).put_attachment(old_payload, "other")
        saved.save()

        # verify: attachments are in couch
        self.assertEqual(len(saved._attachments), 2)
        self.assertEqual(len(saved.external_blobs), 0)

        modified = []
        print_status = mod.print_status

        # setup concurrent modification
        def modify_doc_and_print_status(num, total):
            if not modified:
                # do concurrent modification
                doc = SavedBasicExport.get(saved._id)
                doc.set_payload(new_payload)
                doc.save()
                modified.append(True)
            print_status(num, total)

        # hook print_status() call to simulate concurrent modification
        with replattr(mod, "print_status", modify_doc_and_print_status):
            # do migration
            migrated, skipped = mod.MIGRATIONS[self.slug].migrate()
            self.assertGreaterEqual(skipped, 1)

        # verify: migration state not set when docs are skipped
        with self.assertRaises(mod.BlobMigrationState.DoesNotExist):
            mod.BlobMigrationState.objects.get(slug=self.slug)

        # verify: attachments were not migrated
        exp = SavedBasicExport.get(saved._id)
        self.assertEqual(len(exp._attachments), 1, exp._attachments)
        self.assertEqual(len(exp.external_blobs), 1, exp.external_blobs)
        self.assertEqual(exp.get_payload(), new_payload)
        self.assertEqual(exp.fetch_attachment("other"), old_payload)
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:46,代码来源:test_migrate.py

示例11: test_migrate_saved_exports

# 需要导入模块: from couchexport.models import SavedBasicExport [as 别名]
# 或者: from couchexport.models.SavedBasicExport import save [as 别名]
    def test_migrate_saved_exports(self):
        # setup data
        saved = SavedBasicExport(configuration=_mk_config())
        saved.save()
        payload = 'something small and simple'
        name = saved.get_attachment_name()
        super(BlobMixin, saved).put_attachment(payload, name)
        saved.save()

        # verify: attachment is in couch and migration not complete
        self.assertEqual(len(saved._attachments), 1)
        self.assertEqual(len(saved.external_blobs), 0)

        with tempdir() as tmp, replattr(SavedBasicExport, "migrating_blobs_from_couch", True):
            filename = join(tmp, "file.txt")

            # do migration
            migrated, skipped = mod.MIGRATIONS[self.slug].migrate(filename)
            self.assertGreaterEqual(migrated, 1)

            # verify: migration state recorded
            mod.BlobMigrationState.objects.get(slug=self.slug)

            # verify: migrated data was written to the file
            with open(filename) as fh:
                lines = list(fh)
            doc = {d["_id"]: d for d in (json.loads(x) for x in lines)}[saved._id]
            self.assertEqual(doc["_rev"], saved._rev)
            self.assertEqual(len(lines), migrated, lines)

        # verify: attachment was moved to blob db
        exp = SavedBasicExport.get(saved._id)
        self.assertNotEqual(exp._rev, saved._rev)
        self.assertEqual(len(exp.blobs), 1, repr(exp.blobs))
        self.assertFalse(exp._attachments, exp._attachments)
        self.assertEqual(len(exp.external_blobs), 1)
        self.assertEqual(exp.get_payload(), payload)
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:39,代码来源:test_migrate.py

示例12: test_get_saved_and_delete_copies_single

# 需要导入模块: from couchexport.models import SavedBasicExport [as 别名]
# 或者: from couchexport.models.SavedBasicExport import save [as 别名]
 def test_get_saved_and_delete_copies_single(self):
     index = ['single']
     saved_export = SavedBasicExport(configuration=_mk_config(index=index))
     saved_export.save()
     self.assertEqual(saved_export._id, get_saved_export_and_delete_copies(index)._id)
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:7,代码来源:test_saved.py


注:本文中的couchexport.models.SavedBasicExport.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。