Best Python code snippet using localstack_python
cli.py
Source:cli.py
...15 TranslationKey,16 Modulator,17)18from . import ReasonedVoltalisClient, VoltalisClient19def setup_logging_from_config(config_path):20 if os.path.exists(config_path):21 logging.config.fileConfig(config_path, disable_existing_loggers=False)22 else:23 logging.basicConfig(level=logging.INFO)24 logger = logging.getLogger(__name__)25 return logger26setup_logging_from_config("samples/logging.ini")27def main(username, password):28 cli = VoltalisClient(username, password)29 cli.login()30 for site in cli.sites():31 # en resumé32 cli.lastMinuteConsumption(site.uid)33 cli.immediateConsumptionInkW(site.uid)34 cli.siteMaxPower(site.uid)35 modulator = site.modulators[-1]36 # on/off37 cli.onOffState(site.uid, modulator.uid)38 cli.modulatorState(site.uid, modulator.uid)39 # absence40 cli.absenceModeState(site.uid)...
setup.py
Source:setup.py
...42 log_level = "DEBUG"43 log_level = logging._nameToLevel[log_level]44 return log_level45 return logging.DEBUG if config.DEBUG else logging.INFO46def setup_logging_from_config():47 log_level = get_log_level_from_config()48 setup_logging(log_level)49 if config.is_trace_logging_enabled():50 for name, level in trace_log_levels.items():51 logging.getLogger(name).setLevel(level)52 if config.LS_LOG == "trace-internal":53 for name, level in trace_internal_log_levels.items():54 logging.getLogger(name).setLevel(level)55def create_default_handler(log_level: int):56 log_handler = logging.StreamHandler(stream=sys.stderr)57 log_handler.setLevel(log_level)58 log_handler.setFormatter(DefaultFormatter())59 log_handler.addFilter(AddFormattedAttributes())60 return log_handler...
main.py
Source:main.py
...5import os6import sys7from src.server.app import run_app8from src.definitions import LOGGING_DIR, CONFIG_FILE, DATABASE_DIR9def setup_logging_from_config(conf: dict):10 # set the logging directory here from the settings file11 if not os.path.exists(LOGGING_DIR):12 os.mkdir(LOGGING_DIR)13 _config = {14 "version": 1,15 "disable_existing_loggers": False,16 "formatters": {17 "standard": {18 "format": conf['logging']['format'],19 "datefmt": conf['logging']['datefmt']20 },21 "aiohttp": {22 "format": conf['logging']['aiohttp_format'],23 "datefmt": conf['logging']['datefmt']24 }25 },26 "handlers": {27 "console": {28 "level": "DEBUG",29 "formatter": "standard",30 "class": "logging.StreamHandler",31 "stream": "ext://sys.stdout"32 },33 "debug": {34 "level": "DEBUG",35 "formatter": "standard",36 "class": "logging.handlers.RotatingFileHandler",37 "filename": os.path.join(LOGGING_DIR, 'debug.log'),38 "maxBytes": 10485760,39 "backupCount": 540 },41 "error": {42 "level": "ERROR",43 "formatter": "standard",44 "class": "logging.handlers.RotatingFileHandler",45 "filename": os.path.join(LOGGING_DIR, 'error.log'),46 "maxBytes": 10485760,47 "backupCount": 548 },49 "server": {50 "level": "NOTSET",51 "formatter": "aiohttp",52 "class": "logging.handlers.RotatingFileHandler",53 "filename": os.path.join(LOGGING_DIR, 'server.log'),54 "maxBytes": 10485760,55 "backupCount": 556 }57 },58 "loggers": {59 "": {60 "handlers": ["console", "debug", "error"],61 "level": "DEBUG",62 "propogate": True63 },64 "aiohttp.access": {65 "handlers": ["server"],66 "level": "INFO",67 "propogate": False68 }69 }70 }71 logging.config.dictConfig(_config)72def get_config(filepath):73 with open(filepath, 'r') as cfile:74 config = yaml.load(cfile, Loader=yaml.Loader)75 return config76def setup_db_from_config(config: dict):77 mode = config['mode']78 if config[mode]['database'] == 'sqlite':79 if not os.path.exists(DATABASE_DIR):80 os.mkdir(DATABASE_DIR)81 config[mode]['db_file'] = os.path.join(82 DATABASE_DIR, config[mode]['name']83 )84def main(argv=None):85 argv = argv or sys.argv[1:]86 parser = argparse.ArgumentParser(description='LBRY Comment Server')87 parser.add_argument('--port', type=int)88 parser.add_argument('--config', type=str)89 parser.add_argument('--mode', type=str)90 args = parser.parse_args(argv)91 config = get_config(CONFIG_FILE) if not args.config else args.config92 setup_logging_from_config(config)93 if args.mode:94 config['mode'] = args.mode95 setup_db_from_config(config)96 if args.port:97 config['port'] = args.port98 run_app(config)99if __name__ == '__main__':...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!