1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import logging
import os
import subprocess
import threading
from odoo import http
from odoo.http import Response
from odoo.addons.hw_drivers.tools import helpers
from odoo.addons.web.controllers.home import Home
_logger = logging.getLogger(__name__)
class IoTboxHomepage(Home):
def __init__(self):
super(IoTboxHomepage,self).__init__()
self.updating = threading.Lock()
def clean_partition(self):
subprocess.check_call(['sudo', 'bash', '-c', '. /home/pi/odoo/addons/point_of_sale/tools/posbox/configuration/upgrade.sh; cleanup'])
@http.route('/hw_proxy/perform_upgrade', type='http', auth='none')
def perform_upgrade(self):
self.updating.acquire()
os.system('/home/pi/odoo/addons/point_of_sale/tools/posbox/configuration/posbox_update.sh')
self.updating.release()
return 'SUCCESS'
@http.route('/hw_proxy/get_version', type='http', auth='none')
def check_version(self):
return helpers.get_version()
@http.route('/hw_proxy/perform_flashing_create_partition', type='http', auth='none')
def perform_flashing_create_partition(self):
try:
response = subprocess.check_output(['sudo', 'bash', '-c', '. /home/pi/odoo/addons/point_of_sale/tools/posbox/configuration/upgrade.sh; create_partition']).decode().split('\n')[-2]
if response in ['Error_Card_Size', 'Error_Upgrade_Already_Started']:
raise Exception(response)
return Response('success', status=200)
except subprocess.CalledProcessError as e:
raise Exception(e.output)
except Exception as e:
_logger.error('A error encountered : %s ' % e)
return Response(str(e), status=500)
@http.route('/hw_proxy/perform_flashing_download_raspios', type='http', auth='none')
def perform_flashing_download_raspios(self):
try:
response = subprocess.check_output(['sudo', 'bash', '-c', '. /home/pi/odoo/addons/point_of_sale/tools/posbox/configuration/upgrade.sh; download_raspios']).decode().split('\n')[-2]
if response == 'Error_Raspios_Download':
raise Exception(response)
return Response('success', status=200)
except subprocess.CalledProcessError as e:
raise Exception(e.output)
except Exception as e:
self.clean_partition()
_logger.error('A error encountered : %s ' % e)
return Response(str(e), status=500)
@http.route('/hw_proxy/perform_flashing_copy_raspios', type='http', auth='none')
def perform_flashing_copy_raspios(self):
try:
response = subprocess.check_output(['sudo', 'bash', '-c', '. /home/pi/odoo/addons/point_of_sale/tools/posbox/configuration/upgrade.sh; copy_raspios']).decode().split('\n')[-2]
if response == 'Error_Iotbox_Download':
raise Exception(response)
return Response('success', status=200)
except subprocess.CalledProcessError as e:
raise Exception(e.output)
except Exception as e:
self.clean_partition()
_logger.error('A error encountered : %s ' % e)
return Response(str(e), status=500)
|