Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
cd0dd2a6
Commit
cd0dd2a6
authored
Mar 25, 2013
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2496 from lorin/mycnf-quotes
Strip quotes when parsing my.cnf
parents
fee20142
c9990b80
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
6 deletions
+69
-6
library/mysql_db
+34
-3
library/mysql_user
+35
-3
No files found.
library/mysql_db
View file @
cd0dd2a6
...
...
@@ -129,6 +129,37 @@ def db_create(cursor, db, encoding, collation):
res
=
cursor
.
execute
(
query
)
return
True
def
strip_quotes
(
s
):
""" Remove surrounding single or double quotes
>>> print strip_quotes('hello')
hello
>>> print strip_quotes('"hello"')
hello
>>> print strip_quotes("'hello'")
hello
>>> print strip_quotes("'hello")
'hello
"""
single_quote
=
"'"
double_quote
=
'"'
if
s
.
startswith
(
single_quote
)
and
s
.
endswith
(
single_quote
):
s
=
s
.
strip
(
single_quote
)
elif
s
.
startswith
(
double_quote
)
and
s
.
endswith
(
double_quote
):
s
=
s
.
strip
(
double_quote
)
return
s
def
config_get
(
config
,
section
,
option
):
""" Calls ConfigParser.get and strips quotes
See: http://dev.mysql.com/doc/refman/5.0/en/option-files.html
"""
return
strip_quotes
(
config
.
get
(
section
,
option
))
def
load_mycnf
():
config
=
ConfigParser
.
RawConfigParser
()
mycnf
=
os
.
path
.
expanduser
(
'~/.my.cnf'
)
...
...
@@ -141,14 +172,14 @@ def load_mycnf():
# We support two forms of passwords in .my.cnf, both pass= and password=,
# as these are both supported by MySQL.
try
:
passwd
=
config
.
get
(
'client'
,
'password'
)
passwd
=
config
_get
(
config
,
'client'
,
'password'
)
except
(
ConfigParser
.
NoOptionError
):
try
:
passwd
=
config
.
get
(
'client'
,
'pass'
)
passwd
=
config
_get
(
config
,
'client'
,
'pass'
)
except
(
ConfigParser
.
NoOptionError
):
return
False
try
:
creds
=
dict
(
user
=
config
.
get
(
'client'
,
'user'
),
passwd
=
passwd
)
creds
=
dict
(
user
=
config
_get
(
config
,
'client'
,
'user'
),
passwd
=
passwd
)
except
(
ConfigParser
.
NoOptionError
):
return
False
return
creds
...
...
library/mysql_user
View file @
cd0dd2a6
...
...
@@ -252,6 +252,38 @@ def privileges_grant(cursor, user,host,db_table,priv):
query
=
query
+
" WITH GRANT OPTION"
cursor
.
execute
(
query
)
def
strip_quotes
(
s
):
""" Remove surrounding single or double quotes
>>> print strip_quotes('hello')
hello
>>> print strip_quotes('"hello"')
hello
>>> print strip_quotes("'hello'")
hello
>>> print strip_quotes("'hello")
'hello
"""
single_quote
=
"'"
double_quote
=
'"'
if
s
.
startswith
(
single_quote
)
and
s
.
endswith
(
single_quote
):
s
=
s
.
strip
(
single_quote
)
elif
s
.
startswith
(
double_quote
)
and
s
.
endswith
(
double_quote
):
s
=
s
.
strip
(
double_quote
)
return
s
def
config_get
(
config
,
section
,
option
):
""" Calls ConfigParser.get and strips quotes
See: http://dev.mysql.com/doc/refman/5.0/en/option-files.html
"""
return
strip_quotes
(
config
.
get
(
section
,
option
))
def
load_mycnf
():
config
=
ConfigParser
.
RawConfigParser
()
mycnf
=
os
.
path
.
expanduser
(
'~/.my.cnf'
)
...
...
@@ -264,16 +296,16 @@ def load_mycnf():
# We support two forms of passwords in .my.cnf, both pass= and password=,
# as these are both supported by MySQL.
try
:
passwd
=
config
.
get
(
'client'
,
'password'
)
passwd
=
config
_get
(
config
,
'client'
,
'password'
)
except
(
ConfigParser
.
NoOptionError
):
try
:
passwd
=
config
.
get
(
'client'
,
'pass'
)
passwd
=
config
_get
(
config
,
'client'
,
'pass'
)
except
(
ConfigParser
.
NoOptionError
):
return
False
# If .my.cnf doesn't specify a user, default to user login name
try
:
user
=
config
.
get
(
'client'
,
'user'
)
user
=
config
_get
(
config
,
'client'
,
'user'
)
except
(
ConfigParser
.
NoOptionError
):
user
=
getpass
.
getuser
()
creds
=
dict
(
user
=
user
,
passwd
=
passwd
)
...
...
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