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
Klaus Wölfel
slapos.toolbox
Commits
c0cf24d1
Commit
c0cf24d1
authored
Jul 26, 2013
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
runner: simpler file handling + open() defaults to 'r'
parent
6980a891
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
30 deletions
+21
-30
slapos/runner/fileBrowser.py
slapos/runner/fileBrowser.py
+2
-2
slapos/runner/runnertest.py
slapos/runner/runnertest.py
+3
-3
slapos/runner/utils.py
slapos/runner/utils.py
+7
-16
slapos/runner/views.py
slapos/runner/views.py
+9
-9
No files found.
slapos/runner/fileBrowser.py
View file @
c0cf24d1
...
...
@@ -219,6 +219,6 @@ class FileBrowser(object):
if not isText(realfile):
return "
FILE
ERROR
:
Cannot
display
binary
file
,
please
open
a
text
file
only
!
"
if not truncate:
return open(realfile
, 'r'
).read()
return open(realfile).read()
else:
return tail(open(realfile
, 'r'
), 0)
return tail(open(realfile), 0)
slapos/runner/runnertest.py
View file @
c0cf24d1
...
...
@@ -290,7 +290,7 @@ class SlaprunnerTestCase(unittest.TestCase):
self
.
assertEqual
(
response
[
'code'
],
1
)
realFolder
=
response
[
'result'
].
split
(
'#'
)[
0
]
#Check git configuration
config
=
open
(
os
.
path
.
join
(
realFolder
,
'.git/config'
)
,
'r'
).
read
()
config
=
open
(
os
.
path
.
join
(
realFolder
,
'.git/config'
)).
read
()
assert
"slaprunner@nexedi.com"
in
config
and
"Slaprunner test"
in
config
#Checkout to slaprunner branch, this supose that branch slaprunner exit
response
=
loadJson
(
self
.
app
.
post
(
'/newBranch'
,
...
...
@@ -366,7 +366,7 @@ class SlaprunnerTestCase(unittest.TestCase):
self
.
assertTrue
(
response
[
'result'
])
self
.
assertTrue
(
os
.
path
.
exists
(
self
.
app
.
config
[
'software_root'
]))
self
.
assertTrue
(
os
.
path
.
exists
(
self
.
app
.
config
[
'software_log'
]))
assert
"test-application"
in
open
(
self
.
app
.
config
[
'software_log'
]
,
'r'
).
read
()
assert
"test-application"
in
open
(
self
.
app
.
config
[
'software_log'
]).
read
()
sr_dir
=
os
.
listdir
(
self
.
app
.
config
[
'software_root'
])
self
.
assertEqual
(
len
(
sr_dir
),
1
)
createdFile
=
os
.
path
.
join
(
self
.
app
.
config
[
'software_root'
],
sr_dir
[
0
],
...
...
@@ -436,7 +436,7 @@ class SlaprunnerTestCase(unittest.TestCase):
follow_redirects
=
True
))
self
.
assertTrue
(
response
[
'result'
])
#Check that all partitions has been created
assert
"create-file"
in
open
(
self
.
app
.
config
[
'instance_log'
]
,
'r'
).
read
()
assert
"create-file"
in
open
(
self
.
app
.
config
[
'instance_log'
]).
read
()
instanceDir
=
os
.
listdir
(
self
.
app
.
config
[
'instance_root'
])
for
num
in
range
(
int
(
self
.
app
.
config
[
'partition_amount'
])):
partition
=
os
.
path
.
join
(
self
.
app
.
config
[
'instance_root'
],
...
...
slapos/runner/utils.py
View file @
c0cf24d1
...
...
@@ -43,17 +43,11 @@ def getSession(config):
"""
Get the session data of current user.
Returns:
a list of user information or
False if fail to read data
.
a list of user information or
None if the file does not exist
.
"""
user_path
=
os
.
path
.
join
(
config
[
'etc_dir'
],
'.users'
)
user
=
""
if
os
.
path
.
exists
(
user_path
):
f
=
open
(
user_path
,
'r'
)
user
=
f
.
read
().
split
(
';'
)
f
.
close
()
if
type
(
user
)
==
type
(
""
):
return
False
return
user
return
open
(
user_path
).
read
().
split
(
';'
)
def
saveSession
(
config
,
account
):
...
...
@@ -74,11 +68,9 @@ def saveSession(config, account):
backup
=
False
try
:
if
os
.
path
.
exists
(
user
):
f
=
open
(
user
,
'r'
)
#backup previous data
data
=
f
.
read
()
data
=
open
(
user
)
.
read
()
open
(
'%s.back'
%
user
,
'w'
).
write
(
data
)
f
.
close
()
backup
=
True
if
not
account
[
1
]:
account
[
1
]
=
data
.
split
(
';'
)[
1
]
...
...
@@ -125,7 +117,7 @@ def requestInstance(config, software_type=None):
# Write it to conf file for later use
open
(
software_type_path
,
'w'
).
write
(
software_type
)
elif
os
.
path
.
exists
(
software_type_path
):
software_type
=
open
(
software_type_path
,
'r'
).
read
()
software_type
=
open
(
software_type_path
).
read
()
else
:
software_type
=
'default'
...
...
@@ -281,15 +273,14 @@ def config_SR_folder(config):
for
path
in
os
.
listdir
(
config
[
'software_link'
]):
cfg_path
=
os
.
path
.
join
(
config
[
'software_link'
],
path
,
config_name
)
if
os
.
path
.
exists
(
cfg_path
):
cfg
=
open
(
cfg_path
,
'r'
).
read
().
split
(
"#"
)
cfg
=
open
(
cfg_path
).
read
().
split
(
"#"
)
if
len
(
cfg
)
!=
2
:
continue
# there is a broken config file
list
.
append
(
cfg
[
1
])
folder_list
=
os
.
listdir
(
config
[
'software_root'
])
if
len
(
folder_list
)
<
1
:
return
curent_project
=
open
(
os
.
path
.
join
(
config
[
'etc_dir'
],
".project"
),
'r'
).
read
()
curent_project
=
open
(
os
.
path
.
join
(
config
[
'etc_dir'
],
".project"
)).
read
()
projects
=
curent_project
.
split
(
"/"
)
name
=
projects
[
len
(
projects
)
-
2
]
for
folder
in
folder_list
:
...
...
@@ -317,7 +308,7 @@ def loadSoftwareRList(config):
for
path
in
os
.
listdir
(
config
[
'software_link'
]):
cfg_path
=
os
.
path
.
join
(
config
[
'software_link'
],
path
,
config_name
)
if
os
.
path
.
exists
(
cfg_path
):
cfg
=
open
(
cfg_path
,
'r'
).
read
().
split
(
"#"
)
cfg
=
open
(
cfg_path
).
read
().
split
(
"#"
)
if
len
(
cfg
)
!=
2
:
continue
# there is a broken config file
list
.
append
(
dict
(
md5
=
cfg
[
1
],
path
=
cfg
[
0
],
title
=
path
))
...
...
slapos/runner/views.py
View file @
c0cf24d1
...
...
@@ -104,7 +104,7 @@ def dologout():
@
login_required
()
def
configRepo
():
public_key
=
open
(
app
.
config
[
'public_key'
]
,
'r'
).
read
()
public_key
=
open
(
app
.
config
[
'public_key'
]).
read
()
account
=
getSession
(
app
.
config
)
return
render_template
(
'cloneRepository.html'
,
workDir
=
'workspace'
,
public_key
=
public_key
,
name
=
account
[
3
].
decode
(
'utf-8'
),
...
...
@@ -162,7 +162,7 @@ def runSoftwareProfile():
@
login_required
()
def
viewSoftwareLog
():
if
os
.
path
.
exists
(
app
.
config
[
'software_log'
]):
result
=
tail
(
open
(
app
.
config
[
'software_log'
]
,
'r'
),
lines
=
1500
)
result
=
tail
(
open
(
app
.
config
[
'software_log'
]),
lines
=
1500
)
else
:
result
=
'Not found yet'
return
render_template
(
'viewLog.html'
,
type
=
'software'
,
...
...
@@ -246,7 +246,7 @@ def runInstanceProfile():
@
login_required
()
def
viewInstanceLog
():
if
os
.
path
.
exists
(
app
.
config
[
'instance_log'
]):
result
=
open
(
app
.
config
[
'instance_log'
]
,
'r'
).
read
()
result
=
open
(
app
.
config
[
'instance_log'
]).
read
()
else
:
result
=
'Not found yet'
return
render_template
(
'viewLog.html'
,
type
=
'instance'
,
...
...
@@ -392,10 +392,10 @@ def getFileContent():
return
jsonify
(
code
=
0
,
result
=
"Can not open a binary file, please select a text file!"
)
if
'truncate'
in
request
.
form
:
content
=
tail
(
open
(
file_path
,
'r'
),
int
(
request
.
form
[
'truncate'
]))
content
=
tail
(
open
(
file_path
),
int
(
request
.
form
[
'truncate'
]))
return
jsonify
(
code
=
1
,
result
=
content
)
else
:
return
jsonify
(
code
=
1
,
result
=
open
(
file_path
,
'r'
).
read
())
return
jsonify
(
code
=
1
,
result
=
open
(
file_path
).
read
())
else
:
return
jsonify
(
code
=
0
,
result
=
"Error: No such file!"
)
...
...
@@ -494,8 +494,8 @@ def slapgridResult():
request
.
form
[
'log'
]
==
"instance"
:
log_file
=
request
.
form
[
'log'
]
+
"_log"
if
os
.
path
.
exists
(
app
.
config
[
log_file
]):
log_result
=
readFileFrom
(
open
(
app
.
config
[
log_file
]
,
'r'
),
int
(
request
.
form
[
'position'
]))
log_result
=
readFileFrom
(
open
(
app
.
config
[
log_file
]),
int
(
request
.
form
[
'position'
]))
return
jsonify
(
software
=
software_state
,
instance
=
instance_state
,
result
=
(
instance_state
or
software_state
),
content
=
log_result
)
...
...
@@ -561,7 +561,7 @@ def saveParameterXml():
def
getSoftwareType
():
software_type_path
=
os
.
path
.
join
(
app
.
config
[
'etc_dir'
],
".software_type.xml"
)
if
os
.
path
.
exists
(
software_type_path
):
return
jsonify
(
code
=
1
,
result
=
open
(
software_type_path
,
'r'
).
read
())
return
jsonify
(
code
=
1
,
result
=
open
(
software_type_path
).
read
())
return
jsonify
(
code
=
1
,
result
=
"default"
)
...
...
@@ -573,7 +573,7 @@ def getParameterXml(request):
default
=
'<?xml version="1.0" encoding="utf-8"?>
\
n
<instance>
\
n
</instance>'
return
jsonify
(
code
=
1
,
result
=
default
)
if
request
==
"xml"
:
parameters
=
open
(
param_path
,
'r'
).
read
()
parameters
=
open
(
param_path
).
read
()
else
:
parameters
=
readParameters
(
param_path
)
if
type
(
parameters
)
==
type
(
''
)
and
request
!=
"xml"
:
...
...
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