use config in initialization
This commit is contained in:
parent
f83eab785c
commit
4b55227642
1 changed files with 26 additions and 16 deletions
|
|
@ -36,7 +36,7 @@ def _create_db(db: str) -> None:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def _create_config(path: str) -> None:
|
def _create_config(path: str, tracker: str, cached: bool) -> ConfigParser:
|
||||||
"""
|
"""
|
||||||
Create the config file for backlogger.
|
Create the config file for backlogger.
|
||||||
|
|
||||||
|
|
@ -44,32 +44,42 @@ def _create_config(path: str) -> None:
|
||||||
config = ConfigParser()
|
config = ConfigParser()
|
||||||
config['core'] = {
|
config['core'] = {
|
||||||
'version': '1.0',
|
'version': '1.0',
|
||||||
'db_path': os.path.join(path, 'backlogger.db'),
|
'tracker': tracker,
|
||||||
'projects_path': os.path.join(path, 'projects'),
|
'cached': str(cached),
|
||||||
'archive_path': os.path.join(path, 'archive'),
|
|
||||||
'toml_imports_path': os.path.join(path, 'toml_imports'),
|
|
||||||
'import_scripts_path': os.path.join(path, 'import_scripts'),
|
|
||||||
'tracker': 'datalad',
|
|
||||||
'cached': 'True',
|
|
||||||
}
|
}
|
||||||
|
config['paths'] = {
|
||||||
|
'db': 'backlogger.db',
|
||||||
|
'projects_path': 'projects',
|
||||||
|
'archive_path': 'archive',
|
||||||
|
'toml_imports_path': 'toml_imports',
|
||||||
|
'import_scripts_path': 'import_scripts',
|
||||||
|
}
|
||||||
|
return config
|
||||||
|
|
||||||
|
|
||||||
|
def _write_config(path: str, config: ConfigParser) -> None:
|
||||||
|
"""
|
||||||
|
Write the config file to disk.
|
||||||
|
"""
|
||||||
with open(os.path.join(path, '.corrlib'), 'w') as configfile:
|
with open(os.path.join(path, '.corrlib'), 'w') as configfile:
|
||||||
config.write(configfile)
|
config.write(configfile)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def create(path: str, tracker: str = 'datalad') -> None:
|
def create(path: str, tracker: str = 'datalad', cached: bool = True) -> None:
|
||||||
"""
|
"""
|
||||||
Create folder of backlogs.
|
Create folder of backlogs.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
config = _create_config(path, tracker, cached)
|
||||||
init(path, tracker)
|
init(path, tracker)
|
||||||
_create_db(os.path.join(path, 'backlogger.db'))
|
_write_config(path, config)
|
||||||
os.chmod(os.path.join(path, 'backlogger.db'), 0o666)
|
_create_db(os.path.join(path, config['paths']['db']))
|
||||||
_create_config(path)
|
os.chmod(os.path.join(path, config['paths']['db']), 0o666)
|
||||||
os.makedirs(os.path.join(path, 'projects'))
|
os.makedirs(os.path.join(path, config['paths']['projects_path']))
|
||||||
os.makedirs(os.path.join(path, 'archive'))
|
os.makedirs(os.path.join(path, config['paths']['archive_path']))
|
||||||
os.makedirs(os.path.join(path, 'toml_imports'))
|
os.makedirs(os.path.join(path, config['paths']['toml_imports_path']))
|
||||||
os.makedirs(os.path.join(path, 'import_scripts/template.py'))
|
os.makedirs(os.path.join(path, config['paths']['import_scripts_path'], 'template.py'))
|
||||||
with open(os.path.join(path, ".gitignore"), "w") as fp:
|
with open(os.path.join(path, ".gitignore"), "w") as fp:
|
||||||
fp.write(".cache")
|
fp.write(".cache")
|
||||||
fp.close()
|
fp.close()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue