[IMP] posbox: add a software upgrade page that allows to remotely update the posbox's software
bzr revid: fva@openerp.com-20140321162336-n05c693ukz3awfyg
This commit is contained in:
parent
e7ba075c59
commit
88e9f7e90b
|
@ -0,0 +1,25 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import controllers
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
|
||||
{
|
||||
'name': 'PosBox Software Upgrader',
|
||||
'version': '1.0',
|
||||
'category': 'Hardware Drivers',
|
||||
'sequence': 6,
|
||||
'summary': 'Allows to remotely upgrade the PosBox software',
|
||||
'description': """
|
||||
PosBox Software Upgrader
|
||||
========================
|
||||
|
||||
This module allows to remotely upgrade the PosBox software to a
|
||||
new version. This module is specific to the PosBox setup and environment
|
||||
and should not be installed on regular openerp servers.
|
||||
|
||||
""",
|
||||
'author': 'OpenERP SA',
|
||||
'depends': ['hw_proxy'],
|
||||
'test': [
|
||||
],
|
||||
'installable': False,
|
||||
'auto_install': False,
|
||||
}
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
@ -0,0 +1,3 @@
|
|||
import main
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
@ -0,0 +1,126 @@
|
|||
# -*- 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 = """
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>OpenERP's PosBox - Software Upgrade</title>
|
||||
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
|
||||
<script>
|
||||
$(function(){
|
||||
var upgrading = false;
|
||||
$('#upgrade').click(function(){
|
||||
console.log('click');
|
||||
if(!upgrading){
|
||||
upgrading = true;
|
||||
$('#upgrade').text('Upgrading, Please Wait');
|
||||
$.ajax({
|
||||
url:'/hw_proxy/perform_upgrade/'
|
||||
}).then(function(status){
|
||||
$('#upgrade').html('Upgrade Successful<br \\>Click to Restart the PosBox');
|
||||
$('#upgrade').off('click');
|
||||
$('#upgrade').click(function(){
|
||||
$.ajax({ url:'hw_proxy/perform_restart' })
|
||||
$('#upgrade').text('Restarting');
|
||||
$('#upgrade').off('click');
|
||||
setTimeout(function(){
|
||||
window.location = '/'
|
||||
},30*1000);
|
||||
});
|
||||
|
||||
},function(){
|
||||
$('#upgrade').text('Upgrade Failed');
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<style>
|
||||
body {
|
||||
width: 480px;
|
||||
margin: 60px auto;
|
||||
font-family: sans-serif;
|
||||
text-align: justify;
|
||||
color: #6B6B6B;
|
||||
}
|
||||
.centering{
|
||||
text-align: center;
|
||||
}
|
||||
#upgrade {
|
||||
padding: 20px;
|
||||
background: rgb(121, 197, 107);
|
||||
color: white;
|
||||
border-radius: 3px;
|
||||
text-align: center;
|
||||
margin: 30px;
|
||||
text-decoration: none;
|
||||
display: inline-block;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>PosBox Software Upgrade</h1>
|
||||
<p>
|
||||
This tool will help you perform an upgrade of the PosBox's software.
|
||||
However the preferred method to upgrade the posbox is to flash the sd-card with
|
||||
the <a href='http://nightly.openerp.com/trunk/posbox/'>latest image</a>. The upgrade
|
||||
procedure is explained into to the <a href='/hw_proxy/static/doc/manual.pdf'>PosBox manual</a>
|
||||
</p>
|
||||
<p>
|
||||
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.
|
||||
</p>
|
||||
<div class='centering'>
|
||||
<a href='#' id='upgrade'>Upgrade</a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
"""
|
||||
|
||||
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/openerp/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/openerp/restart.sh')
|
||||
self.last_upgrade = time.time()
|
||||
self.upgrading.release()
|
||||
return 'SUCCESS'
|
||||
|
||||
|
Loading…
Reference in New Issue