修复签章浮动靠左问题
1
.gitignore
vendored
@@ -1,4 +1,3 @@
|
||||
mysql/
|
||||
|
||||
.claude
|
||||
*.zip
|
||||
|
||||
@@ -484,6 +484,222 @@ def test_no_spacing_with_table_atleast():
|
||||
print(f"\nno_spacing_atleast: {'1/1' if ok else '0/1'} 通过")
|
||||
|
||||
|
||||
def _sign_with_mode(docx_path, height, relax_layout, signature_mode, stamp_mode, is_signature):
|
||||
"""扩展 _sign:支持 signature_mode/stamp_mode 透传 + 控制 is_signature。"""
|
||||
import base64
|
||||
from lib.word_signer import sign_word
|
||||
|
||||
with open(docx_path, 'rb') as f:
|
||||
docx_data = f.read()
|
||||
with open(INPUT_IMAGE, 'rb') as f:
|
||||
image_bytes = f.read()
|
||||
|
||||
stamps = [{'marker': 'USER_u0', 'image_base64': base64.b64encode(image_bytes).decode(),
|
||||
'image_filename': 'test1.jpg', 'is_signature': is_signature}]
|
||||
params = {
|
||||
'docx_name': 'input.docx',
|
||||
'match_mode': 'upload',
|
||||
'stamps': stamps,
|
||||
'use_global_height': True,
|
||||
'height': height,
|
||||
'relax_layout': relax_layout,
|
||||
'signature_mode': signature_mode,
|
||||
'stamp_mode': stamp_mode,
|
||||
}
|
||||
result, err = sign_word(docx_data, params, log_source='mode测试', trace_id='mode')
|
||||
if err:
|
||||
print(f"sign_word 失败: {err}")
|
||||
sys.exit(1)
|
||||
return result['data']
|
||||
|
||||
|
||||
def _find_image_root(root):
|
||||
"""找到含 inline 或 anchor 图片的 <w:p>。"""
|
||||
for p in root.iter(_ns('p', W)):
|
||||
if list(p.iter(_ns('inline', WP))) or list(p.iter(_ns('anchor', WP))):
|
||||
return p
|
||||
return None
|
||||
|
||||
|
||||
def test_signature_inline_default():
|
||||
"""签名默认走 inline:is_signature=True + 不传 mode → <wp:inline>。"""
|
||||
print(f"\n=== 签名默认 inline 模式(回归)===\n")
|
||||
src = OUT_DIR / "sig_inline.docx"
|
||||
make_docx(src, [("签名默认inline", 21, 283)]) # 行高 exact 0.5cm
|
||||
# 不传 signature_mode/stamp_mode → 应走默认值(signature_mode='inline')
|
||||
signed = _sign_with_mode(src, height=2.0, relax_layout=True,
|
||||
signature_mode='inline', stamp_mode='anchor',
|
||||
is_signature=True)
|
||||
root = ET.fromstring(_read_xml(signed))
|
||||
|
||||
p = _find_image_root(root)
|
||||
inlines = list(p.iter(_ns('inline', WP))) if p is not None else []
|
||||
anchors = list(p.iter(_ns('anchor', WP))) if p is not None else []
|
||||
ok = len(inlines) == 1 and len(anchors) == 0
|
||||
verdict = (f"{'✓' if ok else '✗'} inline={len(inlines)}, anchor={len(anchors)} "
|
||||
f"(期望 inline=1, anchor=0)")
|
||||
print(f" {verdict}")
|
||||
print(f"\nsignature_inline_default: {'1/1' if ok else '0/1'} 通过")
|
||||
|
||||
|
||||
def test_signature_anchor_mode():
|
||||
"""签名切到 anchor:is_signature=True + signature_mode='anchor' → <wp:anchor>。
|
||||
anchor 不触发 relax_layout,段落 spacing 应保持原状(exact/283)。"""
|
||||
print(f"\n=== 签名 anchor 模式(浮动覆盖)===\n")
|
||||
src = OUT_DIR / "sig_anchor.docx"
|
||||
make_docx(src, [("签名anchor", 21, 283)]) # 行高 exact 0.5cm
|
||||
signed = _sign_with_mode(src, height=2.0, relax_layout=True,
|
||||
signature_mode='anchor', stamp_mode='anchor',
|
||||
is_signature=True)
|
||||
root = ET.fromstring(_read_xml(signed))
|
||||
|
||||
p = _find_image_root(root)
|
||||
inlines = list(p.iter(_ns('inline', WP))) if p is not None else []
|
||||
anchors = list(p.iter(_ns('anchor', WP))) if p is not None else []
|
||||
pPr = p.find(_ns('pPr', W)) if p is not None else None
|
||||
spacing = pPr.find(_ns('spacing', W)) if pPr is not None else None
|
||||
line_rule = spacing.get(_ns('lineRule', W)) if spacing is not None else None
|
||||
line_val = spacing.get(_ns('line', W)) if spacing is not None else None
|
||||
|
||||
# 断言1:anchor 元素存在
|
||||
has_anchor = len(anchors) == 1 and len(inlines) == 0
|
||||
# 断言2:anchor 不触发 relax —— spacing 应保持原 exact/283
|
||||
not_relaxed = (line_rule == 'exact' and line_val == '283')
|
||||
# 断言3:anchor 专属属性
|
||||
anchor_elem = anchors[0] if anchors else None
|
||||
behind_doc = anchor_elem.get('behindDoc') if anchor_elem is not None else None
|
||||
allow_overlap = anchor_elem.get('allowOverlap') if anchor_elem is not None else None
|
||||
has_wrap_none = anchor_elem is not None and anchor_elem.find(_ns('wrapNone', WP)) is not None
|
||||
pos_h = anchor_elem.find(_ns('positionH', WP)) if anchor_elem is not None else None
|
||||
pos_v = anchor_elem.find(_ns('positionV', WP)) if anchor_elem is not None else None
|
||||
|
||||
# 期望:posH relativeFrom='paragraph' + posOffset=0(贴段落起点,char 模式不可靠)
|
||||
# posV relativeFrom='paragraph' + posOffset=0
|
||||
h_off_el = pos_h.find(_ns('posOffset', WP)) if pos_h is not None else None
|
||||
h_off_val = int(h_off_el.text) if h_off_el is not None and h_off_el.text else None
|
||||
has_pos = (pos_h is not None and pos_v is not None
|
||||
and pos_h.get('relativeFrom') == 'paragraph'
|
||||
and pos_v.get('relativeFrom') == 'paragraph'
|
||||
and h_off_val == 0)
|
||||
|
||||
ok = has_anchor and not_relaxed and behind_doc == '0' and allow_overlap == '1' and has_wrap_none and has_pos
|
||||
verdict = (f"{'✓' if ok else '✗'} anchor={len(anchors)}, inline={len(inlines)}; "
|
||||
f"spacing lineRule={line_rule}/line={line_val}(期望保持 exact/283 未放宽); "
|
||||
f"behindDoc={behind_doc}, allowOverlap={allow_overlap}, "
|
||||
f"wrapNone={'有' if has_wrap_none else '无'}, "
|
||||
f"posH relativeFrom=paragraph/posOffset={h_off_val}, "
|
||||
f"posV relativeFrom=paragraph")
|
||||
print(f" {verdict}")
|
||||
print(f"\nsignature_anchor_mode: {'1/1' if ok else '0/1'} 通过")
|
||||
|
||||
|
||||
def test_stamp_anchor_default():
|
||||
"""盖章默认走 anchor:is_signature=False + 不传 mode → <wp:anchor>。"""
|
||||
print(f"\n=== 盖章默认 anchor 模式(浮动覆盖)===\n")
|
||||
src = OUT_DIR / "stamp_anchor.docx"
|
||||
make_docx(src, [("盖章默认anchor", 21, 283)])
|
||||
signed = _sign_with_mode(src, height=2.0, relax_layout=True,
|
||||
signature_mode='inline', stamp_mode='anchor',
|
||||
is_signature=False)
|
||||
root = ET.fromstring(_read_xml(signed))
|
||||
|
||||
p = _find_image_root(root)
|
||||
inlines = list(p.iter(_ns('inline', WP))) if p is not None else []
|
||||
anchors = list(p.iter(_ns('anchor', WP))) if p is not None else []
|
||||
anchor_elem = anchors[0] if anchors else None
|
||||
behind_doc = anchor_elem.get('behindDoc') if anchor_elem is not None else None
|
||||
has_wrap_none = anchor_elem is not None and anchor_elem.find(_ns('wrapNone', WP)) is not None
|
||||
|
||||
ok = len(anchors) == 1 and len(inlines) == 0 and behind_doc == '0' and has_wrap_none
|
||||
verdict = (f"{'✓' if ok else '✗'} anchor={len(anchors)}, inline={len(inlines)}, "
|
||||
f"behindDoc={behind_doc}, wrapNone={'有' if has_wrap_none else '无'} "
|
||||
f"(期望 anchor=1, inline=0, behindDoc=0)")
|
||||
print(f" {verdict}")
|
||||
print(f"\nstamp_anchor_default: {'1/1' if ok else '0/1'} 通过")
|
||||
|
||||
|
||||
def test_stamp_inline_override():
|
||||
"""盖章切到 inline:is_signature=False + stamp_mode='inline' → <wp:inline>。"""
|
||||
print(f"\n=== 盖章切到 inline(强制嵌入)===\n")
|
||||
src = OUT_DIR / "stamp_inline.docx"
|
||||
make_docx(src, [("盖章强制inline", 21, 283)])
|
||||
signed = _sign_with_mode(src, height=2.0, relax_layout=True,
|
||||
signature_mode='inline', stamp_mode='inline',
|
||||
is_signature=False)
|
||||
root = ET.fromstring(_read_xml(signed))
|
||||
|
||||
p = _find_image_root(root)
|
||||
inlines = list(p.iter(_ns('inline', WP))) if p is not None else []
|
||||
anchors = list(p.iter(_ns('anchor', WP))) if p is not None else []
|
||||
|
||||
# inline 模式下 spacing 应被放宽为 atLeast
|
||||
pPr = p.find(_ns('pPr', W)) if p is not None else None
|
||||
spacing = pPr.find(_ns('spacing', W)) if pPr is not None else None
|
||||
line_rule = spacing.get(_ns('lineRule', W)) if spacing is not None else None
|
||||
|
||||
ok = len(inlines) == 1 and len(anchors) == 0 and line_rule == 'atLeast'
|
||||
verdict = (f"{'✓' if ok else '✗'} inline={len(inlines)}, anchor={len(anchors)}, "
|
||||
f"spacing lineRule={line_rule}(期望 inline=1, anchor=0, lineRule=atLeast 被放宽)")
|
||||
print(f" {verdict}")
|
||||
print(f"\nstamp_inline_override: {'1/1' if ok else '0/1'} 通过")
|
||||
|
||||
|
||||
def test_anchor_offset_estimation():
|
||||
"""SET 域前有 CJK 文字时,anchor 模式 posOffset 应反映前文字宽度估算。
|
||||
场景:段落 "签字人:" + SET 域(4 个 CJK + 1 全角冒号 = 5 个 CJK 宽度字符)
|
||||
字号 14pt(四号,half_pt=28)→ 期望偏移 ≈ 5 × 14pt × 12700 EMU/pt = 889000 EMU
|
||||
"""
|
||||
from docx import Document
|
||||
from lib import field_codes
|
||||
from docx.oxml.ns import qn
|
||||
from docx.oxml import OxmlElement
|
||||
|
||||
print(f"\n=== anchor 模式 posOffset 估算测试 ===\n")
|
||||
src = OUT_DIR / "anchor_offset.docx"
|
||||
|
||||
doc = Document()
|
||||
p = doc.add_paragraph()
|
||||
# 前缀文字 "签字人:"
|
||||
run = p.add_run("签字人:")
|
||||
rPr = run._element.get_or_add_rPr()
|
||||
sz = OxmlElement('w:sz')
|
||||
sz.set(qn('w:val'), '28') # 14pt
|
||||
rPr.append(sz)
|
||||
|
||||
for r in field_codes.build_set_field_runs('u0'):
|
||||
p._element.append(r)
|
||||
doc.save(str(src))
|
||||
|
||||
signed = _sign_with_mode(src, height=2.0, relax_layout=True,
|
||||
signature_mode='anchor', stamp_mode='anchor',
|
||||
is_signature=True)
|
||||
root = ET.fromstring(_read_xml(signed))
|
||||
|
||||
p_with_image = None
|
||||
for para in root.iter(_ns('p', W)):
|
||||
if list(para.iter(_ns('anchor', WP))):
|
||||
p_with_image = para
|
||||
break
|
||||
|
||||
anchor = list(p_with_image.iter(_ns('anchor', WP)))[0]
|
||||
pos_h = anchor.find(_ns('positionH', WP))
|
||||
h_off_el = pos_h.find(_ns('posOffset', WP))
|
||||
h_off_val = int(h_off_el.text) if h_off_el is not None and h_off_el.text else 0
|
||||
|
||||
# "签字人:" = 3 个 CJK 字符 + 1 个全角冒号 = 4 个 CJK 宽度
|
||||
# 期望偏移 = 4 × 14pt × 12700 EMU/pt = 711200 EMU(容差 ±15%)
|
||||
expected_emu = 4 * 14 * 12700
|
||||
tolerance = int(expected_emu * 0.15)
|
||||
ok = (pos_h.get('relativeFrom') == 'paragraph'
|
||||
and abs(h_off_val - expected_emu) <= tolerance
|
||||
and h_off_val > 0)
|
||||
verdict = (f"{'✓' if ok else '✗'} posH relativeFrom={pos_h.get('relativeFrom')}, "
|
||||
f"posOffset={h_off_val} EMU (≈{h_off_val / 360000:.2f}cm), "
|
||||
f"期望 ≈{expected_emu} EMU (≈{expected_emu / 360000:.2f}cm, 容差 ±15%)")
|
||||
print(f" {verdict}")
|
||||
print(f"\nanchor_offset_estimation: {'1/1' if ok else '0/1'} 通过")
|
||||
|
||||
|
||||
def main():
|
||||
_ensure_path()
|
||||
sys.stdout.reconfigure(encoding='utf-8')
|
||||
@@ -509,6 +725,13 @@ def main():
|
||||
test_no_spacing_with_table_atleast()
|
||||
test_no_paragraph_font_size()
|
||||
|
||||
# 新增 anchor/inline 模式切换场景
|
||||
test_signature_inline_default()
|
||||
test_signature_anchor_mode()
|
||||
test_stamp_anchor_default()
|
||||
test_stamp_inline_override()
|
||||
test_anchor_offset_estimation()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
BIN
image_test/output/auto_size/anchor_offset.docx
Normal file
BIN
image_test/output/auto_size/sig_anchor.docx
Normal file
BIN
image_test/output/auto_size/sig_inline.docx
Normal file
BIN
image_test/output/auto_size/stamp_anchor.docx
Normal file
BIN
image_test/output/auto_size/stamp_inline.docx
Normal file
|
After Width: | Height: | Size: 180 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 180 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 180 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 180 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 180 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 180 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 180 KiB |
|
After Width: | Height: | Size: 18 KiB |
BIN
image_test/output/project_run/mode_stamp1_1_input.png
Normal file
|
After Width: | Height: | Size: 180 KiB |
BIN
image_test/output/project_run/mode_stamp1_2_processed.png
Normal file
|
After Width: | Height: | Size: 18 KiB |
@@ -192,16 +192,151 @@ def _add_picture_run_to_paragraph(paragraph_element, doc_part, image_path, width
|
||||
return run_obj
|
||||
|
||||
|
||||
_PT_PER_EMU = 12700 # 1 pt = 12700 EMU
|
||||
|
||||
|
||||
def _estimate_text_width_emu_before(para_xml, target_elem):
|
||||
"""估算段落起点到 target_elem 之间所有可见文字的水平宽度(EMU)。
|
||||
|
||||
用于浮动图片(anchor 模式)相对段落起点的水平 posOffset 估算,
|
||||
让图片左边缘接近 SET 域在段落中的位置。
|
||||
|
||||
算法:
|
||||
- 遍历段落所有后代,遇到 target_elem 停止;
|
||||
- 对每个 <w:t> 文本,按所在 run 的字号(无字号用段落默认)估算字符宽度:
|
||||
- CJK / 全角 / 中文标点:1.0 × 字号 pt
|
||||
- 空格:0.5 × 字号 pt
|
||||
- 其他 ASCII:0.55 × 字号 pt
|
||||
- 加段落左缩进(<w:ind w:left>,twips → EMU)。
|
||||
|
||||
返回 EMU 整数。Word 实际渲染会有偏差(字体度量、字距差异),但通常 ±10% 内。
|
||||
"""
|
||||
# 段落默认字号(已有函数返回 pt 或 None)
|
||||
default_pt = _detect_paragraph_font_size_pt(para_xml) or 10.5
|
||||
|
||||
# 段落左缩进
|
||||
pPr = para_xml.find(qn('w:pPr'))
|
||||
left_twips = 0
|
||||
if pPr is not None:
|
||||
ind = pPr.find(qn('w:ind'))
|
||||
if ind is not None:
|
||||
left_str = ind.get(qn('w:left')) or ind.get(qn('w:start')) or '0'
|
||||
try:
|
||||
left_twips = int(left_str)
|
||||
except (ValueError, TypeError):
|
||||
pass
|
||||
|
||||
total_emu = int(left_twips * 635.0) # 1 twip = 635 EMU
|
||||
|
||||
# 遍历段落子元素,遇到 target_elem 停止
|
||||
for elem in para_xml.iter():
|
||||
if elem is target_elem:
|
||||
break
|
||||
if elem.tag != qn('w:t'):
|
||||
continue
|
||||
text = elem.text or ''
|
||||
if not text:
|
||||
continue
|
||||
# 找到所在 run 的字号
|
||||
run = elem.getparent()
|
||||
while run is not None and run.tag != qn('w:r'):
|
||||
run = run.getparent()
|
||||
font_pt = default_pt
|
||||
if run is not None:
|
||||
rPr = run.find(qn('w:rPr'))
|
||||
if rPr is not None:
|
||||
sz = rPr.find(qn('w:sz'))
|
||||
if sz is not None and sz.get(qn('w:val')):
|
||||
try:
|
||||
pt = int(sz.get(qn('w:val'))) / 2.0
|
||||
if 4.0 <= pt <= 96.0:
|
||||
font_pt = pt
|
||||
except (ValueError, TypeError):
|
||||
pass
|
||||
# 估算每个字符宽度
|
||||
for ch in text:
|
||||
code = ord(ch)
|
||||
if (0x4E00 <= code <= 0x9FFF # CJK 统一汉字
|
||||
or 0x3000 <= code <= 0x303F # CJK 标点
|
||||
or 0xFF00 <= code <= 0xFFEF # 全角字符
|
||||
or 0x3400 <= code <= 0x4DBF): # CJK 扩展A
|
||||
total_emu += int(font_pt * 1.0 * _PT_PER_EMU)
|
||||
elif ch.isspace():
|
||||
total_emu += int(font_pt * 0.5 * _PT_PER_EMU)
|
||||
else:
|
||||
total_emu += int(font_pt * 0.55 * _PT_PER_EMU)
|
||||
|
||||
return total_emu
|
||||
|
||||
|
||||
def _convert_inline_to_anchor(inline_elem, h_offset_emu=0):
|
||||
"""把 python-docx 生成的 <wp:inline> 原地改造成 <wp:anchor>。
|
||||
|
||||
固定参数:behindDoc=0(盖在文字前)/ wrapNone(不环绕)/ 水平 paragraph 模式
|
||||
+ posOffset=h_offset_emu(默认 0=贴段落起点;可传入 SET 域估算偏移让图片对齐域位置)
|
||||
/ 垂直 paragraph + posOffset=0(贴段落顶部)。
|
||||
保留 <a:graphic> 子树(含 r:embed)。
|
||||
"""
|
||||
# 1. 改 tag
|
||||
inline_elem.tag = qn('wp:anchor')
|
||||
|
||||
# 2. 加 anchor 专属属性
|
||||
inline_elem.set('simplePos', '0')
|
||||
inline_elem.set('relativeHeight', '25')
|
||||
inline_elem.set('behindDoc', '0') # 在文字前面
|
||||
inline_elem.set('locked', '0')
|
||||
inline_elem.set('layoutInCell', '1')
|
||||
inline_elem.set('allowOverlap', '1')
|
||||
|
||||
# 3. 在 <wp:extent> 前插入 simplePos / positionH / positionV
|
||||
extent = inline_elem.find(qn('wp:extent'))
|
||||
|
||||
simple_pos = OxmlElement('wp:simplePos')
|
||||
simple_pos.set('x', '0')
|
||||
simple_pos.set('y', '0')
|
||||
|
||||
pos_h = OxmlElement('wp:positionH')
|
||||
pos_h.set('relativeFrom', 'paragraph')
|
||||
h_off = OxmlElement('wp:posOffset')
|
||||
h_off.text = str(int(h_offset_emu))
|
||||
pos_h.append(h_off)
|
||||
|
||||
pos_v = OxmlElement('wp:positionV')
|
||||
pos_v.set('relativeFrom', 'paragraph') # 垂直相对段落(贴段落顶部)
|
||||
v_off = OxmlElement('wp:posOffset')
|
||||
v_off.text = '0'
|
||||
pos_v.append(v_off)
|
||||
|
||||
# 反序 insert,保证最终顺序:simplePos, positionH, positionV, extent
|
||||
for elem in (pos_v, pos_h, simple_pos):
|
||||
extent.addprevious(elem)
|
||||
|
||||
# 4. 在 <wp:extent> 后插入 effectExtent 和 wrapNone
|
||||
effect = OxmlElement('wp:effectExtent')
|
||||
for k in ('l', 't', 'r', 'b'):
|
||||
effect.set(qn(f'wp:{k}'), '0')
|
||||
extent.addnext(effect)
|
||||
|
||||
wrap_none = OxmlElement('wp:wrapNone')
|
||||
effect.addnext(wrap_none)
|
||||
|
||||
|
||||
def insert_image_after_field(doc, marker, image_path, width_cm, height_cm,
|
||||
log_source='前端操作', relax_layout=True):
|
||||
log_source='前端操作', relax_layout=True,
|
||||
mode='inline'):
|
||||
"""在指定 ``USER_<name>`` 域之后插入签名图片。
|
||||
|
||||
返回插入的图片数量。
|
||||
|
||||
``mode``:
|
||||
- ``'inline'``(默认):嵌入式,受段落行高约束,需 ``relax_layout`` 放宽 + 缩放兜底
|
||||
- ``'anchor'``:浮动覆盖,跳过 relax_layout 与缩放兜底,图片浮在文字上方
|
||||
|
||||
``relax_layout=True``(默认)时,若标记段落或所在表格行有固定高度约束
|
||||
(``lineRule="exact"`` / ``hRule="exact"``)小于签名需要的高度,
|
||||
自动把约束放宽为 ``atLeast`` 并上调数值,避免 Word 硬裁剪图片。
|
||||
设为 ``False`` 时严格保留原文档布局,仅靠等比例缩放把图片压进约束内。
|
||||
仅在 ``mode='inline'`` 时生效,``anchor`` 模式跳过。
|
||||
"""
|
||||
target_name = marker
|
||||
if target_name.startswith('USER_'):
|
||||
@@ -253,7 +388,9 @@ def insert_image_after_field(doc, marker, image_path, width_cm, height_cm,
|
||||
f"{font_pt}" if font_pt else "无",
|
||||
cur_h, extra={'log_source': log_source})
|
||||
|
||||
# 2. 放宽约束(默认开启):把小于签名高度的 exact 约束改成 atLeast
|
||||
# 2. inline 模式:放宽段落/表格行约束 + 缩放兜底
|
||||
# anchor 模式:跳过——浮动图片不受段落约束,可溢出
|
||||
if mode == 'inline':
|
||||
if relax_layout and cur_h and cur_h > 0:
|
||||
_relax_paragraph_for_image(para_xml, cur_h, log_source)
|
||||
_relax_table_row_for_image(para_xml, cur_h, log_source)
|
||||
@@ -275,16 +412,33 @@ def insert_image_after_field(doc, marker, image_path, width_cm, height_cm,
|
||||
f"{max_w_cm:.2f}cm" if max_w_cm else "无",
|
||||
left_cm, right_cm,
|
||||
extra={'log_source': log_source})
|
||||
else: # mode == 'anchor'
|
||||
final_w, final_h = cur_w, cur_h # 浮动模式不缩放
|
||||
logger.info("[Word处理] 浮动覆盖模式(anchor): 使用图片原始尺寸 %.2fx%.2f cm,"
|
||||
"跳过段落约束放宽与缩放兜底",
|
||||
final_w or 0, final_h or 0,
|
||||
extra={'log_source': log_source})
|
||||
|
||||
parent_xml = para_xml.getparent()
|
||||
para_obj = Paragraph(para_xml, part)
|
||||
run_obj = para_obj.add_run()
|
||||
run_obj.add_picture(image_path, width=_Cm(final_w), height=_Cm(final_h))
|
||||
|
||||
# anchor 模式:把生成的 <wp:inline> 原地改造成 <wp:anchor>
|
||||
if mode == 'anchor':
|
||||
drawing = run_obj._element.find(qn('w:drawing'))
|
||||
if drawing is not None:
|
||||
inline = drawing.find(qn('wp:inline'))
|
||||
if inline is not None:
|
||||
# 估算 SET 域在段落中的水平偏移(前面文字宽度 + 左缩进)
|
||||
h_offset_emu = _estimate_text_width_emu_before(para_xml, anchor_elem)
|
||||
_convert_inline_to_anchor(inline, h_offset_emu=h_offset_emu)
|
||||
|
||||
new_run_xml = run_obj._element
|
||||
anchor_elem.addnext(new_run_xml)
|
||||
inserted += 1
|
||||
logger.info("[Word处理] 在 %s 域后插入图片成功", marker, extra={'log_source': log_source})
|
||||
logger.info("[Word处理] 在 %s 域后插入图片成功 (mode=%s)", marker, mode,
|
||||
extra={'log_source': log_source})
|
||||
except Exception as e:
|
||||
logger.error("[Word处理] 插入图片失败 %s: %s", marker, str(e), extra={'log_source': log_source})
|
||||
|
||||
|
||||
@@ -68,6 +68,8 @@ def sign_word(docx_data, params, log_source='前端操作', trace_id=None, clien
|
||||
global_rotate_min = params.get('rotate_min', 0)
|
||||
global_rotate_max = params.get('rotate_max', 0)
|
||||
relax_layout = params.get('relax_layout', True)
|
||||
signature_mode = params.get('signature_mode', 'inline') # 'inline' | 'anchor'
|
||||
stamp_mode = params.get('stamp_mode', 'anchor') # 'inline' | 'anchor'
|
||||
|
||||
if match_mode == 'auto':
|
||||
stamps = [s for s in stamps if (s.get('marker') or '').strip()]
|
||||
@@ -202,6 +204,8 @@ def sign_word(docx_data, params, log_source='前端操作', trace_id=None, clien
|
||||
continue
|
||||
|
||||
is_sig = stamp.get('is_signature', stamp_is_signature)
|
||||
# 按图片类型选模式:签名用 signature_mode,盖章用 stamp_mode
|
||||
image_mode = signature_mode if is_sig else stamp_mode
|
||||
h = _resolve_height(stamp, use_global_height, global_height)
|
||||
noise = _resolve_noise(stamp, use_global_noise, global_noise)
|
||||
rot_min, rot_max = _resolve_rotate(stamp, use_global_rotate, global_rotate_min, global_rotate_max)
|
||||
@@ -243,6 +247,7 @@ def sign_word(docx_data, params, log_source='前端操作', trace_id=None, clien
|
||||
inserted = _insert_signature_image(doc, marker, processed, s_align_h, s_align_v,
|
||||
height_cm=h,
|
||||
relax_layout=relax_layout,
|
||||
image_mode=image_mode,
|
||||
log_source=log_source, trace_id=trace_id)
|
||||
if inserted > 0:
|
||||
success_count += inserted
|
||||
@@ -283,7 +288,7 @@ def sign_word(docx_data, params, log_source='前端操作', trace_id=None, clien
|
||||
|
||||
|
||||
def _insert_signature_image(doc, marker, image_data, align_h, align_v, height_cm=None,
|
||||
relax_layout=True,
|
||||
relax_layout=True, image_mode='inline',
|
||||
log_source='前端操作', trace_id=None):
|
||||
"""插入签名图片到 marker 对应的 SET 域后。
|
||||
|
||||
@@ -293,6 +298,10 @@ def _insert_signature_image(doc, marker, image_data, align_h, align_v, height_cm
|
||||
|
||||
``relax_layout`` 透传给 :func:`field_codes.insert_image_after_field`,
|
||||
控制是否自动放宽段落 / 表格行的固定高度约束以避免签名被裁剪。
|
||||
|
||||
``image_mode`` 透传给 :func:`field_codes.insert_image_after_field`:
|
||||
``'inline'`` 嵌入式(默认,撑大当前行)或 ``'anchor'`` 浮动覆盖(不撑大,
|
||||
浮在文字上方)。
|
||||
"""
|
||||
with tempfile.NamedTemporaryFile(suffix='.png', delete=False) as tmp:
|
||||
tmp.write(image_data)
|
||||
@@ -309,6 +318,7 @@ def _insert_signature_image(doc, marker, image_data, align_h, align_v, height_cm
|
||||
count = field_codes.insert_image_after_field(
|
||||
doc, marker, tmp_path, width_cm, height_cm,
|
||||
log_source=log_source, relax_layout=relax_layout,
|
||||
mode=image_mode,
|
||||
)
|
||||
return count
|
||||
finally:
|
||||
|
||||
@@ -6,3 +6,279 @@
|
||||
[2026-07-20 09:41:49] [INFO] [__main__] Web服务: 0.0.0.0:5001, debug=False
|
||||
[2026-07-20 09:41:49] [INFO] [__main__] 使用 Waitress 生产服务器
|
||||
[2026-07-20 09:41:49] [INFO] [waitress] Serving on http://0.0.0.0:5001
|
||||
[2026-07-20 09:42:15] [INFO] [routes.api] [请求接入] 客户端IP=127.0.0.1, 接口=/api/word/sign, trace_id=20260720094215033530_9172
|
||||
[2026-07-20 09:42:15] [INFO] [routes.api] [参数校验] 校验通过
|
||||
[2026-07-20 09:42:15] [INFO] [lib.word_signer] [签章流程] ====== 开始处理 ====== trace_id=20260720094215033530_9172
|
||||
[2026-07-20 09:42:15] [INFO] [lib.word_signer] [签章流程] 文件名: 通用闭环验证系统应用软件测试报告.docx
|
||||
[2026-07-20 09:42:15] [INFO] [lib.word_signer] [签章流程] 匹配模式: auto
|
||||
[2026-07-20 09:42:15] [INFO] [lib.word_signer] [签章流程] Word文档加载成功
|
||||
[2026-07-20 09:42:15] [INFO] [lib.field_codes] [auto扫描] 发现 1 个 SET USER_<name> 标记
|
||||
[2026-07-20 09:42:15] [INFO] [lib.word_signer] [签章流程] auto模式扫描到 1 个标记
|
||||
[2026-07-20 09:42:15] [INFO] [lib.word_signer] [签章流程] ---- 处理盖章项 1/1 ----
|
||||
[2026-07-20 09:42:15] [INFO] [lib.word_signer] [图片匹配] auto模式, 标记=USER_张三, 查询姓名=张三
|
||||
[2026-07-20 09:42:15] [INFO] [lib.word_signer] [图片匹配] auto匹配成功: 张三
|
||||
[2026-07-20 09:42:15] [INFO] [lib.image_processor] [图片处理] 原始图片: 模式=RGB, 尺寸=(2048, 1382)
|
||||
[2026-07-20 09:42:15] [INFO] [lib.image_processor] [图片处理] 执行手写签字黑白二值化
|
||||
[2026-07-20 09:42:15] [INFO] [lib.image_processor] [图片处理] 执行白底转透明抠图
|
||||
[2026-07-20 09:42:15] [INFO] [lib.image_processor] [图片处理] 执行透明边框裁剪
|
||||
[2026-07-20 09:42:16] [INFO] [lib.image_processor] [图片处理] 剔除噪点簇: 共 59 簇,移除 52 簇 (143 像素,占内容 0.16%);阈值=187 px (相对 0.010% + 绝对 50 px)
|
||||
[2026-07-20 09:42:16] [INFO] [lib.image_processor] [图片处理] 紧致裁剪诊断: 尺寸=(2025, 921), bbox=(254, 0, 1756, 721), 高alpha像素=90114/1865025 (4.8%), 暗像素=90257/1865025 (4.8%), 内容像素=90114/1865025 (4.8%)
|
||||
[2026-07-20 09:42:16] [INFO] [lib.image_processor] [图片处理] 紧致裁剪: (2025, 921) -> (1502, 721) (bbox=(254, 0, 1756, 721))
|
||||
[2026-07-20 09:42:16] [INFO] [lib.image_processor] [图片处理] 处理完成: 最终尺寸=(1502, 721), 大小=18659 bytes
|
||||
[2026-07-20 09:42:16] [INFO] [lib.word_signer] [签章流程][DEBUG] 已保存处理前后对比图到 E:\projects\wxwx\projects_job\GeneralRequirement\SignatureSystem\BackEnd\Code\image_test\output\project_run (tag=20260720094215033530_9172_stamp1)
|
||||
[2026-07-20 09:42:16] [INFO] [lib.field_codes] [Word处理] 自动尺寸: 字号=14.0pt → 推算 height=0.99 cm
|
||||
[2026-07-20 09:42:16] [INFO] [lib.field_codes] [Word处理] 段落无显式行高,新增 spacing atLeast/562 twips (0.99cm) 以容纳 0.99cm 高签名
|
||||
[2026-07-20 09:42:16] [INFO] [lib.field_codes] [Word处理] 在 USER_张三 域后插入图片成功
|
||||
[2026-07-20 09:42:16] [INFO] [lib.field_codes] [Word处理] 自动尺寸: 字号=14.0pt → 推算 height=0.99 cm
|
||||
[2026-07-20 09:42:16] [INFO] [lib.field_codes] [Word处理] 段落无显式行高,新增 spacing atLeast/562 twips (0.99cm) 以容纳 0.99cm 高签名
|
||||
[2026-07-20 09:42:16] [INFO] [lib.field_codes] [Word处理] 在 USER_张三 域后插入图片成功
|
||||
[2026-07-20 09:42:16] [INFO] [lib.field_codes] [Word处理] 段落无显式字号,使用文档默认字号 无pt
|
||||
[2026-07-20 09:42:16] [INFO] [lib.field_codes] [Word处理] 自动尺寸: 字号=无pt → 推算 height=0.74 cm
|
||||
[2026-07-20 09:42:16] [INFO] [lib.field_codes] [Word处理] 段落无显式行高,新增 spacing atLeast/420 twips (0.74cm) 以容纳 0.74cm 高签名
|
||||
[2026-07-20 09:42:16] [INFO] [lib.field_codes] [Word处理] 在 USER_张三 域后插入图片成功
|
||||
[2026-07-20 09:42:16] [INFO] [lib.word_signer] [签章流程] 盖章项1签章成功: marker=USER_张三, 插入3处
|
||||
[2026-07-20 09:42:16] [INFO] [lib.word_signer] [签章流程] ====== 处理完成 ====== 成功3项, 告警0条, trace_id=20260720094215033530_9172
|
||||
[2026-07-20 09:42:46] [INFO] [routes.api] [请求接入] 客户端IP=127.0.0.1, 接口=/api/word/sign, trace_id=20260720094246267801_9172
|
||||
[2026-07-20 09:42:46] [INFO] [routes.api] [参数校验] 校验通过
|
||||
[2026-07-20 09:42:46] [INFO] [lib.word_signer] [签章流程] ====== 开始处理 ====== trace_id=20260720094246267801_9172
|
||||
[2026-07-20 09:42:46] [INFO] [lib.word_signer] [签章流程] 文件名: 通用闭环验证系统应用软件测试报告.docx
|
||||
[2026-07-20 09:42:46] [INFO] [lib.word_signer] [签章流程] 匹配模式: auto
|
||||
[2026-07-20 09:42:46] [INFO] [lib.word_signer] [签章流程] Word文档加载成功
|
||||
[2026-07-20 09:42:46] [INFO] [lib.field_codes] [auto扫描] 发现 1 个 SET USER_<name> 标记
|
||||
[2026-07-20 09:42:46] [INFO] [lib.word_signer] [签章流程] auto模式扫描到 1 个标记
|
||||
[2026-07-20 09:42:46] [INFO] [lib.word_signer] [签章流程] ---- 处理盖章项 1/1 ----
|
||||
[2026-07-20 09:42:46] [INFO] [lib.word_signer] [图片匹配] auto模式, 标记=USER_张三, 查询姓名=张三
|
||||
[2026-07-20 09:42:46] [INFO] [lib.word_signer] [图片匹配] auto匹配成功: 张三
|
||||
[2026-07-20 09:42:46] [INFO] [lib.image_processor] [图片处理] 原始图片: 模式=RGB, 尺寸=(2048, 1382)
|
||||
[2026-07-20 09:42:46] [INFO] [lib.image_processor] [图片处理] 执行手写签字黑白二值化
|
||||
[2026-07-20 09:42:46] [INFO] [lib.image_processor] [图片处理] 执行白底转透明抠图
|
||||
[2026-07-20 09:42:47] [INFO] [lib.image_processor] [图片处理] 执行透明边框裁剪
|
||||
[2026-07-20 09:42:47] [INFO] [lib.image_processor] [图片处理] 剔除噪点簇: 共 59 簇,移除 52 簇 (143 像素,占内容 0.16%);阈值=187 px (相对 0.010% + 绝对 50 px)
|
||||
[2026-07-20 09:42:47] [INFO] [lib.image_processor] [图片处理] 紧致裁剪诊断: 尺寸=(2025, 921), bbox=(254, 0, 1756, 721), 高alpha像素=90114/1865025 (4.8%), 暗像素=90257/1865025 (4.8%), 内容像素=90114/1865025 (4.8%)
|
||||
[2026-07-20 09:42:47] [INFO] [lib.image_processor] [图片处理] 紧致裁剪: (2025, 921) -> (1502, 721) (bbox=(254, 0, 1756, 721))
|
||||
[2026-07-20 09:42:47] [INFO] [lib.image_processor] [图片处理] 处理完成: 最终尺寸=(1502, 721), 大小=18659 bytes
|
||||
[2026-07-20 09:42:47] [INFO] [lib.word_signer] [签章流程][DEBUG] 已保存处理前后对比图到 E:\projects\wxwx\projects_job\GeneralRequirement\SignatureSystem\BackEnd\Code\image_test\output\project_run (tag=20260720094246267801_9172_stamp1)
|
||||
[2026-07-20 09:42:47] [INFO] [lib.field_codes] [Word处理] 段落无显式行高,新增 spacing atLeast/1701 twips (3.00cm) 以容纳 3.00cm 高签名
|
||||
[2026-07-20 09:42:47] [INFO] [lib.field_codes] [Word处理] 在 USER_张三 域后插入图片成功
|
||||
[2026-07-20 09:42:47] [INFO] [lib.field_codes] [Word处理] 段落无显式行高,新增 spacing atLeast/1701 twips (3.00cm) 以容纳 3.00cm 高签名
|
||||
[2026-07-20 09:42:47] [INFO] [lib.field_codes] [Word处理] 在 USER_张三 域后插入图片成功
|
||||
[2026-07-20 09:42:47] [INFO] [lib.field_codes] [Word处理] 段落无显式行高,新增 spacing atLeast/1701 twips (3.00cm) 以容纳 3.00cm 高签名
|
||||
[2026-07-20 09:42:47] [INFO] [lib.field_codes] [Word处理] 在 USER_张三 域后插入图片成功
|
||||
[2026-07-20 09:42:47] [INFO] [lib.word_signer] [签章流程] 盖章项1签章成功: marker=USER_张三, 插入3处
|
||||
[2026-07-20 09:42:47] [INFO] [lib.word_signer] [签章流程] ====== 处理完成 ====== 成功3项, 告警0条, trace_id=20260720094246267801_9172
|
||||
[2026-07-20 14:43:12] [INFO] [__main__] ===== 自动签名系统启动 =====
|
||||
[2026-07-20 14:43:12] [INFO] [__main__] 限制配置: docx_max=1048576 bytes, image_max=262144 bytes, stamp_max=100, log_max=1000
|
||||
[2026-07-20 14:43:12] [INFO] [lib.db] MySQL 数据表初始化完成
|
||||
[2026-07-20 14:43:12] [INFO] [lib.db] 数据库初始化完成 (MySQL)
|
||||
[2026-07-20 14:43:12] [INFO] [__main__] 数据库初始化完成, 当前使用: MYSQL
|
||||
[2026-07-20 14:43:12] [INFO] [__main__] Web服务: 0.0.0.0:5001, debug=False
|
||||
[2026-07-20 14:43:12] [INFO] [__main__] 使用 Waitress 生产服务器
|
||||
[2026-07-20 14:43:12] [INFO] [waitress] Serving on http://0.0.0.0:5001
|
||||
[2026-07-20 14:43:45] [INFO] [routes.api] [请求接入] 客户端IP=127.0.0.1, 接口=/api/word/sign, trace_id=20260720144345022466_5980
|
||||
[2026-07-20 14:43:45] [INFO] [routes.api] [参数校验] 校验通过
|
||||
[2026-07-20 14:43:45] [INFO] [lib.word_signer] [签章流程] ====== 开始处理 ====== trace_id=20260720144345022466_5980
|
||||
[2026-07-20 14:43:45] [INFO] [lib.word_signer] [签章流程] 文件名: 通用闭环验证系统应用软件测试报告.docx
|
||||
[2026-07-20 14:43:45] [INFO] [lib.word_signer] [签章流程] 匹配模式: auto
|
||||
[2026-07-20 14:43:45] [INFO] [lib.word_signer] [签章流程] Word文档加载成功
|
||||
[2026-07-20 14:43:45] [INFO] [lib.field_codes] [auto扫描] 发现 1 个 SET USER_<name> 标记
|
||||
[2026-07-20 14:43:45] [INFO] [lib.word_signer] [签章流程] auto模式扫描到 1 个标记
|
||||
[2026-07-20 14:43:45] [INFO] [lib.word_signer] [签章流程] ---- 处理盖章项 1/1 ----
|
||||
[2026-07-20 14:43:45] [INFO] [lib.word_signer] [图片匹配] auto模式, 标记=USER_张三, 查询姓名=张三
|
||||
[2026-07-20 14:43:45] [INFO] [lib.word_signer] [图片匹配] auto匹配成功: 张三
|
||||
[2026-07-20 14:43:45] [INFO] [lib.image_processor] [图片处理] 原始图片: 模式=RGB, 尺寸=(2048, 1382)
|
||||
[2026-07-20 14:43:45] [INFO] [lib.image_processor] [图片处理] 执行手写签字黑白二值化
|
||||
[2026-07-20 14:43:45] [INFO] [lib.image_processor] [图片处理] 执行白底转透明抠图
|
||||
[2026-07-20 14:43:45] [INFO] [lib.image_processor] [图片处理] 执行透明边框裁剪
|
||||
[2026-07-20 14:43:45] [INFO] [lib.image_processor] [图片处理] 剔除噪点簇: 共 59 簇,移除 52 簇 (143 像素,占内容 0.16%);阈值=187 px (相对 0.010% + 绝对 50 px)
|
||||
[2026-07-20 14:43:45] [INFO] [lib.image_processor] [图片处理] 紧致裁剪诊断: 尺寸=(2025, 921), bbox=(254, 0, 1756, 721), 高alpha像素=90114/1865025 (4.8%), 暗像素=90257/1865025 (4.8%), 内容像素=90114/1865025 (4.8%)
|
||||
[2026-07-20 14:43:45] [INFO] [lib.image_processor] [图片处理] 紧致裁剪: (2025, 921) -> (1502, 721) (bbox=(254, 0, 1756, 721))
|
||||
[2026-07-20 14:43:45] [INFO] [lib.image_processor] [图片处理] 处理完成: 最终尺寸=(1502, 721), 大小=18659 bytes
|
||||
[2026-07-20 14:43:45] [INFO] [lib.word_signer] [签章流程][DEBUG] 已保存处理前后对比图到 E:\projects\wxwx\projects_job\GeneralRequirement\SignatureSystem\BackEnd\Code\image_test\output\project_run (tag=20260720144345022466_5980_stamp1)
|
||||
[2026-07-20 14:43:46] [INFO] [lib.field_codes] [Word处理] 浮动覆盖模式(anchor): 使用图片原始尺寸 10.42x5.00 cm,跳过段落约束放宽与缩放兜底
|
||||
[2026-07-20 14:43:46] [INFO] [lib.field_codes] [Word处理] 在 USER_张三 域后插入图片成功 (mode=anchor)
|
||||
[2026-07-20 14:43:46] [INFO] [lib.field_codes] [Word处理] 浮动覆盖模式(anchor): 使用图片原始尺寸 10.42x5.00 cm,跳过段落约束放宽与缩放兜底
|
||||
[2026-07-20 14:43:46] [INFO] [lib.field_codes] [Word处理] 在 USER_张三 域后插入图片成功 (mode=anchor)
|
||||
[2026-07-20 14:43:46] [INFO] [lib.field_codes] [Word处理] 浮动覆盖模式(anchor): 使用图片原始尺寸 10.42x5.00 cm,跳过段落约束放宽与缩放兜底
|
||||
[2026-07-20 14:43:46] [INFO] [lib.field_codes] [Word处理] 在 USER_张三 域后插入图片成功 (mode=anchor)
|
||||
[2026-07-20 14:43:46] [INFO] [lib.word_signer] [签章流程] 盖章项1签章成功: marker=USER_张三, 插入3处
|
||||
[2026-07-20 14:43:46] [INFO] [lib.word_signer] [签章流程] ====== 处理完成 ====== 成功3项, 告警0条, trace_id=20260720144345022466_5980
|
||||
[2026-07-20 14:44:33] [INFO] [routes.api] [请求接入] 客户端IP=127.0.0.1, 接口=/api/word/sign, trace_id=20260720144433414845_5980
|
||||
[2026-07-20 14:44:33] [INFO] [routes.api] [参数校验] 校验通过
|
||||
[2026-07-20 14:44:33] [INFO] [lib.word_signer] [签章流程] ====== 开始处理 ====== trace_id=20260720144433414845_5980
|
||||
[2026-07-20 14:44:33] [INFO] [lib.word_signer] [签章流程] 文件名: 通用闭环验证系统应用软件测试报告.docx
|
||||
[2026-07-20 14:44:33] [INFO] [lib.word_signer] [签章流程] 匹配模式: auto
|
||||
[2026-07-20 14:44:33] [INFO] [lib.word_signer] [签章流程] Word文档加载成功
|
||||
[2026-07-20 14:44:33] [INFO] [lib.field_codes] [auto扫描] 发现 1 个 SET USER_<name> 标记
|
||||
[2026-07-20 14:44:33] [INFO] [lib.word_signer] [签章流程] auto模式扫描到 1 个标记
|
||||
[2026-07-20 14:44:33] [INFO] [lib.word_signer] [签章流程] ---- 处理盖章项 1/1 ----
|
||||
[2026-07-20 14:44:33] [INFO] [lib.word_signer] [图片匹配] auto模式, 标记=USER_张三, 查询姓名=张三
|
||||
[2026-07-20 14:44:33] [INFO] [lib.word_signer] [图片匹配] auto匹配成功: 张三
|
||||
[2026-07-20 14:44:33] [INFO] [lib.image_processor] [图片处理] 原始图片: 模式=RGB, 尺寸=(2048, 1382)
|
||||
[2026-07-20 14:44:33] [INFO] [lib.image_processor] [图片处理] 执行手写签字黑白二值化
|
||||
[2026-07-20 14:44:33] [INFO] [lib.image_processor] [图片处理] 执行白底转透明抠图
|
||||
[2026-07-20 14:44:34] [INFO] [lib.image_processor] [图片处理] 执行透明边框裁剪
|
||||
[2026-07-20 14:44:34] [INFO] [lib.image_processor] [图片处理] 剔除噪点簇: 共 59 簇,移除 52 簇 (143 像素,占内容 0.16%);阈值=187 px (相对 0.010% + 绝对 50 px)
|
||||
[2026-07-20 14:44:34] [INFO] [lib.image_processor] [图片处理] 紧致裁剪诊断: 尺寸=(2025, 921), bbox=(254, 0, 1756, 721), 高alpha像素=90114/1865025 (4.8%), 暗像素=90257/1865025 (4.8%), 内容像素=90114/1865025 (4.8%)
|
||||
[2026-07-20 14:44:34] [INFO] [lib.image_processor] [图片处理] 紧致裁剪: (2025, 921) -> (1502, 721) (bbox=(254, 0, 1756, 721))
|
||||
[2026-07-20 14:44:34] [INFO] [lib.image_processor] [图片处理] 处理完成: 最终尺寸=(1502, 721), 大小=18659 bytes
|
||||
[2026-07-20 14:44:34] [INFO] [lib.word_signer] [签章流程][DEBUG] 已保存处理前后对比图到 E:\projects\wxwx\projects_job\GeneralRequirement\SignatureSystem\BackEnd\Code\image_test\output\project_run (tag=20260720144433414845_5980_stamp1)
|
||||
[2026-07-20 14:44:34] [INFO] [lib.field_codes] [Word处理] 浮动覆盖模式(anchor): 使用图片原始尺寸 4.17x2.00 cm,跳过段落约束放宽与缩放兜底
|
||||
[2026-07-20 14:44:34] [INFO] [lib.field_codes] [Word处理] 在 USER_张三 域后插入图片成功 (mode=anchor)
|
||||
[2026-07-20 14:44:34] [INFO] [lib.field_codes] [Word处理] 浮动覆盖模式(anchor): 使用图片原始尺寸 4.17x2.00 cm,跳过段落约束放宽与缩放兜底
|
||||
[2026-07-20 14:44:34] [INFO] [lib.field_codes] [Word处理] 在 USER_张三 域后插入图片成功 (mode=anchor)
|
||||
[2026-07-20 14:44:34] [INFO] [lib.field_codes] [Word处理] 浮动覆盖模式(anchor): 使用图片原始尺寸 4.17x2.00 cm,跳过段落约束放宽与缩放兜底
|
||||
[2026-07-20 14:44:34] [INFO] [lib.field_codes] [Word处理] 在 USER_张三 域后插入图片成功 (mode=anchor)
|
||||
[2026-07-20 14:44:34] [INFO] [lib.word_signer] [签章流程] 盖章项1签章成功: marker=USER_张三, 插入3处
|
||||
[2026-07-20 14:44:34] [INFO] [lib.word_signer] [签章流程] ====== 处理完成 ====== 成功3项, 告警0条, trace_id=20260720144433414845_5980
|
||||
[2026-07-20 14:45:09] [INFO] [routes.api] [请求接入] 客户端IP=127.0.0.1, 接口=/api/word/sign, trace_id=20260720144509334655_5980
|
||||
[2026-07-20 14:45:09] [INFO] [routes.api] [参数校验] 校验通过
|
||||
[2026-07-20 14:45:09] [INFO] [lib.word_signer] [签章流程] ====== 开始处理 ====== trace_id=20260720144509334655_5980
|
||||
[2026-07-20 14:45:09] [INFO] [lib.word_signer] [签章流程] 文件名: 通用闭环验证系统应用软件测试报告.docx
|
||||
[2026-07-20 14:45:09] [INFO] [lib.word_signer] [签章流程] 匹配模式: auto
|
||||
[2026-07-20 14:45:09] [INFO] [lib.word_signer] [签章流程] Word文档加载成功
|
||||
[2026-07-20 14:45:09] [INFO] [lib.field_codes] [auto扫描] 发现 1 个 SET USER_<name> 标记
|
||||
[2026-07-20 14:45:09] [INFO] [lib.word_signer] [签章流程] auto模式扫描到 1 个标记
|
||||
[2026-07-20 14:45:09] [INFO] [lib.word_signer] [签章流程] ---- 处理盖章项 1/1 ----
|
||||
[2026-07-20 14:45:09] [INFO] [lib.word_signer] [图片匹配] auto模式, 标记=USER_张三, 查询姓名=张三
|
||||
[2026-07-20 14:45:09] [INFO] [lib.word_signer] [图片匹配] auto匹配成功: 张三
|
||||
[2026-07-20 14:45:09] [INFO] [lib.image_processor] [图片处理] 原始图片: 模式=RGB, 尺寸=(2048, 1382)
|
||||
[2026-07-20 14:45:09] [INFO] [lib.image_processor] [图片处理] 执行手写签字黑白二值化
|
||||
[2026-07-20 14:45:09] [INFO] [lib.image_processor] [图片处理] 执行白底转透明抠图
|
||||
[2026-07-20 14:45:10] [INFO] [lib.image_processor] [图片处理] 执行透明边框裁剪
|
||||
[2026-07-20 14:45:10] [INFO] [lib.image_processor] [图片处理] 剔除噪点簇: 共 59 簇,移除 52 簇 (143 像素,占内容 0.16%);阈值=187 px (相对 0.010% + 绝对 50 px)
|
||||
[2026-07-20 14:45:10] [INFO] [lib.image_processor] [图片处理] 紧致裁剪诊断: 尺寸=(2025, 921), bbox=(254, 0, 1756, 721), 高alpha像素=90114/1865025 (4.8%), 暗像素=90257/1865025 (4.8%), 内容像素=90114/1865025 (4.8%)
|
||||
[2026-07-20 14:45:10] [INFO] [lib.image_processor] [图片处理] 紧致裁剪: (2025, 921) -> (1502, 721) (bbox=(254, 0, 1756, 721))
|
||||
[2026-07-20 14:45:10] [INFO] [lib.image_processor] [图片处理] 处理完成: 最终尺寸=(1502, 721), 大小=18659 bytes
|
||||
[2026-07-20 14:45:10] [INFO] [lib.word_signer] [签章流程][DEBUG] 已保存处理前后对比图到 E:\projects\wxwx\projects_job\GeneralRequirement\SignatureSystem\BackEnd\Code\image_test\output\project_run (tag=20260720144509334655_5980_stamp1)
|
||||
[2026-07-20 14:45:10] [INFO] [lib.field_codes] [Word处理] 自动尺寸: 字号=14.0pt → 推算 height=0.99 cm
|
||||
[2026-07-20 14:45:10] [INFO] [lib.field_codes] [Word处理] 浮动覆盖模式(anchor): 使用图片原始尺寸 2.06x0.99 cm,跳过段落约束放宽与缩放兜底
|
||||
[2026-07-20 14:45:10] [INFO] [lib.field_codes] [Word处理] 在 USER_张三 域后插入图片成功 (mode=anchor)
|
||||
[2026-07-20 14:45:10] [INFO] [lib.field_codes] [Word处理] 自动尺寸: 字号=14.0pt → 推算 height=0.99 cm
|
||||
[2026-07-20 14:45:10] [INFO] [lib.field_codes] [Word处理] 浮动覆盖模式(anchor): 使用图片原始尺寸 2.06x0.99 cm,跳过段落约束放宽与缩放兜底
|
||||
[2026-07-20 14:45:10] [INFO] [lib.field_codes] [Word处理] 在 USER_张三 域后插入图片成功 (mode=anchor)
|
||||
[2026-07-20 14:45:10] [INFO] [lib.field_codes] [Word处理] 段落无显式字号,使用文档默认字号 无pt
|
||||
[2026-07-20 14:45:10] [INFO] [lib.field_codes] [Word处理] 自动尺寸: 字号=无pt → 推算 height=0.74 cm
|
||||
[2026-07-20 14:45:10] [INFO] [lib.field_codes] [Word处理] 浮动覆盖模式(anchor): 使用图片原始尺寸 1.54x0.74 cm,跳过段落约束放宽与缩放兜底
|
||||
[2026-07-20 14:45:10] [INFO] [lib.field_codes] [Word处理] 在 USER_张三 域后插入图片成功 (mode=anchor)
|
||||
[2026-07-20 14:45:10] [INFO] [lib.word_signer] [签章流程] 盖章项1签章成功: marker=USER_张三, 插入3处
|
||||
[2026-07-20 14:45:10] [INFO] [lib.word_signer] [签章流程] ====== 处理完成 ====== 成功3项, 告警0条, trace_id=20260720144509334655_5980
|
||||
[2026-07-20 14:45:44] [INFO] [routes.api] [请求接入] 客户端IP=127.0.0.1, 接口=/api/word/sign, trace_id=20260720144544566824_5980
|
||||
[2026-07-20 14:45:44] [INFO] [routes.api] [参数校验] 校验通过
|
||||
[2026-07-20 14:45:44] [INFO] [lib.word_signer] [签章流程] ====== 开始处理 ====== trace_id=20260720144544566824_5980
|
||||
[2026-07-20 14:45:44] [INFO] [lib.word_signer] [签章流程] 文件名: 通用闭环验证系统应用软件测试报告.docx
|
||||
[2026-07-20 14:45:44] [INFO] [lib.word_signer] [签章流程] 匹配模式: auto
|
||||
[2026-07-20 14:45:44] [INFO] [lib.word_signer] [签章流程] Word文档加载成功
|
||||
[2026-07-20 14:45:44] [INFO] [lib.field_codes] [auto扫描] 发现 1 个 SET USER_<name> 标记
|
||||
[2026-07-20 14:45:44] [INFO] [lib.word_signer] [签章流程] auto模式扫描到 1 个标记
|
||||
[2026-07-20 14:45:44] [INFO] [lib.word_signer] [签章流程] ---- 处理盖章项 1/1 ----
|
||||
[2026-07-20 14:45:44] [INFO] [lib.word_signer] [图片匹配] auto模式, 标记=USER_张三, 查询姓名=张三
|
||||
[2026-07-20 14:45:44] [INFO] [lib.word_signer] [图片匹配] auto匹配成功: 张三
|
||||
[2026-07-20 14:45:44] [INFO] [lib.image_processor] [图片处理] 原始图片: 模式=RGB, 尺寸=(2048, 1382)
|
||||
[2026-07-20 14:45:44] [INFO] [lib.image_processor] [图片处理] 执行手写签字黑白二值化
|
||||
[2026-07-20 14:45:44] [INFO] [lib.image_processor] [图片处理] 执行白底转透明抠图
|
||||
[2026-07-20 14:45:45] [INFO] [lib.image_processor] [图片处理] 执行透明边框裁剪
|
||||
[2026-07-20 14:45:45] [INFO] [lib.image_processor] [图片处理] 剔除噪点簇: 共 59 簇,移除 52 簇 (143 像素,占内容 0.16%);阈值=187 px (相对 0.010% + 绝对 50 px)
|
||||
[2026-07-20 14:45:45] [INFO] [lib.image_processor] [图片处理] 紧致裁剪诊断: 尺寸=(2025, 921), bbox=(254, 0, 1756, 721), 高alpha像素=90114/1865025 (4.8%), 暗像素=90257/1865025 (4.8%), 内容像素=90114/1865025 (4.8%)
|
||||
[2026-07-20 14:45:45] [INFO] [lib.image_processor] [图片处理] 紧致裁剪: (2025, 921) -> (1502, 721) (bbox=(254, 0, 1756, 721))
|
||||
[2026-07-20 14:45:45] [INFO] [lib.image_processor] [图片处理] 处理完成: 最终尺寸=(1502, 721), 大小=18659 bytes
|
||||
[2026-07-20 14:45:45] [INFO] [lib.word_signer] [签章流程][DEBUG] 已保存处理前后对比图到 E:\projects\wxwx\projects_job\GeneralRequirement\SignatureSystem\BackEnd\Code\image_test\output\project_run (tag=20260720144544566824_5980_stamp1)
|
||||
[2026-07-20 14:45:45] [INFO] [lib.field_codes] [Word处理] 自动尺寸: 字号=14.0pt → 推算 height=0.99 cm
|
||||
[2026-07-20 14:45:45] [INFO] [lib.field_codes] [Word处理] 浮动覆盖模式(anchor): 使用图片原始尺寸 2.06x0.99 cm,跳过段落约束放宽与缩放兜底
|
||||
[2026-07-20 14:45:45] [INFO] [lib.field_codes] [Word处理] 在 USER_张三 域后插入图片成功 (mode=anchor)
|
||||
[2026-07-20 14:45:45] [INFO] [lib.field_codes] [Word处理] 自动尺寸: 字号=14.0pt → 推算 height=0.99 cm
|
||||
[2026-07-20 14:45:45] [INFO] [lib.field_codes] [Word处理] 浮动覆盖模式(anchor): 使用图片原始尺寸 2.06x0.99 cm,跳过段落约束放宽与缩放兜底
|
||||
[2026-07-20 14:45:45] [INFO] [lib.field_codes] [Word处理] 在 USER_张三 域后插入图片成功 (mode=anchor)
|
||||
[2026-07-20 14:45:45] [INFO] [lib.field_codes] [Word处理] 段落无显式字号,使用文档默认字号 无pt
|
||||
[2026-07-20 14:45:45] [INFO] [lib.field_codes] [Word处理] 自动尺寸: 字号=无pt → 推算 height=0.74 cm
|
||||
[2026-07-20 14:45:45] [INFO] [lib.field_codes] [Word处理] 浮动覆盖模式(anchor): 使用图片原始尺寸 1.54x0.74 cm,跳过段落约束放宽与缩放兜底
|
||||
[2026-07-20 14:45:45] [INFO] [lib.field_codes] [Word处理] 在 USER_张三 域后插入图片成功 (mode=anchor)
|
||||
[2026-07-20 14:45:45] [INFO] [lib.word_signer] [签章流程] 盖章项1签章成功: marker=USER_张三, 插入3处
|
||||
[2026-07-20 14:45:45] [INFO] [lib.word_signer] [签章流程] ====== 处理完成 ====== 成功3项, 告警0条, trace_id=20260720144544566824_5980
|
||||
[2026-07-20 14:47:00] [INFO] [routes.api] [请求接入] 客户端IP=127.0.0.1, 接口=/api/word/sign, trace_id=20260720144700118405_5980
|
||||
[2026-07-20 14:47:00] [INFO] [routes.api] [参数校验] 校验通过
|
||||
[2026-07-20 14:47:00] [INFO] [lib.word_signer] [签章流程] ====== 开始处理 ====== trace_id=20260720144700118405_5980
|
||||
[2026-07-20 14:47:00] [INFO] [lib.word_signer] [签章流程] 文件名: 通用闭环验证系统应用软件测试报告.docx
|
||||
[2026-07-20 14:47:00] [INFO] [lib.word_signer] [签章流程] 匹配模式: auto
|
||||
[2026-07-20 14:47:00] [INFO] [lib.word_signer] [签章流程] Word文档加载成功
|
||||
[2026-07-20 14:47:00] [INFO] [lib.field_codes] [auto扫描] 发现 1 个 SET USER_<name> 标记
|
||||
[2026-07-20 14:47:00] [INFO] [lib.word_signer] [签章流程] auto模式扫描到 1 个标记
|
||||
[2026-07-20 14:47:00] [INFO] [lib.word_signer] [签章流程] ---- 处理盖章项 1/1 ----
|
||||
[2026-07-20 14:47:00] [INFO] [lib.word_signer] [图片匹配] auto模式, 标记=USER_张三, 查询姓名=张三
|
||||
[2026-07-20 14:47:00] [INFO] [lib.word_signer] [图片匹配] auto匹配成功: 张三
|
||||
[2026-07-20 14:47:00] [INFO] [lib.image_processor] [图片处理] 原始图片: 模式=RGB, 尺寸=(2048, 1382)
|
||||
[2026-07-20 14:47:00] [INFO] [lib.image_processor] [图片处理] 执行手写签字黑白二值化
|
||||
[2026-07-20 14:47:00] [INFO] [lib.image_processor] [图片处理] 执行白底转透明抠图
|
||||
[2026-07-20 14:47:00] [INFO] [lib.image_processor] [图片处理] 执行透明边框裁剪
|
||||
[2026-07-20 14:47:01] [INFO] [lib.image_processor] [图片处理] 剔除噪点簇: 共 59 簇,移除 52 簇 (143 像素,占内容 0.16%);阈值=187 px (相对 0.010% + 绝对 50 px)
|
||||
[2026-07-20 14:47:01] [INFO] [lib.image_processor] [图片处理] 紧致裁剪诊断: 尺寸=(2025, 921), bbox=(254, 0, 1756, 721), 高alpha像素=90114/1865025 (4.8%), 暗像素=90257/1865025 (4.8%), 内容像素=90114/1865025 (4.8%)
|
||||
[2026-07-20 14:47:01] [INFO] [lib.image_processor] [图片处理] 紧致裁剪: (2025, 921) -> (1502, 721) (bbox=(254, 0, 1756, 721))
|
||||
[2026-07-20 14:47:01] [INFO] [lib.image_processor] [图片处理] 处理完成: 最终尺寸=(1502, 721), 大小=18659 bytes
|
||||
[2026-07-20 14:47:01] [INFO] [lib.word_signer] [签章流程][DEBUG] 已保存处理前后对比图到 E:\projects\wxwx\projects_job\GeneralRequirement\SignatureSystem\BackEnd\Code\image_test\output\project_run (tag=20260720144700118405_5980_stamp1)
|
||||
[2026-07-20 14:47:01] [INFO] [lib.field_codes] [Word处理] 自动尺寸: 字号=14.0pt → 推算 height=0.99 cm
|
||||
[2026-07-20 14:47:01] [INFO] [lib.field_codes] [Word处理] 浮动覆盖模式(anchor): 使用图片原始尺寸 2.06x0.99 cm,跳过段落约束放宽与缩放兜底
|
||||
[2026-07-20 14:47:01] [INFO] [lib.field_codes] [Word处理] 在 USER_张三 域后插入图片成功 (mode=anchor)
|
||||
[2026-07-20 14:47:01] [INFO] [lib.field_codes] [Word处理] 自动尺寸: 字号=14.0pt → 推算 height=0.99 cm
|
||||
[2026-07-20 14:47:01] [INFO] [lib.field_codes] [Word处理] 浮动覆盖模式(anchor): 使用图片原始尺寸 2.06x0.99 cm,跳过段落约束放宽与缩放兜底
|
||||
[2026-07-20 14:47:01] [INFO] [lib.field_codes] [Word处理] 在 USER_张三 域后插入图片成功 (mode=anchor)
|
||||
[2026-07-20 14:47:01] [INFO] [lib.field_codes] [Word处理] 段落无显式字号,使用文档默认字号 无pt
|
||||
[2026-07-20 14:47:01] [INFO] [lib.field_codes] [Word处理] 自动尺寸: 字号=无pt → 推算 height=0.74 cm
|
||||
[2026-07-20 14:47:01] [INFO] [lib.field_codes] [Word处理] 浮动覆盖模式(anchor): 使用图片原始尺寸 1.54x0.74 cm,跳过段落约束放宽与缩放兜底
|
||||
[2026-07-20 14:47:01] [INFO] [lib.field_codes] [Word处理] 在 USER_张三 域后插入图片成功 (mode=anchor)
|
||||
[2026-07-20 14:47:01] [INFO] [lib.word_signer] [签章流程] 盖章项1签章成功: marker=USER_张三, 插入3处
|
||||
[2026-07-20 14:47:01] [INFO] [lib.word_signer] [签章流程] ====== 处理完成 ====== 成功3项, 告警0条, trace_id=20260720144700118405_5980
|
||||
[2026-07-20 14:59:52] [INFO] [__main__] ===== 自动签名系统启动 =====
|
||||
[2026-07-20 14:59:52] [INFO] [__main__] 限制配置: docx_max=1048576 bytes, image_max=262144 bytes, stamp_max=100, log_max=1000
|
||||
[2026-07-20 14:59:52] [INFO] [lib.db] MySQL 数据表初始化完成
|
||||
[2026-07-20 14:59:52] [INFO] [lib.db] 数据库初始化完成 (MySQL)
|
||||
[2026-07-20 14:59:52] [INFO] [__main__] 数据库初始化完成, 当前使用: MYSQL
|
||||
[2026-07-20 14:59:52] [INFO] [__main__] Web服务: 0.0.0.0:5001, debug=False
|
||||
[2026-07-20 14:59:52] [INFO] [__main__] 使用 Waitress 生产服务器
|
||||
[2026-07-20 14:59:52] [INFO] [waitress] Serving on http://0.0.0.0:5001
|
||||
[2026-07-20 15:00:21] [INFO] [routes.api] [请求接入] 客户端IP=127.0.0.1, 接口=/api/word/sign, trace_id=20260720150021573226_20828
|
||||
[2026-07-20 15:00:21] [INFO] [routes.api] [参数校验] 校验通过
|
||||
[2026-07-20 15:00:21] [INFO] [lib.word_signer] [签章流程] ====== 开始处理 ====== trace_id=20260720150021573226_20828
|
||||
[2026-07-20 15:00:21] [INFO] [lib.word_signer] [签章流程] 文件名: 通用闭环验证系统应用软件测试报告.docx
|
||||
[2026-07-20 15:00:21] [INFO] [lib.word_signer] [签章流程] 匹配模式: auto
|
||||
[2026-07-20 15:00:21] [INFO] [lib.word_signer] [签章流程] Word文档加载成功
|
||||
[2026-07-20 15:00:21] [INFO] [lib.field_codes] [auto扫描] 发现 1 个 SET USER_<name> 标记
|
||||
[2026-07-20 15:00:21] [INFO] [lib.word_signer] [签章流程] auto模式扫描到 1 个标记
|
||||
[2026-07-20 15:00:21] [INFO] [lib.word_signer] [签章流程] ---- 处理盖章项 1/1 ----
|
||||
[2026-07-20 15:00:21] [INFO] [lib.word_signer] [图片匹配] auto模式, 标记=USER_张三, 查询姓名=张三
|
||||
[2026-07-20 15:00:21] [INFO] [lib.word_signer] [图片匹配] auto匹配成功: 张三
|
||||
[2026-07-20 15:00:21] [INFO] [lib.image_processor] [图片处理] 原始图片: 模式=RGB, 尺寸=(2048, 1382)
|
||||
[2026-07-20 15:00:21] [INFO] [lib.image_processor] [图片处理] 执行手写签字黑白二值化
|
||||
[2026-07-20 15:00:21] [INFO] [lib.image_processor] [图片处理] 执行白底转透明抠图
|
||||
[2026-07-20 15:00:22] [INFO] [lib.image_processor] [图片处理] 执行透明边框裁剪
|
||||
[2026-07-20 15:00:22] [INFO] [lib.image_processor] [图片处理] 剔除噪点簇: 共 59 簇,移除 52 簇 (143 像素,占内容 0.16%);阈值=187 px (相对 0.010% + 绝对 50 px)
|
||||
[2026-07-20 15:00:22] [INFO] [lib.image_processor] [图片处理] 紧致裁剪诊断: 尺寸=(2025, 921), bbox=(254, 0, 1756, 721), 高alpha像素=90114/1865025 (4.8%), 暗像素=90257/1865025 (4.8%), 内容像素=90114/1865025 (4.8%)
|
||||
[2026-07-20 15:00:22] [INFO] [lib.image_processor] [图片处理] 紧致裁剪: (2025, 921) -> (1502, 721) (bbox=(254, 0, 1756, 721))
|
||||
[2026-07-20 15:00:22] [INFO] [lib.image_processor] [图片处理] 处理完成: 最终尺寸=(1502, 721), 大小=18659 bytes
|
||||
[2026-07-20 15:00:22] [INFO] [lib.word_signer] [签章流程][DEBUG] 已保存处理前后对比图到 E:\projects\wxwx\projects_job\GeneralRequirement\SignatureSystem\BackEnd\Code\image_test\output\project_run (tag=20260720150021573226_20828_stamp1)
|
||||
[2026-07-20 15:00:22] [INFO] [lib.field_codes] [Word处理] 自动尺寸: 字号=14.0pt → 推算 height=0.99 cm
|
||||
[2026-07-20 15:00:22] [INFO] [lib.field_codes] [Word处理] 浮动覆盖模式(anchor): 使用图片原始尺寸 2.06x0.99 cm,跳过段落约束放宽与缩放兜底
|
||||
[2026-07-20 15:00:22] [INFO] [lib.field_codes] [Word处理] 在 USER_张三 域后插入图片成功 (mode=anchor)
|
||||
[2026-07-20 15:00:22] [INFO] [lib.field_codes] [Word处理] 自动尺寸: 字号=14.0pt → 推算 height=0.99 cm
|
||||
[2026-07-20 15:00:22] [INFO] [lib.field_codes] [Word处理] 浮动覆盖模式(anchor): 使用图片原始尺寸 2.06x0.99 cm,跳过段落约束放宽与缩放兜底
|
||||
[2026-07-20 15:00:22] [INFO] [lib.field_codes] [Word处理] 在 USER_张三 域后插入图片成功 (mode=anchor)
|
||||
[2026-07-20 15:00:22] [INFO] [lib.field_codes] [Word处理] 段落无显式字号,使用文档默认字号 无pt
|
||||
[2026-07-20 15:00:22] [INFO] [lib.field_codes] [Word处理] 自动尺寸: 字号=无pt → 推算 height=0.74 cm
|
||||
[2026-07-20 15:00:22] [INFO] [lib.field_codes] [Word处理] 浮动覆盖模式(anchor): 使用图片原始尺寸 1.54x0.74 cm,跳过段落约束放宽与缩放兜底
|
||||
[2026-07-20 15:00:22] [INFO] [lib.field_codes] [Word处理] 在 USER_张三 域后插入图片成功 (mode=anchor)
|
||||
[2026-07-20 15:00:22] [INFO] [lib.word_signer] [签章流程] 盖章项1签章成功: marker=USER_张三, 插入3处
|
||||
[2026-07-20 15:00:22] [INFO] [lib.word_signer] [签章流程] ====== 处理完成 ====== 成功3项, 告警0条, trace_id=20260720150021573226_20828
|
||||
[2026-07-20 15:22:05] [INFO] [__main__] ===== 自动签名系统启动 =====
|
||||
[2026-07-20 15:22:05] [INFO] [__main__] 限制配置: docx_max=1048576 bytes, image_max=262144 bytes, stamp_max=100, log_max=1000
|
||||
[2026-07-20 15:22:05] [INFO] [lib.db] MySQL 数据表初始化完成
|
||||
[2026-07-20 15:22:05] [INFO] [lib.db] 数据库初始化完成 (MySQL)
|
||||
[2026-07-20 15:22:05] [INFO] [__main__] 数据库初始化完成, 当前使用: MYSQL
|
||||
[2026-07-20 15:22:05] [INFO] [__main__] Web服务: 0.0.0.0:5001, debug=False
|
||||
[2026-07-20 15:22:05] [INFO] [__main__] 使用 Waitress 生产服务器
|
||||
[2026-07-20 15:22:05] [INFO] [waitress] Serving on http://0.0.0.0:5001
|
||||
[2026-07-20 16:37:34] [INFO] [__main__] ===== 自动签名系统启动 =====
|
||||
[2026-07-20 16:37:34] [INFO] [__main__] 限制配置: docx_max=1048576 bytes, image_max=262144 bytes, stamp_max=100, log_max=1000
|
||||
[2026-07-20 16:37:34] [INFO] [lib.db] MySQL 数据表初始化完成
|
||||
[2026-07-20 16:37:34] [INFO] [lib.db] 数据库初始化完成 (MySQL)
|
||||
[2026-07-20 16:37:34] [INFO] [__main__] 数据库初始化完成, 当前使用: MYSQL
|
||||
[2026-07-20 16:37:34] [INFO] [__main__] Web服务: 0.0.0.0:5001, debug=False
|
||||
[2026-07-20 16:37:34] [INFO] [__main__] 使用 Waitress 生产服务器
|
||||
[2026-07-20 16:37:34] [INFO] [waitress] Serving on http://0.0.0.0:5001
|
||||
|
||||
5301
mysql/LICENSE
Normal file
17
mysql/README
Normal file
@@ -0,0 +1,17 @@
|
||||
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
|
||||
|
||||
This is a release of MySQL, an SQL database server.
|
||||
|
||||
License information can be found in the LICENSE file.
|
||||
|
||||
This distribution may include materials developed by third parties.
|
||||
For license and attribution notices for these materials,
|
||||
please refer to the LICENSE file.
|
||||
|
||||
For further information on MySQL or additional documentation, visit
|
||||
http://dev.mysql.com/doc/
|
||||
|
||||
For additional downloads and the source of MySQL, visit
|
||||
http://dev.mysql.com/downloads/
|
||||
|
||||
MySQL is brought to you by the MySQL team at Oracle.
|
||||
BIN
mysql/bin/echo.exe
Normal file
BIN
mysql/bin/innochecksum.exe
Normal file
BIN
mysql/bin/libmecab.dll
Normal file
BIN
mysql/bin/libsasl.dll
Normal file
BIN
mysql/bin/lz4_decompress.exe
Normal file
BIN
mysql/bin/my_print_defaults.exe
Normal file
BIN
mysql/bin/myisam_ftdump.exe
Normal file
BIN
mysql/bin/myisamchk.exe
Normal file
BIN
mysql/bin/myisamlog.exe
Normal file
BIN
mysql/bin/myisampack.exe
Normal file
BIN
mysql/bin/mysql.exe
Normal file
BIN
mysql/bin/mysql_client_test_embedded.exe
Normal file
252
mysql/bin/mysql_config.pl
Normal file
@@ -0,0 +1,252 @@
|
||||
#!/usr/bin/perl
|
||||
# -*- cperl -*-
|
||||
#
|
||||
# Copyright (c) 2007, 2023, Oracle and/or its affiliates.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License, version 2.0,
|
||||
# as published by the Free Software Foundation.
|
||||
#
|
||||
# This program is also distributed with certain software (including
|
||||
# but not limited to OpenSSL) that is licensed under separate terms,
|
||||
# as designated in a particular file or component or in included license
|
||||
# documentation. The authors of MySQL hereby grant you an additional
|
||||
# permission to link the program and your derivative works with the
|
||||
# separately licensed software that they have included with MySQL.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License, version 2.0, for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# This script reports various configuration settings that may be needed
|
||||
# when using the MySQL client library.
|
||||
#
|
||||
# This script try to match the shell script version as close as possible,
|
||||
# but in addition being compatible with ActiveState Perl on Windows.
|
||||
#
|
||||
# All unrecognized arguments to this script are passed to mysqld.
|
||||
#
|
||||
# NOTE: This script will only be used on Windows until solved how to
|
||||
# handle and other strings inserted that might contain
|
||||
# several arguments, possibly with spaces in them.
|
||||
#
|
||||
# NOTE: This script was deliberately written to be as close to the shell
|
||||
# script as possible, to make the maintenance of both in parallel
|
||||
# easier.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
use File::Basename;
|
||||
use Getopt::Long;
|
||||
use Cwd;
|
||||
use strict;
|
||||
|
||||
my $cwd = cwd();
|
||||
my $basedir;
|
||||
|
||||
my $socket = '/tmp/mysql.sock';
|
||||
my $version = '5.7.44';
|
||||
|
||||
sub which
|
||||
{
|
||||
my $file = shift;
|
||||
|
||||
my $IFS = $^O eq "MSWin32" ? ";" : ":";
|
||||
|
||||
foreach my $dir ( split($IFS, $ENV{PATH}) )
|
||||
{
|
||||
if ( -f "$dir/$file" or -f "$dir/$file.exe" )
|
||||
{
|
||||
return "$dir/$file";
|
||||
}
|
||||
}
|
||||
print STDERR "which: no $file in ($ENV{PATH})\n";
|
||||
exit 1;
|
||||
}
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
# If we can find the given directory relatively to where mysql_config is
|
||||
# we should use this instead of the incompiled one.
|
||||
# This is to ensure that this script also works with the binary MySQL
|
||||
# version
|
||||
# ----------------------------------------------------------------------
|
||||
|
||||
sub fix_path
|
||||
{
|
||||
my $default = shift;
|
||||
my @dirs = @_;
|
||||
|
||||
foreach my $dirname ( @dirs )
|
||||
{
|
||||
my $path = "$basedir/$dirname";
|
||||
if ( -d $path )
|
||||
{
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
return $default;
|
||||
}
|
||||
|
||||
sub get_full_path
|
||||
{
|
||||
my $file = shift;
|
||||
|
||||
# if the file is a symlink, try to resolve it
|
||||
if ( $^O ne "MSWin32" and -l $file )
|
||||
{
|
||||
$file = readlink($file);
|
||||
}
|
||||
|
||||
if ( $file =~ m,^/, )
|
||||
{
|
||||
# Do nothing, absolute path
|
||||
}
|
||||
elsif ( $file =~ m,/, )
|
||||
{
|
||||
# Make absolute, and remove "/./" in path
|
||||
$file = "$cwd/$file";
|
||||
$file =~ s,/\./,/,g;
|
||||
}
|
||||
else
|
||||
{
|
||||
# Find in PATH
|
||||
$file = which($file);
|
||||
}
|
||||
|
||||
return $file;
|
||||
}
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Form a command line that can handle spaces in paths and arguments
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
sub quote_options {
|
||||
my @cmd;
|
||||
foreach my $opt ( @_ )
|
||||
{
|
||||
next unless $opt; # If undefined or empty, just skip
|
||||
push(@cmd, "\"$opt\""); # Quote argument
|
||||
}
|
||||
return join(" ", @cmd);
|
||||
}
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Main program
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
my $me = get_full_path($0);
|
||||
$basedir = dirname(dirname($me)); # Remove "/bin/mysql_config" part
|
||||
|
||||
my $ldata = 'C:/Program Files/MySQL/MySQL Server 5.7/data';
|
||||
my $execdir = 'C:/Program Files (x86)/MySQL/bin';
|
||||
my $bindir = 'C:/Program Files (x86)/MySQL/bin';
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
# If installed, search for the compiled in directory first (might be "lib64")
|
||||
# ----------------------------------------------------------------------
|
||||
|
||||
my $pkglibdir = fix_path('C:/Program Files (x86)/MySQL/lib',"libmysql/relwithdebinfo",
|
||||
"libmysql/release","libmysql/debug","lib/mysql","lib");
|
||||
|
||||
my $pkgincludedir = fix_path('C:/Program Files (x86)/MySQL/include', "include/mysql", "include");
|
||||
|
||||
# Assume no argument with space in it
|
||||
my @ldflags = split(" ",'');
|
||||
|
||||
my $port;
|
||||
if ( '0' == 0 ) {
|
||||
$port = 0;
|
||||
} else {
|
||||
$port = '3306';
|
||||
}
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
# Create options
|
||||
# ----------------------------------------------------------------------
|
||||
|
||||
my(@lib_opts,@lib_e_opts);
|
||||
if ( $^O eq "MSWin32" )
|
||||
{
|
||||
my $linkpath = "$pkglibdir";
|
||||
@lib_opts = ("$linkpath/LIBMYSQL_OS_OUTPUT_NAME-NOTFOUND");
|
||||
@lib_e_opts = ("$linkpath/mysqlserver");
|
||||
}
|
||||
else
|
||||
{
|
||||
my $linkpath = "-L$pkglibdir";
|
||||
@lib_opts = ($linkpath,"-lLIBMYSQL_OS_OUTPUT_NAME-NOTFOUND");
|
||||
@lib_e_opts = ($linkpath,"-lmysqlserver");
|
||||
}
|
||||
|
||||
|
||||
my $flags;
|
||||
$flags->{libs} = [@lib_opts, qw(ws2_32 crypt32 Secur32)];
|
||||
$flags->{embedded_libs} = [@lib_e_opts, qw(ws2_32 crypt32)];
|
||||
|
||||
$flags->{include} = ["-I$pkgincludedir"];
|
||||
$flags->{cflags} = [@{$flags->{include}},split(" ",'')];
|
||||
$flags->{cxxflags}= [@{$flags->{include}},split(" ",'')];
|
||||
|
||||
my $include = quote_options(@{$flags->{include}});
|
||||
my $cflags = quote_options(@{$flags->{cflags}});
|
||||
my $cxxflags= quote_options(@{$flags->{cxxflags}});
|
||||
my $libs = quote_options(@{$flags->{libs}});
|
||||
my $embedded_libs = quote_options(@{$flags->{embedded_libs}});
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Usage information, output if no option is given
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
sub usage
|
||||
{
|
||||
print <<EOF;
|
||||
Usage: $0 [OPTIONS]
|
||||
Options:
|
||||
--cflags [$cflags]
|
||||
--cxxflags [$cxxflags]
|
||||
--include [$include]
|
||||
--libs [$libs]
|
||||
--libs_r [$libs]
|
||||
--socket [$socket]
|
||||
--port [$port]
|
||||
--version [$version]
|
||||
--libmysqld-libs [$embedded_libs]
|
||||
EOF
|
||||
exit 1;
|
||||
}
|
||||
|
||||
@ARGV or usage();
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Get options and output the values
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
GetOptions(
|
||||
"cflags" => sub { print "$cflags\n" },
|
||||
"cxxflags"=> sub { print "$cxxflags\n" },
|
||||
"include" => sub { print "$include\n" },
|
||||
"libs" => sub { print "$libs\n" },
|
||||
"libs_r" => sub { print "$libs\n" },
|
||||
"socket" => sub { print "$socket\n" },
|
||||
"port" => sub { print "$port\n" },
|
||||
"version" => sub { print "$version\n" },
|
||||
"embedded-libs|embedded|libmysqld-libs" =>
|
||||
sub { print "$embedded_libs\n" },
|
||||
) or usage();
|
||||
|
||||
exit 0
|
||||
BIN
mysql/bin/mysql_config_editor.exe
Normal file
BIN
mysql/bin/mysql_embedded.exe
Normal file
BIN
mysql/bin/mysql_plugin.exe
Normal file
BIN
mysql/bin/mysql_secure_installation.exe
Normal file
BIN
mysql/bin/mysql_ssl_rsa_setup.exe
Normal file
BIN
mysql/bin/mysql_tzinfo_to_sql.exe
Normal file
BIN
mysql/bin/mysql_upgrade.exe
Normal file
BIN
mysql/bin/mysqladmin.exe
Normal file
BIN
mysql/bin/mysqlbinlog.exe
Normal file
BIN
mysql/bin/mysqlcheck.exe
Normal file
BIN
mysql/bin/mysqld.exe
Normal file
BIN
mysql/bin/mysqld.pdb
Normal file
926
mysql/bin/mysqld_multi.pl
Normal file
@@ -0,0 +1,926 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
# Copyright (c) 2000, 2023, Oracle and/or its affiliates.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License, version 2.0,
|
||||
# as published by the Free Software Foundation.
|
||||
#
|
||||
# This program is also distributed with certain software (including
|
||||
# but not limited to OpenSSL) that is licensed under separate terms,
|
||||
# as designated in a particular file or component or in included license
|
||||
# documentation. The authors of MySQL hereby grant you an additional
|
||||
# permission to link the program and your derivative works with the
|
||||
# separately licensed software that they have included with MySQL.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License, version 2.0, for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Library General Public
|
||||
# License along with this library; if not, write to the Free
|
||||
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
|
||||
# MA 02110-1301, USA
|
||||
|
||||
use Getopt::Long;
|
||||
use POSIX qw(strftime getcwd);
|
||||
use File::Path qw(mkpath);
|
||||
|
||||
$|=1;
|
||||
$VER="2.16";
|
||||
|
||||
my @defaults_options; # Leading --no-defaults, --defaults-file, etc.
|
||||
|
||||
$opt_example = 0;
|
||||
$opt_help = 0;
|
||||
$opt_log = undef();
|
||||
$opt_mysqladmin = "C:/Program Files (x86)/MySQL/bin/mysqladmin";
|
||||
$opt_mysqld = "C:/Program Files (x86)/MySQL/bin/mysqld";
|
||||
$opt_no_log = 0;
|
||||
$opt_password = undef();
|
||||
$opt_tcp_ip = 0;
|
||||
$opt_user = "root";
|
||||
$opt_version = 0;
|
||||
$opt_silent = 0;
|
||||
$opt_verbose = 0;
|
||||
|
||||
my $my_print_defaults_exists= 1;
|
||||
my $logdir= undef();
|
||||
|
||||
my ($mysqld, $mysqladmin, $groupids, $homedir, $my_progname);
|
||||
|
||||
$homedir = $ENV{HOME};
|
||||
$my_progname = $0;
|
||||
$my_progname =~ s/.*[\/]//;
|
||||
|
||||
|
||||
if (defined($ENV{UMASK})) {
|
||||
my $UMASK = $ENV{UMASK};
|
||||
my $m;
|
||||
my $fmode = "0640";
|
||||
|
||||
if(($UMASK =~ m/[^0246]/) || ($UMASK =~ m/^[^0]/) || (length($UMASK) != 4)) {
|
||||
printf("UMASK must be a 3-digit mode with an additional leading 0 to indicate octal.\n");
|
||||
printf("The first digit will be corrected to 6, the others may be 0, 2, 4, or 6.\n"); }
|
||||
else {
|
||||
$fmode= substr $UMASK, 2, 2;
|
||||
$fmode= "06${fmode}"; }
|
||||
|
||||
if($fmode != $UMASK) {
|
||||
printf("UMASK corrected from $UMASK to $fmode ...\n"); }
|
||||
|
||||
$fmode= oct($fmode);
|
||||
|
||||
umask($fmode);
|
||||
}
|
||||
|
||||
|
||||
main();
|
||||
|
||||
####
|
||||
#### main sub routine
|
||||
####
|
||||
|
||||
sub main
|
||||
{
|
||||
my $flag_exit= 0;
|
||||
|
||||
if (!defined(my_which(my_print_defaults)))
|
||||
{
|
||||
# We can't throw out yet, since --version, --help, or --example may
|
||||
# have been given
|
||||
print "WARNING: my_print_defaults command not found.\n";
|
||||
print "Please make sure you have this command available and\n";
|
||||
print "in your path. The command is available from the latest\n";
|
||||
print "MySQL distribution.\n";
|
||||
$my_print_defaults_exists= 0;
|
||||
}
|
||||
|
||||
# Remove leading defaults options from @ARGV
|
||||
while (@ARGV > 0)
|
||||
{
|
||||
last unless $ARGV[0] =~
|
||||
/^--(?:no-defaults$|(?:defaults-file|defaults-extra-file)=)/;
|
||||
push @defaults_options, (shift @ARGV);
|
||||
}
|
||||
|
||||
foreach (@defaults_options)
|
||||
{
|
||||
$_ = quote_shell_word($_);
|
||||
}
|
||||
|
||||
# Add [mysqld_multi] options to front of @ARGV, ready for GetOptions()
|
||||
unshift @ARGV, defaults_for_group('mysqld_multi');
|
||||
|
||||
# We've already handled --no-defaults, --defaults-file, etc.
|
||||
if (!GetOptions("help", "example", "version", "mysqld=s", "mysqladmin=s",
|
||||
"user=s", "password=s", "log=s", "no-log",
|
||||
"tcp-ip", "silent", "verbose"))
|
||||
{
|
||||
$flag_exit= 1;
|
||||
}
|
||||
usage() if ($opt_help);
|
||||
|
||||
if ($opt_verbose && $opt_silent)
|
||||
{
|
||||
print "Both --verbose and --silent have been given. Some of the warnings ";
|
||||
print "will be disabled\nand some will be enabled.\n\n";
|
||||
}
|
||||
|
||||
init_log() if (!defined($opt_log));
|
||||
$groupids = $ARGV[1];
|
||||
if ($opt_version)
|
||||
{
|
||||
print "$my_progname version $VER by Jani Tolonen\n";
|
||||
exit(0);
|
||||
}
|
||||
example() if ($opt_example);
|
||||
if ($flag_exit)
|
||||
{
|
||||
print "Error with an option, see $my_progname --help for more info.\n";
|
||||
exit(1);
|
||||
}
|
||||
if (!defined(my_which(my_print_defaults)))
|
||||
{
|
||||
print "ABORT: Can't find command 'my_print_defaults'.\n";
|
||||
print "This command is available from the latest MySQL\n";
|
||||
print "distribution. Please make sure you have the command\n";
|
||||
print "in your PATH.\n";
|
||||
exit(1);
|
||||
}
|
||||
usage() if (!defined($ARGV[0]) ||
|
||||
(!($ARGV[0] =~ m/^start$/i) &&
|
||||
!($ARGV[0] =~ m/^stop$/i) &&
|
||||
!($ARGV[0] =~ m/^reload$/i) &&
|
||||
!($ARGV[0] =~ m/^report$/i)));
|
||||
|
||||
if (!$opt_no_log)
|
||||
{
|
||||
w2log("$my_progname log file version $VER; run: ",
|
||||
"$opt_log", 1, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
print "$my_progname log file version $VER; run: ";
|
||||
print strftime "%a %b %e %H:%M:%S %Y", localtime;
|
||||
print "\n";
|
||||
}
|
||||
if (($ARGV[0] =~ m/^start$/i) || ($ARGV[0] =~ m/^reload$/i))
|
||||
{
|
||||
if (!defined(($mysqld= my_which($opt_mysqld))) && $opt_verbose)
|
||||
{
|
||||
print "WARNING: Couldn't find the default mysqld binary.\n";
|
||||
print "Tried: $opt_mysqld\n";
|
||||
print "This is OK, if you are using option \"mysqld=...\" in ";
|
||||
print "groups [mysqldN] separately for each.\n\n";
|
||||
}
|
||||
if ($ARGV[0] =~ m/^start$/i) {
|
||||
start_mysqlds();
|
||||
} elsif ($ARGV[0] =~ m/^reload$/i) {
|
||||
reload_mysqlds();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!defined(($mysqladmin= my_which($opt_mysqladmin))) && $opt_verbose)
|
||||
{
|
||||
print "WARNING: Couldn't find the default mysqladmin binary.\n";
|
||||
print "Tried: $opt_mysqladmin\n";
|
||||
print "This is OK, if you are using option \"mysqladmin=...\" in ";
|
||||
print "groups [mysqldN] separately for each.\n\n";
|
||||
}
|
||||
if ($ARGV[0] =~ m/^report$/i)
|
||||
{
|
||||
report_mysqlds();
|
||||
}
|
||||
else
|
||||
{
|
||||
stop_mysqlds();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#
|
||||
# Quote word for shell
|
||||
#
|
||||
|
||||
sub quote_shell_word
|
||||
{
|
||||
my ($option)= @_;
|
||||
|
||||
$option =~ s!([^\w=./-])!\\$1!g;
|
||||
return $option;
|
||||
}
|
||||
|
||||
sub defaults_for_group
|
||||
{
|
||||
my ($group) = @_;
|
||||
|
||||
return () unless $my_print_defaults_exists;
|
||||
|
||||
my $com= join ' ', 'my_print_defaults', @defaults_options, $group;
|
||||
my @defaults = `$com`;
|
||||
chomp @defaults;
|
||||
return @defaults;
|
||||
}
|
||||
|
||||
####
|
||||
#### Init log file. Check for appropriate place for log file, in the following
|
||||
#### order: my_print_defaults mysqld datadir, C:/Program Files (x86)/MySQL/share
|
||||
####
|
||||
|
||||
sub init_log
|
||||
{
|
||||
foreach my $opt (defaults_for_group('mysqld'))
|
||||
{
|
||||
if ($opt =~ m/^--datadir=(.*)/ && -d "$1" && -w "$1")
|
||||
{
|
||||
$logdir= $1;
|
||||
}
|
||||
}
|
||||
if (!defined($logdir))
|
||||
{
|
||||
$logdir= "C:/Program Files (x86)/MySQL/share" if (-d "C:/Program Files (x86)/MySQL/share" && -w "C:/Program Files (x86)/MySQL/share");
|
||||
}
|
||||
if (!defined($logdir))
|
||||
{
|
||||
# Log file was not specified and we could not log to a standard place,
|
||||
# so log file be disabled for now.
|
||||
if (!$opt_silent)
|
||||
{
|
||||
print "WARNING: Log file disabled. Maybe directory or file isn't writable?\n";
|
||||
}
|
||||
$opt_no_log= 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$opt_log= "$logdir/mysqld_multi.log";
|
||||
}
|
||||
}
|
||||
|
||||
####
|
||||
#### Report living and not running MySQL servers
|
||||
####
|
||||
|
||||
sub report_mysqlds
|
||||
{
|
||||
my (@groups, $com, $i, @options, $pec);
|
||||
|
||||
print "Reporting MySQL servers\n";
|
||||
if (!$opt_no_log)
|
||||
{
|
||||
w2log("\nReporting MySQL servers","$opt_log",0,0);
|
||||
}
|
||||
@groups = &find_groups($groupids);
|
||||
for ($i = 0; defined($groups[$i]); $i++)
|
||||
{
|
||||
$com= get_mysqladmin_options($i, @groups);
|
||||
$com.= " ping >> /dev/null 2>&1";
|
||||
system($com);
|
||||
$pec = $? >> 8;
|
||||
if ($pec)
|
||||
{
|
||||
print "MySQL server from group: $groups[$i] is not running\n";
|
||||
if (!$opt_no_log)
|
||||
{
|
||||
w2log("MySQL server from group: $groups[$i] is not running",
|
||||
"$opt_log", 0, 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print "MySQL server from group: $groups[$i] is running\n";
|
||||
if (!$opt_no_log)
|
||||
{
|
||||
w2log("MySQL server from group: $groups[$i] is running",
|
||||
"$opt_log", 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$i)
|
||||
{
|
||||
print "No groups to be reported (check your GNRs)\n";
|
||||
if (!$opt_no_log)
|
||||
{
|
||||
w2log("No groups to be reported (check your GNRs)", "$opt_log", 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
####
|
||||
#### start multiple servers
|
||||
####
|
||||
|
||||
sub start_mysqlds()
|
||||
{
|
||||
my (@groups, $com, $tmp, $i, @options, $j, $mysqld_found, $info_sent);
|
||||
|
||||
if (!$opt_no_log)
|
||||
{
|
||||
w2log("\nStarting MySQL servers\n","$opt_log",0,0);
|
||||
}
|
||||
else
|
||||
{
|
||||
print "\nStarting MySQL servers\n";
|
||||
}
|
||||
@groups = &find_groups($groupids);
|
||||
for ($i = 0; defined($groups[$i]); $i++)
|
||||
{
|
||||
@options = defaults_for_group($groups[$i]);
|
||||
|
||||
$basedir_found= 0; # The default
|
||||
$mysqld_found= 1; # The default
|
||||
$mysqld_found= 0 if (!length($mysqld));
|
||||
$com= "$mysqld";
|
||||
for ($j = 0, $tmp= ""; defined($options[$j]); $j++)
|
||||
{
|
||||
if ("--datadir=" eq substr($options[$j], 0, 10)) {
|
||||
$datadir = $options[$j];
|
||||
$datadir =~ s/\-\-datadir\=//;
|
||||
eval { mkpath($datadir) };
|
||||
if ($@) {
|
||||
print "FATAL ERROR: Cannot create data directory $datadir: $!\n";
|
||||
exit(1);
|
||||
}
|
||||
if (! -d $datadir."/mysql") {
|
||||
if (-w $datadir) {
|
||||
print "\n\nInstalling new database in $datadir\n\n";
|
||||
$install_cmd="C:/Program Files (x86)/MySQL/bin/mysqld ";
|
||||
$install_cmd.="--initialize ";
|
||||
$install_cmd.="--user=mysql ";
|
||||
$install_cmd.="--datadir=$datadir";
|
||||
system($install_cmd);
|
||||
} else {
|
||||
print "\n";
|
||||
print "FATAL ERROR: Tried to create mysqld under group [$groups[$i]],\n";
|
||||
print "but the data directory is not writable.\n";
|
||||
print "data directory used: $datadir\n";
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (! -d $datadir."/mysql") {
|
||||
print "\n";
|
||||
print "FATAL ERROR: Tried to start mysqld under group [$groups[$i]],\n";
|
||||
print "but no data directory was found or could be created.\n";
|
||||
print "data directory used: $datadir\n";
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if ("--mysqladmin=" eq substr($options[$j], 0, 13))
|
||||
{
|
||||
# catch this and ignore
|
||||
}
|
||||
elsif ("--mysqld=" eq substr($options[$j], 0, 9))
|
||||
{
|
||||
$options[$j]=~ s/\-\-mysqld\=//;
|
||||
$com= $options[$j];
|
||||
$mysqld_found= 1;
|
||||
}
|
||||
elsif ("--basedir=" eq substr($options[$j], 0, 10))
|
||||
{
|
||||
$basedir= $options[$j];
|
||||
$basedir =~ s/^--basedir=//;
|
||||
$basedir_found= 1;
|
||||
$options[$j]= quote_shell_word($options[$j]);
|
||||
$tmp.= " $options[$j]";
|
||||
}
|
||||
else
|
||||
{
|
||||
$options[$j]= quote_shell_word($options[$j]);
|
||||
$tmp.= " $options[$j]";
|
||||
}
|
||||
}
|
||||
if ($opt_verbose && $com =~ m/\/(safe_mysqld|mysqld_safe)$/ && !$info_sent)
|
||||
{
|
||||
print "WARNING: $1 is being used to start mysqld. In this case you ";
|
||||
print "may need to pass\n\"ledir=...\" under groups [mysqldN] to ";
|
||||
print "$1 in order to find the actual mysqld binary.\n";
|
||||
print "ledir (library executable directory) should be the path to the ";
|
||||
print "wanted mysqld binary.\n\n";
|
||||
$info_sent= 1;
|
||||
}
|
||||
$com.= $tmp;
|
||||
$com.= " >> $opt_log 2>&1" if (!$opt_no_log);
|
||||
$com.= " &";
|
||||
if (!$mysqld_found)
|
||||
{
|
||||
print "\n";
|
||||
print "FATAL ERROR: Tried to start mysqld under group [$groups[$i]], ";
|
||||
print "but no mysqld binary was found.\n";
|
||||
print "Please add \"mysqld=...\" in group [mysqld_multi], or add it to ";
|
||||
print "group [$groups[$i]] separately.\n";
|
||||
exit(1);
|
||||
}
|
||||
if ($basedir_found)
|
||||
{
|
||||
$curdir=getcwd();
|
||||
chdir($basedir) or die "Can't change to datadir $basedir";
|
||||
}
|
||||
system($com);
|
||||
if ($basedir_found)
|
||||
{
|
||||
chdir($curdir) or die "Can't change back to original dir $curdir";
|
||||
}
|
||||
}
|
||||
if (!$i && !$opt_no_log)
|
||||
{
|
||||
w2log("No MySQL servers to be started (check your GNRs)",
|
||||
"$opt_log", 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
####
|
||||
#### reload multiple servers
|
||||
####
|
||||
|
||||
sub reload_mysqlds()
|
||||
{
|
||||
my (@groups, $com, $tmp, $i, @options, $j);
|
||||
|
||||
if (!$opt_no_log)
|
||||
{
|
||||
w2log("\nReloading MySQL servers\n","$opt_log",0,0);
|
||||
}
|
||||
else
|
||||
{
|
||||
print "\nReloading MySQL servers\n";
|
||||
}
|
||||
@groups = &find_groups($groupids);
|
||||
for ($i = 0; defined($groups[$i]); $i++)
|
||||
{
|
||||
$mysqld_server = $mysqld;
|
||||
@options = defaults_for_group($groups[$i]);
|
||||
|
||||
for ($j = 0, $tmp= ""; defined($options[$j]); $j++)
|
||||
{
|
||||
if ("--mysqladmin=" eq substr($options[$j], 0, 13))
|
||||
{
|
||||
# catch this and ignore
|
||||
}
|
||||
elsif ("--mysqld=" eq substr($options[$j], 0, 9))
|
||||
{
|
||||
$options[$j] =~ s/\-\-mysqld\=//;
|
||||
$mysqld_server = $options[$j];
|
||||
}
|
||||
elsif ("--pid-file=" eq substr($options[$j], 0, 11))
|
||||
{
|
||||
$options[$j] =~ s/\-\-pid-file\=//;
|
||||
$pid_file = $options[$j];
|
||||
}
|
||||
}
|
||||
$com = "killproc -p $pid_file -HUP $mysqld_server";
|
||||
system($com);
|
||||
|
||||
$com = "touch $pid_file";
|
||||
system($com);
|
||||
}
|
||||
if (!$i && !$opt_no_log)
|
||||
{
|
||||
w2log("No MySQL servers to be reloaded (check your GNRs)",
|
||||
"$opt_log", 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
###
|
||||
#### stop multiple servers
|
||||
####
|
||||
|
||||
sub stop_mysqlds()
|
||||
{
|
||||
my (@groups, $com, $i, @options);
|
||||
|
||||
if (!$opt_no_log)
|
||||
{
|
||||
w2log("\nStopping MySQL servers\n","$opt_log",0,0);
|
||||
}
|
||||
else
|
||||
{
|
||||
print "\nStopping MySQL servers\n";
|
||||
}
|
||||
@groups = &find_groups($groupids);
|
||||
for ($i = 0; defined($groups[$i]); $i++)
|
||||
{
|
||||
$com= get_mysqladmin_options($i, @groups);
|
||||
$com.= " shutdown";
|
||||
$com.= " >> $opt_log 2>&1" if (!$opt_no_log);
|
||||
$com.= " &";
|
||||
system($com);
|
||||
}
|
||||
if (!$i && !$opt_no_log)
|
||||
{
|
||||
w2log("No MySQL servers to be stopped (check your GNRs)",
|
||||
"$opt_log", 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
####
|
||||
#### Sub function for mysqladmin option parsing
|
||||
####
|
||||
|
||||
sub get_mysqladmin_options
|
||||
{
|
||||
my ($i, @groups)= @_;
|
||||
my ($mysqladmin_found, $com, $tmp, $j);
|
||||
|
||||
@options = defaults_for_group($groups[$i]);
|
||||
|
||||
$mysqladmin_found= 1; # The default
|
||||
$mysqladmin_found= 0 if (!length($mysqladmin));
|
||||
$com = "$mysqladmin";
|
||||
$tmp = " -u $opt_user";
|
||||
if (defined($opt_password)) {
|
||||
my $pw= $opt_password;
|
||||
# Protect single quotes in password
|
||||
$pw =~ s/'/'"'"'/g;
|
||||
$tmp.= " -p'$pw'";
|
||||
}
|
||||
$tmp.= $opt_tcp_ip ? " -h 127.0.0.1" : "";
|
||||
for ($j = 0; defined($options[$j]); $j++)
|
||||
{
|
||||
if ("--mysqladmin=" eq substr($options[$j], 0, 13))
|
||||
{
|
||||
$options[$j]=~ s/\-\-mysqladmin\=//;
|
||||
$com= $options[$j];
|
||||
$mysqladmin_found= 1;
|
||||
}
|
||||
elsif ((($options[$j] =~ m/^(\-\-socket\=)(.*)$/) && !$opt_tcp_ip) ||
|
||||
($options[$j] =~ m/^(\-\-port\=)(.*)$/))
|
||||
{
|
||||
$tmp.= " $options[$j]";
|
||||
}
|
||||
}
|
||||
if (!$mysqladmin_found)
|
||||
{
|
||||
print "\n";
|
||||
print "FATAL ERROR: Tried to use mysqladmin in group [$groups[$i]], ";
|
||||
print "but no mysqladmin binary was found.\n";
|
||||
print "Please add \"mysqladmin=...\" in group [mysqld_multi], or ";
|
||||
print "in group [$groups[$i]].\n";
|
||||
exit(1);
|
||||
}
|
||||
$com.= $tmp;
|
||||
return $com;
|
||||
}
|
||||
|
||||
# Return a list of option files which can be opened. Similar, but not
|
||||
# identical, to behavior of my_search_option_files()
|
||||
sub list_defaults_files
|
||||
{
|
||||
my %opt;
|
||||
foreach (@defaults_options)
|
||||
{
|
||||
return () if /^--no-defaults$/;
|
||||
$opt{$1} = $2 if /^--defaults-(extra-file|file)=(.*)$/;
|
||||
}
|
||||
|
||||
return ($opt{file}) if exists $opt{file};
|
||||
|
||||
my %seen; # Don't list the same file more than once
|
||||
return grep { defined $_ and not $seen{$_}++ and -f $_ and -r $_ }
|
||||
('/etc/my.cnf',
|
||||
'/etc/mysql/my.cnf',
|
||||
'C:/Program Files (x86)/MySQL/my.cnf',
|
||||
($ENV{MYSQL_HOME} ? "$ENV{MYSQL_HOME}/my.cnf" : undef),
|
||||
$opt{'extra-file'},
|
||||
($ENV{HOME} ? "$ENV{HOME}/.my.cnf" : undef));
|
||||
}
|
||||
|
||||
|
||||
# Takes a specification of GNRs (see --help), and returns a list of matching
|
||||
# groups which actually are mentioned in a relevant config file
|
||||
sub find_groups
|
||||
{
|
||||
my ($raw_gids) = @_;
|
||||
|
||||
my %gids;
|
||||
my @groups;
|
||||
|
||||
if (defined($raw_gids))
|
||||
{
|
||||
# Make a hash of the wanted group ids
|
||||
foreach my $raw_gid (split ',', $raw_gids)
|
||||
{
|
||||
# Match 123 or 123-456
|
||||
my ($start, $end) = ($raw_gid =~ /^\s*(\d+)(?:\s*-\s*(\d+))?\s*$/);
|
||||
$end = $start if not defined $end;
|
||||
if (not defined $start or $end < $start or $start < 0)
|
||||
{
|
||||
print "ABORT: Bad GNR: $raw_gid; see $my_progname --help\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
foreach my $i ($start .. $end)
|
||||
{
|
||||
# Use $i + 0 to normalize numbers (002 + 0 -> 2)
|
||||
$gids{$i + 0}= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
my @defaults_files = list_defaults_files();
|
||||
#warn "@{[sort keys %gids]} -> @defaults_files\n";
|
||||
foreach my $file (@defaults_files)
|
||||
{
|
||||
next unless open CONF, "< $file";
|
||||
|
||||
while (<CONF>)
|
||||
{
|
||||
if (/^\s*\[\s*(mysqld)(\d+)\s*\]\s*$/)
|
||||
{
|
||||
#warn "Found a group: $1$2\n";
|
||||
# Use $2 + 0 to normalize numbers (002 + 0 -> 2)
|
||||
if (not defined($raw_gids) or $gids{$2 + 0})
|
||||
{
|
||||
push @groups, "$1$2";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
close CONF;
|
||||
}
|
||||
return @groups;
|
||||
}
|
||||
|
||||
####
|
||||
#### w2log: Write to a logfile.
|
||||
#### 1.arg: append to the log file (given string, or from a file. if a file,
|
||||
#### file will be read from $opt_logdir)
|
||||
#### 2.arg: logfile -name (w2log assumes that the logfile is in $opt_logdir).
|
||||
#### 3.arg. 0 | 1, if true, print current date to the logfile. 3. arg will
|
||||
#### be ignored, if 1. arg is a file.
|
||||
#### 4.arg. 0 | 1, if true, first argument is a file, else a string
|
||||
####
|
||||
|
||||
sub w2log
|
||||
{
|
||||
my ($msg, $file, $date_flag, $is_file)= @_;
|
||||
my (@data);
|
||||
|
||||
open (LOGFILE, ">>$opt_log")
|
||||
or die "FATAL: w2log: Couldn't open log file: $opt_log\n";
|
||||
|
||||
if ($is_file)
|
||||
{
|
||||
open (FROMFILE, "<$msg") && (@data=<FROMFILE>) &&
|
||||
close(FROMFILE)
|
||||
or die "FATAL: w2log: Couldn't open file: $msg\n";
|
||||
foreach my $line (@data)
|
||||
{
|
||||
print LOGFILE "$line";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print LOGFILE "$msg";
|
||||
print LOGFILE strftime "%a %b %e %H:%M:%S %Y", localtime if ($date_flag);
|
||||
print LOGFILE "\n";
|
||||
}
|
||||
close (LOGFILE);
|
||||
return;
|
||||
}
|
||||
|
||||
####
|
||||
#### my_which is used, because we can't assume that every system has the
|
||||
#### which -command. my_which can take only one argument at a time.
|
||||
#### Return values: requested system command with the first found path,
|
||||
#### or undefined, if not found.
|
||||
####
|
||||
|
||||
sub my_which
|
||||
{
|
||||
my ($command) = @_;
|
||||
my (@paths, $path);
|
||||
|
||||
# If the argument is not 'my_print_defaults' then it would be of the format
|
||||
# <absolute_path>/<program>
|
||||
return $command if ($command ne 'my_print_defaults' && -f $command &&
|
||||
-x $command);
|
||||
|
||||
@paths = split(':', $ENV{'PATH'});
|
||||
foreach $path (@paths)
|
||||
{
|
||||
$path .= "/$command";
|
||||
return $path if (-f $path && -x $path);
|
||||
}
|
||||
return undef();
|
||||
}
|
||||
|
||||
|
||||
####
|
||||
#### example
|
||||
####
|
||||
|
||||
sub example
|
||||
{
|
||||
print <<EOF;
|
||||
# This is an example of a my.cnf file for $my_progname.
|
||||
# Usually this file is located in home dir ~/.my.cnf or /etc/my.cnf
|
||||
#
|
||||
# SOME IMPORTANT NOTES FOLLOW:
|
||||
#
|
||||
# 1.COMMON USER
|
||||
#
|
||||
# Make sure that the MySQL user, who is stopping the mysqld services, has
|
||||
# the same password to all MySQL servers being accessed by $my_progname.
|
||||
# This user needs to have the 'Shutdown_priv' -privilege, but for security
|
||||
# reasons should have no other privileges. It is advised that you create a
|
||||
# common 'multi_admin' user for all MySQL servers being controlled by
|
||||
# $my_progname. Here is an example how to do it:
|
||||
#
|
||||
# GRANT SHUTDOWN ON *.* TO multi_admin\@localhost IDENTIFIED BY 'password'
|
||||
#
|
||||
# You will need to apply the above to all MySQL servers that are being
|
||||
# controlled by $my_progname. 'multi_admin' will shutdown the servers
|
||||
# using 'mysqladmin' -binary, when '$my_progname stop' is being called.
|
||||
#
|
||||
# 2.PID-FILE
|
||||
#
|
||||
# If you are using mysqld_safe to start mysqld, make sure that every
|
||||
# MySQL server has a separate pid-file. In order to use mysqld_safe
|
||||
# via $my_progname, you need to use two options:
|
||||
#
|
||||
# mysqld=/path/to/mysqld_safe
|
||||
# ledir=/path/to/mysqld-binary/
|
||||
#
|
||||
# ledir (library executable directory), is an option that only mysqld_safe
|
||||
# accepts, so you will get an error if you try to pass it to mysqld directly.
|
||||
# For this reason you might want to use the above options within [mysqld#]
|
||||
# group directly.
|
||||
#
|
||||
# 3.DATA DIRECTORY
|
||||
#
|
||||
# It is NOT advised to run many MySQL servers within the same data directory.
|
||||
# You can do so, but please make sure to understand and deal with the
|
||||
# underlying caveats. In short they are:
|
||||
# - Speed penalty
|
||||
# - Risk of table/data corruption
|
||||
# - Data synchronising problems between the running servers
|
||||
# - Heavily media (disk) bound
|
||||
# - Relies on the system (external) file locking
|
||||
# - Is not applicable with all table types. (Such as InnoDB)
|
||||
# Trying so will end up with undesirable results.
|
||||
#
|
||||
# 4.TCP/IP Port
|
||||
#
|
||||
# Every server requires one and it must be unique.
|
||||
#
|
||||
# 5.[mysqld#] Groups
|
||||
#
|
||||
# In the example below the first and the fifth mysqld group was
|
||||
# intentionally left out. You may have 'gaps' in the config file. This
|
||||
# gives you more flexibility.
|
||||
#
|
||||
# 6.MySQL Server User
|
||||
#
|
||||
# You can pass the user=... option inside [mysqld#] groups. This
|
||||
# can be very handy in some cases, but then you need to run $my_progname
|
||||
# as UNIX root.
|
||||
#
|
||||
# 7.A Start-up Manage Script for $my_progname
|
||||
#
|
||||
# In the recent MySQL distributions you can find a file called
|
||||
# mysqld_multi.server.sh. It is a wrapper for $my_progname. This can
|
||||
# be used to start and stop multiple servers during boot and shutdown.
|
||||
#
|
||||
# You can place the file in /etc/init.d/mysqld_multi.server.sh and
|
||||
# make the needed symbolic links to it from various run levels
|
||||
# (as per Linux/Unix standard). You may even replace the
|
||||
# /etc/init.d/mysql.server script with it.
|
||||
#
|
||||
# Before using, you must create a my.cnf file either in C:/Program Files (x86)/MySQL/my.cnf
|
||||
# or /root/.my.cnf and add the [mysqld_multi] and [mysqld#] groups.
|
||||
#
|
||||
# The script can be found from support-files/mysqld_multi.server.sh
|
||||
# in MySQL distribution. (Verify the script before using)
|
||||
#
|
||||
|
||||
[mysqld_multi]
|
||||
mysqld = C:/Program Files (x86)/MySQL/bin/mysqld_safe
|
||||
mysqladmin = C:/Program Files (x86)/MySQL/bin/mysqladmin
|
||||
user = multi_admin
|
||||
password = my_password
|
||||
|
||||
[mysqld2]
|
||||
socket = /tmp/mysql.sock2
|
||||
port = 3307
|
||||
pid-file = C:/Program Files/MySQL/MySQL Server 5.7/data2/hostname.pid2
|
||||
datadir = C:/Program Files/MySQL/MySQL Server 5.7/data2
|
||||
language = C:/Program Files (x86)/MySQL/share/mysql/english
|
||||
user = unix_user1
|
||||
|
||||
[mysqld3]
|
||||
mysqld = /path/to/mysqld_safe
|
||||
ledir = /path/to/mysqld-binary/
|
||||
mysqladmin = /path/to/mysqladmin
|
||||
socket = /tmp/mysql.sock3
|
||||
port = 3308
|
||||
pid-file = C:/Program Files/MySQL/MySQL Server 5.7/data3/hostname.pid3
|
||||
datadir = C:/Program Files/MySQL/MySQL Server 5.7/data3
|
||||
language = C:/Program Files (x86)/MySQL/share/mysql/swedish
|
||||
user = unix_user2
|
||||
|
||||
[mysqld4]
|
||||
socket = /tmp/mysql.sock4
|
||||
port = 3309
|
||||
pid-file = C:/Program Files/MySQL/MySQL Server 5.7/data4/hostname.pid4
|
||||
datadir = C:/Program Files/MySQL/MySQL Server 5.7/data4
|
||||
language = C:/Program Files (x86)/MySQL/share/mysql/estonia
|
||||
user = unix_user3
|
||||
|
||||
[mysqld6]
|
||||
socket = /tmp/mysql.sock6
|
||||
port = 3311
|
||||
pid-file = C:/Program Files/MySQL/MySQL Server 5.7/data6/hostname.pid6
|
||||
datadir = C:/Program Files/MySQL/MySQL Server 5.7/data6
|
||||
language = C:/Program Files (x86)/MySQL/share/mysql/japanese
|
||||
user = unix_user4
|
||||
EOF
|
||||
exit(0);
|
||||
}
|
||||
|
||||
####
|
||||
#### usage
|
||||
####
|
||||
|
||||
sub usage
|
||||
{
|
||||
print <<EOF;
|
||||
$my_progname version $VER by Jani Tolonen
|
||||
|
||||
Description:
|
||||
$my_progname can be used to start, reload, or stop any number of separate
|
||||
mysqld processes running in different TCP/IP ports and UNIX sockets.
|
||||
|
||||
$my_progname can read group [mysqld_multi] from my.cnf file. You may
|
||||
want to put options mysqld=... and mysqladmin=... there. Since
|
||||
version 2.10 these options can also be given under groups [mysqld#],
|
||||
which gives more control over different versions. One can have the
|
||||
default mysqld and mysqladmin under group [mysqld_multi], but this is
|
||||
not mandatory. Please note that if mysqld or mysqladmin is missing
|
||||
from both [mysqld_multi] and [mysqld#], a group that is tried to be
|
||||
used, $my_progname will abort with an error.
|
||||
|
||||
$my_progname will search for groups named [mysqld#] from my.cnf (or
|
||||
the given --defaults-extra-file=...), where '#' can be any positive
|
||||
integer starting from 1. These groups should be the same as the regular
|
||||
[mysqld] group, but with those port, socket and any other options
|
||||
that are to be used with each separate mysqld process. The number
|
||||
in the group name has another function; it can be used for starting,
|
||||
reloading, stopping, or reporting any specific mysqld server.
|
||||
|
||||
Usage: $my_progname [OPTIONS] {start|reload|stop|report} [GNR,GNR,GNR...]
|
||||
or $my_progname [OPTIONS] {start|reload|stop|report} [GNR-GNR,GNR,GNR-GNR,...]
|
||||
|
||||
The GNR means the group number. You can start, reload, stop or report any GNR,
|
||||
or several of them at the same time. (See --example) The GNRs list can
|
||||
be comma separated or a dash combined. The latter means that all the
|
||||
GNRs between GNR1-GNR2 will be affected. Without GNR argument all the
|
||||
groups found will either be started, reloaded, stopped, or reported. Note that
|
||||
syntax for specifying GNRs must appear without spaces.
|
||||
|
||||
Options:
|
||||
|
||||
These options must be given before any others:
|
||||
--no-defaults Do not read any defaults file
|
||||
--defaults-file=... Read only this configuration file, do not read the
|
||||
standard system-wide and user-specific files
|
||||
--defaults-extra-file=... Read this configuration file in addition to the
|
||||
standard system-wide and user-specific files
|
||||
Using: @{[join ' ', @defaults_options]}
|
||||
|
||||
--example Give an example of a config file with extra information.
|
||||
--help Print this help and exit.
|
||||
--log=... Log file. Full path to and the name for the log file. NOTE:
|
||||
If the file exists, everything will be appended.
|
||||
Using: $opt_log
|
||||
--mysqladmin=... mysqladmin binary to be used for a server shutdown.
|
||||
Since version 2.10 this can be given within groups [mysqld#]
|
||||
Using: $mysqladmin
|
||||
--mysqld=... mysqld binary to be used. Note that you can give mysqld_safe
|
||||
to this option also. The options are passed to mysqld. Just
|
||||
make sure you have mysqld in your PATH or fix mysqld_safe.
|
||||
Using: $mysqld
|
||||
Please note: Since mysqld_multi version 2.3 you can also
|
||||
give this option inside groups [mysqld#] in ~/.my.cnf,
|
||||
where '#' stands for an integer (number) of the group in
|
||||
question. This will be recognised as a special option and
|
||||
will not be passed to the mysqld. This will allow one to
|
||||
start different mysqld versions with mysqld_multi.
|
||||
--no-log Print to stdout instead of the log file. By default the log
|
||||
file is turned on.
|
||||
--password=... Password for mysqladmin user.
|
||||
--silent Disable warnings.
|
||||
--tcp-ip Connect to the MySQL server(s) via the TCP/IP port instead
|
||||
of the UNIX socket. This affects stopping and reporting.
|
||||
If a socket file is missing, the server may still be
|
||||
running, but can be accessed only via the TCP/IP port.
|
||||
By default connecting is done via the UNIX socket.
|
||||
--user=... mysqladmin user. Using: $opt_user
|
||||
--verbose Be more verbose.
|
||||
--version Print the version number and exit.
|
||||
EOF
|
||||
exit(0);
|
||||
}
|
||||
BIN
mysql/bin/mysqldump.exe
Normal file
217
mysql/bin/mysqldumpslow.pl
Normal file
@@ -0,0 +1,217 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
# Copyright (c) 2000, 2023, Oracle and/or its affiliates.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License, version 2.0,
|
||||
# as published by the Free Software Foundation.
|
||||
#
|
||||
# This program is also distributed with certain software (including
|
||||
# but not limited to OpenSSL) that is licensed under separate terms,
|
||||
# as designated in a particular file or component or in included license
|
||||
# documentation. The authors of MySQL hereby grant you an additional
|
||||
# permission to link the program and your derivative works with the
|
||||
# separately licensed software that they have included with MySQL.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License, version 2.0, for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Library General Public
|
||||
# License along with this library; if not, write to the Free
|
||||
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
|
||||
# MA 02110-1301, USA
|
||||
|
||||
# mysqldumpslow - parse and summarize the MySQL slow query log
|
||||
|
||||
# Original version by Tim Bunce, sometime in 2000.
|
||||
# Further changes by Tim Bunce, 8th March 2001.
|
||||
# Handling of strings with \ and double '' by Monty 11 Aug 2001.
|
||||
|
||||
use strict;
|
||||
use Getopt::Long;
|
||||
|
||||
# t=time, l=lock time, r=rows
|
||||
# at, al, and ar are the corresponding averages
|
||||
|
||||
my %opt = (
|
||||
s => 'at',
|
||||
h => '*',
|
||||
);
|
||||
|
||||
GetOptions(\%opt,
|
||||
'v|verbose+',# verbose
|
||||
'help+', # write usage info
|
||||
'd|debug+', # debug
|
||||
's=s', # what to sort by (al, at, ar, c, t, l, r)
|
||||
'r!', # reverse the sort order (largest last instead of first)
|
||||
't=i', # just show the top n queries
|
||||
'a!', # don't abstract all numbers to N and strings to 'S'
|
||||
'n=i', # abstract numbers with at least n digits within names
|
||||
'g=s', # grep: only consider stmts that include this string
|
||||
'h=s', # hostname of db server for *-slow.log filename (can be wildcard)
|
||||
'i=s', # name of server instance (if using mysql.server startup script)
|
||||
'l!', # don't subtract lock time from total time
|
||||
) or usage("bad option");
|
||||
|
||||
$opt{'help'} and usage();
|
||||
|
||||
unless (@ARGV) {
|
||||
my $defaults = `my_print_defaults mysqld`;
|
||||
my $basedir = ($defaults =~ m/--basedir=(.*)/)[0]
|
||||
or die "Can't determine basedir from 'my_print_defaults mysqld' output: $defaults";
|
||||
warn "basedir=$basedir\n" if $opt{v};
|
||||
|
||||
my $datadir = ($defaults =~ m/--datadir=(.*)/)[0];
|
||||
my $slowlog = ($defaults =~ m/--slow-query-log-file=(.*)/)[0];
|
||||
if (!$datadir or $opt{i}) {
|
||||
# determine the datadir from the instances section of /etc/my.cnf, if any
|
||||
my $instances = `my_print_defaults instances`;
|
||||
die "Can't determine datadir from 'my_print_defaults mysqld' output: $defaults"
|
||||
unless $instances;
|
||||
my @instances = ($instances =~ m/^--(\w+)-/mg);
|
||||
die "No -i 'instance_name' specified to select among known instances: @instances.\n"
|
||||
unless $opt{i};
|
||||
die "Instance '$opt{i}' is unknown (known instances: @instances)\n"
|
||||
unless grep { $_ eq $opt{i} } @instances;
|
||||
$datadir = ($instances =~ m/--$opt{i}-datadir=(.*)/)[0]
|
||||
or die "Can't determine --$opt{i}-datadir from 'my_print_defaults instances' output: $instances";
|
||||
warn "datadir=$datadir\n" if $opt{v};
|
||||
}
|
||||
|
||||
if ( -f $slowlog ) {
|
||||
@ARGV = ($slowlog);
|
||||
die "Can't find '$slowlog'\n" unless @ARGV;
|
||||
} else {
|
||||
@ARGV = <$datadir/$opt{h}-slow.log>;
|
||||
die "Can't find '$datadir/$opt{h}-slow.log'\n" unless @ARGV;
|
||||
}
|
||||
}
|
||||
|
||||
warn "\nReading mysql slow query log from @ARGV\n";
|
||||
|
||||
my @pending;
|
||||
my %stmt;
|
||||
$/ = ";\n#"; # read entire statements using paragraph mode
|
||||
while ( defined($_ = shift @pending) or defined($_ = <>) ) {
|
||||
warn "[[$_]]\n" if $opt{d}; # show raw paragraph being read
|
||||
|
||||
my @chunks = split /^\/.*Version.*started with[\000-\377]*?Time.*Id.*Command.*Argument.*\n/m;
|
||||
if (@chunks > 1) {
|
||||
unshift @pending, map { length($_) ? $_ : () } @chunks;
|
||||
warn "<<".join(">>\n<<",@chunks).">>" if $opt{d};
|
||||
next;
|
||||
}
|
||||
|
||||
s/^#? Time: \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d+(Z|[+-]\d{2}:\d{2}).*\n//;
|
||||
my ($user,$host,$dummy,$thread_id) = s/^#? User\@Host:\s+(\S+)\s+\@\s+(\S+)\s+\S+(\s+Id:\s+(\d+))?.*\n// ? ($1,$2,$3,$4) : ('','','','','');
|
||||
|
||||
s/^# Query_time: ([0-9.]+)\s+Lock_time: ([0-9.]+)\s+Rows_sent: ([0-9.]+).*\n//;
|
||||
my ($t, $l, $r) = ($1, $2, $3);
|
||||
$t -= $l unless $opt{l};
|
||||
|
||||
# remove fluff that mysqld writes to log when it (re)starts:
|
||||
s!^/.*Version.*started with:.*\n!!mg;
|
||||
s!^Tcp port: \d+ Unix socket: \S+\n!!mg;
|
||||
s!^Time.*Id.*Command.*Argument.*\n!!mg;
|
||||
|
||||
s/^use \w+;\n//; # not consistently added
|
||||
s/^SET timestamp=\d+;\n//;
|
||||
|
||||
s/^[ ]*\n//mg; # delete blank lines
|
||||
s/^[ ]*/ /mg; # normalize leading whitespace
|
||||
s/\s*;\s*(#\s*)?$//; # remove trailing semicolon(+newline-hash)
|
||||
|
||||
next if $opt{g} and !m/$opt{g}/io;
|
||||
|
||||
unless ($opt{a}) {
|
||||
s/\b\d+\b/N/g;
|
||||
s/\b0x[0-9A-Fa-f]+\b/N/g;
|
||||
s/''/'S'/g;
|
||||
s/""/"S"/g;
|
||||
s/(\\')//g;
|
||||
s/(\\")//g;
|
||||
s/'[^']+'/'S'/g;
|
||||
s/"[^"]+"/"S"/g;
|
||||
# -n=8: turn log_20001231 into log_NNNNNNNN
|
||||
s/([a-z_]+)(\d{$opt{n},})/$1.('N' x length($2))/ieg if $opt{n};
|
||||
# abbreviate massive "in (...)" statements and similar
|
||||
s!(([NS],){100,})!sprintf("$2,{repeated %d times}",length($1)/2)!eg;
|
||||
}
|
||||
|
||||
my $s = $stmt{$_} ||= { users=>{}, hosts=>{} };
|
||||
$s->{c} += 1;
|
||||
$s->{t} += $t;
|
||||
$s->{l} += $l;
|
||||
$s->{r} += $r;
|
||||
$s->{users}->{$user}++ if $user;
|
||||
$s->{hosts}->{$host}++ if $host;
|
||||
|
||||
warn "{{$_}}\n\n" if $opt{d}; # show processed statement string
|
||||
}
|
||||
|
||||
foreach (keys %stmt) {
|
||||
my $v = $stmt{$_} || die;
|
||||
my ($c, $t, $l, $r) = @{ $v }{qw(c t l r)};
|
||||
$v->{at} = $t / $c;
|
||||
$v->{al} = $l / $c;
|
||||
$v->{ar} = $r / $c;
|
||||
}
|
||||
|
||||
my @sorted = sort { $stmt{$b}->{$opt{s}} <=> $stmt{$a}->{$opt{s}} } keys %stmt;
|
||||
@sorted = @sorted[0 .. $opt{t}-1] if $opt{t};
|
||||
@sorted = reverse @sorted if $opt{r};
|
||||
|
||||
foreach (@sorted) {
|
||||
my $v = $stmt{$_} || die;
|
||||
my ($c, $t,$at, $l,$al, $r,$ar) = @{ $v }{qw(c t at l al r ar)};
|
||||
my @users = keys %{$v->{users}};
|
||||
my $user = (@users==1) ? $users[0] : sprintf "%dusers",scalar @users;
|
||||
my @hosts = keys %{$v->{hosts}};
|
||||
my $host = (@hosts==1) ? $hosts[0] : sprintf "%dhosts",scalar @hosts;
|
||||
printf "Count: %d Time=%.2fs (%ds) Lock=%.2fs (%ds) Rows=%.1f (%d), $user\@$host\n%s\n\n",
|
||||
$c, $at,$t, $al,$l, $ar,$r, $_;
|
||||
}
|
||||
|
||||
sub usage {
|
||||
my $str= shift;
|
||||
my $text= <<HERE;
|
||||
Usage: mysqldumpslow [ OPTS... ] [ LOGS... ]
|
||||
|
||||
Parse and summarize the MySQL slow query log. Options are
|
||||
|
||||
--verbose verbose
|
||||
--debug debug
|
||||
--help write this text to standard output
|
||||
|
||||
-v verbose
|
||||
-d debug
|
||||
-s ORDER what to sort by (al, at, ar, c, l, r, t), 'at' is default
|
||||
al: average lock time
|
||||
ar: average rows sent
|
||||
at: average query time
|
||||
c: count
|
||||
l: lock time
|
||||
r: rows sent
|
||||
t: query time
|
||||
-r reverse the sort order (largest last instead of first)
|
||||
-t NUM just show the top n queries
|
||||
-a don't abstract all numbers to N and strings to 'S'
|
||||
-n NUM abstract numbers with at least n digits within names
|
||||
-g PATTERN grep: only consider stmts that include this string
|
||||
-h HOSTNAME hostname of db server for *-slow.log filename (can be wildcard),
|
||||
default is '*', i.e. match all
|
||||
-i NAME name of server instance (if using mysql.server startup script)
|
||||
-l don't subtract lock time from total time
|
||||
|
||||
HERE
|
||||
if ($str) {
|
||||
print STDERR "ERROR: $str\n\n";
|
||||
print STDERR $text;
|
||||
exit 1;
|
||||
} else {
|
||||
print $text;
|
||||
exit 0;
|
||||
}
|
||||
}
|
||||
BIN
mysql/bin/mysqlimport.exe
Normal file
BIN
mysql/bin/mysqlpump.exe
Normal file
BIN
mysql/bin/mysqlshow.exe
Normal file
BIN
mysql/bin/mysqlslap.exe
Normal file
BIN
mysql/bin/mysqltest_embedded.exe
Normal file
BIN
mysql/bin/mysqlxtest.exe
Normal file
BIN
mysql/bin/perror.exe
Normal file
BIN
mysql/bin/replace.exe
Normal file
BIN
mysql/bin/resolveip.exe
Normal file
BIN
mysql/bin/saslSCRAM.dll
Normal file
BIN
mysql/bin/zlib_decompress.exe
Normal file
2
mysql/data/auto.cnf
Normal file
@@ -0,0 +1,2 @@
|
||||
[auto]
|
||||
server-uuid=72c254a5-7527-11f1-b6c8-54b2039762bc
|
||||
BIN
mysql/data/ca-key.pem
Normal file
BIN
mysql/data/ca.pem
Normal file
BIN
mysql/data/client-cert.pem
Normal file
BIN
mysql/data/client-key.pem
Normal file
9
mysql/data/f117-v.err
Normal file
@@ -0,0 +1,9 @@
|
||||
2026-07-01T08:32:51.031789Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
|
||||
2026-07-01T08:32:51.337660Z 0 [Warning] InnoDB: New log files created, LSN=45790
|
||||
2026-07-01T08:32:51.387036Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
|
||||
2026-07-01T08:32:51.471348Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 72c254a5-7527-11f1-b6c8-54b2039762bc.
|
||||
2026-07-01T08:32:51.476534Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
|
||||
2026-07-01T08:32:51.906064Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
|
||||
2026-07-01T08:32:51.911925Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
|
||||
2026-07-01T08:32:51.917155Z 0 [Warning] CA certificate ca.pem is self signed.
|
||||
2026-07-01T08:32:52.197414Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
|
||||
1
mysql/data/f117-v.pid
Normal file
@@ -0,0 +1 @@
|
||||
2876
|
||||
89
mysql/data/ib_buffer_pool
Normal file
@@ -0,0 +1,89 @@
|
||||
1,37
|
||||
1,36
|
||||
1,35
|
||||
21,3
|
||||
21,2
|
||||
21,1
|
||||
21,0
|
||||
0,313
|
||||
6,8
|
||||
6,7
|
||||
6,6
|
||||
0,312
|
||||
6,5
|
||||
6,4
|
||||
7,15
|
||||
7,16
|
||||
7,10
|
||||
7,14
|
||||
7,8
|
||||
7,13
|
||||
7,12
|
||||
7,7
|
||||
0,311
|
||||
7,11
|
||||
7,9
|
||||
7,4
|
||||
7,6
|
||||
7,5
|
||||
4,94
|
||||
4,41
|
||||
4,27
|
||||
4,93
|
||||
4,92
|
||||
4,91
|
||||
4,90
|
||||
4,89
|
||||
4,88
|
||||
4,87
|
||||
4,86
|
||||
4,85
|
||||
4,84
|
||||
4,83
|
||||
4,82
|
||||
4,81
|
||||
4,80
|
||||
4,79
|
||||
4,78
|
||||
4,77
|
||||
4,76
|
||||
4,75
|
||||
4,74
|
||||
4,73
|
||||
4,72
|
||||
4,40
|
||||
4,16
|
||||
4,71
|
||||
4,70
|
||||
4,69
|
||||
4,68
|
||||
4,67
|
||||
4,66
|
||||
4,65
|
||||
4,64
|
||||
4,39
|
||||
4,38
|
||||
4,37
|
||||
4,36
|
||||
4,35
|
||||
4,34
|
||||
4,33
|
||||
4,32
|
||||
4,31
|
||||
4,30
|
||||
4,29
|
||||
4,28
|
||||
4,17
|
||||
4,26
|
||||
4,25
|
||||
4,24
|
||||
4,23
|
||||
4,22
|
||||
4,21
|
||||
4,20
|
||||
4,19
|
||||
4,18
|
||||
4,4
|
||||
4,15
|
||||
4,14
|
||||
4,13
|
||||
BIN
mysql/data/ib_logfile0
Normal file
BIN
mysql/data/ib_logfile1
Normal file
BIN
mysql/data/ibdata1
Normal file
BIN
mysql/data/ibtmp1
Normal file
0
mysql/data/mysql/columns_priv.MYD
Normal file
BIN
mysql/data/mysql/columns_priv.MYI
Normal file
BIN
mysql/data/mysql/columns_priv.frm
Normal file
1
mysql/data/mysql/db.MYD
Normal file
@@ -0,0 +1 @@
|
||||
ÿlocalhost performance_schema mysql.session ÿlocalhost sys mysql.sys ÿ127.0.0.1 word_sign admin ÿlocalhost word_sign admin ÿ% word_sign admin
|
||||
BIN
mysql/data/mysql/db.MYI
Normal file
BIN
mysql/data/mysql/db.frm
Normal file
2
mysql/data/mysql/db.opt
Normal file
@@ -0,0 +1,2 @@
|
||||
default-character-set=latin1
|
||||
default-collation=latin1_swedish_ci
|
||||