Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
Odoo scripts
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Container Registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
Mise à jour Heptapod 17.8.2 faite
Show more breadcrumbs
XCG
Odoo scripts
Commits
3b5e05295e5e
Commit
3b5e05295e5e
authored
7 years ago
by
Vincent Hatakeyama
Browse files
Options
Downloads
Patches
Plain Diff
docker dev start: option to create user (also tries to detect if connection will work)
parent
929d341db31f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
docker_dev_start.py
+38
-1
38 additions, 1 deletion
docker_dev_start.py
with
38 additions
and
1 deletion
docker_dev_start.py
+
38
−
1
View file @
3b5e0529
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
"""
"""
import
argparse
import
argparse
import
logging
import
logging
import
pwd
from
subprocess
import
call
from
subprocess
import
call
import
sys
import
sys
import
os
import
os
...
@@ -12,6 +13,7 @@
...
@@ -12,6 +13,7 @@
import
ConfigParser
import
ConfigParser
from
netifaces
import
interfaces
,
ifaddresses
,
AF_INET
from
netifaces
import
interfaces
,
ifaddresses
,
AF_INET
from
psycopg2
import
connect
,
OperationalError
# TODO auto create list of module
# TODO auto create list of module
...
@@ -97,7 +99,13 @@
...
@@ -97,7 +99,13 @@
help
=
"
Module to avoid including demo data [default: %(default)s]
"
,
help
=
"
Module to avoid including demo data [default: %(default)s]
"
,
default
=
None
,
default
=
None
,
)
)
# XXX add auto create user and password?
parser
.
add_argument
(
'
--create
'
,
help
=
"
Create user/database (using your user)
"
,
action
=
'
store_true
'
,
)
# TODO detect that user is member of docker group
# TODO add a way to add options to docker
# TODO add a way to add options to docker
# TODO add a way to add arg to odoo
# TODO add a way to add arg to odoo
...
@@ -176,8 +184,10 @@
...
@@ -176,8 +184,10 @@
# auto detect local conf
# auto detect local conf
local_conf_path
=
'
conf/dev/odoo.conf
'
local_conf_path
=
'
conf/dev/odoo.conf
'
user
=
db_user
password
=
db_password
if
os
.
path
.
isfile
(
local_conf_path
):
if
os
.
path
.
isfile
(
local_conf_path
):
logging
.
info
(
'
Local configuration file found: %s
'
%
local_conf_path
)
logging
.
info
(
'
Local configuration file found: %s
'
%
local_conf_path
)
options
.
append
(
'
--volume
'
)
options
.
append
(
'
--volume
'
)
options
.
append
(
'
%s:/opt/odoo/etc/odoo.conf
'
%
os
.
path
.
join
(
options
.
append
(
'
%s:/opt/odoo/etc/odoo.conf
'
%
os
.
path
.
join
(
project_path
,
local_conf_path
))
project_path
,
local_conf_path
))
...
@@ -179,8 +189,35 @@
...
@@ -179,8 +189,35 @@
if
os
.
path
.
isfile
(
local_conf_path
):
if
os
.
path
.
isfile
(
local_conf_path
):
logging
.
info
(
'
Local configuration file found: %s
'
%
local_conf_path
)
logging
.
info
(
'
Local configuration file found: %s
'
%
local_conf_path
)
options
.
append
(
'
--volume
'
)
options
.
append
(
'
--volume
'
)
options
.
append
(
'
%s:/opt/odoo/etc/odoo.conf
'
%
os
.
path
.
join
(
options
.
append
(
'
%s:/opt/odoo/etc/odoo.conf
'
%
os
.
path
.
join
(
project_path
,
local_conf_path
))
project_path
,
local_conf_path
))
cp_local
=
ConfigParser
.
ConfigParser
()
cp_local
.
read
(
local_conf_path
)
if
not
user
:
user
=
cp_local
.
get
(
'
options
'
,
'
db_user
'
,
'
pg
'
)
if
not
password
:
password
=
cp_local
.
get
(
'
options
'
,
'
db_password
'
,
'
THIS-IS-NOT-USED-DONOT-CHANGE
'
)
# Check that connection can be done, try to create user if asked to
try
:
test_connection
=
connect
(
user
=
user
,
password
=
password
,
database
=
'
postgres
'
,
host
=
local_ip
)
except
OperationalError
as
exception
:
if
nmspc
.
create
:
logging
.
info
(
'
Cannot connect to database with user %s
'
,
user
)
logging
.
info
(
exception
)
logging
.
info
(
'
Creating user %s
'
,
user
)
loginname
=
pwd
.
getpwuid
(
os
.
getuid
())[
0
]
connection
=
connect
(
user
=
loginname
,
database
=
'
postgres
'
)
with
connection
.
cursor
()
as
cursor
:
# not injection safe but you are on your own machine
# with already full access to db
cursor
.
execute
(
'
CREATE ROLE %s LOGIN CREATEDB PASSWORD %%s
'
%
user
,
(
password
,
))
connection
.
commit
()
connection
.
close
()
else
:
logging
.
warn
(
'
Cannot connect to database with user %s
'
,
user
)
logging
.
warn
(
exception
)
# volume magic
# volume magic
for
addons_dir
in
addon_dirs
:
for
addons_dir
in
addon_dirs
:
...
...
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