corrlib/corrlib/initialization.py

53 lines
1.5 KiB
Python

import sqlite3
import datalad.api as dl
import os
def _create_db(db):
"""
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,
current_version 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()
def create(path):
"""
Create folder of backlogs.
"""
dl.create(path)
_create_db(path + '/backlogger.db')
os.chmod(path + '/backlogger.db', 0o666) # why does this not work?
os.makedirs(path + '/projects')
os.makedirs(path + '/archive')
os.makedirs(path + '/toml_imports')
os.makedirs(path + '/import_scripts/template.py')
with open(path + "/.gitignore", "w") as fp:
fp.write(".cache")
fp.close()
dl.save(path, dataset=path, message="Initialize backlogger directory.")