def Login(): BASEDIR = os.path.dirname(os.path.abspath(__file__)) try: login_options, ok = config.ReadConfig( os.path.join(BASEDIR, 'conf.ini'), 'LOGIN') except Exception as e: return MAX_LOGIN_TIMES = float(login_options['max_login_times']) ADMIN_NAME = login_options['admin_name'] ADMIN_PWD = login_options['admin_pwd'] is_login = False count = 1 while count <= MAX_LOGIN_TIMES: username = InputMsg("请输入管理员用户名:") if username == ADMIN_NAME: count = 1 while count <= MAX_LOGIN_TIMES: # password = InputMsg("请输入管理员密码:") password = getpass.getpass("请输入管理员密码:") if hash(password) == ADMIN_PWD: SuccMsg("你已经登陆成功!") is_login = True return is_login else: WarnMsg("你输入的密码有误,请重新输入!") count += 1 else: WarnMsg("你输入的用户名错误,请重新输入!") count += 1 WarnMsg("你输入错误已经超过三次,账号被锁定!") is_login = False return is_login
def Connect(): global GLOGCONN global GLOGCUR needCreateTb = False cfg = config.ReadConfig() try: dbname = cfg.get("LogDb", "LogDbName") except Exception as e: print("[Error] config.get(DataBase, DbName)") print(e.message) return -1 if os.path.exists(dbname) == False: needCreateTb = True try: con = sqlite3.connect(dbname, check_same_thread=False) except Exception as e: print("[Error] sqlite3.connect(%s)" % (dbname)) print(e.message) return -1 GLOGCONN = con GLOGCUR = con.cursor() if needCreateTb: ret = CreateTb_Log() return ret[0] return 0
def connect(): cfg, ok = config.ReadConfig(FILENAME, 'DB') if not ok: return cfg, False try: conn = pymysql.connect(host=cfg['host'], user=cfg['username'], password=cfg['password'], port=int(cfg['port'])) except Exception as e: return None return conn
def LockUser(): BASEDIR = os.path.dirname(os.path.abspath(__file__)) try: lock_options, ok = config.ReadConfig(os.path.join(BASEDIR, 'conf.ini'), 'LOCK') except Exception as e: return LOCK_FILE = lock_options['lock_file'] current_time = str(time.time()) Write_File(LOCK_FILE, current_time, '')
def LoadParams(self, configfile): oCfg = CFG.ReadConfig(configfile) self.TestTime = int(oCfg.GetConfigValue('TESTTIME')) self.PollTime = int(oCfg.GetConfigValue('POLLTIME')) self.RestTime = int(oCfg.GetConfigValue('RESTTIME')) self.MaxConRunTime = int(oCfg.GetConfigValue('MAXCONRUNTIME')) self.IntNetwork = oCfg.GetConfigValue('INTNETWORK') self.ExtNetwork = oCfg.GetConfigValue('EXTNETWORK') self.OffThres = float(oCfg.GetConfigValue( 'OFFTHRES')) # % RH - Threshold to turn OFF power self.OnThres = float(oCfg.GetConfigValue( 'ONTHRES')) # % RH - Threshold to turn ON power
def SendFormEmail(request): dispatch_email = config.ReadConfig('dispatch.email') if not dispatch_email: logging.info( 'Dispatch email config not found. Would have sent email here') return None logging.info('Sending email to ', dispatch_email) subject = GenerateSubject(request) body = GenerateEmail(request) mail.send_mail(sender=dispatch_email, to=dispatch_email, subject=subject, body=body)
def SendFormEmail(request): dispatch_email = config.ReadConfig('dispatch.email') if not dispatch_email: logging.info( 'Dispatch email config not found. Would have sent email here') for key in _REQUEST_KEYS: logging.info('%s: %s' % (key, ', '.join(request.get_all(key)))) return None logging.info('Sending email to ', dispatch_email) subject = GenerateSubject(request) body = GenerateEmail(request) mail.send_mail(sender=dispatch_email, to=dispatch_email, subject=subject, body=body)
def __init__(self): o_cfg = CFG.ReadConfig('config.txt') self.define() self.writelog()
self.ReScan = True #end class gpio_input_status(object) ############################################################################### # Main Program Starts Here ............ ############################################################################### import RPi.GPIO as GPIO # Rapberry Pi GPIO support library import time as T import sys import DU # Derek's Utilities import config as CFG # Reads data for site specefic Pi eg: temp sensors, location,etc # instantiate objects for run o_cfg = CFG.ReadConfig('config.txt') DATA_DIR = o_cfg.GetConfigValue('DataPath') LOGS_DIR = DATA_DIR + "logs/" o_DT = DU.c_datetime() o_LOG = DU.c_logger(LOGS_DIR, "GPIO_log.txt") o_TempLOG = DU.c_logger(LOGS_DIR, "Temperature_log.txt") ### In case of recovery from mains power failure # allow time for router and TPLink (Ethernet over mains) units to initialise! wait2start = 60 * 4 T.sleep(wait2start) o_LOG.write("Starting program after a wait of " + str(wait2start) + " seconds.")
#print(table) # close the communication with the PostgreSQL cur.close() except (Exception, psycopg2.DatabaseError) as error: print(error) finally: if conn is not None: conn.close() print('Database connection closed.') return result if __name__ == '__main__': #connect() sections = config.ReadConfig() listdb = config.ConfigSectionMap('listdb').split(',') path_backup = config.ConfigSectionGet('listdb', 'path') for section in sections: if section != 'listdb': host_name = config.ConfigSectionGet(section, 'host') user_name = config.ConfigSectionGet(section, 'user') password = config.ConfigSectionGet(section, 'password') res = get_databases(section) for r in res: if r[0] in listdb: print('Starting backup database:')
import adb import config import run_one # Read config config = config.ReadConfig("./python/config.json") config.print() # Push model files into adb adb_runner = adb.AdbRunner("./python/output.txt") adb_runner.push_files("./resource/<model name>") # Run One one_runner = run_one.OneRunner(config) #adb_runner.run("""ls -all #echo "hi" #echo "nice to meet you" #""", clean = True) #adb_runner.close() # run