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
19c0f590
Commit
19c0f590
authored
May 30, 2017
by
mouadh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
db_config_file
parent
18470cf9
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
130 additions
and
33 deletions
+130
-33
MANIFEST.in
MANIFEST.in
+1
-0
config/olapy-config.xml
config/olapy-config.xml
+15
-0
olapy/core/mdx/tools/connection.py
olapy/core/mdx/tools/connection.py
+14
-7
olapy/core/mdx/tools/olapy_config_file_parser.py
olapy/core/mdx/tools/olapy_config_file_parser.py
+56
-0
setup.py
setup.py
+44
-26
No files found.
MANIFEST.in
View file @
19c0f590
include *.rst *.txt *.ini *.py *.cfg *.yml
recursive-include olapy *
recursive-include cubes_templates *
recursive-include olapy/config *
prune tmp
prune instance
prune .git
\ No newline at end of file
config/olapy-config.xml
0 → 100644
View file @
19c0f590
<?xml version="1.0" encoding="UTF-8"?>
<olapy>
<database>
<!--<sgbd>postgres</sgbd>-->
<user_name>
postgres
</user_name>
<passowrd>
root
</passowrd>
<host>
localhost
</host>
</database>
</olapy>
olapy/core/mdx/tools/connection.py
View file @
19c0f590
import
psycopg2
as
pg
# postgres connection
USERNAME
=
'postgres'
PASSWORD
=
'root'
HOST
=
'localhost'
from
olapy.core.mdx.tools.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'
)
def
__init__
(
self
,
username
=
USERNAME
,
password
=
PASSWORD
,
username
=
get_db_credentials
()[
'user_name'
]
,
password
=
get_db_credentials
()[
'passowrd'
]
,
db
=
None
,
host
=
HOST
):
host
=
get_db_credentials
()[
'host'
]
):
if
db
is
None
:
self
.
connection
=
pg
.
connect
(
"user={0} password={1} host='{2}'"
.
format
(
username
,
password
,
host
))
...
...
olapy/core/mdx/tools/olapy_config_file_parser.py
0 → 100644
View file @
19c0f590
from
__future__
import
absolute_import
,
division
,
print_function
import
os
from
lxml
import
etree
class
DbConfigParser
:
# TODO one config file (I will try to merge dimensions between them in web part)
def
__init__
(
self
,
config_path
=
None
,
file_name
=
'olapy-config.xml'
):
"""
:param cube_path: path to cube (csv folders)
:param file_name: config file name (DEFAULT = cubes-config.xml)
"""
if
config_path
is
None
:
from
os.path
import
expanduser
home_directory
=
expanduser
(
"~"
)
self
.
cube_path
=
os
.
path
.
join
(
home_directory
,
'olapy-data'
)
else
:
self
.
cube_path
=
config_path
self
.
file_name
=
file_name
def
config_file_exist
(
self
):
"""
Check whether the config file exists or not.
:return: True | False
"""
return
os
.
path
.
isfile
(
os
.
path
.
join
(
self
.
cube_path
,
self
.
file_name
))
def
get_db_credentials
(
self
):
"""
Get all db credentials in the config file.
:return: list of cube name as key and cube source as value (csv or postgres) (right now only postgres is supported)
"""
with
open
(
os
.
path
.
join
(
self
.
cube_path
,
self
.
file_name
))
as
config_file
:
parser
=
etree
.
XMLParser
()
tree
=
etree
.
parse
(
config_file
,
parser
)
try
:
return
[
{
'sgbd'
:
db
.
find
(
'sgbd'
).
text
,
'user_name'
:
db
.
find
(
'user_name'
).
text
,
'passowrd'
:
db
.
find
(
'passowrd'
).
text
,
'host'
:
db
.
find
(
'host'
).
text
,
}
for
db
in
tree
.
xpath
(
'/olapy/database'
)
]
except
:
raise
(
'missed name or source tags'
)
setup.py
View file @
19c0f590
...
...
@@ -4,6 +4,7 @@ from __future__ import absolute_import, division, print_function
import
os
import
zipfile
from
os.path
import
expanduser
from
shutil
import
copyfile
from
pip.download
import
PipSession
from
pip.req
import
parse_requirements
...
...
@@ -11,7 +12,7 @@ from setuptools import find_packages, setup
RUNNING_TOX
=
'RUNNING_TOX'
in
os
.
environ
from
setuptools.command.install
import
install
#
from setuptools.command.install import install
# class PostDevelopCommand(develop):
...
...
@@ -27,27 +28,27 @@ from setuptools.command.install import install
# from manage import initdb
# initdb()
# # PUT YOUR POST-INSTALL SCRIPT HERE or CALL A FUNCTION
class
PostInstallCommand
(
install
):
"""Post-installation for installation mode."""
def
run
(
self
):
# PUT YOUR PRE-INSTALL SCRIPT HERE or CALL A FUNCTION
install
.
run
(
self
)
# initiate cubes examples
if
RUNNING_TOX
:
home_directory
=
os
.
environ
.
get
(
'HOME_DIR'
)
else
:
home_directory
=
expanduser
(
"~"
)
if
not
os
.
path
.
isdir
(
os
.
path
.
join
(
home_directory
,
'olapy-data'
,
'cubes'
)):
try
:
os
.
makedirs
(
os
.
path
.
join
(
home_directory
,
'olapy-data'
,
'cubes'
))
zip_ref
=
zipfile
.
ZipFile
(
'cubes_templates/cubes_temp.zip'
,
'r'
)
zip_ref
.
extractall
(
os
.
path
.
join
(
home_directory
,
'olapy-data'
,
'cubes'
))
zip_ref
.
close
()
except
:
raise
Exception
(
'unable to create cubes directory !'
)
#
#
class PostInstallCommand(install):
#
"""Post-installation for installation mode."""
#
def run(self):
#
# PUT YOUR PRE-INSTALL SCRIPT HERE or CALL A FUNCTION
#
#
install.run(self)
#
# initiate cubes examples
#
if RUNNING_TOX:
#
home_directory = os.environ.get('HOME_DIR')
#
else:
#
home_directory = expanduser("~")
#
#
if not os.path.isdir(os.path.join(home_directory, 'olapy-data', 'cubes')):
#
try:
#
os.makedirs(os.path.join(home_directory, 'olapy-data', 'cubes'))
#
zip_ref = zipfile.ZipFile('cubes_templates/cubes_temp.zip', 'r')
#
zip_ref.extractall(os.path.join(home_directory, 'olapy-data', 'cubes'))
#
zip_ref.close()
#
except:
#
raise Exception('unable to create cubes directory !')
session
=
PipSession
()
...
...
@@ -66,10 +67,10 @@ setup(
long_description
=
open
(
'README.rst'
).
read
(),
install_requires
=
install_requires
,
include_package_data
=
False
,
cmdclass
=
{
# 'develop': PostDevelopCommand,
'install'
:
PostInstallCommand
,
},
#
cmdclass={
#
# 'develop': PostDevelopCommand,
#
'install': PostInstallCommand,
#
},
classifiers
=
[
"Programming Language :: Python"
,
'Development Status :: 3 - Alpha'
,
...
...
@@ -82,4 +83,21 @@ setup(
# # generate and set secret key
# os.environ["SECRET_KEY"]
if
RUNNING_TOX
:
home_directory
=
os
.
environ
.
get
(
'HOME_DIR'
)
else
:
home_directory
=
expanduser
(
"~"
)
if
not
os
.
path
.
isdir
(
os
.
path
.
join
(
home_directory
,
'olapy-data'
,
'cubes'
)):
try
:
os
.
makedirs
(
os
.
path
.
join
(
home_directory
,
'olapy-data'
,
'cubes'
))
zip_ref
=
zipfile
.
ZipFile
(
'cubes_templates/cubes_temp.zip'
,
'r'
)
zip_ref
.
extractall
(
os
.
path
.
join
(
home_directory
,
'olapy-data'
,
'cubes'
))
zip_ref
.
close
()
except
:
raise
Exception
(
'unable to create cubes directory !'
)
if
not
os
.
path
.
isfile
(
os
.
path
.
join
(
home_directory
,
'olapy-data'
,
'olapy-config.xml'
)):
copyfile
(
'config/olapy-config.xml'
,
os
.
path
.
join
(
home_directory
,
'olapy-data'
,
'olapy-config.xml'
))
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