77 lines
2.3 KiB
Python
77 lines
2.3 KiB
Python
from configparser import ConfigParser
|
|
import sqlite3
|
|
import os
|
|
from .tracker import save, init
|
|
|
|
|
|
def _create_db(db: str) -> None:
|
|
"""
|
|
Create the database file and the table.
|
|
|
|
"""
|
|
conn = sqlite3.connect(db)
|
|
c = conn.cursor()
|
|
c.execute('''CREATE TABLE IF NOT EXISTS backlogs
|
|
(id INTEGER PRIMARY KEY,
|
|
name TEXT,
|
|
ensemble TEXT,
|
|
code TEXT,
|
|
path TEXT,
|
|
project TEXT,
|
|
customTags TEXT,
|
|
parameters TEXT,
|
|
parameter_file TEXT,
|
|
created_at TEXT,
|
|
updated_at TEXT)''')
|
|
c.execute('''CREATE TABLE IF NOT EXISTS projects
|
|
(id TEXT PRIMARY KEY,
|
|
aliases TEXT,
|
|
customTags TEXT,
|
|
owner TEXT,
|
|
code TEXT,
|
|
created_at TEXT,
|
|
updated_at TEXT)''')
|
|
conn.commit()
|
|
conn.close()
|
|
return
|
|
|
|
|
|
def _create_config(path: str) -> None:
|
|
"""
|
|
Create the config file for backlogger.
|
|
|
|
"""
|
|
config = ConfigParser()
|
|
config['core'] = {
|
|
'version': '1.0',
|
|
'db_path': os.path.join(path, 'backlogger.db'),
|
|
'projects_path': os.path.join(path, 'projects'),
|
|
'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',
|
|
}
|
|
with open(os.path.join(path, '.corrlib'), 'w') as configfile:
|
|
config.write(configfile)
|
|
return
|
|
|
|
|
|
def create(path: str, tracker: str = 'datalad') -> None:
|
|
"""
|
|
Create folder of backlogs.
|
|
|
|
"""
|
|
init(path, tracker)
|
|
_create_db(os.path.join(path, 'backlogger.db'))
|
|
os.chmod(os.path.join(path, 'backlogger.db'), 0o666)
|
|
_create_config(path)
|
|
os.makedirs(os.path.join(path, 'projects'))
|
|
os.makedirs(os.path.join(path, 'archive'))
|
|
os.makedirs(os.path.join(path, 'toml_imports'))
|
|
os.makedirs(os.path.join(path, 'import_scripts/template.py'))
|
|
with open(os.path.join(path, ".gitignore"), "w") as fp:
|
|
fp.write(".cache")
|
|
fp.close()
|
|
save(path, message="Initialized correlator library")
|
|
return
|