예제 #1
0
 def _lazy_load_object(config_type, key, namespace, attr):
     try:
         obj = getattr(namespace.config, config_type)[key]
     except KeyError:
         raise arghparse.ArgumentError(
             "Failed loading object %s of type %s" % (config_type, key))
         raise argparse.ArgumentError(
             self, "couldn't find %s %r" % (self.config_type, name))
     setattr(namespace, attr, obj)
예제 #2
0
 def _get_sections(self, config, namespace):
     domain = None
     if self.domain:
         domain = getattr(namespace, self.domain, None)
         if domain is None and self.domain_forced:
             raise arghparse.ArgumentError(
                 "No domain found, but one was forced for %s; "
                 "internal bug.  NS=%s" % (self, namespace))
     if domain is None:
         return StoreConfigObject._get_sections(self, config, namespace)
     return domain.repos_raw if self.raw else domain.repos_configured_filtered
예제 #3
0
 def store_default(config_type, namespace, attr, option_string=None):
     config = getattr(namespace, 'config', None)
     if config is None:
         raise arghparse.ArgumentError(
             "no config found.  Internal bug, or broken on disk configuration."
         )
     obj = config.get_default(config_type)
     if obj is None:
         known_objs = sorted(getattr(config, config_type).keys())
         msg = "config error: no default object of type %r found.  " % (
             config_type, )
         if not option_string:
             msg += "Please fix your configuration."
         else:
             msg += "Please either fix your configuration, or set the %s " \
                 "via the %s option." % (config_type, option_string)
         if known_objs:
             msg += "Known %ss: %s" % (config_type, ', '.join(
                 map(repr, known_objs)))
         raise NoDefaultConfigError(msg)
     setattr(namespace, attr, obj)