def setUp(self): cfg = configuration.Configuration() cfg_file = "../config/common.ini" cfg.fileConfig(cfg_file) device_id = cfg.getValue('COMMON', 'device_id') app_package = cfg.getValue('COMMON', 'app_package') app_activity = cfg.getValue('COMMON', 'start_activity') login_btn = cfg.getValue('LOGIN', 'login_btn') img_path = cfg.getValue('COMMON', 'img_path') vpn_btn = cfg.getValue('INDEX', 'vpn_btn') img_device_path = cfg.getValue('COMMON', 'img_device_path') mylogger = logger.Log("debug") device = adbtools.AdbTools(device_id) l = device.get_device_state() self.assertNotIn('error', l, 'device connect error.') mylogger.debug(">>>>>>>>>>>>>>>>>>>>>>>>>start install app") common.install_app(device_id) l = myuiautomator.shellPIPE('adb shell pm list packages %s' % app_package) self.assertIn(app_package, l, 'install failure') mylogger.debug(">>>>>>>>>>>>>>>>>>>>>>>>start open app") common.start_app(app_package, app_activity, device_id, vpn_btn, login_btn, img_device_path, img_path) mylogger.debug(">>>>>>>>>>>>>>>>>>>>>screenShot after login") common.click_i_know(device_id, img_path) el = myuiautomator.find_element_by_id(device_id, vpn_btn) self.assertIsNotNone(el, 'can not find vpn btn,this is not index page.')
def __init__(self,device_id=''): self.__system=platform.system() self.__find='' self.__command='' self.__device_id=device_id self.__get_find() self.__check_adb() self.__connection_devices() self.__mylogger = logger.Log("debug")
# All rights reserved. import os.path import sys import paho.mqtt.client as mqtt import json import threading import time from time import sleep from uptime import uptime from lib import logger, calc from config import * # register the application logger appLogger = logger.Log(__name__, LOG_LEVEL, LOG_DIR) def up_time(): total_seconds = uptime() # Helper vars: MINUTE = 60 HOUR = MINUTE * 60 DAY = HOUR * 24 # Get the days, hours, etc: days = int(total_seconds / DAY) hours = int((total_seconds % DAY) / HOUR) minutes = int((total_seconds % HOUR) / MINUTE)
#encoding:utf-8 import time from lib import run,getfile,TP,logger,getIpInfo,bar from etc.setting_general import counter_bar from multiprocessing import Pool log = logger.Log() #def getIpInfo(): # try: # with open('ip') as f: # return f.readlines() # except Exception as e: # print(e) # return [] # def main(): # pool = TP.ThreadPool(5) # for ip in getIpInfo.IpInfo(): # #ip = ip.split() # pool.run(func=run.run,args=(ip,)) # pool.colse() # while True: # if pool.active_count ==1: # getfile.insert_db() # break # else: # time.sleep(1) def main(): pool = TP.ThreadPool(20) for ip in getIpInfo.Ipinfo()
import paho.mqtt.client as mqtt import json import threading import time from time import sleep from conf import * from lib import logger from lib.calcdata import CalcData except Exception as e: print('Import error {}, check requirements.txt'.format(e)) sys.exit(1) # register the application logger appLogger = logger.Log("MQTTSERVICE", MQTT_CLEINTID, LOG_LEVEL) def MicsaleData(): """Main Application """ def on_connect(client, userdata, flags, rc): # The callback for when the client receives a CONNACK response from the server. if rc == mqtt.CONNACK_ACCEPTED: appLogger.debug("{} connected OK, subscribe to topic {}".format( MQTT_HOST, MQTT_DATATOPIC)) # Subscribing in on_connect() means that if we lose the connection and # reconnect then subscriptions will be renewed. client.subscribe(MQTT_DATATOPIC) else: appLogger.error("{} Bad connection, returned code= {}".format(
import subprocess import re import time import xml.etree.cElementTree as ET from lib import configuration from lib import logger cfg = configuration.Configuration() cfg_file = "../config/common.ini" cfg.fileConfig(cfg_file) ui_path = cfg.getValue('COMMON', 'ui_xml') img_path = cfg.getValue('COMMON', 'img_path') device_id = cfg.getValue('COMMON', 'device_id') install_btn = cfg.getValue('INSTALL', 'install_btn') mylogger = logger.Log("debug") def shellPIPE(cmd): p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) out, err = p.communicate() return out class Element(object): def __init__(self, device_id): self.tempFile = ui_path
import paho.mqtt.publish as publish import time import json import csv from conf import * from lib import logger from lib import body_metrics from lib import body_score from lib import mqtt from lib import influxdata except Exception as e: print('Import error {}, check requirements.txt'.format(e)) sys.exit(1) log = logger.Log(__name__, MI2_SHORTNAME, LOG_LEVEL) class CalcData(): version = '1.0.1' def __init__(self, data: dict = None, useAgeCalc: bool = True): self.useAgeCalc = useAgeCalc # current user settings self.user = '******' self.dob = None self.height = 175 self.age = 18 self.sex = 'male' self.athletic = False
import json import matplotlib as mlp import matplotlib.pyplot as plt import numpy as np from datetime import datetime from lib import calcdata from conf import * from lib import logger except Exception as e: print( f"Import error: {str(e)} line {sys.exc_info()[-1].tb_lineno}, check requirements.txt" ) sys.exit(1) log = logger.Log("scalefactors", MI2_SHORTNAME, 20) def round_to_value(number, roundto: float = 0.5): return (round(float(number) / roundto) * roundto) def plotResults(results: list = None, title: str = "Results", output: str = "result.png"): try: data = dict() data['bmi'] = dict() data['fat'] = dict() data['visceral'] = dict()
import sys sys.path.append("..") try: import csv from datetime import datetime from lib import calcdata from conf import * from lib import logger except Exception as e: print(f"Import error: {str(e)} line {sys.exc_info()[-1].tb_lineno}, check requirements.txt") sys.exit(1) log = logger.Log("csvtestcase", MI2_SHORTNAME, 10) def doCalc(scaledata, data) -> dict: mCalc = calcdata.CalcData(scaledata, True) user = mCalc.getUserData() mCalc.impedance = (int(user['height'])**2) / float(data['wasser']) # get the data from the calculation result = mCalc.getData('full', 'data') useAthletic = result['athletic'] useAthletic = False # try to rescale the calculated values if useAthletic:
try: import os import signal import time from conf import * from lib import logger from lib import mqtt except Exception as e: print( f"Import error: {str(e)} line {sys.exc_info()[-1].tb_lineno}, check requirements.txt" ) sys.exit(1) log = logger.Log("SignalTestcase", MI2_SHORTNAME, 10) print(__name__, MI2_SHORTNAME, 20) # store default handler of signal.SIGINT # default_handler = signal.getsignal(signal.SIGINT) def publish(state: str = "Online"): mqtt_client = mqtt.client() if mqtt_client and mqtt_client.ready: mqtt_client.publish_simple("tele/apptest/LWT", state, True) def handler(signum, frame): publish('Offline') log.debug("Ende Application")
import time from conf import * from lib import logger from lib import mqtt from lib.miscale2 import Miscale2Decoder from lib.calcdata import CalcData except Exception as e: print( f"Import error: {str(e)} line {sys.exc_info()[-1].tb_lineno}, check requirements.txt" ) sys.exit(1) log = logger.Log('MI_SCALE2_APP', MI2_SHORTNAME, LOG_LEVEL) def publishDeviceState(topicmode: str = 'Online', payload: dict = None): mqtt_client = mqtt.client() if mqtt_client and mqtt_client.ready: if topicmode == 'Online': mqtt_client.publish_simple(MQTT_AVAILABILITY_TOPIC, topicmode, True) elif topicmode == 'Offline': mqtt_client.publish_simple(MQTT_AVAILABILITY_TOPIC, topicmode, True) else: if payload: mqtt_client.publish(topicmode, payload, True)