Fix resource access
This commit is contained in:
parent
2c2e87209c
commit
383bc7a0eb
@ -15,7 +15,8 @@ def command_init(args):
|
||||
import fcntl
|
||||
import json
|
||||
import os
|
||||
import pkg_resources
|
||||
|
||||
import resources
|
||||
|
||||
cfd = args.config_dir
|
||||
# Create the directory if it doesn't exist.
|
||||
@ -27,7 +28,7 @@ def command_init(args):
|
||||
return -1
|
||||
|
||||
# Update or create global config.
|
||||
def_cfg = pkg_resources.resource_stream(__name__, "resources/default_config.json")
|
||||
def_cfg = resources.get_stream("global.json")
|
||||
if args.update and os.path.isfile(os.path.join(cfd, "config.json")):
|
||||
with open(os.path.join(cfd, "config.json"), 'r+', encoding='utf8') as cfg_file:
|
||||
fcntl.lockf(cfg_file, fcntl.LOCK_EX)
|
||||
|
@ -3,11 +3,11 @@ import copy
|
||||
import json
|
||||
import logging.config
|
||||
import os
|
||||
import pkg_resources
|
||||
|
||||
# Module imports
|
||||
from errors import MissingConfigError, MalformedConfigError
|
||||
from config.loader import json_ro
|
||||
import resources
|
||||
|
||||
|
||||
def verify_config_dir(config_dir):
|
||||
@ -23,7 +23,7 @@ def verify_config_dir(config_dir):
|
||||
if not os.path.isfile(global_config_path):
|
||||
raise MissingConfigError("Config directory missing global config file: {}".format(config_dir))
|
||||
# Check that global config file has all the default settings
|
||||
def_cfg_s = pkg_resources.resource_stream("__main__", "resources/default_config.json")
|
||||
def_cfg_s = resources.get_stream("global.json")
|
||||
def_cfg = json.load(def_cfg_s)
|
||||
with json_ro(global_config_path) as global_config_file:
|
||||
for key in def_cfg.keys():
|
||||
|
5
amanuensis/resources/__init__.py
Normal file
5
amanuensis/resources/__init__.py
Normal file
@ -0,0 +1,5 @@
|
||||
import pkg_resources
|
||||
|
||||
def get_stream(*path):
|
||||
rs_path = "/".join(path)
|
||||
return pkg_resources.resource_stream(__name__, rs_path)
|
Loading…
Reference in New Issue
Block a user