Exemple #1
0
def format_settings_list(settings):
    errors = settings.get_errors()
    lines = []
    for (key, value) in sorted(settings.current.iteritems()):
        default_value = settings.default.get(key)
        masked_value = mask_value_if_secret(key, value)
        lines.append(u'%s: %s' % (key, indent(pformat(masked_value), places=2)))
        if value != default_value and default_value is not None:
            lines.append(u'  Default: %s' %
                indent(pformat(default_value), places=4))
        if errors.get(key) is not None:
            lines.append(u'  Error: %s' % errors[key])
    return '\n'.join(lines)
Exemple #2
0
def format_settings_list(settings):
    errors = settings.get_errors()
    lines = []
    for (key, value) in sorted(settings.current.iteritems()):
        default_value = settings.default.get(key)
        masked_value = mask_value_if_secret(key, value)
        lines.append(u'%s: %s' %
                     (key, log.indent(pprint.pformat(masked_value), places=2)))
        if value != default_value and default_value is not None:
            lines.append(u'  Default: %s' %
                         log.indent(pprint.pformat(default_value), places=4))
        if errors.get(key) is not None:
            lines.append(u'  Error: %s' % errors[key])
    return '\n'.join(lines)
Exemple #3
0
 def validate(self, interactive):
     if interactive:
         self._read_missing_settings_from_stdin(self.current, self.runtime)
     if self.get_errors():
         logger.error(u'Settings validation errors: %s',
             log.indent(self.get_errors_as_string()))
         raise SettingsError(u'Settings validation failed.')
Exemple #4
0
 def send_response(self, output):
     """Send a response to the client."""
     logger.debug(u'Output to [%s]:%s: %s', self.client_address,
         self.client_port, indent(output))
     output = u'%s%s' % (output, LINE_TERMINATOR)
     data = output.encode(ENCODING)
     self.push(data)
Exemple #5
0
 def validate(self, interactive):
     if interactive:
         self._read_missing_settings_from_stdin(self.current, self.runtime)
     if self.get_errors():
         logger.error(u'Settings validation errors: %s',
                      log.indent(self.get_errors_as_string()))
         raise SettingsError(u'Settings validation failed.')
Exemple #6
0
def format_dependency_list(adapters=None):
    if adapters is None:
        adapters = [
            platform_info,
            python_info,
            gstreamer_info,
            pykka_info,
            pyspotify_info,
            pylast_info,
            dbus_info,
            serial_info,
        ]

    lines = []
    for adapter in adapters:
        dep_info = adapter()
        lines.append(
            '%(name)s: %(version)s' % {
                'name': dep_info['name'],
                'version': dep_info.get('version', 'not found'),
            })
        if 'path' in dep_info:
            lines.append('  Imported from: %s' %
                         (os.path.dirname(dep_info['path'])))
        if 'other' in dep_info:
            lines.append('  Other: %s' % (indent(dep_info['other'])), )
    return '\n'.join(lines)
Exemple #7
0
def format_dependency_list(adapters=None):
    if adapters is None:
        adapters = [
            platform_info,
            python_info,
            gstreamer_info,
            pykka_info,
            pyspotify_info,
            pylast_info,
            dbus_info,
            serial_info,
        ]

    lines = []
    for adapter in adapters:
        dep_info = adapter()
        lines.append('%(name)s: %(version)s' % {
            'name': dep_info['name'],
            'version': dep_info.get('version', 'not found'),
        })
        if 'path' in dep_info:
            lines.append('  Imported from: %s' % (
                os.path.dirname(dep_info['path'])))
        if 'other' in dep_info:
            lines.append('  Other: %s' % (
                indent(dep_info['other'])),)
    return '\n'.join(lines)
Exemple #8
0
 def found_terminator(self):
     """Handle request when a terminator is found."""
     data = ''.join(self.input_buffer).strip()
     self.input_buffer = []
     try:
         request = data.decode(ENCODING)
         logger.debug(u'Input from [%s]:%s: %s', self.client_address,
             self.client_port, indent(request))
         self.handle_request(request)
     except UnicodeDecodeError as e:
         logger.warning(u'Received invalid data: %s', e)
Exemple #9
0
    def on_line_received(self, line):
        logger.debug(u'Request from [%s]:%s to %s: %s', self.host, self.port,
            self.actor_urn, line)

        response = self.dispatcher.handle_request(line)
        if not response:
            return

        logger.debug(u'Response to [%s]:%s from %s: %s', self.host, self.port,
            self.actor_urn, log.indent(self.terminator.join(response)))

        self.send_lines(response)
Exemple #10
0
 def send_response(self, response):
     """
     Format a response from the MPD command handlers and send it to the
     client.
     """
     if response:
         response = LINE_TERMINATOR.join(response)
         logger.debug(u'Response to [%s]:%s: %s', self.client_address,
             self.client_port, indent(response))
         response = u'%s%s' % (response, LINE_TERMINATOR)
         data = response.encode(ENCODING)
         self.push(data)
Exemple #11
0
    def on_line_received(self, line):
        logger.debug(u'Request from [%s]:%s to %s: %s', self.host, self.port,
                     self.actor_urn, line)

        response = self.dispatcher.handle_request(line)
        if not response:
            return

        logger.debug(u'Response to [%s]:%s from %s: %s', self.host,
                     self.port, self.actor_urn,
                     log.indent(self.terminator.join(response)))

        self.send_lines(response)
Exemple #12
0
def list_settings_optparse_callback(*args):
    """
    Prints a list of all settings.

    Called by optparse when Mopidy is run with the :option:`--list-settings`
    option.
    """
    from mopidy import settings
    errors = settings.get_errors()
    lines = []
    for (key, value) in sorted(settings.current.iteritems()):
        default_value = settings.default.get(key)
        if key.endswith('PASSWORD') and len(value):
            value = u'********'
        lines.append(u'%s:' % key)
        lines.append(u'  Value: %s' % repr(value))
        if value != default_value and default_value is not None:
            lines.append(u'  Default: %s' % repr(default_value))
        if errors.get(key) is not None:
            lines.append(u'  Error: %s' % errors[key])
    print u'Settings: %s' % indent('\n'.join(lines), places=2)
    sys.exit(0)
Exemple #13
0
 def validate(self):
     if self.get_errors():
         logger.error(u'Settings validation errors: %s',
             indent(self.get_errors_as_string()))
         raise SettingsError(u'Settings validation failed.')
Exemple #14
0
 def handle_request(self, request):
     """Handle the request using the MPD command handlers."""
     request = request.decode(ENCODING)
     logger.debug(u'Request from [%s]:%s: %s', self.client_address,
         self.client_port, indent(request))
     return self.dispatcher.handle_request(request)