本文整理汇总了Python中builder.Builder.write_template方法的典型用法代码示例。如果您正苦于以下问题:Python Builder.write_template方法的具体用法?Python Builder.write_template怎么用?Python Builder.write_template使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类builder.Builder
的用法示例。
在下文中一共展示了Builder.write_template方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ObserverHandler
# 需要导入模块: from builder import Builder [as 别名]
# 或者: from builder.Builder import write_template [as 别名]
class ObserverHandler(FileSystemEventHandler):
"""
Watch for file changes in the src directory and update preview
directory using Builder class.
"""
def __init__(self, src_dir, dest_dir):
# Init super
super(ObserverHandler, self).__init__()
# Cache values
self.src_dir = src_dir
self.dest_dir = dest_dir
# New builder & local syncer
self.builder = Builder(self.src_dir, self.dest_dir, LocalSyncer())
self.builder.build()
def dispatch(self, event):
# Modified to not dispatch create
if not isinstance(event, DirModifiedEvent):
self.on_any_event(event)
# Dispatch to individual listeners
_method_map = {
'modified': self.on_modified,
'moved': self.on_moved,
'deleted': self.on_deleted,
}
_method_map[event.event_type](event)
def on_any_event(self, event):
# Cache common paths
abs_path = event.src_path
rel_path = abs_path.replace(self.src_dir, '')
# Break path into parts and gether info about parts
parts = rel_path.strip('/').split('/')
parts_len = len(parts)
# Build individual parts of method based on what
# file/dir was changed:
def build_message():
# /message/name
if (parts_len == 2):
self.builder.build_single(abs_path)
# /message/name/file
# /message/name/images
elif (parts_len == 3):
if (parts[2] == 'images'):
msg_dir = os.path.dirname(abs_path)
self.builder.mirror_imgs(msg_dir)
else:
self.builder.write_template(abs_path)
# /message/name/images/file
elif (parts_len == 4):
img_dir = os.path.dirname(abs_path)
msg_dir = os.path.dirname(img_dir)
self.builder.mirror_imgs(msg_dir)
# If file was deleted remove, else build
if not os.path.exists(event.src_path):
self.builder.remove(event.src_path)
else:
if parts[0] == 'masters':
# If an asset in the masters dir was altered
# we must rebuild everything
self.builder.build()
else:
# Else we just build the part of the message
# that was changed
build_message()