本文整理匯總了Python中couchexport.models.SavedBasicExport.view方法的典型用法代碼示例。如果您正苦於以下問題:Python SavedBasicExport.view方法的具體用法?Python SavedBasicExport.view怎麽用?Python SavedBasicExport.view使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類couchexport.models.SavedBasicExport
的用法示例。
在下文中一共展示了SavedBasicExport.view方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: export_for_group
# 需要導入模塊: from couchexport.models import SavedBasicExport [as 別名]
# 或者: from couchexport.models.SavedBasicExport import view [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)
示例2: handle
# 需要導入模塊: from couchexport.models import SavedBasicExport [as 別名]
# 或者: from couchexport.models.SavedBasicExport import view [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)