1 # -*- coding: utf-8 -*-
7 import openerp.addons.hw_proxy.controllers.main as hw_proxy
9 from openerp import http
10 from openerp.http import request
11 from openerp.tools.translate import _
13 _logger = logging.getLogger(__name__)
15 upgrade_template = """
19 <title>OpenERP's PosBox - Software Upgrade</title>
20 <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
23 var upgrading = false;
24 $('#upgrade').click(function(){
28 $('#upgrade').text('Upgrading, Please Wait');
30 url:'/hw_proxy/perform_upgrade/'
31 }).then(function(status){
32 $('#upgrade').html('Upgrade Successful<br \\>Click to Restart the PosBox');
33 $('#upgrade').off('click');
34 $('#upgrade').click(function(){
35 $.ajax({ url:'hw_proxy/perform_restart' })
36 $('#upgrade').text('Restarting');
37 $('#upgrade').off('click');
38 setTimeout(function(){
44 $('#upgrade').text('Upgrade Failed');
54 font-family: sans-serif;
63 background: rgb(121, 197, 107);
68 text-decoration: none;
69 display: inline-block;
74 <h1>PosBox Software Upgrade</h1>
76 This tool will help you perform an upgrade of the PosBox's software.
77 However the preferred method to upgrade the posbox is to flash the sd-card with
78 the <a href='http://nightly.openerp.com/trunk/posbox/'>latest image</a>. The upgrade
79 procedure is explained into to the <a href='/hw_proxy/static/doc/manual.pdf'>PosBox manual</a>
82 To upgrade the posbox, click on the upgrade button. The upgrade will take a few minutes. <b>Do not reboot</b> the PosBox during the upgrade.
84 <div class='centering'>
85 <a href='#' id='upgrade'>Upgrade</a>
92 class PosboxUpgrader(hw_proxy.Proxy):
94 super(PosboxUpgrader,self).__init__()
95 self.upgrading = threading.Lock()
98 @http.route('/hw_proxy/upgrade', type='http', auth='none', )
100 return upgrade_template
102 @http.route('/hw_proxy/perform_upgrade', type='http', auth='none')
103 def perform_upgrade(self):
104 self.upgrading.acquire()
105 if time.time() - self.last_upgrade < 30:
106 self.upgrading.release()
109 os.system('/bin/bash /home/pi/openerp/update.sh')
110 self.last_upgrade = time.time()
111 self.upgrading.release()
114 @http.route('/hw_proxy/perform_restart', type='http', auth='none')
115 def perform_restart(self):
116 self.upgrading.acquire()
117 if time.time() - self.last_upgrade < 30:
118 self.upgrading.release()
121 os.system('/bin/bash /home/pi/openerp/restart.sh')
122 self.last_upgrade = time.time()
123 self.upgrading.release()