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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jérome Perrin
slapos.toolbox
Commits
a3c09a4b
Commit
a3c09a4b
authored
Jul 27, 2013
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
runner: grammar nazi
parent
ab224625
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
28 additions
and
29 deletions
+28
-29
slapos/runner/fileBrowser.py
slapos/runner/fileBrowser.py
+10
-10
slapos/runner/gittools.py
slapos/runner/gittools.py
+5
-5
slapos/runner/process.py
slapos/runner/process.py
+4
-4
slapos/runner/runnertest.py
slapos/runner/runnertest.py
+5
-5
slapos/runner/utils.py
slapos/runner/utils.py
+3
-3
slapos/runner/views.py
slapos/runner/views.py
+1
-2
No files found.
slapos/runner/fileBrowser.py
View file @
a3c09a4b
...
@@ -15,7 +15,7 @@ from slapos.runner.utils import realpath, tail, isText
...
@@ -15,7 +15,7 @@ from slapos.runner.utils import realpath, tail, isText
class
FileBrowser
(
object
):
class
FileBrowser
(
object
):
"""This class contain all base functions for file browser"""
"""This class contain
s
all base functions for file browser"""
def
__init__
(
self
,
config
):
def
__init__
(
self
,
config
):
self
.
config
=
config
self
.
config
=
config
...
@@ -115,7 +115,7 @@ class FileBrowser(object):
...
@@ -115,7 +115,7 @@ class FileBrowser(object):
details = realfile.split('/')
details = realfile.split('/')
dest = os.path.join(realdir, details[-1])
dest = os.path.join(realdir, details[-1])
if os.path.exists(dest):
if os.path.exists(dest):
raise NameError('NOT ALLOWED OPERATION : File or directory already exist')
raise NameError('NOT ALLOWED OPERATION : File or directory already exist
s
')
if os.path.isdir(realfile):
if os.path.isdir(realfile):
shutil.copytree(realfile, dest)
shutil.copytree(realfile, dest)
if del_source:
if del_source:
...
@@ -138,7 +138,7 @@ class FileBrowser(object):
...
@@ -138,7 +138,7 @@ class FileBrowser(object):
if not os.path.exists(tofile):
if not os.path.exists(tofile):
os.rename(realfile, tofile)
os.rename(realfile, tofile)
return "
{
result
:
'1'
}
"
return "
{
result
:
'1'
}
"
raise NameError('NOT ALLOWED OPERATION : File or directory already exist')
raise NameError('NOT ALLOWED OPERATION : File or directory already exist
s
')
def copyAsFile(self, dir, filename, newfilename):
def copyAsFile(self, dir, filename, newfilename):
"""Copy file or directory to dir/filename"""
"""Copy file or directory to dir/filename"""
...
@@ -146,14 +146,14 @@ class FileBrowser(object):
...
@@ -146,14 +146,14 @@ class FileBrowser(object):
fromfile = os.path.join(realdir, filename)
fromfile = os.path.join(realdir, filename)
tofile = os.path.join(realdir, newfilename)
tofile = os.path.join(realdir, newfilename)
if not os.path.exists(fromfile):
if not os.path.exists(fromfile):
raise NameError('NOT ALLOWED OPERATION : File or directory not exist')
raise NameError('NOT ALLOWED OPERATION : File or directory
does
not exist')
if not os.path.exists(tofile):
if not os.path.exists(tofile):
shutil.copy(fromfile, tofile)
shutil.copy(fromfile, tofile)
return "
{
result
:
'1'
}
"
return "
{
result
:
'1'
}
"
raise NameError('NOT ALLOWED OPERATION : File or directory already exist')
raise NameError('NOT ALLOWED OPERATION : File or directory already exist
s
')
def uploadFile(self, dir, files):
def uploadFile(self, dir, files):
"""Upload a list of file in directory dir"""
"""Upload a list of file
s
in directory dir"""
realdir = self._realdir(dir)
realdir = self._realdir(dir)
for file in files:
for file in files:
if files[file]:
if files[file]:
...
@@ -177,7 +177,7 @@ class FileBrowser(object):
...
@@ -177,7 +177,7 @@ class FileBrowser(object):
tozip = os.path.join(realdir, newfilename)
tozip = os.path.join(realdir, newfilename)
fromzip = os.path.join(realdir, filename)
fromzip = os.path.join(realdir, filename)
if not os.path.exists(fromzip):
if not os.path.exists(fromzip):
raise NameError('NOT ALLOWED OPERATION : File or directory not exist')
raise NameError('NOT ALLOWED OPERATION : File or directory
does
not exist')
if not os.path.exists(tozip):
if not os.path.exists(tozip):
zip = zipfile.ZipFile(tozip, 'w', zipfile.ZIP_DEFLATED)
zip = zipfile.ZipFile(tozip, 'w', zipfile.ZIP_DEFLATED)
if os.path.isdir(fromzip):
if os.path.isdir(fromzip):
...
@@ -190,7 +190,7 @@ class FileBrowser(object):
...
@@ -190,7 +190,7 @@ class FileBrowser(object):
zip.write(fromzip)
zip.write(fromzip)
zip.close()
zip.close()
return "
{
result
:
'1'
}
"
return "
{
result
:
'1'
}
"
raise NameError('NOT ALLOWED OPERATION : File or directory already exist')
raise NameError('NOT ALLOWED OPERATION : File or directory already exist
s
')
def unzipFile(self, dir, filename, newfilename):
def unzipFile(self, dir, filename, newfilename):
"""Extract a zipped archive"""
"""Extract a zipped archive"""
...
@@ -198,7 +198,7 @@ class FileBrowser(object):
...
@@ -198,7 +198,7 @@ class FileBrowser(object):
target = os.path.join(realdir, newfilename)
target = os.path.join(realdir, newfilename)
archive = os.path.join(realdir, filename)
archive = os.path.join(realdir, filename)
if not os.path.exists(archive):
if not os.path.exists(archive):
raise NameError('NOT ALLOWED OPERATION : File or directory not exist')
raise NameError('NOT ALLOWED OPERATION : File or directory
does
not exist')
if not os.path.exists(target):
if not os.path.exists(target):
zip = zipfile.ZipFile(archive)
zip = zipfile.ZipFile(archive)
#member = zip.namelist()
#member = zip.namelist()
...
@@ -208,7 +208,7 @@ class FileBrowser(object):
...
@@ -208,7 +208,7 @@ class FileBrowser(object):
#else:
#else:
# zip.extract(member[0], newfilename)
# zip.extract(member[0], newfilename)
return "
{
result
:
'1'
}
"
return "
{
result
:
'1'
}
"
raise NameError('NOT ALLOWED OPERATION : File or directory already exist')
raise NameError('NOT ALLOWED OPERATION : File or directory already exist
s
')
def readFile(self, dir, filename, truncate=False):
def readFile(self, dir, filename, truncate=False):
"""Read file dir/filename and return content"""
"""Read file dir/filename and return content"""
...
...
slapos/runner/gittools.py
View file @
a3c09a4b
...
@@ -12,19 +12,19 @@ from flask import jsonify
...
@@ -12,19 +12,19 @@ from flask import jsonify
def
cloneRepo
(
data
):
def
cloneRepo
(
data
):
"""Clon
n
e a repository
"""Clone a repository
Args:
Args:
data: a dictionary of parameters to use:
data: a dictionary of parameters to use:
data['path'] is the path of the new project
data['path'] is the path of the new project
data['repo'] is the url of the repository to be cloned
data['repo'] is the url of the repository to be cloned
data['email'] is the user email
data['email'] is the user
's
email
data['user'] is the name of the user
data['user'] is the name of the user
Returns:
Returns:
a jsonify data"""
a jsonify data"""
workDir
=
data
[
'path'
]
workDir
=
data
[
'path'
]
if
not
workDir
:
if
not
workDir
:
return
jsonify
(
code
=
0
,
return
jsonify
(
code
=
0
,
result
=
"Can
not create project folder: Permission Denied"
)
result
=
"Cannot create project folder: Permission Denied"
)
code
=
0
code
=
0
json
=
""
json
=
""
try
:
try
:
...
@@ -46,7 +46,7 @@ def cloneRepo(data):
...
@@ -46,7 +46,7 @@ def cloneRepo(data):
def
gitStatus
(
project
):
def
gitStatus
(
project
):
"""Run git status and return status of specified project folder
"""Run git status and return status of specified project folder
Args:
Args:
project: path of the projet t
i
get status
project: path of the projet t
o
get status
Returns:
Returns:
a parsed string that contains the result of git status"""
a parsed string that contains the result of git status"""
code
=
0
code
=
0
...
@@ -146,7 +146,7 @@ def gitPush(project, msg):
...
@@ -146,7 +146,7 @@ def gitPush(project, msg):
git
.
push
(
'origin'
,
current_branch
)
git
.
push
(
'origin'
,
current_branch
)
code
=
1
code
=
1
else
:
else
:
json
=
"Nothing to
be commited
"
json
=
"Nothing to
commit
"
code
=
1
code
=
1
except
Exception
as
e
:
except
Exception
as
e
:
if
undo_commit
:
if
undo_commit
:
...
...
slapos/runner/process.py
View file @
a3c09a4b
...
@@ -9,7 +9,7 @@ SLAPRUNNER_PROCESS_LIST = []
...
@@ -9,7 +9,7 @@ SLAPRUNNER_PROCESS_LIST = []
class
Popen
(
subprocess
.
Popen
):
class
Popen
(
subprocess
.
Popen
):
"""
"""
Extension of Popen to launch and kill process in a clean way
Extension of Popen to launch and kill process
es
in a clean way
"""
"""
def
__init__
(
self
,
*
args
,
**
kwargs
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
"""
"""
...
@@ -28,7 +28,7 @@ class Popen(subprocess.Popen):
...
@@ -28,7 +28,7 @@ class Popen(subprocess.Popen):
def
kill
(
self
,
sig
=
signal
.
SIGTERM
,
recursive
=
False
):
def
kill
(
self
,
sig
=
signal
.
SIGTERM
,
recursive
=
False
):
"""
"""
Kill process and all its descendant if recursive
Kill process and all its descendant
s
if recursive
"""
"""
if
self
.
poll
()
is
None
:
if
self
.
poll
()
is
None
:
if
recursive
:
if
recursive
:
...
@@ -83,7 +83,7 @@ def isRunning(name):
...
@@ -83,7 +83,7 @@ def isRunning(name):
def
killRunningProcess
(
name
,
recursive
=
False
):
def
killRunningProcess
(
name
,
recursive
=
False
):
"""
"""
Kill all process
with
name
Kill all process
es with a given
name
"""
"""
for
process
in
SLAPRUNNER_PROCESS_LIST
:
for
process
in
SLAPRUNNER_PROCESS_LIST
:
if
process
.
name
==
name
:
if
process
.
name
==
name
:
...
@@ -92,7 +92,7 @@ def killRunningProcess(name, recursive=False):
...
@@ -92,7 +92,7 @@ def killRunningProcess(name, recursive=False):
def
handler
(
sig
,
frame
):
def
handler
(
sig
,
frame
):
"""
"""
Signal handler to kill all process
Signal handler to kill all process
es
"""
"""
pid
=
os
.
getpid
()
pid
=
os
.
getpid
()
os
.
kill
(
-
pid
,
sig
)
os
.
kill
(
-
pid
,
sig
)
...
...
slapos/runner/runnertest.py
View file @
a3c09a4b
...
@@ -5,12 +5,12 @@
...
@@ -5,12 +5,12 @@
import
argparse
import
argparse
import
ConfigParser
import
ConfigParser
import
datetime
import
datetime
import
hashlib
import
json
import
json
import
os
import
os
import
shutil
import
shutil
import
time
import
time
import
unittest
import
unittest
import
hashlib
from
slapos.runner.utils
import
(
getProfilePath
,
getSession
,
isInstanceRunning
,
from
slapos.runner.utils
import
(
getProfilePath
,
getSession
,
isInstanceRunning
,
isSoftwareRunning
,
startProxy
)
isSoftwareRunning
,
startProxy
)
...
@@ -174,7 +174,7 @@ class SlaprunnerTestCase(unittest.TestCase):
...
@@ -174,7 +174,7 @@ class SlaprunnerTestCase(unittest.TestCase):
self
.
assertEqual
(
proxy
,
status
)
self
.
assertEqual
(
proxy
,
status
)
def
setupProjectFolder
(
self
,
withSoftware
=
False
):
def
setupProjectFolder
(
self
,
withSoftware
=
False
):
"""Helper
for
create a project folder as for slapos.git"""
"""Helper
to
create a project folder as for slapos.git"""
base
=
os
.
path
.
join
(
self
.
app
.
config
[
'workspace'
],
'slapos'
)
base
=
os
.
path
.
join
(
self
.
app
.
config
[
'workspace'
],
'slapos'
)
software
=
os
.
path
.
join
(
base
,
'software'
)
software
=
os
.
path
.
join
(
base
,
'software'
)
os
.
mkdir
(
base
)
os
.
mkdir
(
base
)
...
@@ -193,7 +193,7 @@ class SlaprunnerTestCase(unittest.TestCase):
...
@@ -193,7 +193,7 @@ class SlaprunnerTestCase(unittest.TestCase):
'w'
).
write
(
sr
)
'w'
).
write
(
sr
)
def
setupSoftwareFolder
(
self
):
def
setupSoftwareFolder
(
self
):
"""Helper
for
setup compiled software release dir"""
"""Helper
to
setup compiled software release dir"""
self
.
setupProjectFolder
(
withSoftware
=
True
)
self
.
setupProjectFolder
(
withSoftware
=
True
)
md5
=
hashlib
.
md5
(
os
.
path
.
join
(
self
.
app
.
config
[
'workspace'
],
md5
=
hashlib
.
md5
(
os
.
path
.
join
(
self
.
app
.
config
[
'workspace'
],
"slapos/software/slaprunner-test"
,
"slapos/software/slaprunner-test"
,
...
@@ -218,7 +218,7 @@ class SlaprunnerTestCase(unittest.TestCase):
...
@@ -218,7 +218,7 @@ class SlaprunnerTestCase(unittest.TestCase):
#Begin test case here
#Begin test case here
def
test_wrong_login
(
self
):
def
test_wrong_login
(
self
):
"""Test Login user before create session. This should return error value"""
"""Test Login user before create session. This should return
an
error value"""
response
=
self
.
login
(
self
.
users
[
0
],
self
.
users
[
1
])
response
=
self
.
login
(
self
.
users
[
0
],
self
.
users
[
1
])
#redirect to config account page
#redirect to config account page
assert
"<h2 class='title'>Your personal information</h2><br/>"
in
response
.
data
assert
"<h2 class='title'>Your personal information</h2><br/>"
in
response
.
data
...
@@ -249,7 +249,7 @@ class SlaprunnerTestCase(unittest.TestCase):
...
@@ -249,7 +249,7 @@ class SlaprunnerTestCase(unittest.TestCase):
assert
"<h2>Login to Slapos Web Runner</h2>"
in
result
.
data
assert
"<h2>Login to Slapos Web Runner</h2>"
in
result
.
data
def
test_updateAccount
(
self
):
def
test_updateAccount
(
self
):
"""test Update accound, this need
user to login
g in"""
"""test Update accound, this need
s the user to lo
g in"""
self
.
setAccount
()
self
.
setAccount
()
response
=
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
)
...
...
slapos/runner/utils.py
View file @
a3c09a4b
...
@@ -3,12 +3,10 @@
...
@@ -3,12 +3,10 @@
# pylint: disable-msg=W0311,C0301,C0103,C0111,W0141,W0142
# pylint: disable-msg=W0311,C0301,C0103,C0111,W0141,W0142
import
md5
import
logging
import
logging
import
md5
import
multiprocessing
import
multiprocessing
import
re
import
re
from
slapos.runner.process
import
Popen
,
isRunning
,
killRunningProcess
from
slapos.htpasswd
import
HtpasswdFile
import
shutil
import
shutil
import
os
import
os
import
time
import
time
...
@@ -18,6 +16,8 @@ from xml.dom import minidom
...
@@ -18,6 +16,8 @@ from xml.dom import minidom
import
xml_marshaller
import
xml_marshaller
from
flask
import
jsonify
from
flask
import
jsonify
from
slapos.runner.process
import
Popen
,
isRunning
,
killRunningProcess
from
slapos.htpasswd
import
HtpasswdFile
import
slapos.slap
import
slapos.slap
# Setup default flask (werkzeug) parser
# Setup default flask (werkzeug) parser
...
...
slapos/runner/views.py
View file @
a3c09a4b
...
@@ -490,8 +490,7 @@ def slapgridResult():
...
@@ -490,8 +490,7 @@ def slapgridResult():
'position'
:
0
,
'position'
:
0
,
'truncated'
:
False
'truncated'
:
False
}
}
if
request
.
form
[
'log'
]
==
"software"
or
\
if
request
.
form
[
'log'
]
in
[
'software'
,
'instance'
]:
request
.
form
[
'log'
]
==
"instance"
:
log_file
=
request
.
form
[
'log'
]
+
"_log"
log_file
=
request
.
form
[
'log'
]
+
"_log"
if
os
.
path
.
exists
(
app
.
config
[
log_file
]):
if
os
.
path
.
exists
(
app
.
config
[
log_file
]):
log_result
=
readFileFrom
(
open
(
app
.
config
[
log_file
]),
log_result
=
readFileFrom
(
open
(
app
.
config
[
log_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