Skip to content

Commit

Permalink
[FIX] hw_drivers: Use branch of connected DB
Browse files Browse the repository at this point in the history
Preivously, the code of the IoT Box was retrieved from the branch that
was used during the build but the drivers were retrieved from the
connected Odoo DB. Both could be in different versions, which forced
used to make old drivers compatible with the new Box or new drivers
compatible with old versions of the Box.

All of this made it quite hard to modify the existing code, even for
new versions of the Box in master.

When connecting the IoT Box to an Odoo DB, we now retrieve the version
of Odoo that is used and checkout the Box to this branch. This means
that we can now modify the code of the Box in master without having to
worry about users using the latest build with older DBs.

TaskID: 2120749
  • Loading branch information
aprieels committed Nov 26, 2019
1 parent 27ec74a commit 6af5d66
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
1 change: 1 addition & 0 deletions addons/hw_drivers/controllers/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ def run(self):
"""
Thread that will check connected/disconnected device, load drivers if needed and contact the odoo server with the updates
"""
helpers.check_git_branch()
helpers.check_certificate()
updated_devices = {}
self.send_alldevices()
Expand Down
39 changes: 39 additions & 0 deletions addons/hw_drivers/tools/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io
import json
import logging
import os
import subprocess
import zipfile

Expand Down Expand Up @@ -50,6 +51,44 @@ def check_certificate():
else:
load_certificate()

def check_git_branch():
"""
Check if the local branch is the same than the connected Odoo DB and
checkout to match it if needed.
"""
server = get_odoo_server_url()
if server:
urllib3.disable_warnings()
http = urllib3.PoolManager(cert_reqs='CERT_NONE')
try:
response = http.request(
'POST',
server + "/web/webclient/version_info",
body = '{}',
headers = {'Content-type': 'application/json'}
)

if response.status == 200:
git = ['git', '--work-tree=/home/pi/odoo/', '--git-dir=/home/pi/odoo/.git']

db_branch = json.loads(response.data)['result']['server_serie'].replace('~', '-')
if not subprocess.check_output(git + ['ls-remote', 'origin', db_branch]):
db_branch = 'master'

local_branch = subprocess.check_output(git + ['symbolic-ref', '-q', '--short', 'HEAD']).decode('utf-8').rstrip()

if db_branch != local_branch:
subprocess.check_call(["sudo", "mount", "-o", "remount,rw", "/"])
subprocess.check_call(git + ['branch', '-m', db_branch])
subprocess.check_call(git + ['remote', 'set-branches', 'origin', db_branch])
os.system('/home/pi/odoo/addons/point_of_sale/tools/posbox/configuration/posbox_update.sh')
subprocess.check_call(["sudo", "mount", "-o", "remount,ro", "/"])
subprocess.check_call(["sudo", "mount", "-o", "remount,rw", "/root_bypass_ramdisks/etc/cups"])

except Exception as e:
_logger.error('Could not reach configured server')
_logger.error('A error encountered : %s ' % e)

def get_ip():
try:
return netifaces.ifaddresses('eth0')[netifaces.AF_INET][0]['addr']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ localremote=$(git config branch.$localbranch.remote)
git fetch "${localremote}" "${localbranch}" --depth=1
git reset "${localremote}"/"${localbranch}" --hard
sudo mount -o remount,ro /
(sleep 5 && sudo reboot) &
(sleep 5 && sudo service odoo restart) &

0 comments on commit 6af5d66

Please sign in to comment.