Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CCS
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Marko Mecina
CCS
Commits
cd127aba
Commit
cd127aba
authored
1 year ago
by
Marko Mecina
Browse files
Options
Downloads
Patches
Plain Diff
add ignore option to mib import script
parent
b82545f7
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Ccs/tools/import_mib.py
+20
-6
20 additions, 6 deletions
Ccs/tools/import_mib.py
with
20 additions
and
6 deletions
Ccs/tools/import_mib.py
+
20
−
6
View file @
cd127aba
...
...
@@ -71,7 +71,7 @@ def create_schema():
s
.
close
()
def
import_mib
():
def
import_mib
(
skip_over_errors
=
False
):
eng
=
create_engine
(
DBURL
+
'
/
'
+
DBNAME
)
sf
=
sessionmaker
(
bind
=
eng
)
s
=
sf
()
...
...
@@ -85,13 +85,21 @@ def import_mib():
# replace empty strings with DEFAULT
rows
=
[(
'"'
+
i
.
replace
(
'
\t
'
,
'"
,
"'
).
strip
()
+
'"'
).
replace
(
'""'
,
'
DEFAULT
'
)
for
i
in
mfile
]
try
:
for
row
in
rows
:
s
.
execute
(
text
(
'
INSERT IGNORE INTO {} VALUES ({})
'
.
format
(
fn
[:
-
4
],
row
)))
# IGNORE truncates too long strings
except
Exception
as
err
:
s
.
rollback
()
s
.
close
()
raise
err
if
skip_over_errors
:
print
(
'
Fatal error when importing MIB table
'
+
fn
)
print
(
'
Error description:
'
+
str
(
err
))
print
(
'
Continuing with other tables ...
'
)
else
:
s
.
close
()
raise
err
s
.
commit
()
s
.
close
()
...
...
@@ -100,6 +108,11 @@ def import_mib():
if
__name__
==
'
__main__
'
:
do_import
=
True
ignore_errors
=
False
if
'
--ignore
'
in
sys
.
argv
:
sys
.
argv
.
remove
(
'
--ignore
'
)
ignore_errors
=
True
if
'
-c
'
in
sys
.
argv
:
MIBDIR
=
'
/home/user/space/mib
'
# directory containing the SCOS2000 *.dat files
...
...
@@ -120,8 +133,9 @@ if __name__ == '__main__':
else
:
print
(
'
USAGE: ./import_mib.py <MIBDIR> <DBSCHEMA> <DBUSERNAME> [-c]
\n
'
'
Options:
\n\t
-c
\t
Use configuration in script, any command line arguments will be ignored.
\n
'
'
\t
--dummy
\t
Create empty MIB structure only. Omit <MIBDIR> argument.
'
)
'
Options:
\n\t
-c
\t\t
Use configuration in script, any command line arguments will be ignored.
\n
'
'
\t
--dummy
\t\t
Create empty MIB structure only. Omit <MIBDIR> argument.
\n
'
'
\t
--ignore
\t
Continue if a table import fails.
'
)
sys
.
exit
()
...
...
@@ -129,6 +143,6 @@ if __name__ == '__main__':
create_schema
()
if
do_import
:
import_mib
()
import_mib
(
skip_over_errors
=
ignore_errors
)
print
(
'
...DONE!
'
)
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