Bundle sudo actions into system task for cleaner permissions - some users may not be comfortable with this

This commit is contained in:
James Barnsley
2018-04-16 15:51:35 +12:00
parent 55ade30130
commit b3007b7bd5
8 changed files with 25472 additions and 23500 deletions

View File

@ -504,47 +504,45 @@ class IrisCore(object):
else:
return response
def upgrade(self, *args, **kwargs):
def start_upgrade(self, *args, **kwargs):
callback = kwargs.get('callback', False)
try:
subprocess.check_call(["sudo", "pip", "install", "--upgrade", "mopidy-iris"])
response = {
'message': "Upgrade completed, restarting..."
}
if (callback):
callback(response)
self.broadcast(data={
'method': "upgrading",
'params': {}
})
self.restart()
# Run the system task
subprocess.Popen(["sudo /home/iris/system.sh upgrade"], shell=True)
response = {
'message': "Upgrade completed, restarting..."
}
if (callback):
callback(response)
else:
return response
except subprocess.CalledProcessError as e:
error = {
'result': "Could not start upgrade"
}
if (callback):
callback(False, error)
else:
return error
def restart(self, *args, **kwargs):
callback = kwargs.get('callback', False)
# Send callback if we have one, otherwise don't bother. We can't return anything
# when we're rebooting ourselves...
if (callback):
result = {
'message': "Restarting... please wait"
}
callback(result)
self.broadcast(data={
'method': "restarting",
'params': {}
})
subprocess.Popen(["sudo /etc/init.d/mopidy restart"], shell=True)
return
subprocess.Popen(["sudo /home/iris/system.sh restart"], shell=True)
# Send callback if we have one, otherwise don't bother. We can't return anything
# when we're rebooting ourselves...
response = {
'message': "Restarting... please wait"
}
if (callback):
callback(response)
else:
return response
##