diff options
| author | lejeune quentin <qle@odoo.com> | 2019-08-21 17:25:07 +0200 |
|---|---|---|
| committer | lejeune quentin <qle@odoo.com> | 2019-08-23 12:21:02 +0200 |
| commit | 84de7cbcb623e04994c768fa6023366a945aea8a (patch) | |
| tree | 3c0d485e44a5813f805bd17de0bdc4a21fc05f8f /addons/hw_drivers/tools | |
| parent | dc625b2036950792a7151c2e4f5faa5d1484312f (diff) | |
[ADD] iot: Improve usage of helpers in IoT Box
With this commit we move the helpers to a separate file for
easier access from the IoT Box
Diffstat (limited to 'addons/hw_drivers/tools')
| -rw-r--r-- | addons/hw_drivers/tools/helpers.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/addons/hw_drivers/tools/helpers.py b/addons/hw_drivers/tools/helpers.py new file mode 100644 index 00000000000..1d6cfed3bb0 --- /dev/null +++ b/addons/hw_drivers/tools/helpers.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +import netifaces +from pathlib import Path + +#---------------------------------------------------------- +# Helper +#---------------------------------------------------------- + +def get_ip(): + try: + return netifaces.ifaddresses('eth0')[netifaces.AF_INET][0]['addr'] + except: + return netifaces.ifaddresses('wlan0')[netifaces.AF_INET][0]['addr'] + +def get_mac_address(): + try: + return netifaces.ifaddresses('eth0')[netifaces.AF_LINK][0]['addr'] + except: + return netifaces.ifaddresses('wlan0')[netifaces.AF_LINK][0]['addr'] + +def get_odoo_server_url(): + return read_file_first_line('odoo-remote-server.conf') + +def get_token(): + return read_file_first_line('token') + +def get_version(): + return '19_07' + +def read_file_first_line(filename): + path = Path.home() / filename + if path.exists(): + with path.open('r') as f: + return f.readline().strip('\n') + return '' + +def unlink_file(filename): + subprocess.check_call(["sudo", "mount", "-o", "remount,rw", "/"]) + path = Path.home() / filename + if path.exists(): + path.unlink() + subprocess.check_call(["sudo", "mount", "-o", "remount,ro", "/"]) + +def write_file(filename, text): + subprocess.check_call(["sudo", "mount", "-o", "remount,rw", "/"]) + path = Path.home() / filename + path.write_text(text) + subprocess.check_call(["sudo", "mount", "-o", "remount,ro", "/"])
\ No newline at end of file |
