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
c3ad77a6
Commit
c3ad77a6
authored
Oct 12, 2012
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pylint-ified
parent
29e73bc9
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
78 additions
and
66 deletions
+78
-66
slapos/runner/decorators.py
slapos/runner/decorators.py
+1
-0
slapos/runner/fileBrowser.py
slapos/runner/fileBrowser.py
+1
-1
slapos/runner/gittools.py
slapos/runner/gittools.py
+3
-1
slapos/runner/runnertest.py
slapos/runner/runnertest.py
+25
-19
slapos/runner/utils.py
slapos/runner/utils.py
+35
-35
slapos/runner/views.py
slapos/runner/views.py
+13
-10
No files found.
slapos/runner/decorators.py
View file @
c3ad77a6
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# vim: set et sts=2:
# vim: set et sts=2:
#pylint: disable-all
import
json
import
json
...
...
slapos/runner/fileBrowser.py
View file @
c3ad77a6
...
@@ -14,7 +14,7 @@ import werkzeug
...
@@ -14,7 +14,7 @@ import werkzeug
from
slapos.runner.utils
import
realpath
,
tail
,
isText
from
slapos.runner.utils
import
realpath
,
tail
,
isText
class
f
ileBrowser
(
object
):
class
F
ileBrowser
(
object
):
"""This class contain all bases function for file browser"""
"""This class contain all bases function for file browser"""
def
__init__
(
self
,
config
):
def
__init__
(
self
,
config
):
...
...
slapos/runner/gittools.py
View file @
c3ad77a6
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# vim: set et sts=2:
# vim: set et sts=2:
# pylint: disable-msg=W0311,C0301,C0103,C0111
import
os
import
os
import
re
import
re
...
@@ -163,5 +165,5 @@ def gitPull(project):
...
@@ -163,5 +165,5 @@ def gitPull(project):
def
safeResult
(
result
):
def
safeResult
(
result
):
"""Parse string and remove credential of the user"""
"""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)
slapos/runner/runnertest.py
View file @
c3ad77a6
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# vim: set et sts=2:
# vim: set et sts=2:
# pylint: disable-msg=W0311,C0301,C0103,C0111,R0904
import
ConfigParser
import
ConfigParser
import
datetime
import
datetime
...
@@ -12,8 +13,18 @@ from slapos.runner.utils import (getProfilePath, getSession, isInstanceRunning,
...
@@ -12,8 +13,18 @@ from slapos.runner.utils import (getProfilePath, getSession, isInstanceRunning,
recursifKill
,
startProxy
)
recursifKill
,
startProxy
)
from
slapos.runner
import
views
from
slapos.runner
import
views
#Helpers
def
loadJson
(
response
):
return
json
.
loads
(
response
.
data
)
class
Config
:
class
Config
:
def
__init__
(
self
):
self
.
runner_workdir
=
None
self
.
software_root
=
None
self
.
instance_root
=
None
self
.
configuration_file_path
=
None
def
setConfig
(
self
):
def
setConfig
(
self
):
"""
"""
Set options given by parameters.
Set options given by parameters.
...
@@ -97,11 +108,6 @@ class SlaprunnerTestCase(unittest.TestCase):
...
@@ -97,11 +108,6 @@ class SlaprunnerTestCase(unittest.TestCase):
if
os
.
path
.
exists
(
self
.
app
.
config
[
'instance_root'
]):
if
os
.
path
.
exists
(
self
.
app
.
config
[
'instance_root'
]):
shutil
.
rmtree
(
self
.
app
.
config
[
'instance_root'
])
shutil
.
rmtree
(
self
.
app
.
config
[
'instance_root'
])
#Helpers
def
loadJson
(
self
,
response
):
return
json
.
loads
(
response
.
data
)
def
configAccount
(
self
,
username
,
password
,
email
,
name
,
rcode
):
def
configAccount
(
self
,
username
,
password
,
email
,
name
,
rcode
):
"""Helper for configAccount"""
"""Helper for configAccount"""
return
self
.
app
.
post
(
'/configAccount'
,
data
=
dict
(
return
self
.
app
.
post
(
'/configAccount'
,
data
=
dict
(
...
@@ -121,9 +127,9 @@ class SlaprunnerTestCase(unittest.TestCase):
...
@@ -121,9 +127,9 @@ class SlaprunnerTestCase(unittest.TestCase):
def
setAccount
(
self
):
def
setAccount
(
self
):
"""Initialize user account and log user in"""
"""Initialize user account and log user in"""
response
=
self
.
loadJson
(
self
.
configAccount
(
self
.
users
[
0
],
self
.
users
[
1
],
response
=
loadJson
(
self
.
configAccount
(
self
.
users
[
0
],
self
.
users
[
1
],
self
.
users
[
2
],
self
.
users
[
3
],
self
.
rcode
))
self
.
users
[
2
],
self
.
users
[
3
],
self
.
rcode
))
response2
=
self
.
loadJson
(
self
.
login
(
self
.
users
[
0
],
self
.
users
[
1
]))
response2
=
loadJson
(
self
.
login
(
self
.
users
[
0
],
self
.
users
[
1
]))
self
.
assertEqual
(
response
[
'result'
],
""
)
self
.
assertEqual
(
response
[
'result'
],
""
)
self
.
assertEqual
(
response2
[
'result'
],
""
)
self
.
assertEqual
(
response2
[
'result'
],
""
)
...
@@ -172,22 +178,22 @@ class SlaprunnerTestCase(unittest.TestCase):
...
@@ -172,22 +178,22 @@ class SlaprunnerTestCase(unittest.TestCase):
"""For the first lauch of slaprunner user need do create first account"""
"""For the first lauch of slaprunner user need do create first account"""
result
=
self
.
configAccount
(
self
.
users
[
0
],
self
.
users
[
1
],
self
.
users
[
2
],
result
=
self
.
configAccount
(
self
.
users
[
0
],
self
.
users
[
1
],
self
.
users
[
2
],
self
.
users
[
3
],
self
.
rcode
)
self
.
users
[
3
],
self
.
rcode
)
response
=
self
.
loadJson
(
result
)
response
=
loadJson
(
result
)
self
.
assertEqual
(
response
[
'code'
],
1
)
self
.
assertEqual
(
response
[
'code'
],
1
)
account
=
getSession
(
self
.
app
.
config
)
account
=
getSession
(
self
.
app
.
config
)
self
.
assertEqual
(
account
,
self
.
users
)
self
.
assertEqual
(
account
,
self
.
users
)
def
test_login_logout
(
self
):
def
test_login_logout
(
self
):
"""test login with good and wrong values, test logout"""
"""test login with good and wrong values, test logout"""
response
=
self
.
loadJson
(
self
.
configAccount
(
self
.
users
[
0
],
self
.
users
[
1
],
response
=
loadJson
(
self
.
configAccount
(
self
.
users
[
0
],
self
.
users
[
1
],
self
.
users
[
2
],
self
.
users
[
3
],
self
.
rcode
))
self
.
users
[
2
],
self
.
users
[
3
],
self
.
rcode
))
self
.
assertEqual
(
response
[
'result'
],
""
)
self
.
assertEqual
(
response
[
'result'
],
""
)
result
=
self
.
loadJson
(
self
.
login
(
self
.
users
[
0
],
"wrongpwd"
))
result
=
loadJson
(
self
.
login
(
self
.
users
[
0
],
"wrongpwd"
))
self
.
assertEqual
(
result
[
'result'
],
"Login or password is incorrect, please check it!"
)
self
.
assertEqual
(
result
[
'result'
],
"Login or password is incorrect, please check it!"
)
resultwr
=
self
.
loadJson
(
self
.
login
(
"wronglogin"
,
"wrongpwd"
))
resultwr
=
loadJson
(
self
.
login
(
"wronglogin"
,
"wrongpwd"
))
self
.
assertEqual
(
resultwr
[
'result'
],
"Login or password is incorrect, please check it!"
)
self
.
assertEqual
(
resultwr
[
'result'
],
"Login or password is incorrect, please check it!"
)
#try now with true values
#try now with true values
resultlg
=
self
.
loadJson
(
self
.
login
(
self
.
users
[
0
],
self
.
users
[
1
]))
resultlg
=
loadJson
(
self
.
login
(
self
.
users
[
0
],
self
.
users
[
1
]))
self
.
assertEqual
(
resultlg
[
'result'
],
""
)
self
.
assertEqual
(
resultlg
[
'result'
],
""
)
#after login test logout
#after login test logout
result
=
self
.
logout
()
result
=
self
.
logout
()
...
@@ -196,12 +202,12 @@ class SlaprunnerTestCase(unittest.TestCase):
...
@@ -196,12 +202,12 @@ class SlaprunnerTestCase(unittest.TestCase):
def
test_updateAccount
(
self
):
def
test_updateAccount
(
self
):
"""test Update accound, this need user to loging in"""
"""test Update accound, this need user to loging in"""
self
.
setAccount
()
self
.
setAccount
()
response
=
self
.
loadJson
(
self
.
updateAccount
(
self
.
updateUser
,
self
.
rcode
))
response
=
loadJson
(
self
.
updateAccount
(
self
.
updateUser
,
self
.
rcode
))
self
.
assertEqual
(
response
[
'code'
],
1
)
self
.
assertEqual
(
response
[
'code'
],
1
)
result
=
self
.
logout
()
result
=
self
.
logout
()
assert
"<h2>Login to Slapos Web Runner</h2>"
in
result
.
data
assert
"<h2>Login to Slapos Web Runner</h2>"
in
result
.
data
#retry login with new values
#retry login with new values
response
=
self
.
loadJson
(
self
.
login
(
self
.
updateUser
[
0
],
self
.
updateUser
[
1
]))
response
=
loadJson
(
self
.
login
(
self
.
updateUser
[
0
],
self
.
updateUser
[
1
]))
self
.
assertEqual
(
response
[
'result'
],
""
)
self
.
assertEqual
(
response
[
'result'
],
""
)
#log out now!
#log out now!
self
.
logout
()
self
.
logout
()
...
@@ -218,12 +224,12 @@ class SlaprunnerTestCase(unittest.TestCase):
...
@@ -218,12 +224,12 @@ class SlaprunnerTestCase(unittest.TestCase):
folder
=
'workspace/'
+
self
.
project
folder
=
'workspace/'
+
self
.
project
data
=
{
"repo"
:
self
.
repo
,
"user"
:
'Slaprunner test'
,
data
=
{
"repo"
:
self
.
repo
,
"user"
:
'Slaprunner test'
,
"email"
:
'slaprunner@nexedi.com'
,
"name"
:
folder
}
"email"
:
'slaprunner@nexedi.com'
,
"name"
:
folder
}
response
=
self
.
loadJson
(
self
.
app
.
post
(
'/cloneRepository'
,
data
=
data
,
response
=
loadJson
(
self
.
app
.
post
(
'/cloneRepository'
,
data
=
data
,
follow_redirects
=
True
))
follow_redirects
=
True
))
self
.
assertEqual
(
response
[
'result'
],
""
)
self
.
assertEqual
(
response
[
'result'
],
""
)
#Get realpath of create project
#Get realpath of create project
path_data
=
dict
(
file
=
folder
)
path_data
=
dict
(
file
=
folder
)
response
=
self
.
loadJson
(
self
.
app
.
post
(
'/getPath'
,
data
=
path_data
,
response
=
loadJson
(
self
.
app
.
post
(
'/getPath'
,
data
=
path_data
,
follow_redirects
=
True
))
follow_redirects
=
True
))
self
.
assertEqual
(
response
[
'code'
],
1
)
self
.
assertEqual
(
response
[
'code'
],
1
)
realFolder
=
response
[
'result'
].
split
(
'#'
)[
0
]
realFolder
=
response
[
'result'
].
split
(
'#'
)[
0
]
...
@@ -231,7 +237,7 @@ class SlaprunnerTestCase(unittest.TestCase):
...
@@ -231,7 +237,7 @@ class SlaprunnerTestCase(unittest.TestCase):
config
=
open
(
os
.
path
.
join
(
realFolder
,
'.git/config'
),
'r'
).
read
()
config
=
open
(
os
.
path
.
join
(
realFolder
,
'.git/config'
),
'r'
).
read
()
assert
"slaprunner@nexedi.com"
in
config
and
"Slaprunner test"
in
config
assert
"slaprunner@nexedi.com"
in
config
and
"Slaprunner test"
in
config
#Checkout to slaprunner branch, this supose that branch slaprunner exit
#Checkout to slaprunner branch, this supose that branch slaprunner exit
response
=
self
.
loadJson
(
self
.
app
.
post
(
'/newBranch'
,
data
=
dict
(
response
=
loadJson
(
self
.
app
.
post
(
'/newBranch'
,
data
=
dict
(
project
=
folder
,
project
=
folder
,
create
=
'0'
,
create
=
'0'
,
name
=
'slaprunner'
),
name
=
'slaprunner'
),
...
@@ -246,7 +252,7 @@ class SlaprunnerTestCase(unittest.TestCase):
...
@@ -246,7 +252,7 @@ class SlaprunnerTestCase(unittest.TestCase):
self
.
login
(
self
.
users
[
0
],
self
.
users
[
1
])
self
.
login
(
self
.
users
[
0
],
self
.
users
[
1
])
#test create SR
#test create SR
newSoftware
=
os
.
path
.
join
(
self
.
software
,
'slaprunner-test'
)
newSoftware
=
os
.
path
.
join
(
self
.
software
,
'slaprunner-test'
)
response
=
self
.
loadJson
(
self
.
app
.
post
(
'/createSoftware'
,
response
=
loadJson
(
self
.
app
.
post
(
'/createSoftware'
,
data
=
dict
(
folder
=
newSoftware
),
data
=
dict
(
folder
=
newSoftware
),
follow_redirects
=
True
))
follow_redirects
=
True
))
self
.
assertEqual
(
response
[
'result'
],
""
)
self
.
assertEqual
(
response
[
'result'
],
""
)
...
@@ -260,7 +266,7 @@ class SlaprunnerTestCase(unittest.TestCase):
...
@@ -260,7 +266,7 @@ class SlaprunnerTestCase(unittest.TestCase):
#Login
#Login
self
.
login
(
self
.
users
[
0
],
self
.
users
[
1
])
self
.
login
(
self
.
users
[
0
],
self
.
users
[
1
])
software
=
os
.
path
.
join
(
self
.
software
,
'drupal'
)
#Drupal SR must exist in SR folder
software
=
os
.
path
.
join
(
self
.
software
,
'drupal'
)
#Drupal SR must exist in SR folder
response
=
self
.
loadJson
(
self
.
app
.
post
(
'/setCurrentProject'
,
response
=
loadJson
(
self
.
app
.
post
(
'/setCurrentProject'
,
data
=
dict
(
path
=
software
),
data
=
dict
(
path
=
software
),
follow_redirects
=
True
))
follow_redirects
=
True
))
self
.
assertEqual
(
response
[
'result'
],
""
)
self
.
assertEqual
(
response
[
'result'
],
""
)
...
...
slapos/runner/utils.py
View file @
c3ad77a6
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# vim: set et sts=2:
# vim: set et sts=2:
# pylint: disable-msg=W0311,C0301,C0103,C0111,W0141,W0142
import
hashlib
import
md5
import
logging
import
logging
import
multiprocessing
import
multiprocessing
import
re
import
re
import
signal
import
signal
import
shutil
import
shutil
import
string
import
os
import
os
import
subprocess
import
subprocess
import
time
import
time
...
@@ -45,7 +46,7 @@ html_escape_table = {
...
@@ -45,7 +46,7 @@ html_escape_table = {
def
html_escape
(
text
):
def
html_escape
(
text
):
"""Produce entities within text."""
"""Produce entities within text."""
return
""
.
join
(
html_escape_table
.
get
(
c
,
c
)
for
c
in
text
)
return
""
.
join
(
html_escape_table
.
get
(
c
,
c
)
for
c
in
text
)
def
getSession
(
config
):
def
getSession
(
config
):
"""
"""
...
@@ -258,7 +259,6 @@ def startProxy(config):
...
@@ -258,7 +259,6 @@ def startProxy(config):
def
stopProxy
(
config
):
def
stopProxy
(
config
):
"""Stop Slapproxy server"""
"""Stop Slapproxy server"""
killRunningProcess
(
config
,
'proxy.pid'
)
killRunningProcess
(
config
,
'proxy.pid'
)
pass
def
removeProxyDb
(
config
):
def
removeProxyDb
(
config
):
...
@@ -431,7 +431,7 @@ def getSlapStatus(config):
...
@@ -431,7 +431,7 @@ def getSlapStatus(config):
if
partition_list
:
if
partition_list
:
for
i
in
xrange
(
0
,
int
(
config
[
'partition_amount'
])):
for
i
in
xrange
(
0
,
int
(
config
[
'partition_amount'
])):
slappart_id
=
'%s%s'
%
(
"slappart"
,
i
)
slappart_id
=
'%s%s'
%
(
"slappart"
,
i
)
if
not
[
x
[
0
]
for
x
in
partition_list
if
slappart_id
==
x
[
0
]]:
if
not
[
x
[
0
]
for
x
in
partition_list
if
slappart_id
==
x
[
0
]]:
partition_list
.
append
((
slappart_id
,
[]))
partition_list
.
append
((
slappart_id
,
[]))
return
partition_list
return
partition_list
...
@@ -444,7 +444,7 @@ def removeInstanceRoot(config):
...
@@ -444,7 +444,7 @@ def removeInstanceRoot(config):
"""Clean instance directory and stop all its running process"""
"""Clean instance directory and stop all its running process"""
if
os
.
path
.
exists
(
config
[
'instance_root'
]):
if
os
.
path
.
exists
(
config
[
'instance_root'
]):
svcStopAll
(
config
)
svcStopAll
(
config
)
for
root
,
dirs
,
files
in
os
.
walk
(
config
[
'instance_root'
]):
for
root
,
dirs
,
_
in
os
.
walk
(
config
[
'instance_root'
]):
for
fname
in
dirs
:
for
fname
in
dirs
:
fullPath
=
os
.
path
.
join
(
root
,
fname
)
fullPath
=
os
.
path
.
join
(
root
,
fname
)
if
not
os
.
access
(
fullPath
,
os
.
W_OK
)
:
if
not
os
.
access
(
fullPath
,
os
.
W_OK
)
:
...
@@ -501,11 +501,11 @@ def getFolderContent(config, folder):
...
@@ -501,11 +501,11 @@ def getFolderContent(config, folder):
Returns:
Returns:
Html formated string or error message when fail.
Html formated string or error message when fail.
"""
"""
r
=
['
<
ul
class
=
"jqueryFileTree"
style
=
"display: none;"
>
']
r
=
['
<
ul
class
=
"jqueryFileTree"
style
=
"display: none;"
>
']
try:
try:
folder = str(folder)
folder = str(folder)
r
=
['
<
ul
class
=
"jqueryFileTree"
style
=
"display: none;"
>
']
r
=
['
<
ul
class
=
"jqueryFileTree"
style
=
"display: none;"
>
']
d
=
urllib.unquote(folder)
d
=
urllib.unquote(folder)
realdir = realpath(config, d)
realdir = realpath(config, d)
if not realdir:
if not realdir:
r.append('
Could
not
load
directory
:
Permission
denied
')
r.append('
Could
not
load
directory
:
Permission
denied
')
...
@@ -515,14 +515,14 @@ def getFolderContent(config, folder):
...
@@ -515,14 +515,14 @@ def getFolderContent(config, folder):
for f in ldir:
for f in ldir:
if f.startswith('
.
'): #do not displays this file/folder
if f.startswith('
.
'): #do not displays this file/folder
continue
continue
ff
=os.path.join(d,
f)
ff
= os.path.join(d,
f)
if os.path.isdir(os.path.join(realdir,f)):
if os.path.isdir(os.path.join(realdir,
f)):
r.append('
<
li
class
=
"directory collapsed"
><
a
href
=
"#%s"
rel
=
"%s/"
>%
s
</
a
></
li
>
' % (ff, ff,f))
r.append('
<
li
class
=
"directory collapsed"
><
a
href
=
"#%s"
rel
=
"%s/"
>%
s
</
a
></
li
>
' % (ff, ff,
f))
else:
else:
e
=
os.path.splitext(f)[1][1:] # get .ext and remove dot
e
=
os.path.splitext(f)[1][1:] # get .ext and remove dot
r.append('
<
li
class
=
"file ext_%s"
><
a
href
=
"#%s"
rel
=
"%s"
>%
s
</
a
></
li
>
' % (e, ff,
ff,
f))
r.append('
<
li
class
=
"file ext_%s"
><
a
href
=
"#%s"
rel
=
"%s"
>%
s
</
a
></
li
>
' % (e, ff,
ff,
f))
r.append('
</
ul
>
')
r.append('
</
ul
>
')
except Exception
,
e:
except Exception
as
e:
r.append('
Could
not
load
directory
:
%
s
' % str(e))
r.append('
Could
not
load
directory
:
%
s
' % str(e))
r.append('
</
ul
>
')
r.append('
</
ul
>
')
return jsonify(result=''.join(r))
return jsonify(result=''.join(r))
...
@@ -538,11 +538,11 @@ def getFolder(config, folder):
...
@@ -538,11 +538,11 @@ def getFolder(config, folder):
Returns:
Returns:
Html formated string or error message when fail.
Html formated string or error message when fail.
"""
"""
r
=
['
<
ul
class
=
"jqueryFileTree"
style
=
"display: none;"
>
']
r
=
['
<
ul
class
=
"jqueryFileTree"
style
=
"display: none;"
>
']
try:
try:
folder = str(folder)
folder = str(folder)
r
=
['
<
ul
class
=
"jqueryFileTree"
style
=
"display: none;"
>
']
r
=
['
<
ul
class
=
"jqueryFileTree"
style
=
"display: none;"
>
']
d
=
urllib.unquote(folder)
d
=
urllib.unquote(folder)
realdir = realpath(config, d)
realdir = realpath(config, d)
if not realdir:
if not realdir:
r.append('
Could
not
load
directory
:
Permission
denied
')
r.append('
Could
not
load
directory
:
Permission
denied
')
...
@@ -552,11 +552,11 @@ def getFolder(config, folder):
...
@@ -552,11 +552,11 @@ def getFolder(config, folder):
for f in ldir:
for f in ldir:
if f.startswith('
.
'): #do not display this file/folder
if f.startswith('
.
'): #do not display this file/folder
continue
continue
ff
=os.path.join(d,
f)
ff
= os.path.join(d,
f)
if os.path.isdir(os.path.join(realdir,f)):
if os.path.isdir(os.path.join(realdir,
f)):
r.append('
<
li
class
=
"directory collapsed"
><
a
href
=
"#%s"
rel
=
"%s/"
>%
s
</
a
></
li
>
' % (ff, ff, f))
r.append('
<
li
class
=
"directory collapsed"
><
a
href
=
"#%s"
rel
=
"%s/"
>%
s
</
a
></
li
>
' % (ff, ff, f))
r.append('
</
ul
>
')
r.append('
</
ul
>
')
except Exception
,
e:
except Exception
as
e:
r.append('
Could
not
load
directory
:
%
s
' % str(e))
r.append('
Could
not
load
directory
:
%
s
' % str(e))
r.append('
</
ul
>
')
r.append('
</
ul
>
')
return jsonify(result=''.join(r))
return jsonify(result=''.join(r))
...
@@ -634,7 +634,7 @@ def newSoftware(folder, config, session):
...
@@ -634,7 +634,7 @@ def newSoftware(folder, config, session):
else:
else:
json = "Bad folder or Directory '" + folder +
\
json = "Bad folder or Directory '" + folder +
\
"' already exist, please enter a new name for your software"
"' already exist, please enter a new name for your software"
except Exception
,
e:
except Exception
as
e:
json = "Can not create your software, please try again! : " + str(e)
json = "Can not create your software, please try again! : " + str(e)
if os.path.exists(folderPath):
if os.path.exists(folderPath):
shutil.rmtree(folderPath)
shutil.rmtree(folderPath)
...
@@ -652,8 +652,8 @@ def getProjectTitle(config):
...
@@ -652,8 +652,8 @@ def getProjectTitle(config):
conf = os.path.join(config['
etc_dir
'], ".project")
conf = os.path.join(config['
etc_dir
'], ".project")
if os.path.exists(conf):
if os.path.exists(conf):
project = open(conf, "r").read().split("/")
project = open(conf, "r").read().split("/")
software = project[
len(project) -
2]
software = project[
-
2]
return
software + " (" + string.join(project[:(len(project) - 2)], '
/
') + ")"
return
'
%
s
(
%
s
)
' % (software, '
/
'.join(project[:-2]))
return "No Profile"
return "No Profile"
def getSoftwareReleaseName(config):
def getSoftwareReleaseName(config):
...
@@ -661,7 +661,7 @@ def getSoftwareReleaseName(config):
...
@@ -661,7 +661,7 @@ def getSoftwareReleaseName(config):
sr_profile = os.path.join(config['
etc_dir
'], ".project")
sr_profile = os.path.join(config['
etc_dir
'], ".project")
if os.path.exists(sr_profile):
if os.path.exists(sr_profile):
project = open(sr_profile, "r").read().split("/")
project = open(sr_profile, "r").read().split("/")
software = project[
len(project) -
2]
software = project[
-
2]
return software.replace('
', '
_
')
return software.replace('
', '
_
')
return "No_name"
return "No_name"
...
@@ -704,14 +704,14 @@ def tail(f, lines=20):
...
@@ -704,14 +704,14 @@ def tail(f, lines=20):
data.insert(0, f.read(BUFSIZ))
data.insert(0, f.read(BUFSIZ))
else:
else:
# file too small, start from begining
# file too small, start from begining
f.seek(0,0)
f.seek(0,
0)
# only read what was not read
# only read what was not read
data.insert(0, f.read(bytes))
data.insert(0, f.read(bytes))
linesFound = data[0].count('
\
n
')
linesFound = data[0].count('
\
n
')
size -= linesFound
size -= linesFound
bytes -= BUFSIZ
bytes -= BUFSIZ
block -= 1
block -= 1
return
string.join(''.join(data).splitlines()[-lines:], '
\
n
'
)
return
'
\
n
'.join(''.join(data).splitlines()[-lines:]
)
def readFileFrom(f, lastPosition):
def readFileFrom(f, lastPosition):
"""
"""
...
@@ -735,7 +735,7 @@ def readFileFrom(f, lastPosition):
...
@@ -735,7 +735,7 @@ def readFileFrom(f, lastPosition):
else:
else:
margin = abs(block*BUFSIZ) - size
margin = abs(block*BUFSIZ) - size
if length < BUFSIZ:
if length < BUFSIZ:
f.seek(0,0)
f.seek(0,
0)
else:
else:
seek = block * BUFSIZ + margin
seek = block * BUFSIZ + margin
f.seek(seek, 2)
f.seek(seek, 2)
...
@@ -749,7 +749,7 @@ def isText(file):
...
@@ -749,7 +749,7 @@ def isText(file):
"""Return True if the mimetype of file is Text"""
"""Return True if the mimetype of file is Text"""
if not os.path.exists(file):
if not os.path.exists(file):
return False
return False
text_range = ''.join(map(chr, [7,
8,9,10,12,13,
27] + range(0x20, 0x100)))
text_range = ''.join(map(chr, [7,
8, 9, 10, 12, 13,
27] + range(0x20, 0x100)))
is_binary_string = lambda bytes: bool(bytes.translate(None, text_range))
is_binary_string = lambda bytes: bool(bytes.translate(None, text_range))
try:
try:
return not is_binary_string(open(file).read(1024))
return not is_binary_string(open(file).read(1024))
...
@@ -762,7 +762,7 @@ def md5sum(file):
...
@@ -762,7 +762,7 @@ def md5sum(file):
return False
return False
try:
try:
fh = open(file, 'rb')
fh = open(file, 'rb')
m =
hashlib
.md5()
m =
md5
.md5()
while True:
while True:
data = fh.read(8192)
data = fh.read(8192)
if not data:
if not data:
...
@@ -805,14 +805,14 @@ def readParameters(path):
...
@@ -805,14 +805,14 @@ def readParameters(path):
if os.path.exists(path):
if os.path.exists(path):
try:
try:
xmldoc = xml.dom.minidom.parse(path)
xmldoc = xml.dom.minidom.parse(path)
obj
ect
= {}
obj = {}
for elt in xmldoc.childNodes:
for elt in xmldoc.childNodes:
sub_obj
ect
= {}
sub_obj = {}
for subnode in elt.childNodes:
for subnode in elt.childNodes:
if subnode.nodeType != subnode.TEXT_NODE:
if subnode.nodeType != subnode.TEXT_NODE:
sub_obj
ect
[str(subnode.getAttribute('
id
'))] = subnode.childNodes[0].data #.decode('
utf
-
8
').decode('
utf
-
8
')
sub_obj[str(subnode.getAttribute('
id
'))] = subnode.childNodes[0].data #.decode('
utf
-
8
').decode('
utf
-
8
')
obj
ect[str(elt.tagName)] = sub_object
obj
[str(elt.tagName)] = sub_obj
return obj
ect
return obj
except Exception, e:
except Exception, e:
return str(e)
return str(e)
else:
else:
...
...
slapos/runner/views.py
View file @
c3ad77a6
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# vim: set et sts=2:
# vim: set et sts=2:
# pylint: disable-msg=W0311,C0301,C0103,C0111
import
os
import
os
import
shutil
import
shutil
...
@@ -16,7 +18,7 @@ from slapos.runner.utils import (checkSoftwareFolder, configNewSR, getFolder, ge
...
@@ -16,7 +18,7 @@ from slapos.runner.utils import (checkSoftwareFolder, configNewSR, getFolder, ge
removeInstanceRoot
,
removeProxyDb
,
removeSoftwareByName
,
runInstanceWithLock
,
removeInstanceRoot
,
removeProxyDb
,
removeSoftwareByName
,
runInstanceWithLock
,
runSoftwareWithLock
,
saveSession
,
svcStartStopProcess
,
svcStopAll
,
tail
,
runSoftwareWithLock
,
saveSession
,
svcStartStopProcess
,
svcStopAll
,
tail
,
updateInstanceParameter
)
updateInstanceParameter
)
from
slapos.runner.fileBrowser
import
f
ileBrowser
from
slapos.runner.fileBrowser
import
F
ileBrowser
from
slapos.runner.gittools
import
(
cloneRepo
,
gitStatus
,
switchBranch
,
addBranch
,
getDiff
,
from
slapos.runner.gittools
import
(
cloneRepo
,
gitStatus
,
switchBranch
,
addBranch
,
getDiff
,
gitPush
,
gitPull
)
gitPush
,
gitPull
)
...
@@ -25,7 +27,7 @@ app = Flask(__name__)
...
@@ -25,7 +27,7 @@ app = Flask(__name__)
app
.
config
[
'MAX_CONTENT_LENGTH'
]
=
20
*
1024
*
1024
app
.
config
[
'MAX_CONTENT_LENGTH'
]
=
20
*
1024
*
1024
auth
=
Auth
(
app
,
login_url_name
=
'login'
)
auth
=
Auth
(
app
,
login_url_name
=
'login'
)
auth
.
user_timeout
=
0
auth
.
user_timeout
=
0
file_request
=
f
ileBrowser
(
app
.
config
)
file_request
=
F
ileBrowser
(
app
.
config
)
# Setup default flask (werkzeug) parser
# Setup default flask (werkzeug) parser
import
logging
import
logging
...
@@ -73,7 +75,7 @@ def myAccount():
...
@@ -73,7 +75,7 @@ def myAccount():
@
app
.
route
(
"/dologout"
)
@
app
.
route
(
"/dologout"
)
def
dologout
():
def
dologout
():
user_data
=
logout
()
_
=
logout
()
return
redirect
(
url_for
(
'login'
))
return
redirect
(
url_for
(
'login'
))
@
login_required
()
@
login_required
()
...
@@ -108,6 +110,7 @@ def inspectSoftware():
...
@@ -108,6 +110,7 @@ def inspectSoftware():
result
=
""
result
=
""
else
:
else
:
result
=
app
.
config
[
'software_root'
]
result
=
app
.
config
[
'software_root'
]
# XXX not used??
return
render_template
(
'runResult.html'
,
softwareRoot
=
'software_link/'
,
return
render_template
(
'runResult.html'
,
softwareRoot
=
'software_link/'
,
softwares
=
loadSoftwareRList
(
app
.
config
))
softwares
=
loadSoftwareRList
(
app
.
config
))
...
@@ -173,11 +176,11 @@ def supervisordStatus():
...
@@ -173,11 +176,11 @@ def supervisordStatus():
html
=
"<tr><th>Partition and Process name</th><th>Status</th><th>Process PID </th><th> UpTime</th><th></th></tr>"
html
=
"<tr><th>Partition and Process name</th><th>Status</th><th>Process PID </th><th> UpTime</th><th></th></tr>"
for
item
in
result
:
for
item
in
result
:
html
+=
"<tr>"
html
+=
"<tr>"
html
+=
"<td class='first'><b><a href='"
+
url_for
(
'tailProcess'
,
process
=
item
[
0
])
+
"'>"
+
item
[
0
]
+
"</a></b></td>"
html
+=
"<td class='first'><b><a href='"
+
url_for
(
'tailProcess'
,
process
=
item
[
0
])
+
"'>"
+
item
[
0
]
+
"</a></b></td>"
html
+=
"<td align='center'><a href='"
+
url_for
(
'startStopProccess'
,
process
=
item
[
0
],
action
=
item
[
1
])
+
"'>"
+
item
[
1
]
+
"</a></td>"
html
+=
"<td align='center'><a href='"
+
url_for
(
'startStopProccess'
,
process
=
item
[
0
],
action
=
item
[
1
])
+
"'>"
+
item
[
1
]
+
"</a></td>"
html
+=
"<td align='center'>"
+
item
[
3
]
+
"</td><td>"
+
item
[
5
]
+
"</td>"
html
+=
"<td align='center'>"
+
item
[
3
]
+
"</td><td>"
+
item
[
5
]
+
"</td>"
html
+=
"<td align='center'><a href='"
+
url_for
(
'startStopProccess'
,
process
=
item
[
0
],
action
=
'RESTART'
)
+
"'>Restart</a></td>"
html
+=
"<td align='center'><a href='"
+
url_for
(
'startStopProccess'
,
process
=
item
[
0
],
action
=
'RESTART'
)
+
"'>Restart</a></td>"
html
+=
"</tr>"
html
+=
"</tr>"
return
jsonify
(
code
=
1
,
result
=
html
)
return
jsonify
(
code
=
1
,
result
=
html
)
@
login_required
()
@
login_required
()
...
@@ -295,7 +298,7 @@ def createFile():
...
@@ -295,7 +298,7 @@ def createFile():
request
.
form
[
'type'
]
+
": Permission Denied"
)
request
.
form
[
'type'
]
+
": Permission Denied"
)
try
:
try
:
if
request
.
form
[
'type'
]
==
"file"
:
if
request
.
form
[
'type'
]
==
"file"
:
f
=
open
(
path
,
'w'
).
write
(
" "
)
open
(
path
,
'w'
)
else
:
else
:
os
.
mkdir
(
path
)
os
.
mkdir
(
path
)
return
jsonify
(
code
=
1
,
result
=
""
)
return
jsonify
(
code
=
1
,
result
=
""
)
...
@@ -575,7 +578,7 @@ def fileBrowser():
...
@@ -575,7 +578,7 @@ def fileBrowser():
except
:
except
:
abort
(
404
)
abort
(
404
)
elif
opt
==
9
:
elif
opt
==
9
:
truncateTo
=
int
(
request
.
form
.
get
(
'truncate'
,
'0'
))
truncateTo
=
int
(
request
.
form
.
get
(
'truncate'
,
'0'
))
# XXX not used??
result
=
file_request
.
readFile
(
dir
,
filename
)
result
=
file_request
.
readFile
(
dir
,
filename
)
elif
opt
==
11
:
elif
opt
==
11
:
#Upload file
#Upload 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