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
Tristan Cavelier
slapos.toolbox
Commits
7f695c24
Commit
7f695c24
authored
Jan 25, 2012
by
Alain Takoudjou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update Software inspection and Project Management
parent
7a935c83
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
93 additions
and
33 deletions
+93
-33
slapos/runner/static/fileTree.py
slapos/runner/static/fileTree.py
+0
-25
slapos/runner/utils.py
slapos/runner/utils.py
+54
-3
slapos/runner/views.py
slapos/runner/views.py
+39
-5
No files found.
slapos/runner/static/fileTree.py
deleted
100644 → 0
View file @
7a935c83
#
# jQuery File Tree
# Python/Django connector script
# By Martin Skou
#
import
os
import
urllib
def
dirlist
(
request
):
r
=
[
'<ul class="jqueryFileTree" style="display: none;">'
]
try
:
r
=
[
'<ul class="jqueryFileTree" style="display: none;">'
]
d
=
urllib
.
unquote
(
request
.
POST
.
get
(
'dir'
,
'c:
\
\
temp'
))
for
f
in
os
.
listdir
(
d
):
ff
=
os
.
path
.
join
(
d
,
f
)
if
os
.
path
.
isdir
(
ff
):
r
.
append
(
'<li class="directory collapsed"><a href="#" rel="%s/">%s</a></li>'
%
(
ff
,
f
))
else
:
e
=
os
.
path
.
splitext
(
f
)[
1
][
1
:]
# get .ext and remove dot
r
.
append
(
'<li class="file ext_%s"><a href="#" rel="%s">%s</a></li>'
%
(
e
,
ff
,
f
))
r
.
append
(
'</ul>'
)
except
Exception
,
e
:
r
.
append
(
'Could not load directory: %s'
%
str
(
e
))
r
.
append
(
'</ul>'
)
return
HttpResponse
(
''
.
join
(
r
))
\ No newline at end of file
slapos/runner/utils.py
View file @
7f695c24
...
@@ -133,6 +133,20 @@ def runSoftwareWithLock(config):
...
@@ -133,6 +133,20 @@ def runSoftwareWithLock(config):
slapgrid
=
Popen
([
config
[
'slapgrid_sr'
],
'-vc'
,
config
[
'configuration_file_path'
]],
stdout
=
logfile
)
slapgrid
=
Popen
([
config
[
'slapgrid_sr'
],
'-vc'
,
config
[
'configuration_file_path'
]],
stdout
=
logfile
)
writePid
(
slapgrid_pid
,
slapgrid
.
pid
)
writePid
(
slapgrid_pid
,
slapgrid
.
pid
)
slapgrid
.
wait
()
slapgrid
.
wait
()
#Saves the current compile software for re-use
data
=
loadSoftwareData
(
config
[
'runner_workdir'
])
md5
=
""
for
path
in
os
.
listdir
(
config
[
'software_root'
]):
exist
=
False
for
val
in
data
:
if
val
[
'md5'
]
==
path
:
exist
=
True
if
not
exist
:
#save this compile software folder
data
.
append
({
"title"
:
getProjectTitle
(
config
),
"md5"
:
path
,
"path"
:
open
(
os
.
path
.
join
(
config
[
'runner_workdir'
],
".project"
),
'r'
).
read
()})
writeSoftwareData
(
config
[
'runner_workdir'
],
data
)
break
return
True
return
True
return
False
return
False
...
@@ -222,7 +236,7 @@ def getSvcTailProcess(config, process):
...
@@ -222,7 +236,7 @@ def getSvcTailProcess(config, process):
"tail", process]).communicate()[0]
"tail", process]).communicate()[0]
def svcStartStopProcess(config, process, action):
def svcStartStopProcess(config, process, action):
cmd = {"RESTART":"restart", "STOPPED":"start", "RUNNING":"stop"}
cmd = {"RESTART":"restart", "STOPPED":"start", "RUNNING":"stop"
, "EXITED":"start", "STOP":"stop"
}
return Popen([config['
supervisor
'], config['
configuration_file_path
'],
return Popen([config['
supervisor
'], config['
configuration_file_path
'],
cmd[action], process]).communicate()[0]
cmd[action], process]).communicate()[0]
...
@@ -315,5 +329,42 @@ def getProjectTitle(config):
...
@@ -315,5 +329,42 @@ def getProjectTitle(config):
project = open(conf, "r").read().replace(config['
workspace
'] + "/", "").split("/")
project = open(conf, "r").read().replace(config['
workspace
'] + "/", "").split("/")
software = project[len(project) - 1]
software = project[len(project) - 1]
del project[len(project) - 1]
del project[len(project) - 1]
return software + "(" + string.join(project, '
/
') + ")"
return software + "(in " + string.join(project, '
/
') + ")"
return ""
return "No Profile"
\ No newline at end of file
def loadSoftwareData(runner_dir):
import pickle
file_path = os.path.join(runner_dir, '
.
softdata
')
if not os.path.exists(file_path):
return []
pkl_file = open(file_path, 'rb')
data = pickle.load(pkl_file)
pkl_file.close()
return data
def writeSoftwareData(runner_dir, data):
import pickle
file_path = os.path.join(runner_dir, '
.
softdata
')
pkl_file = open(file_path, '
wb
')
# Pickle dictionary using protocol 0.
pickle.dump(data, pkl_file)
pkl_file.close()
def removeSoftwareByName(config, folderName):
if isSoftwareRunning(config) or isInstanceRunning(config):
return jsonify(code=0, result="Software installation or instantiation in progress, cannot remove")
path = os.path.join(config['
software_root
'], folderName)
if not os.path.exists(path):
return jsonify(code=0, result="Can not remove software: No such file or directory")
svcStopAll(config)
shutil.rmtree(path)
#update compiled software list
data = loadSoftwareData(config['
runner_workdir
'])
i = 0
for p in data:
if p['
md5
'] == folderName:
del data[i]
writeSoftwareData(config['
runner_workdir
'], data)
break
i = i+1
return jsonify(code=1, result=data)
\ No newline at end of file
slapos/runner/views.py
View file @
7f695c24
...
@@ -3,7 +3,8 @@ from flask import Flask, request, redirect, url_for, \
...
@@ -3,7 +3,8 @@ from flask import Flask, request, redirect, url_for, \
from
utils
import
*
from
utils
import
*
import
os
import
os
import
shutil
import
shutil
from
gittools
import
cloneRepo
,
gitStatus
from
gittools
import
cloneRepo
,
gitStatus
,
switchBranch
,
createBranch
,
getDiff
,
\
gitPush
app
=
Flask
(
__name__
)
app
=
Flask
(
__name__
)
...
@@ -40,10 +41,9 @@ def inspectSoftware():
...
@@ -40,10 +41,9 @@ def inspectSoftware():
if
not
os
.
path
.
exists
(
app
.
config
[
'software_root'
]):
if
not
os
.
path
.
exists
(
app
.
config
[
'software_root'
]):
result
=
""
result
=
""
else
:
else
:
#process = Popen(['find'], cwd=app.config['software_root'])
result
=
app
.
config
[
'software_root'
]
result
=
app
.
config
[
'software_root'
]
return
render_template
(
'runResult.html'
,
type
=
'Software'
,
return
render_template
(
'runResult.html'
,
softwareRoot
=
app
.
config
[
'software_root'
]
,
result
=
result
)
softwares
=
loadSoftwareData
(
app
.
config
[
'runner_workdir'
])
)
@
app
.
route
(
'/removeSoftware'
)
@
app
.
route
(
'/removeSoftware'
)
def
removeSoftware
():
def
removeSoftware
():
...
@@ -52,6 +52,7 @@ def removeSoftware():
...
@@ -52,6 +52,7 @@ def removeSoftware():
elif
os
.
path
.
exists
(
app
.
config
[
'software_root'
]):
elif
os
.
path
.
exists
(
app
.
config
[
'software_root'
]):
svcStopAll
(
app
.
config
)
svcStopAll
(
app
.
config
)
shutil
.
rmtree
(
app
.
config
[
'software_root'
])
shutil
.
rmtree
(
app
.
config
[
'software_root'
])
os
.
remove
(
os
.
path
.
join
(
config
[
'runner_workdir'
],
".softdata"
))
flash
(
'Software removed'
)
flash
(
'Software removed'
)
return
redirect
(
url_for
(
'inspectSoftware'
))
return
redirect
(
url_for
(
'inspectSoftware'
))
...
@@ -244,6 +245,21 @@ def createFile():
...
@@ -244,6 +245,21 @@ def createFile():
except
Exception
,
e
:
except
Exception
,
e
:
return
jsonify
(
code
=
0
,
result
=
str
(
e
))
return
jsonify
(
code
=
0
,
result
=
str
(
e
))
@
app
.
route
(
"/removeFile"
,
methods
=
[
'POST'
])
def
removeFile
():
try
:
if
request
.
form
[
'type'
]
==
"folder"
:
shutil
.
rmtree
(
request
.
form
[
'path'
])
else
:
os
.
remove
(
request
.
form
[
'path'
])
return
jsonify
(
code
=
1
,
result
=
""
)
except
Exception
,
e
:
return
jsonify
(
code
=
0
,
result
=
str
(
e
))
@
app
.
route
(
"/removeSoftwareDir"
,
methods
=
[
'POST'
])
def
removeSoftwareDir
():
return
removeSoftwareByName
(
app
.
config
,
request
.
form
[
'name'
])
@
app
.
route
(
"/getFileContent"
,
methods
=
[
'POST'
])
@
app
.
route
(
"/getFileContent"
,
methods
=
[
'POST'
])
def
getFileContent
():
def
getFileContent
():
if
os
.
path
.
exists
(
request
.
form
[
'file'
]):
if
os
.
path
.
exists
(
request
.
form
[
'file'
]):
...
@@ -257,4 +273,22 @@ def saveFileContent():
...
@@ -257,4 +273,22 @@ def saveFileContent():
open
(
request
.
form
[
'file'
],
'w'
).
write
(
request
.
form
[
'content'
])
open
(
request
.
form
[
'file'
],
'w'
).
write
(
request
.
form
[
'content'
])
return
jsonify
(
code
=
1
,
result
=
""
)
return
jsonify
(
code
=
1
,
result
=
""
)
else
:
else
:
return
jsonify
(
code
=
0
,
result
=
"Error: No such file!"
)
return
jsonify
(
code
=
0
,
result
=
"Error: No such file!"
)
\ No newline at end of file
@
app
.
route
(
"/changeBranch"
,
methods
=
[
'POST'
])
def
changeBranch
():
return
switchBranch
(
request
.
form
[
'project'
],
request
.
form
[
'name'
])
@
app
.
route
(
"/newBranch"
,
methods
=
[
'POST'
])
def
newBranch
():
return
createBranch
(
request
.
form
[
'project'
],
request
.
form
[
'name'
])
@
app
.
route
(
"/getProjectDiff/<project>"
,
methods
=
[
'GET'
])
def
getProjectDiff
(
project
):
path
=
os
.
path
.
join
(
app
.
config
[
'workspace'
],
project
)
return
render_template
(
'projectDiff.html'
,
project
=
project
,
diff
=
getDiff
(
path
))
@
app
.
route
(
"/pushProjectFiles"
,
methods
=
[
'POST'
])
def
pushProjectFiles
():
return
gitPush
(
request
.
form
[
'project'
],
request
.
form
[
'msg'
],
False
)
\ No newline at end of file
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