Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LOFAR
Manage
Activity
Members
Labels
Plan
Issues
Wiki
Jira issues
Open Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
RadioObservatory
LOFAR
Commits
e38c7022
Commit
e38c7022
authored
7 years ago
by
Adriaan Renting
Browse files
Options
Downloads
Patches
Plain Diff
Task #10981: Added script to read and process MoM DB dump
parent
b7b2f0d1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
.gitattributes
+1
-0
1 addition, 0 deletions
.gitattributes
support/tools/MoM/process_mom_sql.py
+83
-0
83 additions, 0 deletions
support/tools/MoM/process_mom_sql.py
with
84 additions
and
0 deletions
.gitattributes
+
1
−
0
View file @
e38c7022
...
...
@@ -5564,4 +5564,5 @@ SubSystems/RAServices/RAServices.ini -text
SubSystems/SAS_Tools/CMakeLists.txt -text
/jenkins_make -text
/lofar_config.h.cmake -text
support/tools/MoM/process_mom_sql.py -text
support/tools/lofstorman -text
This diff is collapsed.
Click to expand it.
support/tools/MoM/process_mom_sql.py
0 → 100755
+
83
−
0
View file @
e38c7022
#!/usr/bin/python
infile
=
"
backup_lofar_mom3.sql.1
"
indatabase
=
"
lofar_mom3
"
outdatabase
=
"
lofar_mom_test_rt_trigger
"
outdir
=
"
test/
"
outfile
=
open
(
outdir
+
"
000000_CREATE_DATABASE.sql
"
,
'
w
'
)
# Please note that "Comments" in the SQL that look like this
# /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
# are not really comments, but conditionals, which mean that they will
# only be interpreted by MySQL and only if the version is above e.g. 4.01.01
# see https://dev.mysql.com/doc/refman/5.7/en/comments.html
# This script is not robust, but tries to be efficient based on assumptions
# on the current mom database. When adding new triggers or views, it might need updates.
# after running this script a "grep <indatabase> *.sql" should be used to verify
# Fun state machine to parse a SQL dump follows
buffer
=
""
# Buffer to store lines until we know what we found next
use_found
=
False
# When to close the CREATE_DATABASE script
line_nr
=
0
possible_trigger
=
False
trigger
=
False
with
open
(
infile
)
as
f
:
for
line
in
f
:
if
not
use_found
or
trigger
or
(
line
[
0
:
13
]
==
"
/*!50001 VIEW
"
)
or
(
line
[
0
:
2
]
==
'
--
'
):
if
indatabase
in
line
:
#doing this for each line would be expensive
line
=
line
.
replace
(
indatabase
,
outdatabase
)
if
line
[
0
:
3
]
==
"
USE
"
:
if
use_found
:
outfile
=
open
(
outdir
+
"
%06d_
"
%
line_nr
+
"
USE_%s.sql
"
%
outdatabase
,
'
w
'
)
outfile
.
write
(
buffer
)
buffer
=
""
if
indatabase
in
line
:
# could also be in the first if in the for loop
line
=
line
.
replace
(
indatabase
,
outdatabase
)
outfile
.
write
(
line
)
else
:
use_found
=
True
# End of the general database creation
outfile
.
write
(
buffer
)
buffer
=
""
outfile
.
write
(
line
)
elif
"
UNLOCK TABLES
"
in
line
:
# Triggers on a table are possible after the WRITE
possible_trigger
=
True
outfile
.
write
(
line
)
elif
possible_trigger
and
line
[
0
:
8
]
==
"
/*!50003
"
:
#Special BiRT views
buffer
+=
line
elif
possible_trigger
and
"
DELIMITER ;;
"
in
line
:
# Trigger code follows
buffer
+=
line
trigger
=
True
possible_trigger
=
False
elif
"
END */;;
"
in
line
:
# End of trigger code
trigger
=
False
outfile
.
write
(
line
)
possible_trigger
=
True
# There might be more trigger code.
elif
not
trigger
and
(
line
[
0
:
2
]
==
'
--
'
or
line
.
isspace
()
or
not
use_found
):
buffer
+=
line
elif
buffer
:
# We should have a line that tells us what is happening next
print
line
outfile
.
close
()
possible_trigger
=
False
filename
=
line
.
translate
(
None
,
'
/*;`!@=
\n
()
'
).
replace
(
'
'
,
'
_
'
)
if
'
DROP_TABLE_IF_EXISTS_
'
in
filename
:
filename
=
'
CREATE_TABLE_OR_VIEW_
'
+
filename
[
filename
.
find
(
'
DROP_TABLE_IF_EXISTS_
'
)
+
21
:]
if
'
LOCK_TABLES_
'
in
filename
:
filename
=
'
WRITE_TABLE_
'
+
filename
[
12
:
-
6
]
if
'
TRIGGER
'
in
line
:
filename
=
'
CREATE_
'
+
filename
[
filename
.
find
(
'
TRIGGER
'
):
-
19
]
outfile
=
open
(
outdir
+
"
%06d_
"
%
line_nr
+
filename
+
"
.sql
"
,
'
w
'
)
outfile
.
write
(
buffer
)
buffer
=
""
outfile
.
write
(
line
)
elif
trigger
:
outfile
.
write
(
line
)
elif
"
Dump completed
"
in
line
:
# Last line of dump
outfile
.
write
(
buffer
)
buffer
=
""
outfile
.
close
()
break
else
:
outfile
.
write
(
line
)
line_nr
+=
1
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment