Commit 8176e5e0 by Bach Dániel

add update function

parent 56bbc183
...@@ -10,8 +10,11 @@ import logging ...@@ -10,8 +10,11 @@ import logging
import subprocess import subprocess
import fileinput import fileinput
import platform import platform
from shutil import rmtree import sys
# from os import path import tarfile
from StringIO import StringIO
from base64 import decodestring
from shutil import rmtree, move
from datetime import datetime from datetime import datetime
from utils import SerialLineReceiverBase from utils import SerialLineReceiverBase
...@@ -172,6 +175,24 @@ class Context(object): ...@@ -172,6 +175,24 @@ class Context(object):
pass pass
@staticmethod @staticmethod
def update(data):
cur_dir = sys.path[0]
new_dir = cur_dir + '.new'
old_dir = cur_dir + '.old'
f = StringIO(decodestring(data))
try:
tar = tarfile.TarFile.open("dummy", fileobj=f, mode='r|bz2')
tar.extractall(new_dir)
except tarfile.ReadError as e:
logger.error(e)
else:
rmtree(old_dir, ignore_errors=True)
move(cur_dir, old_dir)
move(new_dir, cur_dir)
logger.info('Updated')
reactor.stop()
@staticmethod
def ipaddresses(): def ipaddresses():
import netifaces import netifaces
args = {} args = {}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment