Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
X
xls2db
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
utilities
xls2db
Commits
d0386dd9
Commit
d0386dd9
authored
8 years ago
by
Rafael Ostertag
Browse files
Options
Downloads
Patches
Plain Diff
Bumped version to 0.3. Database name must now be provided as cmd argument.
parent
8890a9b2
No related branches found
Branches containing commit
Tags
v0.3
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
setup.py
+1
-1
1 addition, 1 deletion
setup.py
xls2db.py
+7
-1
7 additions, 1 deletion
xls2db.py
xls2dblib/db.py
+12
-6
12 additions, 6 deletions
xls2dblib/db.py
with
20 additions
and
8 deletions
setup.py
+
1
−
1
View file @
d0386dd9
...
...
@@ -2,7 +2,7 @@ from distutils.core import setup
setup
(
name
=
'
xls2db
'
,
version
=
'
0.
2
'
,
version
=
'
0.
3
'
,
packages
=
[
'
xls2dblib
'
],
scripts
=
[
'
xls2db.py
'
],
url
=
'
https://git.math.uzh.ch/utilities/xsl2db
'
,
...
...
This diff is collapsed.
Click to expand it.
xls2db.py
+
7
−
1
View file @
d0386dd9
#!/usr/bin/env python
from
__future__
import
print_function
import
argparse
import
getpass
import
logging
import
sys
__author__
=
'
Rafael Ostertag <rafael.ostertag@math.uzh.ch>
'
...
...
@@ -20,6 +22,8 @@ def parse_argument():
nargs
=
'
*
'
)
parser
.
add_argument
(
"
--excel-file
"
,
help
=
"
Excel file to read. Can be a XSLX or XSL file.
"
,
required
=
True
)
parser
.
add_argument
(
"
--debug-output
"
,
help
=
"
Turn on debug output
"
,
action
=
'
store_true
'
,
default
=
False
)
parser
.
add_argument
(
"
--drop-database
"
,
help
=
"
Drop existing database
"
,
action
=
'
store_true
'
,
default
=
False
)
parser
.
add_argument
(
"
--database
"
,
help
=
"
Name of the database
"
,
default
=
None
,
required
=
True
)
return
parser
.
parse_args
()
...
...
@@ -96,11 +100,13 @@ if __name__ == "__main__":
if
arguments
.
user
:
server_connection_info
[
'
user
'
]
=
arguments
.
user
excel_file
=
excel
.
ExcelFile
(
arguments
.
excel_file
)
database
=
db
.
create_database
(
'
tmp
'
,
**
server_connection_info
)
database
=
db
.
create_database
(
arguments
.
database
,
arguments
.
drop_database
,
**
server_connection_info
)
sheet_info_list
=
make_sheet_info_from_argument
(
excel_file
,
arguments
.
sheet
)
for
sheet_info
in
sheet_info_list
:
import_sheet
(
database
,
excel_file
,
sheet_info
)
print
(
database
.
database_name
)
This diff is collapsed.
Click to expand it.
xls2dblib/db.py
+
12
−
6
View file @
d0386dd9
...
...
@@ -19,22 +19,28 @@ def _make_database_name(prefix):
def
_make_database_create
(
name
):
return
"
CREATE DATABASE {};
"
.
format
(
name
)
return
"
CREATE DATABASE
IF NOT EXISTS
{};
"
.
format
(
name
)
def
_make_database_drop
(
name
):
return
"
DROP DATABASE IF EXISTS {};
"
.
format
(
name
)
def
create_database
(
prefix
,
**
kwargs
):
def
create_database
(
name
,
drop
=
False
,
**
kwargs
):
db
=
MySQLdb
.
connect
(
**
kwargs
)
logger
.
debug
(
'
Connected to server %s
'
,
kwargs
[
'
host
'
])
cursor
=
db
.
cursor
()
database_name
=
_make_database_name
(
prefix
)
sql
=
_make_database_create
(
database_name
)
if
drop
:
sql
=
_make_database_drop
(
name
)
cursor
.
execute
(
sql
)
sql
=
_make_database_create
(
name
)
cursor
.
execute
(
sql
)
logger
.
debug
(
'
Created database %s
'
,
database_name
)
return
Database
(
database_name
,
**
kwargs
)
logger
.
debug
(
'
Created database %s
'
,
name
)
return
Database
(
name
,
**
kwargs
)
class
Database
(
object
):
...
...
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