# -*- coding: utf-8 -*-
+from locale import getpreferredencoding
from optparse import (OptionParser, OptionValueError, SUPPRESS_HELP)
from os import environ
'sw': ['-S', '--hostname'],
'type': 'string',
'dest': 'host',
- 'help': 'Hostname MPD in running on'},
+ 'help': 'Hostname MPD in running on (default: localhost or MPD_HOST if set)'},
{
'sw': ['-P', '--port'],
'type': 'int',
'dest': 'port',
- 'help': 'Port MPD in listening on'},
+ 'help': 'Port MPD in listening on (default: 6600 or MPD_PORT if set)'},
])
#}}}
"""
def __init__(self, script_info, child_options):#{{{
+ # Strong assumption?
+ self.localencoding = 'utf8'
self.parser = None
self.cli_options = dict({})
+ # TODO: dict ?!!? isn't it a list instead?
self.cli_args = dict({})
self.info = dict(script_info)
# options allows to add new cli options within child objects calling
self.options = list(child_options + OPTS)
self.main()#}}}
+ def _get_encoding(self):#{{{
+ """Get local encoding"""
+ self.localencoding = getpreferredencoding()#}}}
+
+ def _u8_convert(self, string):
+ """Convert CLI input string to UTF8 (mpd standart)"""
+ return unicode(string, self.localencoding).encode('UTF-8')
+
def declare_opts(self):#{{{
"""
Declare options in OptionParser object.
def main(self):
"""declare options, parse command line"""
self.declare_opts()
+ self._get_encoding()
(self.cli_options, self.cli_args) = self.parser.parse_args()