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
Joanne Hugé
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):
"""
Initialize all possible options.
"""
OptionParser
.
__init__
(
self
,
usage
=
usage
,
version
=
version
,
option_list
=
[
option_list
=
[
Option
(
"-l"
,
"--log_file"
,
help
=
"The path to the log file used by the script."
,
type
=
str
),
...
...
@@ -38,7 +37,10 @@ class Parser(OptionParser):
default
=
False
,
action
=
"store_true"
,
help
=
"Debug mode."
),
])
]
OptionParser
.
__init__
(
self
,
usage
=
usage
,
version
=
version
,
option_list
=
option_list
)
def
check_args
(
self
):
"""
...
...
@@ -50,6 +52,7 @@ class Parser(OptionParser):
return
options
,
args
[
0
]
class
Config
:
def
__init__
(
self
):
self
.
configuration_file_path
=
None
...
...
@@ -125,6 +128,7 @@ def run():
sys
.
exit
(
return_code
)
def
serve
(
config
):
from
views
import
app
from
werkzeug.contrib.fixers
import
ProxyFix
...
...
@@ -134,7 +138,7 @@ def serve(config):
app
.
config
.
update
(
software_log
=
config
.
software_root
.
rstrip
(
'/'
)
+
'.log'
,
instance_log
=
config
.
instance_root
.
rstrip
(
'/'
)
+
'.log'
,
workspace
=
workdir
,
workspace
=
workdir
,
software_link
=
software_link
,
instance_profile
=
'instance.cfg'
,
software_profile
=
'software.cfg'
,
...
...
slapos/runner/decorators.py
View file @
5f34b3f6
...
...
@@ -11,4 +11,3 @@ def as_json(f):
def
inner
(
*
args
,
**
kwargs
):
return
Response
(
json
.
dumps
(
f
(
*
args
,
**
kwargs
)),
mimetype
=
'application/json'
)
return
inner
slapos/runner/fileBrowser.py
View file @
5f34b3f6
...
...
@@ -31,19 +31,19 @@ class FileBrowser(object):
html
=
'var gsdirs = [], gsfiles = [];'
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
)
if
not
realdir
:
raise
NameError
(
'Could not load directory %s: Permission denied'
%
dir
)
ldir
=
sorted
(
os
.
listdir
(
realdir
),
key
=
str
.
lower
)
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
ff
=
os
.
path
.
join
(
dir
,
f
)
realfile
=
os
.
path
.
join
(
realdir
,
f
)
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
()
if
not
os
.
path
.
isdir
(
realfile
):
size
=
os
.
path
.
getsize
(
realfile
)
...
...
@@ -61,7 +61,6 @@ class FileBrowser(object):
ff + '", "
0
", "' + md5sum + '", "
dir
", "' + mdate + '"));'
return html
def makeDirectory(self, dir, filename):
"""Create a directory"""
realdir = self._realdir(dir)
...
...
@@ -72,7 +71,6 @@ class FileBrowser(object):
else:
return '{result:
\
'
0
\
'
}'
def makeFile(self, dir, filename):
"""Create a file in a directory dir taken"""
realdir = self._realdir(dir)
...
...
@@ -85,17 +83,19 @@ class FileBrowser(object):
def deleteItem(self, dir, files):
"""Delete a list of files or directories"""
# XXX-Marco do not shadow 'dir'
realdir = self._realdir(dir)
lfiles = urllib.unquote(files).split(',,,')
try:
# XXX-Marco do not shadow 'file'
for file in lfiles:
file = os.path.join(realdir, file)
if not os.path.exists(file):
continue
#
silent skip file....
continue
#
silent skip file....
details = file.split('/')
last = details[-1]
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):
shutil.rmtree(file)
else:
...
...
@@ -109,6 +109,7 @@ class FileBrowser(object):
realdir = self._realdir(dir)
lfiles = urllib.unquote(files).split(',,,')
try:
# XXX-Marco do not shadow 'file'
for file in lfiles:
realfile = realpath(self.config, file)
if not realfile:
...
...
slapos/runner/gittools.py
View file @
5f34b3f6
...
...
@@ -29,7 +29,7 @@ def cloneRepo(data):
json
=
""
try
:
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
)
config_writer
=
repo
.
config_writer
()
config_writer
.
add_section
(
"user"
)
...
...
@@ -42,6 +42,7 @@ def cloneRepo(data):
json
=
safeResult
(
str
(
e
))
return
jsonify
(
code
=
code
,
result
=
json
)
def
gitStatus
(
project
):
"""Run git status and return status of specified project folder
Args:
...
...
@@ -61,6 +62,7 @@ def gitStatus(project):
json
=
safeResult
(
str
(
e
))
return
jsonify
(
code
=
code
,
result
=
json
,
branch
=
branch
,
dirty
=
isdirty
)
def
switchBranch
(
project
,
name
):
"""Switch a git branch
Args:
...
...
@@ -76,13 +78,14 @@ def switchBranch(project, name):
if
name
==
current_branch
:
json
=
"This is already your active branch for this project"
else
:
git
=
repo
.
git
git
=
repo
.
git
git
.
checkout
(
name
)
code
=
1
except
Exception
as
e
:
json
=
safeResult
(
str
(
e
))
return
jsonify
(
code
=
code
,
result
=
json
)
def
addBranch
(
project
,
name
,
onlyCheckout
=
False
):
"""Add new git branch to the repository
Args:
...
...
@@ -95,7 +98,7 @@ def addBranch(project, name, onlyCheckout=False):
json
=
""
try
:
repo
=
Repo
(
project
)
git
=
repo
.
git
git
=
repo
.
git
if
not
onlyCheckout
:
git
.
checkout
(
'-b'
,
name
)
else
:
...
...
@@ -105,6 +108,7 @@ def addBranch(project, name, onlyCheckout=False):
json
=
safeResult
(
str
(
e
))
return
jsonify
(
code
=
code
,
result
=
json
)
def
getDiff
(
project
):
"""Get git diff for the specified project directory"""
result
=
""
...
...
@@ -117,6 +121,7 @@ def getDiff(project):
result
=
safeResult
(
str
(
e
))
return
result
def
gitPush
(
project
,
msg
):
"""Commit and Push changes for the specified repository
Args:
...
...
@@ -145,10 +150,11 @@ def gitPush(project, msg):
code
=
1
except
Exception
as
e
:
if
undo_commit
:
git
.
reset
(
"HEAD~"
)
#
undo previous commit
git
.
reset
(
"HEAD~"
)
#
undo previous commit
json
=
safeResult
(
str
(
e
))
return
jsonify
(
code
=
code
,
result
=
json
)
def
gitPull
(
project
):
result
=
""
code
=
0
...
...
@@ -161,6 +167,7 @@ def gitPull(project):
result
=
safeResult
(
str
(
e
))
return
jsonify
(
code
=
code
,
result
=
result
)
def
safeResult
(
result
):
"""Parse string and remove credential of the user"""
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