<s> import os <EOL> import ujson <EOL> from catsup . logger import logger <EOL> from catsup . options import g <EOL> from catsup . utils import update_nested_dict , urljoin , ObjectDict <EOL> from catsup . parser . themes import find_theme <EOL> from . utils import add_slash <EOL> def parse ( path ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> f = open ( path , '<STR_LIT:r>' ) <EOL> except IOError : <EOL> logger . error ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> exit ( <NUM_LIT:1> ) <EOL> return update_nested_dict ( ObjectDict ( ) , ujson . load ( f ) ) <EOL> def load ( path = None , local = False , base_url = None ) : <EOL> default_config = os . path . join ( g . public_templates_path , '<STR_LIT>' ) <EOL> config = parse ( default_config ) <EOL> if path : <EOL> user_config = parse ( path ) <EOL> config = update_nested_dict ( config , user_config ) <EOL> os . chdir ( os . path . abspath ( os . path . dirname ( path ) ) ) <EOL> g . theme = find_theme ( config ) <EOL> g . source = config . config . source <EOL> g . output = config . config . output <EOL> g . permalink = config . permalink <EOL> if base_url : <EOL> g . base_url = add_slash ( base_url ) <EOL> else : <EOL> g . base_url = add_slash ( config . site . url ) <EOL> config . site . url = g . base_url <EOL> if local : <EOL> import tempfile <EOL> config . config . static_prefix = "<STR_LIT>" <EOL> config . config . output = tempfile . mkdtemp ( ) <EOL> g . static_prefix = urljoin ( <EOL> g . base_url , <EOL> add_slash ( config . config . static_prefix ) <EOL> ) <EOL> g . theme . vars = update_nested_dict ( g . theme . vars , config . theme . vars ) <EOL> config . theme . vars = g . theme . vars <EOL> config . path = path <EOL> return config </s>
