本文整理汇总了Python中couchexport.models.SavedBasicExport.put_attachment方法的典型用法代码示例。如果您正苦于以下问题:Python SavedBasicExport.put_attachment方法的具体用法?Python SavedBasicExport.put_attachment怎么用?Python SavedBasicExport.put_attachment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类couchexport.models.SavedBasicExport
的用法示例。
在下文中一共展示了SavedBasicExport.put_attachment方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
# 需要导入模块: from couchexport.models import SavedBasicExport [as 别名]
# 或者: from couchexport.models.SavedBasicExport import put_attachment [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)