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
Kirill Smelkov
slapos.toolbox
Commits
5f34b3f6
Commit
5f34b3f6
authored
Jul 25, 2013
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
some pep8 love
parent
17a77af3
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
272 additions
and
133 deletions
+272
-133
slapos/runner/__init__.py
slapos/runner/__init__.py
+8
-4
slapos/runner/decorators.py
slapos/runner/decorators.py
+0
-1
slapos/runner/fileBrowser.py
slapos/runner/fileBrowser.py
+8
-7
slapos/runner/gittools.py
slapos/runner/gittools.py
+11
-4
slapos/runner/runnertest.py
slapos/runner/runnertest.py
+69
-54
slapos/runner/utils.py
slapos/runner/utils.py
+100
-48
slapos/runner/views.py
slapos/runner/views.py
+76
-15
No files found.
slapos/runner/__init__.py
View file @
5f34b3f6
...
@@ -21,8 +21,7 @@ class Parser(OptionParser):
...
@@ -21,8 +21,7 @@ class Parser(OptionParser):
"""
"""
Initialize all possible options.
Initialize all possible options.
"""
"""
OptionParser
.
__init__
(
self
,
usage
=
usage
,
version
=
version
,
option_list
=
[
option_list
=
[
Option
(
"-l"
,
"--log_file"
,
Option
(
"-l"
,
"--log_file"
,
help
=
"The path to the log file used by the script."
,
help
=
"The path to the log file used by the script."
,
type
=
str
),
type
=
str
),
...
@@ -38,7 +37,10 @@ class Parser(OptionParser):
...
@@ -38,7 +37,10 @@ class Parser(OptionParser):
default
=
False
,
default
=
False
,
action
=
"store_true"
,
action
=
"store_true"
,
help
=
"Debug mode."
),
help
=
"Debug mode."
),
])
]
OptionParser
.
__init__
(
self
,
usage
=
usage
,
version
=
version
,
option_list
=
option_list
)
def
check_args
(
self
):
def
check_args
(
self
):
"""
"""
...
@@ -50,6 +52,7 @@ class Parser(OptionParser):
...
@@ -50,6 +52,7 @@ class Parser(OptionParser):
return
options
,
args
[
0
]
return
options
,
args
[
0
]
class
Config
:
class
Config
:
def
__init__
(
self
):
def
__init__
(
self
):
self
.
configuration_file_path
=
None
self
.
configuration_file_path
=
None
...
@@ -125,6 +128,7 @@ def run():
...
@@ -125,6 +128,7 @@ def run():
sys
.
exit
(
return_code
)
sys
.
exit
(
return_code
)
def
serve
(
config
):
def
serve
(
config
):
from
views
import
app
from
views
import
app
from
werkzeug.contrib.fixers
import
ProxyFix
from
werkzeug.contrib.fixers
import
ProxyFix
...
@@ -134,7 +138,7 @@ def serve(config):
...
@@ -134,7 +138,7 @@ def serve(config):
app
.
config
.
update
(
app
.
config
.
update
(
software_log
=
config
.
software_root
.
rstrip
(
'/'
)
+
'.log'
,
software_log
=
config
.
software_root
.
rstrip
(
'/'
)
+
'.log'
,
instance_log
=
config
.
instance_root
.
rstrip
(
'/'
)
+
'.log'
,
instance_log
=
config
.
instance_root
.
rstrip
(
'/'
)
+
'.log'
,
workspace
=
workdir
,
workspace
=
workdir
,
software_link
=
software_link
,
software_link
=
software_link
,
instance_profile
=
'instance.cfg'
,
instance_profile
=
'instance.cfg'
,
software_profile
=
'software.cfg'
,
software_profile
=
'software.cfg'
,
...
...
slapos/runner/decorators.py
View file @
5f34b3f6
...
@@ -11,4 +11,3 @@ def as_json(f):
...
@@ -11,4 +11,3 @@ def as_json(f):
def
inner
(
*
args
,
**
kwargs
):
def
inner
(
*
args
,
**
kwargs
):
return
Response
(
json
.
dumps
(
f
(
*
args
,
**
kwargs
)),
mimetype
=
'application/json'
)
return
Response
(
json
.
dumps
(
f
(
*
args
,
**
kwargs
)),
mimetype
=
'application/json'
)
return
inner
return
inner
slapos/runner/fileBrowser.py
View file @
5f34b3f6
...
@@ -31,19 +31,19 @@ class FileBrowser(object):
...
@@ -31,19 +31,19 @@ class FileBrowser(object):
html
=
'var gsdirs = [], gsfiles = [];'
html
=
'var gsdirs = [], gsfiles = [];'
dir
=
urllib
.
unquote
(
dir
)
dir
=
urllib
.
unquote
(
dir
)
#
'dir' is used below. XXX should not shadow a builtin name
#
XXX-Marco 'dir' and 'all' should not shadow builtin names
realdir
=
realpath
(
self
.
config
,
dir
)
realdir
=
realpath
(
self
.
config
,
dir
)
if
not
realdir
:
if
not
realdir
:
raise
NameError
(
'Could not load directory %s: Permission denied'
%
dir
)
raise
NameError
(
'Could not load directory %s: Permission denied'
%
dir
)
ldir
=
sorted
(
os
.
listdir
(
realdir
),
key
=
str
.
lower
)
ldir
=
sorted
(
os
.
listdir
(
realdir
),
key
=
str
.
lower
)
for
f
in
ldir
:
for
f
in
ldir
:
if
f
.
startswith
(
'.'
)
and
not
all
:
#
do not display this file/folder
if
f
.
startswith
(
'.'
)
and
not
all
:
#
do not display this file/folder
continue
continue
ff
=
os
.
path
.
join
(
dir
,
f
)
ff
=
os
.
path
.
join
(
dir
,
f
)
realfile
=
os
.
path
.
join
(
realdir
,
f
)
realfile
=
os
.
path
.
join
(
realdir
,
f
)
mdate
=
datetime
.
datetime
.
fromtimestamp
(
os
.
path
.
getmtime
(
realfile
)
mdate
=
datetime
.
datetime
.
fromtimestamp
(
os
.
path
.
getmtime
(
realfile
)
).
strftime
(
"%Y-%d-%m %I:%M"
)
).
strftime
(
"%Y-%d-%m %I:%M"
)
md5sum
=
md5
.
md5
(
realfile
).
hexdigest
()
md5sum
=
md5
.
md5
(
realfile
).
hexdigest
()
if
not
os
.
path
.
isdir
(
realfile
):
if
not
os
.
path
.
isdir
(
realfile
):
size
=
os
.
path
.
getsize
(
realfile
)
size
=
os
.
path
.
getsize
(
realfile
)
...
@@ -61,7 +61,6 @@ class FileBrowser(object):
...
@@ -61,7 +61,6 @@ class FileBrowser(object):
ff + '", "
0
", "' + md5sum + '", "
dir
", "' + mdate + '"));'
ff + '", "
0
", "' + md5sum + '", "
dir
", "' + mdate + '"));'
return html
return html
def makeDirectory(self, dir, filename):
def makeDirectory(self, dir, filename):
"""Create a directory"""
"""Create a directory"""
realdir = self._realdir(dir)
realdir = self._realdir(dir)
...
@@ -72,7 +71,6 @@ class FileBrowser(object):
...
@@ -72,7 +71,6 @@ class FileBrowser(object):
else:
else:
return '{result:
\
'
0
\
'
}'
return '{result:
\
'
0
\
'
}'
def makeFile(self, dir, filename):
def makeFile(self, dir, filename):
"""Create a file in a directory dir taken"""
"""Create a file in a directory dir taken"""
realdir = self._realdir(dir)
realdir = self._realdir(dir)
...
@@ -85,17 +83,19 @@ class FileBrowser(object):
...
@@ -85,17 +83,19 @@ class FileBrowser(object):
def deleteItem(self, dir, files):
def deleteItem(self, dir, files):
"""Delete a list of files or directories"""
"""Delete a list of files or directories"""
# XXX-Marco do not shadow 'dir'
realdir = self._realdir(dir)
realdir = self._realdir(dir)
lfiles = urllib.unquote(files).split(',,,')
lfiles = urllib.unquote(files).split(',,,')
try:
try:
# XXX-Marco do not shadow 'file'
for file in lfiles:
for file in lfiles:
file = os.path.join(realdir, file)
file = os.path.join(realdir, file)
if not os.path.exists(file):
if not os.path.exists(file):
continue
#
silent skip file....
continue
#
silent skip file....
details = file.split('/')
details = file.split('/')
last = details[-1]
last = details[-1]
if last and last.startswith('.'):
if last and last.startswith('.'):
continue
#
cannot delete this file/directory, to prevent security
continue
#
cannot delete this file/directory, to prevent security
if os.path.isdir(file):
if os.path.isdir(file):
shutil.rmtree(file)
shutil.rmtree(file)
else:
else:
...
@@ -109,6 +109,7 @@ class FileBrowser(object):
...
@@ -109,6 +109,7 @@ class FileBrowser(object):
realdir = self._realdir(dir)
realdir = self._realdir(dir)
lfiles = urllib.unquote(files).split(',,,')
lfiles = urllib.unquote(files).split(',,,')
try:
try:
# XXX-Marco do not shadow 'file'
for file in lfiles:
for file in lfiles:
realfile = realpath(self.config, file)
realfile = realpath(self.config, file)
if not realfile:
if not realfile:
...
...
slapos/runner/gittools.py
View file @
5f34b3f6
...
@@ -29,7 +29,7 @@ def cloneRepo(data):
...
@@ -29,7 +29,7 @@ def cloneRepo(data):
json
=
""
json
=
""
try
:
try
:
if
os
.
path
.
exists
(
workDir
)
and
len
(
os
.
listdir
(
workDir
))
<
2
:
if
os
.
path
.
exists
(
workDir
)
and
len
(
os
.
listdir
(
workDir
))
<
2
:
shutil
.
rmtree
(
workDir
)
#
delete useless files
shutil
.
rmtree
(
workDir
)
#
delete useless files
repo
=
Repo
.
clone_from
(
data
[
"repo"
],
workDir
)
repo
=
Repo
.
clone_from
(
data
[
"repo"
],
workDir
)
config_writer
=
repo
.
config_writer
()
config_writer
=
repo
.
config_writer
()
config_writer
.
add_section
(
"user"
)
config_writer
.
add_section
(
"user"
)
...
@@ -42,6 +42,7 @@ def cloneRepo(data):
...
@@ -42,6 +42,7 @@ def cloneRepo(data):
json
=
safeResult
(
str
(
e
))
json
=
safeResult
(
str
(
e
))
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
"""Run git status and return status of specified project folder
Args:
Args:
...
@@ -61,6 +62,7 @@ def gitStatus(project):
...
@@ -61,6 +62,7 @@ def gitStatus(project):
json
=
safeResult
(
str
(
e
))
json
=
safeResult
(
str
(
e
))
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
"""Switch a git branch
Args:
Args:
...
@@ -76,13 +78,14 @@ def switchBranch(project, name):
...
@@ -76,13 +78,14 @@ def switchBranch(project, name):
if
name
==
current_branch
:
if
name
==
current_branch
:
json
=
"This is already your active branch for this project"
json
=
"This is already your active branch for this project"
else
:
else
:
git
=
repo
.
git
git
=
repo
.
git
git
.
checkout
(
name
)
git
.
checkout
(
name
)
code
=
1
code
=
1
except
Exception
as
e
:
except
Exception
as
e
:
json
=
safeResult
(
str
(
e
))
json
=
safeResult
(
str
(
e
))
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
"""Add new git branch to the repository
Args:
Args:
...
@@ -95,7 +98,7 @@ def addBranch(project, name, onlyCheckout=False):
...
@@ -95,7 +98,7 @@ def addBranch(project, name, onlyCheckout=False):
json
=
""
json
=
""
try
:
try
:
repo
=
Repo
(
project
)
repo
=
Repo
(
project
)
git
=
repo
.
git
git
=
repo
.
git
if
not
onlyCheckout
:
if
not
onlyCheckout
:
git
.
checkout
(
'-b'
,
name
)
git
.
checkout
(
'-b'
,
name
)
else
:
else
:
...
@@ -105,6 +108,7 @@ def addBranch(project, name, onlyCheckout=False):
...
@@ -105,6 +108,7 @@ def addBranch(project, name, onlyCheckout=False):
json
=
safeResult
(
str
(
e
))
json
=
safeResult
(
str
(
e
))
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"""
"""Get git diff for the specified project directory"""
result
=
""
result
=
""
...
@@ -117,6 +121,7 @@ def getDiff(project):
...
@@ -117,6 +121,7 @@ def getDiff(project):
result
=
safeResult
(
str
(
e
))
result
=
safeResult
(
str
(
e
))
return
result
return
result
def
gitPush
(
project
,
msg
):
def
gitPush
(
project
,
msg
):
"""Commit and Push changes for the specified repository
"""Commit and Push changes for the specified repository
Args:
Args:
...
@@ -145,10 +150,11 @@ def gitPush(project, msg):
...
@@ -145,10 +150,11 @@ def gitPush(project, msg):
code
=
1
code
=
1
except
Exception
as
e
:
except
Exception
as
e
:
if
undo_commit
:
if
undo_commit
:
git
.
reset
(
"HEAD~"
)
#
undo previous commit
git
.
reset
(
"HEAD~"
)
#
undo previous commit
json
=
safeResult
(
str
(
e
))
json
=
safeResult
(
str
(
e
))
return
jsonify
(
code
=
code
,
result
=
json
)
return
jsonify
(
code
=
code
,
result
=
json
)
def
gitPull
(
project
):
def
gitPull
(
project
):
result
=
""
result
=
""
code
=
0
code
=
0
...
@@ -161,6 +167,7 @@ def gitPull(project):
...
@@ -161,6 +167,7 @@ def gitPull(project):
result
=
safeResult
(
str
(
e
))
result
=
safeResult
(
str
(
e
))
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"""
"""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)
...
...
slapos/runner/runnertest.py
View file @
5f34b3f6
This diff is collapsed.
Click to expand it.
slapos/runner/utils.py
View file @
5f34b3f6
This diff is collapsed.
Click to expand it.
slapos/runner/views.py
View file @
5f34b3f6
This diff is collapsed.
Click to expand it.
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