X-Git-Url: https://git.kaliko.me/?p=mpd-goodies.git;a=blobdiff_plain;f=lib%2Fstartop.py;h=b73160b3aaf742656d8985efa96ccafce3b28611;hp=44cb64a00a25ef7b8b4f0fe7a45a2e02ec5efdb7;hb=a503dda034de1d644be8c332b687939eb9b91c3f;hpb=bc382cb2c3140986efbf1d8786e2a58655c26b16 diff --git a/lib/startop.py b/lib/startop.py index 44cb64a..b73160b 100644 --- a/lib/startop.py +++ b/lib/startop.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- +from locale import getpreferredencoding from optparse import (OptionParser, OptionValueError, SUPPRESS_HELP) from os import environ @@ -11,12 +12,12 @@ OPTS = list([ '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)'}, ]) #}}} @@ -51,14 +52,27 @@ class StartOpt(object): """ """ - def __init__(self, script_info, options):#{{{ + 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) - self.options = list(options + OPTS) + # options allows to add new cli options within child objects calling + # parent __init__() + 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. @@ -89,6 +103,7 @@ class StartOpt(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()