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
decbd4b3
Commit
decbd4b3
authored
Jun 29, 2012
by
Alain Takoudjou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding comments
parent
5d472df2
Changes
3
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
205 additions
and
4 deletions
+205
-4
slapos/runner/gittools.py
slapos/runner/gittools.py
+33
-0
slapos/runner/utils.py
slapos/runner/utils.py
+161
-4
slapos/runner/views.py
slapos/runner/views.py
+11
-0
No files found.
slapos/runner/gittools.py
View file @
decbd4b3
...
@@ -23,6 +23,15 @@ class Popen(subprocess.Popen):
...
@@ -23,6 +23,15 @@ class Popen(subprocess.Popen):
self
.
stdin
=
None
self
.
stdin
=
None
def
cloneRepo
(
data
):
def
cloneRepo
(
data
):
"""Clonne a repository
Args:
data: a dictionnary of parameters to use:
data['path'] is the path of the new project
data['repo'] is the url of the repository to be cloned
data['email'] is the user email
data['user'] is the name of the user
Returns:
a jsonify data"""
workDir
=
data
[
'path'
]
workDir
=
data
[
'path'
]
if
not
workDir
:
if
not
workDir
:
return
jsonify
(
code
=
0
,
return
jsonify
(
code
=
0
,
...
@@ -47,6 +56,11 @@ def cloneRepo(data):
...
@@ -47,6 +56,11 @@ def cloneRepo(data):
return
jsonify
(
code
=
code
,
result
=
json
)
return
jsonify
(
code
=
code
,
result
=
json
)
def
gitStatus
(
project
):
def
gitStatus
(
project
):
"""Run git status and return status of specified project folder
Args:
project: path of the projet ti get status
Returns:
a parsed string that contains the result of git status"""
code
=
0
code
=
0
json
=
""
json
=
""
try
:
try
:
...
@@ -61,6 +75,12 @@ def gitStatus(project):
...
@@ -61,6 +75,12 @@ def gitStatus(project):
return
jsonify
(
code
=
code
,
result
=
json
,
branch
=
branch
,
dirty
=
isdirty
)
return
jsonify
(
code
=
code
,
result
=
json
,
branch
=
branch
,
dirty
=
isdirty
)
def
switchBranch
(
project
,
name
):
def
switchBranch
(
project
,
name
):
"""Switch a git branch
Args:
project: directory of the local git repository
name: switch from current branch to `name` branch
Returns:
a jsonify data"""
code
=
0
code
=
0
json
=
""
json
=
""
try
:
try
:
...
@@ -78,6 +98,13 @@ def switchBranch(project, name):
...
@@ -78,6 +98,13 @@ def switchBranch(project, name):
return
jsonify
(
code
=
code
,
result
=
json
)
return
jsonify
(
code
=
code
,
result
=
json
)
def
addBranch
(
project
,
name
,
onlyCheckout
=
False
):
def
addBranch
(
project
,
name
,
onlyCheckout
=
False
):
"""Add new git branch to the repository
Args:
project: directory of the local git repository
name: name of the new branch
onlyCheckout: if True then the branch `name` is created before checkout
Returns:
a jsonify data"""
code
=
0
code
=
0
json
=
""
json
=
""
try
:
try
:
...
@@ -93,6 +120,7 @@ def addBranch(project, name, onlyCheckout=False):
...
@@ -93,6 +120,7 @@ def addBranch(project, name, onlyCheckout=False):
return
jsonify
(
code
=
code
,
result
=
json
)
return
jsonify
(
code
=
code
,
result
=
json
)
def
getDiff
(
project
):
def
getDiff
(
project
):
"""Get git diff for the specified project directory"""
result
=
""
result
=
""
try
:
try
:
repo
=
Repo
(
project
)
repo
=
Repo
(
project
)
...
@@ -104,6 +132,10 @@ def getDiff(project):
...
@@ -104,6 +132,10 @@ def getDiff(project):
return
result
return
result
def
gitPush
(
project
,
msg
):
def
gitPush
(
project
,
msg
):
"""Commit and Push changes for the specified repository
Args:
project: directory of the local repository
msg: commit message"""
code
=
0
code
=
0
json
=
""
json
=
""
undo_commit
=
False
undo_commit
=
False
...
@@ -145,5 +177,6 @@ def gitPull(project):
...
@@ -145,5 +177,6 @@ def gitPull(project):
return
jsonify
(
code
=
code
,
result
=
result
)
return
jsonify
(
code
=
code
,
result
=
result
)
def
safeResult
(
result
):
def
safeResult
(
result
):
"""Parse string and remove credential of the user"""
regex
=
re
.
compile
(
"(https:
\
/
\
/)([
\
w
\
d
\
._-]+:[
\
w
\
d
\
._-]+)
\
@([
\
S]+
\
s)
"
, re.VERBOSE)
regex
=
re
.
compile
(
"(https:
\
/
\
/)([
\
w
\
d
\
._-]+:[
\
w
\
d
\
._-]+)
\
@([
\
S]+
\
s)
"
, re.VERBOSE)
return regex.sub(r'
\
1
\
3
', result)
return regex.sub(r'
\
1
\
3
', result)
\ No newline at end of file
slapos/runner/utils.py
View file @
decbd4b3
This diff is collapsed.
Click to expand it.
slapos/runner/views.py
View file @
decbd4b3
...
@@ -77,6 +77,7 @@ def inspectSoftware():
...
@@ -77,6 +77,7 @@ def inspectSoftware():
return
render_template
(
'runResult.html'
,
softwareRoot
=
'software_root'
,
return
render_template
(
'runResult.html'
,
softwareRoot
=
'software_root'
,
softwares
=
loadSoftwareData
(
app
.
config
[
'runner_workdir'
]))
softwares
=
loadSoftwareData
(
app
.
config
[
'runner_workdir'
]))
#remove content of compiled software release
@
app
.
route
(
'/removeSoftware'
)
@
app
.
route
(
'/removeSoftware'
)
def
removeSoftware
():
def
removeSoftware
():
file_config
=
os
.
path
.
join
(
app
.
config
[
'runner_workdir'
],
".softdata"
)
file_config
=
os
.
path
.
join
(
app
.
config
[
'runner_workdir'
],
".softdata"
)
...
@@ -114,6 +115,7 @@ def editInstanceProfile():
...
@@ -114,6 +115,7 @@ def editInstanceProfile():
return
render_template
(
'updateInstanceProfile.html'
,
workDir
=
'workspace'
,
return
render_template
(
'updateInstanceProfile.html'
,
workDir
=
'workspace'
,
profile
=
profile
,
projectList
=
getProjectList
(
app
.
config
[
'workspace'
]))
profile
=
profile
,
projectList
=
getProjectList
(
app
.
config
[
'workspace'
]))
# get status of all computer partitions and process state
@
app
.
route
(
'/inspectInstance'
,
methods
=
[
'GET'
])
@
app
.
route
(
'/inspectInstance'
,
methods
=
[
'GET'
])
def
inspectInstance
():
def
inspectInstance
():
file_content
=
''
file_content
=
''
...
@@ -127,6 +129,7 @@ def inspectInstance():
...
@@ -127,6 +129,7 @@ def inspectInstance():
file_path
=
file_content
,
supervisor
=
result
,
slap_status
=
getSlapStatus
(
app
.
config
),
file_path
=
file_content
,
supervisor
=
result
,
slap_status
=
getSlapStatus
(
app
.
config
),
supervisore
=
result
,
partition_amount
=
app
.
config
[
'partition_amount'
])
supervisore
=
result
,
partition_amount
=
app
.
config
[
'partition_amount'
])
#Reload instance process ans returns new value to ajax
@
app
.
route
(
'/supervisordStatus'
,
methods
=
[
'GET'
])
@
app
.
route
(
'/supervisordStatus'
,
methods
=
[
'GET'
])
def
supervisordStatus
():
def
supervisordStatus
():
result
=
getSvcStatus
(
app
.
config
)
result
=
getSvcStatus
(
app
.
config
)
...
@@ -253,6 +256,7 @@ def getProjectStatus():
...
@@ -253,6 +256,7 @@ def getProjectStatus():
else
:
else
:
return
jsonify
(
code
=
0
,
result
=
"Can not read folder: Permission Denied"
)
return
jsonify
(
code
=
0
,
result
=
"Can not read folder: Permission Denied"
)
#view for current software release files
@
app
.
route
(
"/editCurrentProject"
)
@
app
.
route
(
"/editCurrentProject"
)
def
editCurrentProject
():
def
editCurrentProject
():
project
=
os
.
path
.
join
(
app
.
config
[
'runner_workdir'
],
".project"
)
project
=
os
.
path
.
join
(
app
.
config
[
'runner_workdir'
],
".project"
)
...
@@ -262,6 +266,7 @@ def editCurrentProject():
...
@@ -262,6 +266,7 @@ def editCurrentProject():
projectList
=
getProjectList
(
app
.
config
[
'workspace'
]))
projectList
=
getProjectList
(
app
.
config
[
'workspace'
]))
return
redirect
(
url_for
(
'configRepo'
))
return
redirect
(
url_for
(
'configRepo'
))
#create file or directory
@
app
.
route
(
"/createFile"
,
methods
=
[
'POST'
])
@
app
.
route
(
"/createFile"
,
methods
=
[
'POST'
])
def
createFile
():
def
createFile
():
path
=
realpath
(
app
.
config
,
request
.
form
[
'file'
],
False
)
path
=
realpath
(
app
.
config
,
request
.
form
[
'file'
],
False
)
...
@@ -277,6 +282,7 @@ def createFile():
...
@@ -277,6 +282,7 @@ def createFile():
except
Exception
,
e
:
except
Exception
,
e
:
return
jsonify
(
code
=
0
,
result
=
str
(
e
))
return
jsonify
(
code
=
0
,
result
=
str
(
e
))
#remove file or directory
@
app
.
route
(
"/removeFile"
,
methods
=
[
'POST'
])
@
app
.
route
(
"/removeFile"
,
methods
=
[
'POST'
])
def
removeFile
():
def
removeFile
():
try
:
try
:
...
@@ -296,6 +302,7 @@ def removeSoftwareDir():
...
@@ -296,6 +302,7 @@ def removeSoftwareDir():
except
Exception
,
e
:
except
Exception
,
e
:
return
jsonify
(
code
=
0
,
result
=
str
(
e
))
return
jsonify
(
code
=
0
,
result
=
str
(
e
))
#read file and return content to ajax
@
app
.
route
(
"/getFileContent"
,
methods
=
[
'POST'
])
@
app
.
route
(
"/getFileContent"
,
methods
=
[
'POST'
])
def
getFileContent
():
def
getFileContent
():
file_path
=
realpath
(
app
.
config
,
request
.
form
[
'file'
])
file_path
=
realpath
(
app
.
config
,
request
.
form
[
'file'
])
...
@@ -379,6 +386,7 @@ def getmd5sum():
...
@@ -379,6 +386,7 @@ def getmd5sum():
else
:
else
:
return
jsonify
(
code
=
0
,
result
=
"Can not get md5sum for this file!"
)
return
jsonify
(
code
=
0
,
result
=
"Can not get md5sum for this file!"
)
#return informations about state of slapgrid process
@
app
.
route
(
"/slapgridResult"
,
methods
=
[
'POST'
])
@
app
.
route
(
"/slapgridResult"
,
methods
=
[
'POST'
])
def
slapgridResult
():
def
slapgridResult
():
software_state
=
isSoftwareRunning
(
app
.
config
)
software_state
=
isSoftwareRunning
(
app
.
config
)
...
@@ -415,6 +423,7 @@ def getPath():
...
@@ -415,6 +423,7 @@ def getPath():
else
:
else
:
return
jsonify
(
code
=
1
,
result
=
realfile
)
return
jsonify
(
code
=
1
,
result
=
realfile
)
#update instance parameter into a local xml file
@
app
.
route
(
"/saveParameterXml"
,
methods
=
[
'POST'
])
@
app
.
route
(
"/saveParameterXml"
,
methods
=
[
'POST'
])
def
saveParameterXml
():
def
saveParameterXml
():
project
=
os
.
path
.
join
(
app
.
config
[
'runner_workdir'
],
".project"
)
project
=
os
.
path
.
join
(
app
.
config
[
'runner_workdir'
],
".project"
)
...
@@ -441,6 +450,7 @@ def saveParameterXml():
...
@@ -441,6 +450,7 @@ def saveParameterXml():
return
jsonify
(
code
=
0
,
result
=
"An error occurred while applying your settings!<br/>"
+
str
(
e
))
return
jsonify
(
code
=
0
,
result
=
"An error occurred while applying your settings!<br/>"
+
str
(
e
))
return
jsonify
(
code
=
1
,
result
=
""
)
return
jsonify
(
code
=
1
,
result
=
""
)
#read instance parameters into the local xml file and return a dict
@
app
.
route
(
"/getParameterXml/<request>"
,
methods
=
[
'GET'
])
@
app
.
route
(
"/getParameterXml/<request>"
,
methods
=
[
'GET'
])
def
getParameterXml
(
request
):
def
getParameterXml
(
request
):
param_path
=
os
.
path
.
join
(
app
.
config
[
'runner_workdir'
],
".parameter.xml"
)
param_path
=
os
.
path
.
join
(
app
.
config
[
'runner_workdir'
],
".parameter.xml"
)
...
@@ -457,6 +467,7 @@ def getParameterXml(request):
...
@@ -457,6 +467,7 @@ def getParameterXml(request):
else
:
else
:
return
jsonify
(
code
=
1
,
result
=
parameters
)
return
jsonify
(
code
=
1
,
result
=
parameters
)
#update user account data
@
app
.
route
(
"/updateAccount"
,
methods
=
[
'POST'
])
@
app
.
route
(
"/updateAccount"
,
methods
=
[
'POST'
])
def
updateAccount
():
def
updateAccount
():
account
=
[]
account
=
[]
...
...
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