# -*- coding: utf-8 -*- import logging import os import time import openerp import openerp.addons.hw_proxy.controllers.main as hw_proxy import threading from openerp import http from openerp.http import request from openerp.tools.translate import _ _logger = logging.getLogger(__name__) upgrade_template = """ Odoo's PosBox - Software Upgrade

PosBox Software Upgrade

This tool will help you perform an upgrade of the PosBox's software over the internet.

However the preferred method to upgrade the posbox is to flash the sd-card with the latest image. The upgrade procedure is explained into to the PosBox manual

To upgrade the posbox, click on the upgrade button. The upgrade will take a few minutes. Do not reboot the PosBox during the upgrade.

Upgrade
""" class PosboxUpgrader(hw_proxy.Proxy): def __init__(self): super(PosboxUpgrader,self).__init__() self.upgrading = threading.Lock() self.last_upgrade = 0 @http.route('/hw_proxy/upgrade', type='http', auth='none', ) def upgrade(self): return upgrade_template @http.route('/hw_proxy/perform_upgrade', type='http', auth='none') def perform_upgrade(self): self.upgrading.acquire() if time.time() - self.last_upgrade < 30: self.upgrading.release() return 'UPTODATE' else: os.system('/bin/bash /home/pi/odoo/posbox/update.sh') self.last_upgrade = time.time() self.upgrading.release() return 'SUCCESS' @http.route('/hw_proxy/perform_restart', type='http', auth='none') def perform_restart(self): self.upgrading.acquire() if time.time() - self.last_upgrade < 30: self.upgrading.release() return 'RESTARTED' else: os.system('/bin/bash /home/pi/odoo/posbox/restart.sh') self.last_upgrade = time.time() self.upgrading.release() return 'SUCCESS'