Last active
March 28, 2017 20:26
-
-
Save kanazux/b63feaad90b39fcf8e26 to your computer and use it in GitHub Desktop.
display info ezio 300
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/local/bin/python | |
| # -*- coding: UTF-8 -*- | |
| # | |
| # Author Silvio Giunge <[email protected]> | |
| # Display system info using ezio drivers | |
| # For FreeBSD 8.1 use to compile the drivers on the version 9.1 | |
| # | |
| import os | |
| import re | |
| import sys | |
| import time | |
| import daemon | |
| import signal | |
| import platform | |
| import threading | |
| import subprocess | |
| def control_c(signal, frame): | |
| sys.exit(0) | |
| class display_info(): | |
| def write_display(self, word, line): | |
| if (len(word) < 16): | |
| get_spaces = 16 - len(word) | |
| pre = " " * (get_spaces / 2) | |
| if (get_spaces % 2 == 1): | |
| pos = " " * (get_spaces / 2 + 1) | |
| else: | |
| pos = " " * (get_spaces / 2) | |
| set_info = "".join([pre, word, pos]) | |
| else: | |
| set_info = word[:15] | |
| for idx, char in enumerate(set_info): | |
| os.system('/usr/local/sbin/ezio_300_api -d /dev/cuau1 -C "{}" {} {}'.format(char, line, idx + 1)) | |
| def get_sbp(self, command): | |
| return subprocess.check_output(["{}".format(command)], shell=True) | |
| def get_uptime(self): | |
| get_uptime = [x.strip() for x in subprocess.check_output(['/usr/bin/uptime'], shell=True).split(',')] | |
| uptime = " ".join([get_uptime[0].split()[0], get_uptime[0].split()[2]]) | |
| self.write_display("UPTIME", 1) | |
| self.write_display(uptime, 2) | |
| time.sleep(5) | |
| average = " ".join([get_uptime[2].split(':')[1], get_uptime[3], get_uptime[4]]) | |
| self.write_display("AVERAGE", 1) | |
| self.write_display(average, 2) | |
| time.sleep(5) | |
| def get_hostname(self): | |
| get_hostname = subprocess.check_output(['/bin/hostname'], shell=True).strip() | |
| self.write_display("HOSTNAME", 1) | |
| self.write_display(get_hostname.upper(), 2) | |
| time.sleep(5) | |
| def get_disk_space(self): | |
| st = os.statvfs('/') | |
| free = st.f_bavail * st.f_frsize | |
| total = st.f_blocks * st.f_frsize | |
| free_percent = 100 * free / total | |
| self.write_display("FREE SPACE /", 1) | |
| self.write_display("{}%".format(free_percent), 2) | |
| time.sleep(5) | |
| def get_arch(self): | |
| arch = platform.processor() | |
| self.write_display("PROCESSOR ARCH /", 1) | |
| self.write_display(arch.upper(), 2) | |
| time.sleep(5) | |
| def get_iface_ips(self): | |
| ptrn = re.compile(r'[a-z0-9]+', re.IGNORECASE) | |
| pt_in = re.compile(r"\tinet\ ", re.IGNORECASE) | |
| get_inet = [] | |
| ifs = [i.split(':')[0] for i in self.get_sbp('ifconfig').split('\n') if ptrn.match(i)] | |
| for i in ifs: | |
| for line in self.get_sbp('ifconfig {}'.format(i)).split('\n'): | |
| if pt_in.match(line): | |
| get_inet.append([i, line.split()[1]]) | |
| if len(get_inet) > 0: | |
| for i in get_inet: | |
| if not re.match(r'lo[0-9]', i[0]): | |
| self.write_display(i[0].upper(), 1) | |
| self.write_display(i[1], 2) | |
| time.sleep(4) | |
| def run(self): | |
| while True: | |
| self.get_iface_ips() | |
| self.get_arch() | |
| self.get_disk_space() | |
| self.get_uptime() | |
| self.get_hostname() | |
| def main(): | |
| if os.system('/bin/pgrep -fl display_info.py') == 0: | |
| sys.exit(0) | |
| signal.signal(signal.SIGINT, control_c) | |
| start = display_info() | |
| start.run() | |
| if __name__ == "__main__": | |
| start_main = daemon.DaemonContext() | |
| with start_main: | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, I want to use your code. How can I get the ezio_300_api and drivers for the LCD display?