Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
olapy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
2
Merge Requests
2
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
olapy
Commits
44a31ef6
Commit
44a31ef6
authored
May 30, 2017
by
mouadh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
db config file
parent
19c0f590
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
15 deletions
+26
-15
config/olapy-config.xml
config/olapy-config.xml
+1
-1
olapy/core/mdx/tools/connection.py
olapy/core/mdx/tools/connection.py
+22
-12
olapy/core/mdx/tools/olapy_config_file_parser.py
olapy/core/mdx/tools/olapy_config_file_parser.py
+3
-2
No files found.
config/olapy-config.xml
View file @
44a31ef6
...
...
@@ -6,7 +6,7 @@
<!--<sgbd>postgres</sgbd>-->
<user_name>
postgres
</user_name>
<pass
owrd>
root
</passow
rd>
<pass
word>
root
</passwo
rd>
<host>
localhost
</host>
</database>
...
...
olapy/core/mdx/tools/connection.py
View file @
44a31ef6
import
psycopg2
as
pg
# postgres connection
from
olapy
.core.mdx.tools.olapy
_config_file_parser
import
DbConfigParser
from
olapy_config_file_parser
import
DbConfigParser
class
MyDB
(
object
):
"""Connect to sql database (postgres only right now)."""
@
staticmethod
def
get_
db_credentials
():
db_config
=
DbConfigParser
()
if
db_config
.
config_file_exist
():
# many databases in the future maybe
return
db_config
.
get_db_credentials
()[
0
]
else
:
raise
Exception
(
'Missing database config file'
)
#
@staticmethod
# def
db_credentials():
#
db_config = DbConfigParser()
#
if db_config.config_file_exist():
#
# many databases in the future maybe
#
return db_config.get_db_credentials()[0]
#
else:
#
raise Exception('Missing database config file')
def
__init__
(
self
,
username
=
get_db_credentials
()[
'user_name'
]
,
password
=
get_db_credentials
()[
'passowrd'
]
,
username
=
'postgres'
,
password
=
'root'
,
db
=
None
,
host
=
get_db_credentials
()[
'host'
]):
host
=
'localhost'
):
# TODO temporary
db_config
=
DbConfigParser
()
db_credentials
=
db_config
.
get_db_credentials
()[
0
]
username
=
db_credentials
[
'user_name'
]
password
=
db_credentials
[
'password'
]
host
=
db_credentials
[
'host'
]
if
db
is
None
:
self
.
connection
=
pg
.
connect
(
"user={0} password={1} host='{2}'"
.
format
(
username
,
password
,
host
))
else
:
...
...
olapy/core/mdx/tools/olapy_config_file_parser.py
View file @
44a31ef6
...
...
@@ -45,9 +45,10 @@ class DbConfigParser:
try
:
return
[
{
'sgbd'
:
db
.
find
(
'sgbd'
).
text
,
{
# 'sgbd': db.find('sgbd').text,
'user_name'
:
db
.
find
(
'user_name'
).
text
,
'pass
owrd'
:
db
.
find
(
'passow
rd'
).
text
,
'pass
word'
:
db
.
find
(
'passwo
rd'
).
text
,
'host'
:
db
.
find
(
'host'
).
text
,
}
for
db
in
tree
.
xpath
(
'/olapy/database'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment