removed rtype and param typing from doc strings to help avoid maintaining duplicate information provided by type hints
This commit is contained in:
parent
9d89877b20
commit
f4ddf310a8
32 changed files with 1091 additions and 1357 deletions
|
@ -49,9 +49,9 @@ def execute_file(
|
|||
Provides an alternative way to run execfile to be compatible for
|
||||
both python2/3.
|
||||
|
||||
:param str path: path of file to execute
|
||||
:param dict exec_globals: globals values to pass to execution
|
||||
:param dict exec_locals: local values to pass to execution
|
||||
:param path: path of file to execute
|
||||
:param exec_globals: globals values to pass to execution
|
||||
:param exec_locals: local values to pass to execution
|
||||
:return: nothing
|
||||
"""
|
||||
if exec_globals is None:
|
||||
|
@ -68,9 +68,8 @@ def hashkey(value: Union[str, int]) -> int:
|
|||
of the builtin hash, that no longer behaves consistently
|
||||
in python3.
|
||||
|
||||
:param str/int value: value to hash
|
||||
:param value: value to hash
|
||||
:return: hash value
|
||||
:rtype: int
|
||||
"""
|
||||
if isinstance(value, int):
|
||||
value = str(value)
|
||||
|
@ -94,10 +93,9 @@ def _valid_module(path: str, file_name: str) -> bool:
|
|||
"""
|
||||
Check if file is a valid python module.
|
||||
|
||||
:param str path: path to file
|
||||
:param str file_name: file name to check
|
||||
:param path: path to file
|
||||
:param file_name: file name to check
|
||||
:return: True if a valid python module file, False otherwise
|
||||
:rtype: bool
|
||||
"""
|
||||
file_path = os.path.join(path, file_name)
|
||||
if not os.path.isfile(file_path):
|
||||
|
@ -120,7 +118,6 @@ def _is_class(module: Any, member: Type, clazz: Type) -> bool:
|
|||
:param member: member to validate for service
|
||||
:param clazz: clazz type to check for validation
|
||||
:return: True if a valid service, False otherwise
|
||||
:rtype: bool
|
||||
"""
|
||||
if not inspect.isclass(member):
|
||||
return False
|
||||
|
@ -149,8 +146,8 @@ def which(command: str, required: bool) -> str:
|
|||
"""
|
||||
Find location of desired executable within current PATH.
|
||||
|
||||
:param str command: command to find location for
|
||||
:param bool required: command is required to be found, false otherwise
|
||||
:param command: command to find location for
|
||||
:param required: command is required to be found, false otherwise
|
||||
:return: command location or None
|
||||
:raises ValueError: when not found and required
|
||||
"""
|
||||
|
@ -173,7 +170,6 @@ def make_tuple(obj: Generic[T]) -> Tuple[T]:
|
|||
|
||||
:param obj: object to convert to a tuple
|
||||
:return: converted tuple or the object itself
|
||||
:rtype: tuple
|
||||
"""
|
||||
if hasattr(obj, "__iter__"):
|
||||
return tuple(obj)
|
||||
|
@ -185,10 +181,9 @@ def make_tuple_fromstr(s: str, value_type: Callable[[str], T]) -> Tuple[T]:
|
|||
"""
|
||||
Create a tuple from a string.
|
||||
|
||||
:param str s: string to convert to a tuple
|
||||
:param s: string to convert to a tuple
|
||||
:param value_type: type of values to be contained within tuple
|
||||
:return: tuple from string
|
||||
:rtype: tuple
|
||||
"""
|
||||
# remove tuple braces and strip commands and space from all values in the tuple
|
||||
# string
|
||||
|
@ -204,10 +199,9 @@ def mute_detach(args: str, **kwargs: Dict[str, Any]) -> int:
|
|||
"""
|
||||
Run a muted detached process by forking it.
|
||||
|
||||
:param str args: arguments for the command
|
||||
:param dict kwargs: keyword arguments for the command
|
||||
:param args: arguments for the command
|
||||
:param kwargs: keyword arguments for the command
|
||||
:return: process id of the command
|
||||
:rtype: int
|
||||
"""
|
||||
args = shlex.split(args)
|
||||
kwargs["preexec_fn"] = _detach_init
|
||||
|
@ -227,13 +221,12 @@ def cmd(
|
|||
Execute a command on the host and return a tuple containing the exit status and
|
||||
result string. stderr output is folded into the stdout result string.
|
||||
|
||||
:param str args: command arguments
|
||||
:param dict env: environment to run command with
|
||||
:param str cwd: directory to run command in
|
||||
:param bool wait: True to wait for status, False otherwise
|
||||
:param bool shell: True to use shell, False otherwise
|
||||
:param args: command arguments
|
||||
:param env: environment to run command with
|
||||
:param cwd: directory to run command in
|
||||
:param wait: True to wait for status, False otherwise
|
||||
:param shell: True to use shell, False otherwise
|
||||
:return: combined stdout and stderr
|
||||
:rtype: str
|
||||
:raises CoreCommandError: when there is a non-zero exit status or the file to
|
||||
execute is not found
|
||||
"""
|
||||
|
@ -258,9 +251,9 @@ def file_munge(pathname: str, header: str, text: str) -> None:
|
|||
"""
|
||||
Insert text at the end of a file, surrounded by header comments.
|
||||
|
||||
:param str pathname: file path to add text to
|
||||
:param str header: header text comments
|
||||
:param str text: text to append to file
|
||||
:param pathname: file path to add text to
|
||||
:param header: header text comments
|
||||
:param text: text to append to file
|
||||
:return: nothing
|
||||
"""
|
||||
# prevent duplicates
|
||||
|
@ -276,8 +269,8 @@ def file_demunge(pathname: str, header: str) -> None:
|
|||
"""
|
||||
Remove text that was inserted in a file surrounded by header comments.
|
||||
|
||||
:param str pathname: file path to open for removing a header
|
||||
:param str header: header text to target for removal
|
||||
:param pathname: file path to open for removing a header
|
||||
:param header: header text to target for removal
|
||||
:return: nothing
|
||||
"""
|
||||
with open(pathname, "r") as read_file:
|
||||
|
@ -306,11 +299,10 @@ def expand_corepath(
|
|||
"""
|
||||
Expand a file path given session information.
|
||||
|
||||
:param str pathname: file path to expand
|
||||
:param core.emulator.session.Session session: core session object to expand path
|
||||
:param core.nodes.base.CoreNode node: node to expand path with
|
||||
:param pathname: file path to expand
|
||||
:param session: core session object to expand path
|
||||
:param node: node to expand path with
|
||||
:return: expanded path
|
||||
:rtype: str
|
||||
"""
|
||||
if session is not None:
|
||||
pathname = pathname.replace("~", f"/home/{session.user}")
|
||||
|
@ -329,9 +321,8 @@ def sysctl_devname(devname: str) -> Optional[str]:
|
|||
"""
|
||||
Translate a device name to the name used with sysctl.
|
||||
|
||||
:param str devname: device name to translate
|
||||
:param devname: device name to translate
|
||||
:return: translated device name
|
||||
:rtype: str
|
||||
"""
|
||||
if devname is None:
|
||||
return None
|
||||
|
@ -343,8 +334,8 @@ def load_config(filename: str, d: Dict[str, str]) -> None:
|
|||
Read key=value pairs from a file, into a dict. Skip comments; strip newline
|
||||
characters and spacing.
|
||||
|
||||
:param str filename: file to read into a dictionary
|
||||
:param dict d: dictionary to read file into
|
||||
:param filename: file to read into a dictionary
|
||||
:param d: dictionary to read file into
|
||||
:return: nothing
|
||||
"""
|
||||
with open(filename, "r") as f:
|
||||
|
@ -408,7 +399,7 @@ def load_logging_config(config_path: str) -> None:
|
|||
"""
|
||||
Load CORE logging configuration file.
|
||||
|
||||
:param str config_path: path to logging config file
|
||||
:param config_path: path to logging config file
|
||||
:return: nothing
|
||||
"""
|
||||
with open(config_path, "r") as log_config_file:
|
||||
|
@ -423,10 +414,9 @@ def threadpool(
|
|||
Run provided functions, arguments, and keywords within a threadpool
|
||||
collecting results and exceptions.
|
||||
|
||||
:param iter funcs: iterable that provides a func, args, kwargs
|
||||
:param int workers: number of workers for the threadpool
|
||||
:param funcs: iterable that provides a func, args, kwargs
|
||||
:param workers: number of workers for the threadpool
|
||||
:return: results and exceptions from running functions with args and kwargs
|
||||
:rtype: tuple
|
||||
"""
|
||||
with concurrent.futures.ThreadPoolExecutor(max_workers=workers) as executor:
|
||||
futures = []
|
||||
|
@ -450,7 +440,6 @@ def random_mac() -> str:
|
|||
Create a random mac address using Xen OID 00:16:3E.
|
||||
|
||||
:return: random mac address
|
||||
:rtype: str
|
||||
"""
|
||||
value = random.randint(0, 0xFFFFFF)
|
||||
value |= 0x00163E << 24
|
||||
|
@ -463,9 +452,8 @@ def validate_mac(value: str) -> str:
|
|||
"""
|
||||
Validate mac and return unix formatted version.
|
||||
|
||||
:param str value: address to validate
|
||||
:param value: address to validate
|
||||
:return: unix formatted mac
|
||||
:rtype: str
|
||||
"""
|
||||
try:
|
||||
mac = netaddr.EUI(value)
|
||||
|
@ -479,9 +467,8 @@ def validate_ip(value: str) -> str:
|
|||
"""
|
||||
Validate ip address with prefix and return formatted version.
|
||||
|
||||
:param str value: address to validate
|
||||
:param value: address to validate
|
||||
:return: formatted ip address
|
||||
:rtype: str
|
||||
"""
|
||||
try:
|
||||
ip = netaddr.IPNetwork(value)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue