Imported Debian patch 4.0.5-6~numeezy
This commit is contained in:
committed by
Mario Fetka
parent
c44de33144
commit
10dfc9587b
@@ -17,15 +17,11 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import os
|
||||
from textwrap import wrap
|
||||
|
||||
from ipalib import api
|
||||
from ipalib.plugable import Plugin, API
|
||||
from ipalib.errors import ValidationError
|
||||
from ipapython import admintool
|
||||
from textwrap import wrap
|
||||
from ipapython.ipa_log_manager import log_mgr
|
||||
|
||||
|
||||
@@ -76,62 +72,6 @@ Important! Do not forget to register the class to the API.
|
||||
"""
|
||||
|
||||
|
||||
class _AdviceOutput(object):
|
||||
|
||||
def __init__(self):
|
||||
self.content = []
|
||||
self.prefix = '# '
|
||||
self.options = None
|
||||
|
||||
def comment(self, line, wrapped=True):
|
||||
if wrapped:
|
||||
for wrapped_line in wrap(line, 70):
|
||||
self.content.append(self.prefix + wrapped_line)
|
||||
else:
|
||||
self.content.append(self.prefix + line)
|
||||
|
||||
def debug(self, line):
|
||||
if self.options.verbose:
|
||||
self.comment('DEBUG: ' + line)
|
||||
|
||||
def command(self, line):
|
||||
self.content.append(line)
|
||||
|
||||
|
||||
class Advice(Plugin):
|
||||
"""
|
||||
Base class for advices, plugins for ipa-advise.
|
||||
"""
|
||||
|
||||
options = None
|
||||
require_root = False
|
||||
description = ''
|
||||
|
||||
def __init__(self, api):
|
||||
super(Advice, self).__init__(api)
|
||||
self.log = _AdviceOutput()
|
||||
|
||||
def set_options(self, options):
|
||||
self.options = options
|
||||
self.log.options = options
|
||||
|
||||
def get_info(self):
|
||||
"""
|
||||
This method should be overridden by child Advices.
|
||||
|
||||
Returns a string with instructions.
|
||||
"""
|
||||
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
class AdviseAPI(API):
|
||||
bases = (Advice,)
|
||||
modules = ('ipaserver.advise.plugins.*',)
|
||||
|
||||
advise_api = AdviseAPI()
|
||||
|
||||
|
||||
class IpaAdvise(admintool.AdminTool):
|
||||
"""
|
||||
Admin tool that given systems's configuration provides instructions how to
|
||||
@@ -164,10 +104,10 @@ class IpaAdvise(admintool.AdminTool):
|
||||
def print_config_list(self):
|
||||
self.print_header('List of available advices')
|
||||
|
||||
max_keyword_len = max((len(keyword) for keyword in advise_api.Advice))
|
||||
max_keyword_len = max((len(keyword) for keyword in api.Advice))
|
||||
|
||||
for keyword in advise_api.Advice:
|
||||
advice = getattr(advise_api.Advice, keyword, '')
|
||||
for keyword in api.Advice:
|
||||
advice = getattr(api.Advice, keyword, '')
|
||||
description = getattr(advice, 'description', '')
|
||||
keyword = keyword.replace('_', '-')
|
||||
|
||||
@@ -177,11 +117,11 @@ class IpaAdvise(admintool.AdminTool):
|
||||
wrapped_description = wrap(description, 80 - len(prefix))
|
||||
|
||||
# Print the first line with the prefix (keyword)
|
||||
print(prefix + wrapped_description[0])
|
||||
print prefix + wrapped_description[0]
|
||||
|
||||
# Print the rest wrapped behind the colon
|
||||
for line in wrapped_description[1:]:
|
||||
print("{off}{line}".format(off=' ' * len(prefix), line=line))
|
||||
print "{off}{line}".format(off=' ' * len(prefix), line=line)
|
||||
|
||||
def print_header(self, header, print_shell=False):
|
||||
header_size = len(header)
|
||||
@@ -189,17 +129,17 @@ class IpaAdvise(admintool.AdminTool):
|
||||
prefix = ''
|
||||
if print_shell:
|
||||
prefix = '# '
|
||||
print('#!/bin/sh')
|
||||
print '#!/bin/sh'
|
||||
|
||||
# Do not print out empty header
|
||||
if header_size > 0:
|
||||
print((prefix + '-' * 70))
|
||||
print(prefix + '-' * 70)
|
||||
for line in wrap(header, 70):
|
||||
print((prefix + line))
|
||||
print((prefix + '-' * 70))
|
||||
print(prefix + line)
|
||||
print(prefix + '-' * 70)
|
||||
|
||||
def print_advice(self, keyword):
|
||||
advice = getattr(advise_api.Advice, keyword, None)
|
||||
advice = getattr(api.Advice, keyword, None)
|
||||
|
||||
# Ensure that Configuration class for given --setup option value exists
|
||||
if advice is None:
|
||||
@@ -227,15 +167,13 @@ class IpaAdvise(admintool.AdminTool):
|
||||
advice.get_info()
|
||||
api.Backend.rpcclient.disconnect()
|
||||
for line in advice.log.content:
|
||||
print(line)
|
||||
print line
|
||||
|
||||
def run(self):
|
||||
super(IpaAdvise, self).run()
|
||||
|
||||
api.bootstrap(in_server=False, context='cli')
|
||||
api.bootstrap(in_server=False, context='advise')
|
||||
api.finalize()
|
||||
advise_api.bootstrap(in_server=False, context='cli')
|
||||
advise_api.finalize()
|
||||
if not self.options.verbose:
|
||||
# Do not print connection information by default
|
||||
logger_name = r'ipa\.ipalib\.plugins\.rpcclient'
|
||||
|
||||
Reference in New Issue
Block a user