File size: 1,482 Bytes
bf5c0e0
 
 
 
583741e
bf5c0e0
 
 
 
 
 
583741e
 
 
bf5c0e0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import os
from mmengine import Config as MMConfig
from argparse import Namespace

from src.utils import assemble_project_path, Singleton

def process_general(config: MMConfig) -> MMConfig:

    config.exp_path = assemble_project_path(os.path.join(config.workdir, config.tag))
    os.makedirs(config.exp_path, exist_ok=True)

    config.log_path = os.path.join(config.exp_path, getattr(config, 'log_path', 'paper_agent.log'))
    config.db_path = os.path.join(config.exp_path, getattr(config, 'db_path', 'papers_cache.db'))
    config.frontend_path = assemble_project_path(getattr(config, 'frontend_path', 'frontend'))

    return config

class Config(MMConfig, metaclass=Singleton):
    def __init__(self):
        super(Config, self).__init__()

    def init_config(self, config_path: str, args: Namespace) -> None:
        # Initialize the general configuration
        mmconfig = MMConfig.fromfile(filename=assemble_project_path(config_path))
        if 'cfg_options' not in args or args.cfg_options is None:
            cfg_options = dict()
        else:
            cfg_options = args.cfg_options
        for item in args.__dict__:
            if item not in ['config', 'cfg_options'] and args.__dict__[item] is not None:
                cfg_options[item] = args.__dict__[item]
        mmconfig.merge_from_dict(cfg_options)

        # Process general configuration
        mmconfig = process_general(mmconfig)

        self.__dict__.update(mmconfig.__dict__)

config = Config()