From 0f36e10e7d23d86e1b42f09e3b7f352976cb362a Mon Sep 17 00:00:00 2001 From: Sergey Kacheev Date: Thu, 16 Feb 2017 15:36:31 +0700 Subject: [PATCH 1/5] expand config_dir and '~/.salt/Saltfile' as last resort --- salt/utils/parsers.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/salt/utils/parsers.py b/salt/utils/parsers.py index e8f037c3d6..824a9d7f78 100644 --- a/salt/utils/parsers.py +++ b/salt/utils/parsers.py @@ -377,6 +377,10 @@ class SaltfileMixIn(six.with_metaclass(MixInMeta, object)): saltfile = '' if os.path.isfile(saltfile): self.options.saltfile = saltfile + else: + saltfile = os.path.join(os.path.expanduser("~"), '.salt', 'Saltfile') + if os.path.isfile(saltfile): + self.options.saltfile = saltfile else: saltfile = self.options.saltfile @@ -498,6 +502,7 @@ class ConfigDirMixIn(six.with_metaclass(MixInMeta, object)): ) def process_config_dir(self): + self.options.config_dir = os.path.expanduser(self.options.config_dir) if not os.path.isdir(self.options.config_dir): # No logging is configured yet sys.stderr.write( From 33f3614b1ee9e7bdf99af1f9642aba9512e28c3e Mon Sep 17 00:00:00 2001 From: Sergey Kacheev Date: Thu, 16 Feb 2017 17:03:59 +0700 Subject: [PATCH 2/5] pylint: salt/utils/parsers.py --- salt/utils/parsers.py | 769 +++++++++++++++--------------------------- 1 file changed, 271 insertions(+), 498 deletions(-) diff --git a/salt/utils/parsers.py b/salt/utils/parsers.py index 824a9d7f78..182f6e1f81 100644 --- a/salt/utils/parsers.py +++ b/salt/utils/parsers.py @@ -21,8 +21,8 @@ import getpass import logging import optparse import traceback -import yaml from functools import partial +import yaml # Import salt libs @@ -68,10 +68,7 @@ class MixInMeta(type): class OptionParserMeta(MixInMeta): def __new__(mcs, name, bases, attrs): - instance = super(OptionParserMeta, mcs).__new__(mcs, - name, - bases, - attrs) + instance = super(OptionParserMeta, mcs).__new__(mcs, name, bases, attrs) if not hasattr(instance, '_mixin_setup_funcs'): instance._mixin_setup_funcs = [] if not hasattr(instance, '_mixin_process_funcs'): @@ -87,34 +84,24 @@ class OptionParserMeta(MixInMeta): instance._mixin_setup_funcs.append(func) func = getattr(base, '_mixin_after_parsed', None) - if func is not None and func not in \ - instance._mixin_after_parsed_funcs: + if func is not None and func not in instance._mixin_after_parsed_funcs: instance._mixin_after_parsed_funcs.append(func) func = getattr(base, '_mixin_before_exit', None) - if func is not None and func not in \ - instance._mixin_before_exit_funcs: + if func is not None and func not in instance._mixin_before_exit_funcs: instance._mixin_before_exit_funcs.append(func) # Mark process_ functions with the base priority for sorting for func in dir(base): - if not func.startswith('process_'): - continue - - func = getattr(base, func) - if getattr(func, '_mixin_prio_', None) is not None: - # Function already has the attribute set, don't override it - continue - - if six.PY2: - func.__func__._mixin_prio_ = getattr( - base, '_mixin_prio_', 1000 - ) - else: - func._mixin_prio_ = getattr( - base, '_mixin_prio_', 1000 - ) - + if func.startswith('process_'): + func = getattr(base, func) + if getattr(func, '_mixin_prio_', None) is None: + if six.PY2: + func.__func__._mixin_prio_ = getattr( + base, '_mixin_prio_', 1000 + ) + else: + func._mixin_prio_ = getattr(base, '_mixin_prio_', 1000) return instance @@ -167,9 +154,7 @@ class OptionParser(optparse.OptionParser, object): # them with the options and arguments from the command line. new_inargs = sys.stdin.readlines() new_inargs = [arg.rstrip('\r\n') for arg in new_inargs] - new_options, new_args = optparse.OptionParser.parse_args( - self, - new_inargs) + new_options, new_args = optparse.OptionParser.parse_args(self, new_inargs) options.__dict__.update(new_options.__dict__) args.extend(new_args) @@ -182,16 +167,12 @@ class OptionParser(optparse.OptionParser, object): # This logging handler will be removed once the proper console or # logfile logging is setup. temp_log_level = getattr(self.options, 'log_level', None) - log.setup_temp_logger( - 'error' if temp_log_level is None else temp_log_level - ) + log.setup_temp_logger('error' if temp_log_level is None else temp_log_level) # Gather and run the process_