diff options
| author | Thierry Carrez <thierry@openstack.org> | 2013-05-09 15:10:56 +0200 |
|---|---|---|
| committer | Thierry Carrez <thierry@openstack.org> | 2013-05-09 15:10:56 +0200 |
| commit | 562cc6844d3dc5cbd35ad404307224959900df30 (patch) | |
| tree | dfae138829fbe1ad07695d855d2278b13e7de75f | |
| parent | e523c8c591806454e0e326bbdac57508787f8d24 (diff) | |
| download | oslo-562cc6844d3dc5cbd35ad404307224959900df30.tar.gz oslo-562cc6844d3dc5cbd35ad404307224959900df30.tar.xz oslo-562cc6844d3dc5cbd35ad404307224959900df30.zip | |
Stylistic improvements from quantum-rootwrap
As part of the convergence effort between oslo-rootwrap and
quantum-rootwrap, import stylistic improvements introduced
in quantum-rootwrap, like:
- HACKING-compliant docstrings
- More elegant return construct from match_filter in filters.py
- Remove overridden use of filters in wrapper.py
Change-Id: I49a97271b1c385feb25adf4f62add5c71962b5dd
| -rw-r--r-- | openstack/common/rootwrap/filters.py | 20 | ||||
| -rw-r--r-- | openstack/common/rootwrap/wrapper.py | 8 |
2 files changed, 13 insertions, 15 deletions
diff --git a/openstack/common/rootwrap/filters.py b/openstack/common/rootwrap/filters.py index d9618af..58121cb 100644 --- a/openstack/common/rootwrap/filters.py +++ b/openstack/common/rootwrap/filters.py @@ -20,7 +20,7 @@ import re class CommandFilter(object): - """Command filter only checking that the 1st argument matches exec_path""" + """Command filter only checking that the 1st argument matches exec_path.""" def __init__(self, exec_path, run_as, *args): self.name = '' @@ -30,7 +30,7 @@ class CommandFilter(object): self.real_exec = None def get_exec(self, exec_dirs=[]): - """Returns existing executable, or empty string if none found""" + """Returns existing executable, or empty string if none found.""" if self.real_exec is not None: return self.real_exec self.real_exec = "" @@ -46,10 +46,8 @@ class CommandFilter(object): return self.real_exec def match(self, userargs): - """Only check that the first argument (command) matches exec_path""" - if (os.path.basename(self.exec_path) == userargs[0]): - return True - return False + """Only check that the first argument (command) matches exec_path.""" + return os.path.basename(self.exec_path) == userargs[0] def get_command(self, userargs, exec_dirs=[]): """Returns command to execute (with sudo -u if run_as != root).""" @@ -60,12 +58,12 @@ class CommandFilter(object): return [to_exec] + userargs[1:] def get_environment(self, userargs): - """Returns specific environment to set, None if none""" + """Returns specific environment to set, None if none.""" return None class RegExpFilter(CommandFilter): - """Command filter doing regexp matching for every argument""" + """Command filter doing regexp matching for every argument.""" def match(self, userargs): # Early skip if command or number of args don't match @@ -135,7 +133,7 @@ class PathFilter(CommandFilter): class DnsmasqFilter(CommandFilter): - """Specific filter for the dnsmasq call (which includes env)""" + """Specific filter for the dnsmasq call (which includes env).""" CONFIG_FILE_ARG = 'CONFIG_FILE' @@ -160,7 +158,7 @@ class DnsmasqFilter(CommandFilter): class DeprecatedDnsmasqFilter(DnsmasqFilter): - """Variant of dnsmasq filter to support old-style FLAGFILE""" + """Variant of dnsmasq filter to support old-style FLAGFILE.""" CONFIG_FILE_ARG = 'FLAGFILE' @@ -210,7 +208,7 @@ class KillFilter(CommandFilter): class ReadFileFilter(CommandFilter): - """Specific filter for the utils.read_file_as_root call""" + """Specific filter for the utils.read_file_as_root call.""" def __init__(self, file_path, *args): self.file_path = file_path diff --git a/openstack/common/rootwrap/wrapper.py b/openstack/common/rootwrap/wrapper.py index e0ac9df..d488ddd 100644 --- a/openstack/common/rootwrap/wrapper.py +++ b/openstack/common/rootwrap/wrapper.py @@ -93,7 +93,7 @@ def setup_syslog(execname, facility, level): def build_filter(class_name, *args): - """Returns a filter object of class class_name""" + """Returns a filter object of class class_name.""" if not hasattr(filters, class_name): logging.warning("Skipping unknown filter class (%s) specified " "in filter definitions" % class_name) @@ -103,7 +103,7 @@ def build_filter(class_name, *args): def load_filters(filters_path): - """Load filters from a list of directories""" + """Load filters from a list of directories.""" filterlist = [] for filterdir in filters_path: if not os.path.isdir(filterdir): @@ -121,7 +121,7 @@ def load_filters(filters_path): return filterlist -def match_filter(filters, userargs, exec_dirs=[]): +def match_filter(filter_list, userargs, exec_dirs=[]): """ Checks user command and arguments through command filters and returns the first matching filter. @@ -131,7 +131,7 @@ def match_filter(filters, userargs, exec_dirs=[]): """ first_not_executable_filter = None - for f in filters: + for f in filter_list: if f.match(userargs): # Try other filters if executable is absent if not f.get_exec(exec_dirs=exec_dirs): |
