summaryrefslogtreecommitdiff
path: root/wiki/Chat_log/20190523-mm-chatlog
diff options
context:
space:
mode:
authorWolfram Sang <wsa+renesas@sang-engineering.com>2021-04-13 11:26:36 +0200
committerWolfram Sang <wsa+renesas@sang-engineering.com>2021-04-13 11:28:59 +0200
commitebeffca3f56c6e5819c30d24e71c0f4f747cb2f2 (patch)
tree9b0e092a98cf5967a5f8bb443d02bfe4676f3a04 /wiki/Chat_log/20190523-mm-chatlog
parent19bf11c6a49162b102ebee57ebe29da991887f9c (diff)
linux: bsp-41x: move I2C items to proper places
Either non-target, or a new upport task. Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Diffstat (limited to 'wiki/Chat_log/20190523-mm-chatlog')
0 files changed, 0 insertions, 0 deletions
6'>116 117 118 119 120
#! /usr/bin/env python3
#===============================
#
# base
#
# 2019/02/07 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
#===============================
import os
import re
import subprocess

#====================================
#
# base
#
# it supports do/run/run1 for using external command
#
#====================================
class base:
    __top = os.path.abspath(__file__ + "/../../");
    __key = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"
    __bsp = ["bsp41x", "bsp39x"]

    #--------------------
    # chomp
    #--------------------
    def chomp(self, text):
        return re.sub(r"\n$", r"", text);

    #--------------------
    # top()
    #--------------------
    def top(self):
        return base.__top;

    #--------------------
    # bsp_list()
    #--------------------
    def bsp_list(self):
        return base.__bsp;

    #--------------------
    # is_key()
    #--------------------
    def is_key(self, key):
        return re.match(base.__key, key);

    #--------------------
    # color
    #--------------------
    def color(self, color, text):
        return "\033[{}m{}\033[0m".format(self.config(color), text)

    #--------------------
    # do()
    #
    # do command
    #--------------------
    def do(self, command):
        return subprocess.run(command, shell=True).returncode;

    #--------------------
    # tolist()
    #--------------------
    def tolist(self, string):
        if (len(string) > 0):
            return string.split('\n');

        return [];

    #--------------------
    # run()
    #
    # run command and get result as plane text
    #--------------------
    def run2(self, command):

        # Ughhhh
        # I don't like python external command !!
        # (ノ `Д´)ノ  go away !!
        child = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
        stdout, stderr = child.communicate()

        return self.chomp(stdout.decode("utf-8")), child.returncode;

    def run(self, command):
        return self.run2(command)[0]

    #--------------------
    # run1()
    #
    # run command and get result as list
    #--------------------
    def runl(self, command):

        # call run() and exchange result as array
        #
        # "xxxxxxx
        #  yyyyyyy
        #  zzzzzzz"
        # ->
        # ["xxxxxxx",
        #  "yyyyyyy",
        #  "zzzzzzz"]
        return self.tolist(self.run(command));

    #--------------------
    # config()
    #
    # read settings from config