def json(self): try: with open(self.path) as rf: return json.load(rf) except FileNotFoundError: data = [] with safe_open(self.path, "w") as wf: json.dump(data, wf) return data
def load_config(config, path=None, strict=False): path = path or config.config_path if not os.path.exists(path): logger.info("%s is not found. create as default configuration") if strict: raise ConfigNotFound(path) else: msg = """\ configuration file({}) is not found. plese run 'cctm init' or 'cctm init --project=.' """.format(path) sys.stderr.write(msg) sys.exit(-1) with open(path) as rf: config.settings = config.control.settings = settings = json.load(rf) # xxx return settings
def load(self): try: with safe_open(self.path, "r") as rf: return json.load(rf) except FileNotFoundError: return []