Change add_arguments to be a static method
This commit is contained in:
parent
10fe904d88
commit
823e13ddf4
|
@ -137,12 +137,42 @@ class Config(object):
|
||||||
return file_stream.read()
|
return file_stream.read()
|
||||||
|
|
||||||
def invoke_all(self, name, *args, **kargs):
|
def invoke_all(self, name, *args, **kargs):
|
||||||
|
"""Invoke all instance methods with the given name and arguments in the
|
||||||
|
class's MRO.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
name (str): Name of function to invoke
|
||||||
|
*args
|
||||||
|
**kwargs
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
list: The list of the return values from each method called
|
||||||
|
"""
|
||||||
results = []
|
results = []
|
||||||
for cls in type(self).mro():
|
for cls in type(self).mro():
|
||||||
if name in cls.__dict__:
|
if name in cls.__dict__:
|
||||||
results.append(getattr(cls, name)(self, *args, **kargs))
|
results.append(getattr(cls, name)(self, *args, **kargs))
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def invoke_all_static(cls, name, *args, **kargs):
|
||||||
|
"""Invoke all static methods with the given name and arguments in the
|
||||||
|
class's MRO.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
name (str): Name of function to invoke
|
||||||
|
*args
|
||||||
|
**kwargs
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
list: The list of the return values from each method called
|
||||||
|
"""
|
||||||
|
results = []
|
||||||
|
for c in cls.mro():
|
||||||
|
if name in c.__dict__:
|
||||||
|
results.append(getattr(c, name)(*args, **kargs))
|
||||||
|
return results
|
||||||
|
|
||||||
def generate_config(
|
def generate_config(
|
||||||
self,
|
self,
|
||||||
config_dir_path,
|
config_dir_path,
|
||||||
|
@ -241,7 +271,7 @@ class Config(object):
|
||||||
|
|
||||||
# We can only invoke `add_arguments` on an actual object, but
|
# We can only invoke `add_arguments` on an actual object, but
|
||||||
# `add_arguments` should be side effect free so this is probably fine.
|
# `add_arguments` should be side effect free so this is probably fine.
|
||||||
cls().invoke_all("add_arguments", config_parser)
|
cls.invoke_all_static("add_arguments", config_parser)
|
||||||
|
|
||||||
return config_parser
|
return config_parser
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,8 @@ class DatabaseConfig(Config):
|
||||||
if database_path is not None:
|
if database_path is not None:
|
||||||
self.database_config["args"]["database"] = database_path
|
self.database_config["args"]["database"] = database_path
|
||||||
|
|
||||||
def add_arguments(self, parser):
|
@staticmethod
|
||||||
|
def add_arguments(parser):
|
||||||
db_group = parser.add_argument_group("database")
|
db_group = parser.add_argument_group("database")
|
||||||
db_group.add_argument(
|
db_group.add_argument(
|
||||||
"-d",
|
"-d",
|
||||||
|
|
|
@ -103,7 +103,8 @@ class LoggingConfig(Config):
|
||||||
if args.log_file is not None:
|
if args.log_file is not None:
|
||||||
self.log_file = args.log_file
|
self.log_file = args.log_file
|
||||||
|
|
||||||
def add_arguments(cls, parser):
|
@staticmethod
|
||||||
|
def add_arguments(parser):
|
||||||
logging_group = parser.add_argument_group("logging")
|
logging_group = parser.add_argument_group("logging")
|
||||||
logging_group.add_argument(
|
logging_group.add_argument(
|
||||||
"-v",
|
"-v",
|
||||||
|
|
|
@ -222,7 +222,8 @@ class RegistrationConfig(Config):
|
||||||
% locals()
|
% locals()
|
||||||
)
|
)
|
||||||
|
|
||||||
def add_arguments(self, parser):
|
@staticmethod
|
||||||
|
def add_arguments(parser):
|
||||||
reg_group = parser.add_argument_group("registration")
|
reg_group = parser.add_argument_group("registration")
|
||||||
reg_group.add_argument(
|
reg_group.add_argument(
|
||||||
"--enable-registration",
|
"--enable-registration",
|
||||||
|
|
|
@ -639,7 +639,8 @@ class ServerConfig(Config):
|
||||||
if args.print_pidfile is not None:
|
if args.print_pidfile is not None:
|
||||||
self.print_pidfile = args.print_pidfile
|
self.print_pidfile = args.print_pidfile
|
||||||
|
|
||||||
def add_arguments(self, parser):
|
@staticmethod
|
||||||
|
def add_arguments(parser):
|
||||||
server_group = parser.add_argument_group("server")
|
server_group = parser.add_argument_group("server")
|
||||||
server_group.add_argument(
|
server_group.add_argument(
|
||||||
"-D",
|
"-D",
|
||||||
|
|
Loading…
Reference in New Issue