Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.package
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
Ophélie Gagnard
slapos.package
Commits
47ea4458
Commit
47ea4458
authored
Jun 04, 2013
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
whitespace
parent
74d4eb97
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
23 deletions
+22
-23
upload-update.py
upload-update.py
+22
-23
No files found.
upload-update.py
View file @
47ea4458
...
@@ -51,11 +51,11 @@ class Parser(OptionParser):
...
@@ -51,11 +51,11 @@ class Parser(OptionParser):
Option
(
"--upgrade-file"
,
Option
(
"--upgrade-file"
,
default
=
'/etc/slapos-cache/slapos-upgrade'
,
default
=
'/etc/slapos-cache/slapos-upgrade'
,
help
=
"File use as reference to upgrade."
),
help
=
"File use as reference to upgrade."
),
Option
(
"-u"
,
"--upgrade"
,
Option
(
"-u"
,
"--upgrade"
,
default
=
False
,
default
=
False
,
action
=
"store_true"
,
action
=
"store_true"
,
help
=
"If selected will update tomorrow."
),
help
=
"If selected will update tomorrow."
),
Option
(
"-r"
,
"--reboot"
,
Option
(
"-r"
,
"--reboot"
,
default
=
False
,
default
=
False
,
action
=
"store_true"
,
action
=
"store_true"
,
help
=
"If selected will reboot tomorrow."
),
help
=
"If selected will reboot tomorrow."
),
...
@@ -65,7 +65,6 @@ class Parser(OptionParser):
...
@@ -65,7 +65,6 @@ class Parser(OptionParser):
action
=
"store_true"
),
action
=
"store_true"
),
])
])
def
check_args
(
self
):
def
check_args
(
self
):
"""
"""
Check arguments
Check arguments
...
@@ -74,14 +73,14 @@ class Parser(OptionParser):
...
@@ -74,14 +73,14 @@ class Parser(OptionParser):
return
options
return
options
# Utility fonction to get yes/no answers
# Utility fonction to get yes/no answers
def
get_yes_no
(
prompt
):
def
get_yes_no
(
prompt
):
while
True
:
while
True
:
answer
=
raw_input
(
prompt
+
" [y,n]: "
)
answer
=
raw_input
(
prompt
+
" [y,n]: "
)
if
answer
.
upper
()
in
[
'Y'
,
'YES'
]:
return
True
if
answer
.
upper
()
in
[
'Y'
,
'YES'
]:
if
answer
.
upper
()
in
[
'N'
,
'NO'
]:
return
False
return
True
if
answer
.
upper
()
in
[
'N'
,
'NO'
]:
return
False
def
upload_network_cached_from_file
(
path
,
networkcache_options
):
def
upload_network_cached_from_file
(
path
,
networkcache_options
):
...
@@ -94,7 +93,7 @@ def upload_network_cached_from_file(path, networkcache_options):
...
@@ -94,7 +93,7 @@ def upload_network_cached_from_file(path, networkcache_options):
metadata_dict
=
{
metadata_dict
=
{
# XXX: we set date from client side. It can be potentially dangerous
# XXX: we set date from client side. It can be potentially dangerous
# as it can be badly configured.
# as it can be badly configured.
'timestamp'
:
time
.
time
(),
'timestamp'
:
time
.
time
(),
}
}
try
:
try
:
if
helper_upload_network_cached_from_file
(
if
helper_upload_network_cached_from_file
(
...
@@ -115,14 +114,16 @@ def upload_network_cached_from_file(path, networkcache_options):
...
@@ -115,14 +114,16 @@ def upload_network_cached_from_file(path, networkcache_options):
except
Exception
:
except
Exception
:
print
'Unable to upload to cache:
\
n
%s.'
%
traceback
.
format_exc
()
print
'Unable to upload to cache:
\
n
%s.'
%
traceback
.
format_exc
()
def
save_current_state
(
current_state
,
config
):
def
save_current_state
(
current_state
,
config
):
"""
"""
Will save ConfigParser to config file
Will save ConfigParser to config file
"""
"""
file
=
open
(
config
.
upgrade_file
,
"w"
)
file
=
open
(
config
.
upgrade_file
,
"w"
)
current_state
.
write
(
file
)
current_state
.
write
(
file
)
file
.
close
()
file
.
close
()
# Class containing all parameters needed for configuration
# Class containing all parameters needed for configuration
class
Config
:
class
Config
:
def
setConfig
(
self
,
option_dict
):
def
setConfig
(
self
,
option_dict
):
...
@@ -137,16 +138,16 @@ class Config:
...
@@ -137,16 +138,16 @@ class Config:
self
.
tomorrow
=
self
.
today
+
datetime
.
timedelta
(
days
=
1
)
self
.
tomorrow
=
self
.
today
+
datetime
.
timedelta
(
days
=
1
)
def
new_upgrade
(
config
):
def
new_upgrade
(
config
):
upgrade_info
=
ConfigParser
.
RawConfigParser
()
upgrade_info
=
ConfigParser
.
RawConfigParser
()
upgrade_info
.
read
(
config
.
upgrade_file
)
upgrade_info
.
read
(
config
.
upgrade_file
)
if
config
.
reboot
:
if
config
.
reboot
:
upgrade_info
.
set
(
'system'
,
'reboot'
,
config
.
tomorrow
)
upgrade_info
.
set
(
'system'
,
'reboot'
,
config
.
tomorrow
)
if
config
.
upgrade
:
if
config
.
upgrade
:
upgrade_info
.
set
(
'system'
,
'upgrade'
,
config
.
tomorrow
)
upgrade_info
.
set
(
'system'
,
'upgrade'
,
config
.
tomorrow
)
save_current_state
(
upgrade_info
,
config
)
save_current_state
(
upgrade_info
,
config
)
print
" You will update this :"
print
" You will update this :"
print
open
(
config
.
upgrade_file
,
'r'
).
read
()
print
open
(
config
.
upgrade_file
).
read
()
if
not
get_yes_no
(
"Do you want to continue? "
):
if
not
get_yes_no
(
"Do you want to continue? "
):
sys
.
exit
(
0
)
sys
.
exit
(
0
)
...
@@ -154,8 +155,7 @@ def new_upgrade (config):
...
@@ -154,8 +155,7 @@ def new_upgrade (config):
networkcache_info
.
read
(
'/etc/slapos-cache/slapos.cfg'
)
networkcache_info
.
read
(
'/etc/slapos-cache/slapos.cfg'
)
networkcache_info_dict
=
dict
(
networkcache_info
.
items
(
'networkcache'
))
networkcache_info_dict
=
dict
(
networkcache_info
.
items
(
'networkcache'
))
if
not
config
.
dry_run
:
if
not
config
.
dry_run
:
upload_network_cached_from_file
(
config
.
upgrade_file
,
networkcache_info_dict
)
upload_network_cached_from_file
(
config
.
upgrade_file
,
networkcache_info_dict
)
def
main
():
def
main
():
...
@@ -168,6 +168,5 @@ def main():
...
@@ -168,6 +168,5 @@ def main():
sys
.
exit
()
sys
.
exit
()
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
main
()
main
()
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