commonutil.template¶
樣板檔案處理 / Template file processing
-
class
BaseLineBlockedMacroMarker[source]¶ 多行構成的塊狀資料樣板標記 / Line-blocked data template macro marker
-
get_block_line_markers(block_name, marker_parameter)[source]¶ 取得區塊用的巨集放置點標示
Parameters: - block_name – 巨集放置點的名字 / Name of given macro value block
- marker_parameter – 標記參數物件 / Parameter object of marker
Returns: 一個 (tag_s, tag_e,) 形式的 tuple 物件,內容物件為資料區塊的巨集放置點的表示字串的起點與終點
-
get_one_line_marker(block_name, marker_parameter)[source]¶ 取得單行的巨集放置點標示
Parameters: - block_name – 巨集放置點的名字 / Name of given macro value block
- marker_parameter – 標記參數物件 / Parameter object of marker
Returns: 表示單行的巨集放置點的字串
-
is_trapped_end_line(l)[source]¶ 是否偵測到給定的資料列為巨集放置點的結束行
Check if given content line is end line of content block
Parameters: l – 要檢查的資料 Returns: 當為結束行時傳回 (indent_text, block_name,) 形式的 tuple 物件。 分別代表: 縮排的空白字元組成的字串、巨集放置點名稱 如果不是則傳回 None
-
-
class
BaseLineDigestMarker[source]¶ 單行構成的資料樣板雜湊值標記 / Single-lined template digest marker
-
digest_checked_replace_context_in_line_blocked_file(filepath, context_line_iterator, digest_marker, macro_marker, gap_line_for_block_marker=False, keep_empty_content_marker=True)[source]¶ 檢查給定樣板資料雜湊直是不是有變動,如有變動將巨集值由指定檔案中取出後,將給定的樣板資料套用巨集值後存回指定檔案
Check if digest of given template is changed. If digest code is changed, apply given content with pulled macro values from given file then save back
Parameters: - filepath – 要取出與存回的檔案路徑 / Path to fetch and save back template content
- context_line_iterator – 要放入巨集值的樣板資料字串迭代器 / String iterator to place macro values into
- digest_marker – 偵測雜湊值標記偵測與產生物件 / Digest marker detection and generation object
- macro_marker – 偵測巨集放置點的標記偵測與產生物件 / Macro marker detection and generation object
- gap_line_for_block_marker – 是否要在區塊標記與內容間放置一個空白行 / Place a blank line between placed content and block markers
- keep_empty_content_marker – 是否要保留沒有代換內容的標記 / Keep marker of empty content
-
fetch_content_from_line_blocked_context(existed_line_iterator, marker, keep_empty_line=False, keep_empty_content=False)[source]¶ 從既有已填充樣板資料的內容中取出巨集值
Pull macro value from filled template content iterator
Parameters: - existed_line_iterator – 要取出巨集值的樣板資料字串迭代器 / String iterator to pull macro values from
- marker – 偵測巨集放置點的標記偵測與產生物件 / Marker detection and generation object
- keep_empty_line=False – 保留空白的行 / Keep empty lines
- keep_empty_content=False – 保留空白的內容 / Keep empty content
Returns: 儲存有巨集值與鍵的字典物件 / Dictionary object with macro name as key and macro content as value
-
fetch_content_from_line_blocked_file(filepath, marker, keep_empty_line=False, keep_empty_content=False)[source]¶ 將巨集值由指定檔案中取出
Pull macro values from given file
Parameters: - filepath – 要取出資料的檔案路徑 / Path to fetch template content
- marker – 偵測巨集放置點的標記偵測與產生物件 / Marker detection and generation object
- keep_empty_line=False – 保留空白的行 / Keep empty lines
- keep_empty_content=False – 保留空白的內容 / Keep empty content
-
fetch_digest_from_lined_file(filepath, digest_marker)[source]¶ 從檔案中取出樣板的雜湊值 / Fetch digest code from file
Parameters: - filepath – 要取出樣板雜湊值的檔案路徑 / Path to fetch digest of template content
- digest_marker – 雜湊值標記偵測與產生物件 / Marker object of template content digest
Returns: 雜湊值的字串,或是 None 當無法偵測到 / String of digest code or None if cannot detected
-
put_content_to_line_blocked_file(filepath, content_map, marker, gap_line_for_block_marker=False, keep_empty_content_marker=True)[source]¶ 將巨集值放入指定的樣板檔案中
Put macro values into given template file
Parameters: - filepath – 要放入巨集值的樣板檔案路徑 / File path to place macro values into
- content_map – 巨集值的字典物件 / Dictionary contains macro values
- marker – 偵測巨集放置點的標記偵測與產生物件 / Marker detection and generation object
- gap_line_for_block_marker – 是否要在區塊標記與內容間放置一個空白行 / Place a blank line between placed content and block markers
- keep_empty_content_marker – 是否要保留沒有代換內容的標記 / Keep marker of empty content
-
render_line_blocked_context(existed_line_iterator, content_map, marker, gap_line_for_block_marker=False, keep_empty_content_marker=True)[source]¶ 將巨集值放入指定的樣板資料中
Put macro values into given template content lines and return resulted lines
Parameters: - existed_line_iterator – 要放入巨集值的樣板資料字串迭代器 / String iterator to place macro values into
- content_map – 巨集值的字典物件 / Dictionary contains macro values
- marker – 偵測巨集放置點的標記偵測與產生物件 / Marker detection and generation object
- gap_line_for_block_marker – 是否要在區塊標記與內容間放置一個空白行 / Place a blank line between placed content and block markers
- keep_empty_content_marker – 是否要保留沒有代換內容的標記 / Keep marker of empty content
Returns: 儲存有已放入巨集資料的字串串列
-
replace_context_in_line_blocked_file(filepath, context_line_iterator, marker, gap_line_for_block_marker=False, keep_empty_content_marker=True, keep_empty_line=False)[source]¶ 將巨集值由指定檔案中取出後,將給定的樣板資料套用巨集值後存回指定檔案
Apply given content with pulled macro values from given file then save back
Parameters: - filepath – 要取出與存回的檔案路徑 / Path to fetch and save back template content
- context_line_iterator – 要放入巨集值的樣板資料字串迭代器 / String iterator to place macro values into
- marker – 偵測巨集放置點的標記偵測與產生物件 / Marker detection and generation object
- gap_line_for_block_marker – 是否要在區塊標記與內容間放置一個空白行 / Place a blank line between placed content and block markers
- keep_empty_content_marker – 是否要保留沒有代換內容的標記 / Keep marker of empty content
- keep_empty_line=False – 保留空白的行 / Keep empty lines