Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.toolbox
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Eric Zheng
slapos.toolbox
Commits
c6aeb904
Commit
c6aeb904
authored
Mar 26, 2013
by
Cédric de Saint Martin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for running SQL scripts in lampconfigure.
parent
e298fa41
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
13 deletions
+45
-13
slapos/lamp/__init__.py
slapos/lamp/__init__.py
+45
-13
No files found.
slapos/lamp/__init__.py
View file @
c6aeb904
...
@@ -62,6 +62,12 @@ def run():
...
@@ -62,6 +62,12 @@ def run():
script_parser
=
subparsers
.
add_parser
(
'run'
,
help
=
'Run python script'
)
script_parser
=
subparsers
.
add_parser
(
'run'
,
help
=
'Run python script'
)
script_parser
.
add_argument
(
'script'
,
action
=
'store'
,
help
=
'The path of python script to execute'
)
script_parser
.
add_argument
(
'script'
,
action
=
'store'
,
help
=
'The path of python script to execute'
)
script_parser
.
add_argument
(
'-v'
,
action
=
'store'
,
help
=
'Other argument to pass to the script'
,
nargs
=
'+'
,
dest
=
'args'
)
script_parser
.
add_argument
(
'-v'
,
action
=
'store'
,
help
=
'Other argument to pass to the script'
,
nargs
=
'+'
,
dest
=
'args'
)
# A SQL script command
sql_parser
=
subparsers
.
add_parser
(
'sql'
,
help
=
'Run SQL script'
)
sql_parser
.
add_argument
(
'sql_script'
,
action
=
'store'
,
help
=
'The path of python script to execute'
)
sql_parser
.
add_argument
(
'-v'
,
action
=
'store'
,
help
=
'Other argument to pass to the script'
,
nargs
=
'+'
,
dest
=
'args'
)
#A chmod command
#A chmod command
chmod_parser
=
subparsers
.
add_parser
(
'chmod'
,
help
=
'Set the mode of file or directory'
)
chmod_parser
=
subparsers
.
add_parser
(
'chmod'
,
help
=
'Set the mode of file or directory'
)
chmod_parser
.
add_argument
(
'mode'
,
action
=
'store'
,
help
=
'the mode to apply to TARGET'
)
chmod_parser
.
add_argument
(
'mode'
,
action
=
'store'
,
help
=
'the mode to apply to TARGET'
)
...
@@ -91,6 +97,9 @@ def setup(arguments):
...
@@ -91,6 +97,9 @@ def setup(arguments):
if
arguments
.
has_key
(
'script'
):
if
arguments
.
has_key
(
'script'
):
run_script
(
arguments
)
run_script
(
arguments
)
if
arguments
.
has_key
(
'sql_script'
):
run_sql_script
(
arguments
)
if
arguments
.
has_key
(
'chmod_target'
):
if
arguments
.
has_key
(
'chmod_target'
):
chmod
(
arguments
)
chmod
(
arguments
)
return
return
...
@@ -119,18 +128,18 @@ def checkAction(arguments):
...
@@ -119,18 +128,18 @@ def checkAction(arguments):
row
=
cursor
.
fetchone
()
row
=
cursor
.
fetchone
()
if
row
==
None
:
if
row
==
None
:
conn
.
close
()
conn
.
close
()
return
Fals
e
return
Tru
e
else
:
else
:
arguments
[
'table'
]
=
row
[
0
]
arguments
[
'table'
]
=
row
[
0
]
cursor
.
execute
(
"SELECT * FROM "
+
arguments
[
'table'
]
+
" WHERE "
+
arguments
[
'condition'
])
cursor
.
execute
(
"SELECT * FROM "
+
arguments
[
'table'
]
+
" WHERE "
+
arguments
[
'condition'
])
row
=
cursor
.
fetchone
()
row
=
cursor
.
fetchone
()
conn
.
close
()
conn
.
close
()
if
row
==
None
:
if
row
==
None
:
return
False
else
:
return
True
return
True
else
:
else
:
return
os
.
path
.
exists
(
os
.
path
.
join
(
arguments
[
'target_directory'
],
arguments
[
'file_token'
]))
return
False
else
:
return
not
os
.
path
.
exists
(
os
.
path
.
join
(
arguments
[
'target_directory'
],
arguments
[
'file_token'
]))
def
rename
(
arguments
):
def
rename
(
arguments
):
source
=
os
.
path
.
join
(
arguments
[
'target_directory'
],
arguments
[
'source'
])
source
=
os
.
path
.
join
(
arguments
[
'target_directory'
],
arguments
[
'source'
])
...
@@ -155,6 +164,7 @@ def delete(arguments):
...
@@ -155,6 +164,7 @@ def delete(arguments):
def
run_script
(
arguments
):
def
run_script
(
arguments
):
script
=
os
.
path
.
join
(
arguments
[
'target_directory'
],
arguments
[
'script'
])
script
=
os
.
path
.
join
(
arguments
[
'target_directory'
],
arguments
[
'script'
])
print
'Running script: %s'
%
script
if
os
.
path
.
exists
(
script
):
if
os
.
path
.
exists
(
script
):
import
subprocess
import
subprocess
#run python script with predefined data
#run python script with predefined data
...
@@ -168,6 +178,28 @@ def run_script(arguments):
...
@@ -168,6 +178,28 @@ def run_script(arguments):
else
:
else
:
print
"Error: can not read file '%s'"
%
script
print
"Error: can not read file '%s'"
%
script
def
run_sql_script
(
arguments
):
script
=
os
.
path
.
join
(
arguments
[
'target_directory'
],
arguments
[
'sql_script'
])
print
'Running SQL script: %s'
%
script
if
os
.
path
.
exists
(
script
):
conn
=
MySQLdb
.
connect
(
host
=
arguments
[
'mysql_host'
],
port
=
int
(
arguments
[
'mysql_port'
]),
user
=
arguments
[
'mysql_user'
],
passwd
=
arguments
[
'mysql_password'
],
# XXX ugly, to simplify
db
=
arguments
[
'args'
][
0
])
cursor
=
conn
.
cursor
()
with
open
(
script
,
'r'
)
as
f
:
sql_script
=
f
.
read
()
cursor
.
execute
(
sql_script
)
conn
.
close
()
else
:
print
"Error: can not read file '%s'"
%
script
def
chmod
(
arguments
):
def
chmod
(
arguments
):
for
path
in
arguments
[
'chmod_target'
]:
for
path
in
arguments
[
'chmod_target'
]:
path
=
os
.
path
.
join
(
arguments
[
'target_directory'
],
path
)
path
=
os
.
path
.
join
(
arguments
[
'target_directory'
],
path
)
...
...
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