def load(self): """Load configuration data from our various sources""" if self.loaded is True: dbg('ConfigBase::load: config already loaded') return if self.command_line_options: if not self.command_line_options.config: self.command_line_options.config = os.path.join( get_config_dir(), 'config') #filename = self.command_line_options.config filename = os.path.join(os.getcwd(), 'config') print "config path string" + filename else: filename = os.path.join(get_config_dir(), 'config') dbg('looking for config file: %s' % filename) try: configfile = open(filename, 'r') except Exception, ex: if not self.whined: err('ConfigBase::load: Unable to open %s (%s)' % (filename, ex)) self.whined = True return
def save(self): """Save the config to a file""" dbg('ConfigBase::save: saving config') parser = ConfigObj() parser.indent_type = ' ' for section_name in ['global_config', 'keybindings']: dbg('ConfigBase::save: Processing section: %s' % section_name) section = getattr(self, section_name) parser[section_name] = dict_diff(DEFAULTS[section_name], section) parser['profiles'] = {} for profile in self.profiles: dbg('ConfigBase::save: Processing profile: %s' % profile) parser['profiles'][profile] = dict_diff( DEFAULTS['profiles']['default'], self.profiles[profile]) parser['layouts'] = {} for layout in self.layouts: dbg('ConfigBase::save: Processing layout: %s' % layout) parser['layouts'][layout] = self.layouts[layout] parser['plugins'] = {} for plugin in self.plugins: dbg('ConfigBase::save: Processing plugin: %s' % plugin) parser['plugins'][plugin] = self.plugins[plugin] config_dir = get_config_dir() if not os.path.isdir(config_dir): os.makedirs(config_dir) try: parser.write(open(os.path.join(config_dir, 'config'), 'w')) except Exception, ex: err('ConfigBase::save: Unable to save config: %s' % ex)
def save(self): """Save the config to a file""" dbg('ConfigBase::save: saving config') parser = ConfigObj() parser.indent_type = ' ' for section_name in ['global_config', 'keybindings']: dbg('ConfigBase::save: Processing section: %s' % section_name) section = getattr(self, section_name) parser[section_name] = dict_diff(DEFAULTS[section_name], section) parser['profiles'] = {} for profile in self.profiles: dbg('ConfigBase::save: Processing profile: %s' % profile) parser['profiles'][profile] = dict_diff( DEFAULTS['profiles']['default'], self.profiles[profile]) parser['layouts'] = {} for layout in self.layouts: dbg('ConfigBase::save: Processing layout: %s' % layout) parser['layouts'][layout] = self.layouts[layout] parser['plugins'] = {} for plugin in self.plugins: dbg('ConfigBase::save: Processing plugin: %s' % plugin) parser['plugins'][plugin] = self.plugins[plugin] config_dir = get_config_dir() if not os.path.isdir(config_dir): os.makedirs(config_dir) try: parser.write(open(self.command_line_options.config, 'w')) except Exception, ex: err('ConfigBase::save: Unable to save config: %s' % ex)
def save(self): """Save the config to a file""" dbg("ConfigBase::save: saving config") parser = ConfigObj() parser.indent_type = " " for section_name in ["global_config", "keybindings"]: dbg("ConfigBase::save: Processing section: %s" % section_name) section = getattr(self, section_name) parser[section_name] = dict_diff(DEFAULTS[section_name], section) parser["profiles"] = {} for profile in self.profiles: dbg("ConfigBase::save: Processing profile: %s" % profile) parser["profiles"][profile] = dict_diff(DEFAULTS["profiles"]["default"], self.profiles[profile]) parser["layouts"] = {} for layout in self.layouts: dbg("ConfigBase::save: Processing layout: %s" % layout) parser["layouts"][layout] = self.layouts[layout] parser["plugins"] = {} for plugin in self.plugins: dbg("ConfigBase::save: Processing plugin: %s" % plugin) parser["plugins"][plugin] = self.plugins[plugin] config_dir = get_config_dir() if not os.path.isdir(config_dir): os.makedirs(config_dir) try: parser.write(open(self.command_line_options.config, "w")) except Exception, ex: err("ConfigBase::save: Unable to save config: %s" % ex)
def load(self): """Load configuration data from our various sources""" if self.loaded is True: dbg('ConfigBase::load: config already loaded') return if self.command_line_options: if not self.command_line_options.config: self.command_line_options.config = os.path.join(get_config_dir(), 'config') filename = self.command_line_options.config else: filename = os.path.join(get_config_dir(), 'config') dbg('looking for config file: %s' % filename) try: configfile = open(filename, 'r') except Exception, ex: if not self.whined: err('ConfigBase::load: Unable to open %s (%s)' % (filename, ex)) self.whined = True return
def prepare_attributes(self): """Prepare our attributes""" if not self.instances: self.instances = {} if not self.path: self.path = [] (head, _tail) = os.path.split(borg.__file__) self.path.append(os.path.join(head, "plugins")) self.path.append(os.path.join(get_config_dir(), "plugins")) dbg("PluginRegistry::prepare_attributes: Plugin path: %s" % self.path) if not self.done: self.done = False if not self.available_plugins: self.available_plugins = {}
def load(self): """Load configuration data from our various sources""" if self.loaded is True: dbg("ConfigBase::load: config already loaded") return filename = os.path.join(get_config_dir(), "config") dbg("looking for config file: %s" % filename) try: configfile = open(filename, "r") except Exception, ex: if not self.whined: err("ConfigBase::load: Unable to open %s (%s)" % (filename, ex)) self.whined = True return
def prepare_attributes(self): """Prepare our attributes""" if not self.instances: self.instances = {} if not self.path: self.path = [] (head, _tail) = os.path.split(borg.__file__) self.path.append(os.path.join(head, 'plugins')) self.path.append(os.path.join(get_config_dir(), 'plugins')) dbg('PluginRegistry::prepare_attributes: Plugin path: %s' % self.path) if not self.done: self.done = False if not self.available_plugins: self.available_plugins = {}
def load(self): """Load configuration data from our various sources""" if self.loaded is True: dbg('ConfigBase::load: config already loaded') return filename = os.path.join(get_config_dir(), 'config') dbg('looking for config file: %s' % filename) try: configfile = open(filename, 'r') except Exception, ex: if not self.whined: err('ConfigBase::load: Unable to open %s (%s)' % (filename, ex)) self.whined = True return
def save(self, force=False): """Save the config to a file""" if self._nosave: dbg('~ConfigBase::save: WRITE SUPRESSED') return (True) elif force: dbg('~ConfigBase::save: WRITE FORCED') pass elif not self._dirty: dbg('~ConfigBase::save: CONFIG CLEAN') return (True) dbg('~ConfigBase::save: WRITE CONFIG') self._dirty = False # FIXME this craziness must be purged asap. parser = ConfigObj() parser.indent_type = ' ' for section_name in ['global_config', 'keybindings']: dbg('ConfigBase::save: Processing section: %s' % section_name) section = getattr(self, section_name) parser[section_name] = dict_diff(DEFAULTS[section_name], section) parser['profiles'] = {} for profile in self.profiles: dbg('ConfigBase::save: Processing profile: %s' % profile) parser['profiles'][profile] = dict_diff( DEFAULTS['profiles']['default'], self.profiles[profile]) parser['layouts'] = {} for layout in self.layouts: dbg('ConfigBase::save: Processing layout: %s' % layout) parser['layouts'][layout] = self.cleancfg(self.layouts[layout]) parser['plugins'] = {} for plugin in self.plugins: dbg('ConfigBase::save: Processing plugin: %s' % plugin) parser['plugins'][plugin] = self.plugins[plugin] config_dir = get_config_dir() if not os.path.isdir(config_dir): os.makedirs(config_dir) try: parser.write(open(self.command_line_options.config, 'w')) except Exception, ex: err('ConfigBase::save: Unable to save config: %s' % ex)
KEY_LOCATION = "cert/server.key" DATA_PREFIX = "data/img/" API_TOKEN_FILE = "data/.api_token" # ZERO_CONF ZERO_CONF_DESCRIPTION = "Receipt parser server._receipt-service._tcp.local." ZERO_CONF_SERVICE = "_receipt-service._tcp.local." PRINT_DEBUG_OUTPUT = False API_KEY_NAME = "access_token" api_key_query = APIKeyQuery(name=API_KEY_NAME, auto_error=False) api_key_header = APIKeyHeader(name=API_KEY_NAME, auto_error=False) api_key_cookie = APIKeyCookie(name=API_KEY_NAME, auto_error=False) config = read_config(util.get_config_dir() + "/config.yml") if os.path.isfile(API_TOKEN_FILE): with open(API_TOKEN_FILE) as f: line = f.readline().strip() if not line: raise RuntimeError("can't find valid API token") else: API_KEY = line else: raise RuntimeError("API token does not exist.") class Receipt(BaseModel): company: str date: str