Python logging.config.write() Examples
The following are 16
code examples of logging.config.write().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
logging.config
, or try the search function
.
Example #1
Source File: train.py From yolo2-pytorch with GNU Lesser General Public License v3.0 | 6 votes |
def main(): args = make_args() config = configparser.ConfigParser() utils.load_config(config, args.config) for cmd in args.modify: utils.modify_config(config, cmd) with open(os.path.expanduser(os.path.expandvars(args.logging)), 'r') as f: logging.config.dictConfig(yaml.load(f)) if args.run is None: buffer = io.StringIO() config.write(buffer) args.run = hashlib.md5(buffer.getvalue().encode()).hexdigest() logging.info('cd ' + os.getcwd() + ' && ' + subprocess.list2cmdline([sys.executable] + sys.argv)) train = Train(args, config) train() logging.info(pybenchmark.stats)
Example #2
Source File: modules.py From gpt with GNU General Public License v3.0 | 6 votes |
def show_message(self, message, log="info"): """Show notifications in terminal window and status bar if possible""" try: app.obj("statusbar").push(1, message) time.sleep(.1) while Gtk.events_pending(): Gtk.main_iteration() except (AttributeError, NameError): self.log.debug(_("Could not write message to statusbar")) self.log.debug(_("Message: {}").format(message)) # print(message) if log in self.loglevels.keys(): lvl = self.loglevels[log] else: lvl = 0 self.log.log(lvl, message) # function exclusively called by cli
Example #3
Source File: modules.py From gpt with GNU General Public License v3.0 | 6 votes |
def chkdir(self, path): """Create folder if nonexistent, check for write permission then change into directory""" try: os.makedirs(path) self.show_message(_("Folder created.")) self.workdir(path) return True except OSError as exception: if exception.errno == errno.EEXIST: self.show_message(_("Directory already exists. OK.")) if os.access(path, os.W_OK): self.workdir(path) else: self.show_message(_("Error: no write permission")) self.workdir(self.stdir) return True elif exception.errno == errno.EACCES: self.show_message(_("Permission denied.")) return False else: self.show_message(_("Invalid path")) self.workdir(self.stdir) return True # Verzeichnis wechseln
Example #4
Source File: train.py From openpose-pytorch with GNU Lesser General Public License v3.0 | 6 votes |
def main(): args = make_args() config = configparser.ConfigParser() utils.load_config(config, args.config) for cmd in args.modify: utils.modify_config(config, cmd) with open(os.path.expanduser(os.path.expandvars(args.logging)), 'r') as f: logging.config.dictConfig(yaml.load(f)) if args.run is None: buffer = io.StringIO() config.write(buffer) args.run = hashlib.md5(buffer.getvalue().encode()).hexdigest() logging.info('cd ' + os.getcwd() + ' && ' + subprocess.list2cmdline([sys.executable] + sys.argv)) train = Train(args, config) train() logging.info(pybenchmark.stats)
Example #5
Source File: train.py From yolo2-pytorch with GNU Lesser General Public License v3.0 | 5 votes |
def __init__(self, args, config): self.args = args self.config = config self.model_dir = utils.get_model_dir(config) self.cache_dir = utils.get_cache_dir(config) self.category = utils.get_category(config, self.cache_dir) self.anchors = torch.from_numpy(utils.get_anchors(config)).contiguous() logging.info('use cache directory ' + self.cache_dir) logging.info('tensorboard --logdir ' + self.model_dir) if args.delete: logging.warning('delete model directory: ' + self.model_dir) shutil.rmtree(self.model_dir, ignore_errors=True) os.makedirs(self.model_dir, exist_ok=True) with open(self.model_dir + '.ini', 'w') as f: config.write(f) self.step, self.epoch, self.dnn = self.load() self.inference = model.Inference(self.config, self.dnn, self.anchors) logging.info(humanize.naturalsize(sum(var.cpu().numpy().nbytes for var in self.inference.state_dict().values()))) if self.args.finetune: path = os.path.expanduser(os.path.expandvars(self.args.finetune)) logging.info('finetune from ' + path) self.finetune(self.dnn, path) self.inference = ensure_model(self.inference) self.inference.train() self.optimizer = eval(self.config.get('train', 'optimizer'))(filter(lambda p: p.requires_grad, self.inference.parameters()), self.args.learning_rate) self.saver = utils.train.Saver(self.model_dir, config.getint('save', 'keep')) self.timer_save = utils.train.Timer(config.getfloat('save', 'secs'), False) try: self.timer_eval = utils.train.Timer(eval(config.get('eval', 'secs')), config.getboolean('eval', 'first')) except configparser.NoOptionError: self.timer_eval = lambda: False self.summary_worker = SummaryWorker(self) self.summary_worker.start()
Example #6
Source File: modules.py From gpt with GNU General Public License v3.0 | 5 votes |
def createconfig(self, wdir): """Creates new configuration file and writes current working directory""" self.show_message(_("Creating config file...")) config = open(self.config, "w") config.write("""##### CONFIG FILE FOR GOPRO TOOL ##### ##### EDIT IF YOU LIKE. YOU ARE AN ADULT. #####\n""") config.close() self.write_wdir_config(wdir) self.write_kd_supp_config() self.default_app_view = "ext" self.write_app_view_config(self.default_app_view)
Example #7
Source File: modules.py From gpt with GNU General Public License v3.0 | 5 votes |
def write_wdir_config(self, wdir): """Write value for working directory to configuration file""" config = open(self.config, "a") config.write("\n##### working directory #####\nwdir = \"{}\"\n".format(wdir)) config.close()
Example #8
Source File: modules.py From gpt with GNU General Public License v3.0 | 5 votes |
def write_kd_supp_config(self): """Default Kdenlive support is enabled and written to configuration file""" config = open(self.config, "a") config.write("\n##### Kdenlive support #####\nkdsupp = True\n") config.close()
Example #9
Source File: modules.py From gpt with GNU General Public License v3.0 | 5 votes |
def write_app_view_config(self, appview): """Write value for default application window stack page to configuration file""" config = open(self.config, "a") config.write("\n##### default application view #####\nappview = \"{}\"\n".format(appview)) config.close()
Example #10
Source File: modules.py From gpt with GNU General Public License v3.0 | 5 votes |
def replace_wdir_config(self, wdir): """Writes new working directory in config file when changed""" for line in fileinput.input(self.config, inplace=True): if line.startswith("wdir"): sys.stdout.write("wdir = \"{}\"\n".format(wdir)) else: sys.stdout.write(line)
Example #11
Source File: modules.py From gpt with GNU General Public License v3.0 | 5 votes |
def change_appview_config(self, view): """Changes default application stack page in config file when changed (menu item toggled)""" for line in fileinput.input(self.config, inplace=True): if line.startswith("appview"): sys.stdout.write("appview = \"{}\"".format(view)) else: sys.stdout.write(line)
Example #12
Source File: data.py From Faraday-Software with GNU General Public License v3.0 | 5 votes |
def configureData(args, dataConfigPath): ''' Configure Data configuration file from command line :param args: argparse arguments :param dataConfigPath: Path to data.ini file :return: None ''' config = ConfigParser.RawConfigParser() config.read(os.path.join(path, "data.ini")) if args.flaskhost is not None: config.set('FLASK', 'HOST', args.flaskhost) if args.flaskport is not None: config.set('FLASK', 'PORT', args.flaskport) if args.proxyhost is not None: config.set('PROXY', 'HOST', args.proxyhost) if args.proxyport is not None: config.set('PROXY', 'PORT', args.proxyport) with open(dataConfigPath, 'wb') as configfile: config.write(configfile) # Now act upon the command line arguments # Initialize and configure Data
Example #13
Source File: __init__.py From agent with MIT License | 5 votes |
def try_enroll_in_operation_mode(device_id, dev): enroll_token = get_enroll_token() if enroll_token is None: return logger.info("Enroll token found. Trying to automatically enroll the node.") setup_endpoints(dev) response = mtls_request('get', 'claimed', dev=dev, requester_name="Get Node Claim Info") if response is None or not response.ok: logger.error('Did not manage to get claim info from the server.') return logger.debug("[RECEIVED] Get Node Claim Info: {}".format(response)) claim_info = response.json() if claim_info['claimed']: logger.info('The node is already claimed. No enrolling required.') else: claim_token = claim_info['claim_token'] if not enroll_device(enroll_token, claim_token, device_id): logger.error('Node enrolling failed. Will try next time.') return logger.info("Update config...") config = configparser.ConfigParser() config.read(INI_PATH) config.remove_option('DEFAULT', 'enroll_token') with open(INI_PATH, 'w') as configfile: config.write(configfile) os.chmod(INI_PATH, 0o600)
Example #14
Source File: train.py From openpose-pytorch with GNU Lesser General Public License v3.0 | 5 votes |
def __init__(self, args, config): self.args = args self.config = config self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') self.model_dir = utils.get_model_dir(config) self.cache_dir = utils.get_cache_dir(config) _, self.num_parts = utils.get_dataset_mappers(config) self.limbs_index = utils.get_limbs_index(config) logging.info('use cache directory ' + self.cache_dir) logging.info('tensorboard --logdir ' + self.model_dir) if args.delete: logging.warning('delete model directory: ' + self.model_dir) shutil.rmtree(self.model_dir, ignore_errors=True) os.makedirs(self.model_dir, exist_ok=True) with open(self.model_dir + '.ini', 'w') as f: config.write(f) self.step, self.epoch, self.dnn, self.stages = self.load() self.inference = model.Inference(self.config, self.dnn, self.stages) logging.info(humanize.naturalsize(sum(var.cpu().numpy().nbytes for var in self.inference.state_dict().values()))) if self.args.finetune: path = os.path.expanduser(os.path.expandvars(self.args.finetune)) logging.info('finetune from ' + path) self.finetune(self.dnn, path) self.inference = self.inference.to(self.device) self.inference.train() self.optimizer = eval(self.config.get('train', 'optimizer'))(filter(lambda p: p.requires_grad, self.inference.parameters()), self.args.learning_rate) self.saver = utils.train.Saver(self.model_dir, config.getint('save', 'keep')) self.timer_save = utils.train.Timer(config.getfloat('save', 'secs'), False) try: self.timer_eval = utils.train.Timer(eval(config.get('eval', 'secs')), config.getboolean('eval', 'first')) except configparser.NoOptionError: self.timer_eval = lambda: False self.summary_worker = SummaryWorker(self) self.summary_worker.start()
Example #15
Source File: modules.py From gpt with GNU General Public License v3.0 | 4 votes |
def readconfig(self): """Reads working directory and Kdenlive support status (line begins with "wdir = ...") from configuration file and tries to apply given value. If this attempt fails (due to permission problems) or there is no matching line the default value (~/GP) will be set.""" match_wdir = False match_kd = False match_view = False config = open(self.config, "r") for line in config: if line.startswith("wdir"): match_wdir = True self.stdir = line.split("\"")[1] if not self.chkdir(self.stdir): self.stdir = self.defaultwdir self.replace_wdir_config(self.stdir) continue if line.startswith("kdsupp"): if line.split("=")[1].strip() == "True": self.kd_supp = True match_kd = True elif line.split("=")[1].strip() == "False": self.kd_supp = False match_kd = True else: self.change_kd_support_config(True) self.kd_supp = True match_kd = True continue if line.startswith("appview"): if line.split("=")[1].strip() == "compact": self.default_app_view = "compact" match_view = True else: self.default_app_view = "ext" match_view = True continue config.close() # add wdir line when not found if not match_wdir: self.show_message(_("No configuration for working directory in config file. Set default value (~/GP)...")) self.stdir = self.defaultwdir self.chkdir(self.stdir) # write default wdir to config file self.write_wdir_config(self.stdir) if not match_kd: self.show_message(_("Kdenlive support is enabled.")) self.kd_supp = True self.write_kd_supp_config() if not match_view: self.show_message(_("Default application view is set to extended.")) self.default_app_view = "ext" self.write_app_view_config(self.default_app_view)
Example #16
Source File: simpleui.py From Faraday-Software with GNU General Public License v3.0 | 4 votes |
def configureSimpleUI(args): ''' Configure SimpleUI configuration file from command line :param args: argparse arguments :return: None ''' config = ConfigParser.RawConfigParser() config.read(os.path.join(faradayHelper.path, configFile)) if args.callsign is not None: config.set('SIMPLEUI', 'CALLSIGN', args.callsign) if args.nodeid is not None: config.set('SIMPLEUI', 'NODEID', args.nodeid) if args.cmdlocalcallsign is not None: config.set('SIMPLEUI', 'LOCALCALLSIGN', args.cmdlocalcallsign) if args.cmdlocalnodeid is not None: config.set('SIMPLEUI', 'LOCALNODEID', args.cmdlocalnodeid) if args.cmdremotecallsign is not None: config.set('SIMPLEUI', 'REMOTECALLSIGN', args.cmdremotecallsign) if args.cmdremotenodeid is not None: config.set('SIMPLEUI', 'REMOTENODEID', args.cmdremotenodeid) if args.flaskhost is not None: config.set('FLASK', 'HOST', args.flaskhost) if args.flaskport is not None: config.set('FLASK', 'PORT', args.flaskport) if args.proxyhost is not None: config.set('PROXY', 'HOST', args.proxyhost) if args.proxyport is not None: config.set('PROXY', 'PORT', args.proxyport) if args.telemetryhost is not None: config.set('TELEMETRY', 'HOST', args.telemetryhost) if args.telemetryport is not None: config.set('TELEMETRY', 'PORT', args.telemetryport) filename = os.path.join(faradayHelper.path, configFile) with open(filename, 'wb') as configfile: config.write(configfile) # Now act upon the command line arguments # Initialize and configure SimpleUI