From: kaliko Date: Sun, 8 Aug 2010 12:09:19 +0000 (+0000) Subject: * Enhanced description for MPD host and PORT defaults values X-Git-Url: https://git.kaliko.me/?p=mpd-goodies.git;a=commitdiff_plain;h=a503dda034de1d644be8c332b687939eb9b91c3f * Enhanced description for MPD host and PORT defaults values * Add CLI encoding support --- diff --git a/lib/startop.py b/lib/startop.py index 945e5bb..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)'}, ]) #}}} @@ -52,8 +53,11 @@ class StartOpt(object): """ 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 @@ -61,6 +65,14 @@ class StartOpt(object): 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. @@ -91,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()