config load/save

This commit is contained in:
2014-11-04 17:56:34 +01:00
parent ed3fce33d4
commit fdeaefed10

View File

@@ -39,14 +39,18 @@ class bam_config:
CONFIG_DIR = ".bam" CONFIG_DIR = ".bam"
@staticmethod @staticmethod
def find_basedir(): def find_basedir(cwd=None):
""" """
Return the config path (or None when not found) Return the config path (or None when not found)
""" """
import os import os
if cwd is None:
cwd = os.getcwd()
parent = (os.path.normpath( parent = (os.path.normpath(
os.path.abspath( os.path.abspath(
os.getcwd()))) cwd)))
parent_prev = None parent_prev = None
@@ -61,14 +65,27 @@ class bam_config:
return None return None
@staticmethod @staticmethod
def load(id_): def load(id_, cwd=None):
# bam_config.find_basedir() basedir = bam_config.find_basedir(cwd=cwd)
# data = filepath = os.path.join(basedir, id_)
pass
with open(filepath, 'r') as f:
import json
return json.load(f)
@staticmethod @staticmethod
def write(id_, data): def write(id_, data, cwd=None):
pass bam_config.find_basedir(cwd=cwd)
filepath = os.path.join(basedir, id_)
with open(filepath) as f:
import json
json.dump(
data, f, ensure_ascii=False,
check_circular=False,
# optional (pretty)
sort_keys=True, indent=4, separators=(',', ': '),
)
class bam_utils: class bam_utils: