本文整理汇总了Python中fs.osfs.OSFS.isdirempty方法的典型用法代码示例。如果您正苦于以下问题:Python OSFS.isdirempty方法的具体用法?Python OSFS.isdirempty怎么用?Python OSFS.isdirempty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fs.osfs.OSFS
的用法示例。
在下文中一共展示了OSFS.isdirempty方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: export
# 需要导入模块: from fs.osfs import OSFS [as 别名]
# 或者: from fs.osfs.OSFS import isdirempty [as 别名]
def export(course, export_dir):
"""Export the specified course to course_dir. Creates dir if it doesn't exist.
Overwrites files, does not clean out dir beforehand.
"""
fs = OSFS(export_dir, create=True)
if not fs.isdirempty("."):
print ("WARNING: Directory {dir} not-empty." " May clobber/confuse things".format(dir=export_dir))
try:
xml = course.export_to_xml(fs)
with fs.open("course.xml", mode="w") as f:
f.write(xml)
return True
except:
print "Export failed!"
traceback.print_exc()
return False
示例2: export
# 需要导入模块: from fs.osfs import OSFS [as 别名]
# 或者: from fs.osfs.OSFS import isdirempty [as 别名]
def export(course, export_dir):
"""Export the specified course to course_dir. Creates dir if it doesn't exist.
Overwrites files, does not clean out dir beforehand.
"""
fs = OSFS(export_dir, create=True)
if not fs.isdirempty('.'):
print ('WARNING: Directory {dir} not-empty.'
' May clobber/confuse things'.format(dir=export_dir))
try:
course.runtime.export_fs = fs
root = lxml.etree.Element('root')
course.add_xml_to_node(root)
with fs.open('course.xml', mode='w') as f:
root.write(f)
return True
except:
print 'Export failed!'
traceback.print_exc()
return False