-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiasoft_macros.py
More file actions
110 lines (92 loc) · 2.81 KB
/
diasoft_macros.py
File metadata and controls
110 lines (92 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import re
from utils_logger import log_execution
@log_execution()
def parse_diasoft_macros(content: str) -> str:
content = replace_nolock_index(content)
content = replace_rowlock_index(content)
content = replace_updlock_index(content)
content = replace_forceplan(content)
# content = replace_forceplan(content)
content = replace_isolat(content)
content = replace_forceolan_off(content)
content = suser_name(content)
return content
@log_execution()
def suser_name(content: str) -> str:
"""
Заменяет #M_FORCEPLAN на set rowcount 0
"""
return re.sub(
r"#SUSER_NAME\b",
"suser_name()",
content,
flags=re.IGNORECASE
)
@log_execution()
def replace_nolock_index(content: str) -> str:
"""
Заменяет конструкции вида:
#M_NOLOCK_INDEX( XPKtPropertyUs )
#M_NOLOCK_INDEX ( XPKtPropertyUs )
#M_NOLOCK_INDEX ( XPKtPropertyUs)
на:
with ( nolock index=XPKtPropertyUs )
"""
pattern = re.compile(
r"#M_NOLOCK_INDEX\s*\(\s*([A-Za-z0-9_]+)\s*\)",
flags=re.IGNORECASE
)
return pattern.sub(r"with (nolock index=\1)", content)
@log_execution()
def replace_rowlock_index(content: str) -> str:
"""
Заменяет конструкции вида:
#M_ROWLOCK_INDEX( XPKtPropertyUs )
#M_ROWLOCK_INDEX ( XPKtPropertyUs )
#M_ROWLOCK_INDEX ( XPKtPropertyUs)
на:
with ( rowlock index=XPKtPropertyUs )
"""
pattern = re.compile(
r"#M_ROWLOCK_INDEX\s*\(\s*([A-Za-z0-9_]+)\s*\)",
flags=re.IGNORECASE
)
return pattern.sub(r"with (rowlock index=\1)", content)
@log_execution()
def replace_updlock_index(content: str) -> str:
"""
Заменяет конструкции вида:
#M_UPDLOCK_INDEX ( XPKtPropertyUs )
#M_UPDLOCK_INDEX ( XPKtPropertyUs )
#M_UPDLOCK_INDEX ( XPKtPropertyUs)
на:
with ( updlock index=XPKtPropertyUs )
"""
pattern = re.compile(
r"#M_UPDLOCK_INDEX\s*\(\s*([A-Za-z0-9_]+)\s*\)",
flags=re.IGNORECASE
)
return pattern.sub(r"with (updlock index=\1)", content)
@log_execution()
def replace_forceplan(content: str) -> str:
"""
Заменяет #M_FORCEPLAN на set rowcount 0
"""
return re.sub(
r"#M_FORCEPLAN\b",
"set rowcount 0;",
content,
flags=re.IGNORECASE
)
@log_execution()
def replace_isolat(content: str) -> str:
"""
Удаляет #M_ISOLAT (в любом регистре)
"""
return re.sub(r"#M_ISOLAT\b", "", content, flags=re.IGNORECASE)
@log_execution()
def replace_forceolan_off(content: str) -> str:
"""
Удаляет #M_FORCEPLAN_OFF (в любом регистре)
"""
return re.sub(r"#M_FORCEPLAN_OFF\b", "", content, flags=re.IGNORECASE)