From 954090d2f9e8ddcd312e49df3c54ca883f61b703 Mon Sep 17 00:00:00 2001 From: Arul Date: Sat, 12 Jan 2019 12:13:02 +0530 Subject: [PATCH] added dvt class --- testing/SYS-DVT/data.json | 4 +- testing/SYS-DVT/occmd.py | 103 +++++++++++++++++++++++++------------- 2 files changed, 69 insertions(+), 38 deletions(-) diff --git a/testing/SYS-DVT/data.json b/testing/SYS-DVT/data.json index 24e52306aa..16c439cc67 100644 --- a/testing/SYS-DVT/data.json +++ b/testing/SYS-DVT/data.json @@ -1,7 +1,7 @@ { "module": { "bb_current": { - "sys_path": "/sys/bb_sensor", + "sys_path": "/home/oc/sys/bb_sensor", "get_vars": { "bb_shunt_voltage": { "unit": "mV" @@ -21,7 +21,7 @@ }, "bb_temp": { - "sys_path": "/sys/bb_temp", + "sys_path": "/home/oc/sys/bb_temp", "get_vars": { "bb_input_temp": { "unit": "Celcius" diff --git a/testing/SYS-DVT/occmd.py b/testing/SYS-DVT/occmd.py index 6c5a12bdbd..c37643c254 100644 --- a/testing/SYS-DVT/occmd.py +++ b/testing/SYS-DVT/occmd.py @@ -3,58 +3,89 @@ import sys import json DB_FILE = "data.json" -db = ''; -module = '' -operation = '' -param = '' -value = '' -def check_args(args): - global module - global operation - global param - global value +class dvt(): + + def __init__(self, dbfile): + self.module = '' + self.operation = '' + self.param = '' + self.value = '' + self.dbfile = dbfile + self.db = '' + + def get(self): + pass + + def set(self): + pass + + def print_vars(self): + print("module_name: %s" %(self.module)) + print("operation: %s" %(self.operation)) + print("param: %s" %(self.param)) + print("value: %s" %(self.value)) + print("DB file: %s" %(self.dbfile)) + + def load_db(self): + try: + f = open(self.dbfile) + self.db = json.load(f) + f.close() + except: + print "File error %s" %(self.dbfile) + sys.exit(-1); + + return 0 + + def print_cmds(self): + pass; + +def check_args(args, a): # check for module name - if((len(args) < 2) or (args[1] == 'help')): - return -1 + try: + if((len(args) < 1) or (args[1] == 'help')): + return -1 - for x in db['module']: - if(x == args[1]): - module = x + for x in a.db['module']: + if(x == args[1]): + a.module = x + break + + if a.module == '': + return -1 + else: # Check for get/set - if(len(args) < 3 and (args[2] == 'get' or args[2] == 'set')): + if(len(args) < 2 and (args[2] == 'get' or args[2] == 'set')): return -1 else: - operation = args[2] - if(operation == 'set'): - if(len(args) < 5): - return -1 - else: - param = args[3] - value = args[4] - else: # get + a.operation = args[2] + if(a.operation == 'set'): if(len(args) < 4): return -1 else: - param = args[3] - - return 0 + a.param = args[3] + a.value = args[4] + else: # get + if(len(args) < 3): + return -1 + else: + a.param = args[3] + return 0 -def load_database(): - global db - with open(DB_FILE) as json_data: - db = json.load(json_data) - return 0 + except: + return -1 def main(): - load_database() - if(check_args(sys.argv)): - print db['module']['help'] + a = dvt(DB_FILE) + a.load_db() + if(check_args(sys.argv, a)): + print a.db['module']['help'] sys.exit(-1) # We have a valid request request process it - print "Request valid" + a.print_vars() sys.exit(0)