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
5
Merge Requests
5
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
nexedi
slapos.toolbox
Commits
dbdb1853
Commit
dbdb1853
authored
Jul 26, 2019
by
Bryton Lacquement
🚪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip
parent
fbdaf72d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
25 deletions
+40
-25
slapos/runner/utils.py
slapos/runner/utils.py
+40
-25
No files found.
slapos/runner/utils.py
View file @
dbdb1853
...
...
@@ -70,7 +70,8 @@ def getSession(config):
"""
user_path
=
os
.
path
.
join
(
config
[
'etc_dir'
],
'.htpasswd'
)
if
os
.
path
.
exists
(
user_path
):
return
open
(
user_path
).
read
().
split
(
';'
)
with
open
(
user_path
)
as
f
:
return
f
.
read
().
split
(
';'
)
def
checkUserCredential
(
config
,
username
,
password
):
htpasswdfile
=
os
.
path
.
join
(
config
[
'etc_dir'
],
'.htpasswd'
)
...
...
@@ -125,8 +126,8 @@ def getCurrentSoftwareReleaseProfile(config):
Returns used Software Release profile as a string.
"""
try
:
software_folder
=
open
(
os
.
path
.
join
(
config
[
'etc_dir'
],
".project"
))
.
read
().
rstrip
()
with
open
(
os
.
path
.
join
(
config
[
'etc_dir'
],
".project"
))
as
f
:
software_folder
=
f
.
read
().
rstrip
()
return
realpath
(
config
,
os
.
path
.
join
(
software_folder
,
config
[
'software_profile'
]))
# XXXX No Comments
...
...
@@ -141,9 +142,11 @@ def requestInstance(config, software_type=None):
software_type_path
=
os
.
path
.
join
(
config
[
'etc_dir'
],
".software_type.xml"
)
if
software_type
:
# Write it to conf file for later use
open
(
software_type_path
,
'w'
).
write
(
software_type
)
with
open
(
software_type_path
,
'w'
)
as
f
:
f
.
write
(
software_type
)
elif
os
.
path
.
exists
(
software_type_path
):
software_type
=
open
(
software_type_path
).
read
().
rstrip
()
with
open
(
software_type_path
)
as
f
:
software_type
=
f
.
read
().
rstrip
()
else
:
software_type
=
'default'
...
...
@@ -261,7 +264,8 @@ def slapgridResultToFile(config, step, returncode, datetime):
filename
=
step
+
"_info.json"
file
=
os
.
path
.
join
(
config
[
'runner_workdir'
],
filename
)
result
=
{
'last_build'
:
datetime
,
'success'
:
returncode
}
open
(
file
,
"w"
).
write
(
json
.
dumps
(
result
))
with
open
(
file
,
"w"
)
as
f
:
f
.
write
(
json
.
dumps
(
result
))
def
getSlapgridResult
(
config
,
step
):
...
...
@@ -359,7 +363,8 @@ 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
).
read
().
split
(
"#"
)
with
open
(
cfg_path
)
as
f
:
cfg
=
f
.
read
().
split
(
"#"
)
if
len
(
cfg
)
!=
2
:
continue
# there is a broken config file
software_link_list
.
append
(
cfg
[
1
])
...
...
@@ -382,7 +387,8 @@ 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
).
read
().
split
(
"#"
)
with
open
(
cfg_path
)
as
f
:
cfg
=
f
.
read
().
split
(
"#"
)
if
len
(
cfg
)
!=
2
:
continue
# there is a broken config file
sr_list
.
append
(
dict
(
md5
=
cfg
[
1
],
path
=
cfg
[
0
],
title
=
path
))
...
...
@@ -409,7 +415,8 @@ def getProfilePath(projectDir, profile):
"""
if
not
os
.
path
.
exists
(
os
.
path
.
join
(
projectDir
,
".project"
)):
return
False
projectFolder
=
open
(
os
.
path
.
join
(
projectDir
,
".project"
)).
read
()
with
open
(
os
.
path
.
join
(
projectDir
,
".project"
))
as
f
:
projectFolder
=
f
.
read
()
return
os
.
path
.
join
(
projectFolder
,
profile
)
...
...
@@ -567,7 +574,8 @@ def configNewSR(config, projectpath):
sup_process.stopProcess(config, '
slapgrid
-
sr
')
logger.warning("User opened a new SR. Removing all instances...")
removeCurrentInstance(config)
open(os.path.join(config['
etc_dir
'], ".project"), '
w
').write(projectpath)
with open(os.path.join(config['
etc_dir
'], ".project"), '
w
') as f:
f.write(projectpath)
return True
else:
return False
...
...
@@ -596,9 +604,12 @@ def newSoftware(folder, config, session):
except:
#Software.cfg and instance.cfg content will be empty
pass
open(os.path.join(folderPath, config['
software_profile
']), '
w
').write(softwareContent)
open(os.path.join(folderPath, config['
instance_profile
']), '
w
').write("")
open(os.path.join(basedir, ".project"), '
w
').write(folder + "/")
with open(os.path.join(folderPath, config['
software_profile
']), '
w
') as f:
f.write(softwareContent)
with open(os.path.join(folderPath, config['
instance_profile
']), '
w
') as f:
f.write("")
with open(os.path.join(basedir, ".project"), '
w
') as f:
f.write(folder + "/")
#Clean sapproxy Database
stopProxy(config)
removeProxyDb(config)
...
...
@@ -633,7 +644,8 @@ def getProjectTitle(config):
if instance_name:
instance_name = '
%
s
-
' % instance_name
if os.path.exists(conf):
project = open(conf, "r").read().split("/")
with open(conf, "r") as f:
project = f.read().split("/")
software = project[-2]
return '
%
s
%
s
(
%
s
)
' % (instance_name, software, '
/
'.join(project[:-2]))
return "%sNo Profile" % instance_name
...
...
@@ -643,7 +655,8 @@ def getSoftwareReleaseName(config):
"""Get the name of the current Software Release"""
sr_profile = os.path.join(config['
etc_dir
'], ".project")
if os.path.exists(sr_profile):
project = open(sr_profile, "r").read().split("/")
with open(sr_profile, "r") as f:
project = f.read().split("/")
software = project[-2]
return software.replace('
', '
_
')
return None
...
...
@@ -778,14 +791,14 @@ def md5sum(file):
if os.path.isdir(file):
return False
try:
fh = open(file, 'rb')
m = hashlib.md5()
while True:
data = fh.read(8192)
if not data:
break
m.update(data)
return m.hexdigest()
with open(file, 'rb') as fh:
m = hashlib.md5()
while True:
data = fh.read(8192)
if not data:
break
m.update(data)
return m.hexdigest()
except:
return False
...
...
@@ -947,10 +960,12 @@ def setMiniShellHistory(config, command):
command = command + "
\
n
"
history_file = config['
minishell_history_file
']
if os.path.exists(history_file):
history = open(history_file, 'r').readlines()
with open(history_file, 'r') as f:
history = f.readlines()
if len(history) >= history_max_size:
del history[0]
else:
history = []
history.append(command)
open(history_file, '
w
+
').write(''.join(history))
with open(history_file, '
w
+
') as f:
f.write(''.join(history))
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