当前位置: 首页>>代码示例>>Python>>正文


Python config.write方法代码示例

本文整理汇总了Python中logging.config.write方法的典型用法代码示例。如果您正苦于以下问题:Python config.write方法的具体用法?Python config.write怎么用?Python config.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在logging.config的用法示例。


在下文中一共展示了config.write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from logging import config [as 别名]
# 或者: from logging.config import write [as 别名]
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) 
开发者ID:ruiminshen,项目名称:yolo2-pytorch,代码行数:18,代码来源:train.py

示例2: show_message

# 需要导入模块: from logging import config [as 别名]
# 或者: from logging.config import write [as 别名]
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 
开发者ID:encarsia,项目名称:gpt,代码行数:20,代码来源:modules.py

示例3: chkdir

# 需要导入模块: from logging import config [as 别名]
# 或者: from logging.config import write [as 别名]
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 
开发者ID:encarsia,项目名称:gpt,代码行数:27,代码来源:modules.py

示例4: __init__

# 需要导入模块: from logging import config [as 别名]
# 或者: from logging.config import write [as 别名]
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() 
开发者ID:ruiminshen,项目名称:yolo2-pytorch,代码行数:37,代码来源:train.py

示例5: createconfig

# 需要导入模块: from logging import config [as 别名]
# 或者: from logging.config import write [as 别名]
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) 
开发者ID:encarsia,项目名称:gpt,代码行数:14,代码来源:modules.py

示例6: write_wdir_config

# 需要导入模块: from logging import config [as 别名]
# 或者: from logging.config import write [as 别名]
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() 
开发者ID:encarsia,项目名称:gpt,代码行数:7,代码来源:modules.py

示例7: write_kd_supp_config

# 需要导入模块: from logging import config [as 别名]
# 或者: from logging.config import write [as 别名]
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() 
开发者ID:encarsia,项目名称:gpt,代码行数:7,代码来源:modules.py

示例8: write_app_view_config

# 需要导入模块: from logging import config [as 别名]
# 或者: from logging.config import write [as 别名]
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() 
开发者ID:encarsia,项目名称:gpt,代码行数:7,代码来源:modules.py

示例9: replace_wdir_config

# 需要导入模块: from logging import config [as 别名]
# 或者: from logging.config import write [as 别名]
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) 
开发者ID:encarsia,项目名称:gpt,代码行数:9,代码来源:modules.py

示例10: change_appview_config

# 需要导入模块: from logging import config [as 别名]
# 或者: from logging.config import write [as 别名]
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) 
开发者ID:encarsia,项目名称:gpt,代码行数:10,代码来源:modules.py

示例11: configureData

# 需要导入模块: from logging import config [as 别名]
# 或者: from logging.config import write [as 别名]
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 
开发者ID:FaradayRF,项目名称:Faraday-Software,代码行数:29,代码来源:data.py

示例12: try_enroll_in_operation_mode

# 需要导入模块: from logging import config [as 别名]
# 或者: from logging.config import write [as 别名]
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) 
开发者ID:WoTTsecurity,项目名称:agent,代码行数:30,代码来源:__init__.py

示例13: __init__

# 需要导入模块: from logging import config [as 别名]
# 或者: from logging.config import write [as 别名]
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() 
开发者ID:ruiminshen,项目名称:openpose-pytorch,代码行数:38,代码来源:train.py

示例14: readconfig

# 需要导入模块: from logging import config [as 别名]
# 或者: from logging.config import write [as 别名]
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) 
开发者ID:encarsia,项目名称:gpt,代码行数:57,代码来源:modules.py

示例15: configureSimpleUI

# 需要导入模块: from logging import config [as 别名]
# 或者: from logging.config import write [as 别名]
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 
开发者ID:FaradayRF,项目名称:Faraday-Software,代码行数:45,代码来源:simpleui.py


注:本文中的logging.config.write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。