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
Xavier Thompson
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):
slapgrid
=
Popen
([
config
[
'slapgrid_sr'
],
'-vc'
,
config
[
'configuration_file_path'
]],
stdout
=
logfile
)
writePid
(
slapgrid_pid
,
slapgrid
.
pid
)
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
False
...
...
@@ -222,7 +236,7 @@ def getSvcTailProcess(config, process):
"tail", process]).communicate()[0]
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
'],
cmd[action], process]).communicate()[0]
...
...
@@ -315,5 +329,42 @@ def getProjectTitle(config):
project = open(conf, "r").read().replace(config['
workspace
'] + "/", "").split("/")
software = project[len(project) - 1]
del project[len(project) - 1]
return software + "(" + string.join(project, '
/
') + ")"
return ""
\ No newline at end of file
return software + "(in " + string.join(project, '
/
') + ")"
return "No Profile"
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, \
from
utils
import
*
import
os
import
shutil
from
gittools
import
cloneRepo
,
gitStatus
from
gittools
import
cloneRepo
,
gitStatus
,
switchBranch
,
createBranch
,
getDiff
,
\
gitPush
app
=
Flask
(
__name__
)
...
...
@@ -40,10 +41,9 @@ def inspectSoftware():
if
not
os
.
path
.
exists
(
app
.
config
[
'software_root'
]):
result
=
""
else
:
#process = Popen(['find'], cwd=app.config['software_root'])
result
=
app
.
config
[
'software_root'
]
return
render_template
(
'runResult.html'
,
type
=
'Software'
,
result
=
result
)
return
render_template
(
'runResult.html'
,
softwareRoot
=
app
.
config
[
'software_root'
]
,
softwares
=
loadSoftwareData
(
app
.
config
[
'runner_workdir'
])
)
@
app
.
route
(
'/removeSoftware'
)
def
removeSoftware
():
...
...
@@ -52,6 +52,7 @@ def removeSoftware():
elif
os
.
path
.
exists
(
app
.
config
[
'software_root'
]):
svcStopAll
(
app
.
config
)
shutil
.
rmtree
(
app
.
config
[
'software_root'
])
os
.
remove
(
os
.
path
.
join
(
config
[
'runner_workdir'
],
".softdata"
))
flash
(
'Software removed'
)
return
redirect
(
url_for
(
'inspectSoftware'
))
...
...
@@ -244,6 +245,21 @@ def createFile():
except
Exception
,
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'
])
def
getFileContent
():
if
os
.
path
.
exists
(
request
.
form
[
'file'
]):
...
...
@@ -257,4 +273,22 @@ def saveFileContent():
open
(
request
.
form
[
'file'
],
'w'
).
write
(
request
.
form
[
'content'
])
return
jsonify
(
code
=
1
,
result
=
""
)
else
:
return
jsonify
(
code
=
0
,
result
=
"Error: No such file!"
)
\ No newline at end of file
return
jsonify
(
code
=
0
,
result
=
"Error: No such 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