def set_list(section, option, l): """ join the list l to a string separated by , and set it as value to option. Return False on error, else True. """ s = escape_join(",", l) if None == s: return False return set(section, option, s)
def set_defaults(): """ Sets the default values. I know that the ConfigParser class has a method to set defaults but these defaults are global and not bound to a section. If you want a default nick color you can set it but if you have another option with the same name the default value will be the same and this sucks. A further point is that this way realizes "private" values which are not written to config files but can be used with the same API. """ global defaults defaults = {} defaults["aliase"] = {} defaults["nigiri"] = {} defaults["nigiri"]["wrap_input"] = "True" defaults["nigiri"]["command_char"] = "/" defaults["nigiri"]["shortcut_pattern"] = "meta [0-9]" defaults["nigiri"]["server_shortcuts"] = "true" defaults["nigiri"]["show_debug"] = "True" defaults["nigiri"]["logfile"] = os.path.join(xdg_cache_home, "sushi", "nigiri.txt") defaults["nigiri"]["locale_dir"] = get_path("..", "locale") defaults["nigiri"]["plugin_dirs"] = escape_join(",", ( os.path.join(xdg_data_home, "nigiri", "plugins"), os.path.join(xdg_data_home, "chirashi"), get_path("plugins"), get_path("..", "chirashi") )) defaults["chatting"] = {} defaults["chatting"]["quit_message"] = "Quit." defaults["chatting"]["part_message"] = "Part." defaults["chatting"]["last_log_lines"] = "15" defaults["chatting"]["nick_separator"] = ": " defaults["colors"] = {} defaults["colors"]["messages"] = "gray" defaults["colors"]["messages_own"] = "white" defaults["colors"]["messages_highlight"] = "red" defaults["colors"]["actions"] = "gray" defaults["colors"]["actions_own"] = "white" defaults["colors"]["informative"] = "blue" defaults["templates"] = {} # misc defaults["templates"]["datestring"] = "%H:%M" # messages defaults["templates"]["action"] = "%(time)s %(nick)s %(message)s" defaults["templates"]["action_own"] = "%(time)s %(nick)s %(message)s" defaults["templates"]["message"] = "%(time)s <%(prefix)s%(nick)s> %(message)s" defaults["templates"]["message_own"] = "%(time)s <%(prefix)s%(nick)s> %(message)s" defaults["templates"]["ctcp"] = "%(time)s -%(nick)s/%(target)s- %(message)s" defaults["templates"]["ctcp_own"] = "%(time)s -%(nick)s/%(target)s- %(message)s" defaults["templates"]["notice"] = "%(time)s *%(nick)s/%(target)s* %(message)s" defaults["templates"]["notice_own"] = "%(time)s *%(nick)s/%(target)s* %(message)s" # actions defaults["templates"]["invite"] = "%(time)s * %(nick)s invites %(who)s to %(channel)s" defaults["templates"]["invite_own"] = "%(time)s * You were invited by %(nick)s to %(channel)s." defaults["templates"]["join"] = "%(time)s * %(nick)s (%(host)s) has joined %(channel)s." defaults["templates"]["join_own"] = "%(time)s * You have joined %(channel)s." defaults["templates"]["kick"] = "%(time)s * %(who)s got kicked from %(channel)s by %(nick)s (%(reason)s)" defaults["templates"]["kick_own"] = "%(time)s * You got kicked from %(channel)s by %(nick)s (%(reason)s)" defaults["templates"]["nick"] = "%(time)s * %(nick)s is now known as %(new_nick)s." defaults["templates"]["nick_own"] = "%(time)s * You are now known as %(new_nick)s." defaults["templates"]["mode_list"] = "%(time)s * Modes for %(target)s: %(modes)s." defaults["templates"]["mode_list_own"] = "%(time)s * Modes set on you: %(modes)s." defaults["templates"]["mode"] = "%(time)s %(nick)s set %(mode)s%(param)s on %(target)s." defaults["templates"]["mode_own"] = "%(time)s You set %(mode)s%(param)s on %(target)s." defaults["templates"]["oper"] = "%(time)s * %(nick)s is now an OPER." defaults["templates"]["oper_own"] = "%(time)s * You are now an OPER." defaults["templates"]["part"] = "%(time)s * %(nick)s has left %(channel)s (%(reason)s)." defaults["templates"]["part_own"] = "%(time)s * You have left %(channel)s (%(reason)s)." defaults["templates"]["quit"] = "%(time)s * %(nick)s has quit (%(reason)s)." defaults["templates"]["quit_own"] = "%(time)s * You have quit (%(reason)s)." defaults["templates"]["topic"] = "%(time)s * %(nick)s has set the topic on %(channel)s to \"%(topic)s\"." defaults["templates"]["topic_own"] = "%(time)s * You have set the topic on %(channel)s to \"%(topic)s\"." defaults["templates"]["topic_anonymous"] = "* Topic of %(channel)s: %(topic)s" # informative defaults["templates"]["banlist_begin"] = "%(time)s Begin of banlist on channel %(channel)s." defaults["templates"]["banlist_item"] = ">> %(who)s %(mask)s %(when)s" defaults["templates"]["banlist_end"] = "%(time)s End of banlist. (%(channel)s)" defaults["templates"]["cannot_join"] = "%(time)s Can't join channel %(channel)s: %(reason)s" defaults["templates"]["list_begin"] = "%(time)s Begin of list." defaults["templates"]["list_item"] = ">> %(channel)s %(user)s %(topic)s" defaults["templates"]["list_end"] = "%(time)s End of list." defaults["templates"]["names_begin"] = "%(time)s Begin of names (%(channel)s)." defaults["templates"]["names_item"] = "[ %(row)s ]" defaults["templates"]["names_end"] = "%(time)s End of names." defaults["templates"]["no_such"] = "%(time)s No such %(type)s: %(target)s." defaults["templates"]["whois_begin"] = "%(time)s Begin of whois (%(target)s)." defaults["templates"]["whois_item"] = ">> %(nick)s: %(message)s" defaults["templates"]["whois_end"] = "%(time)s End of whois." defaults["templates"]["dcc_new_incoming"] = "%(time)s Incoming file transfer (ID:%(id)d) from %(sender)s: \"%(filename)s\" (%(size)d)." defaults["templates"]["dcc_file_auto_accept"] = "%(time)s Auto accepted file transfer from %(sender)s: \"%(filename)s\" (%(size)d)." # Add default sections to config parser # so setting is easier for section in defaults.keys(): try: config_parser.add_section(section) except ConfigParser.DuplicateSectionError: continue # sections defined below are not added to the configParser and # can't be set by the set method (will raise NoSectionError) pass
def set_defaults(): """ Sets the default values. I know that the ConfigParser class has a method to set defaults but these defaults are global and not bound to a section. If you want a default nick color you can set it but if you have another option with the same name the default value will be the same and this sucks. A further point is that this way realizes "private" values which are not written to config files but can be used with the same API. """ global defaults defaults = {} defaults["aliase"] = {} defaults["nigiri"] = {} defaults["nigiri"]["wrap_input"] = "True" defaults["nigiri"]["command_char"] = "/" defaults["nigiri"]["shortcut_pattern"] = "meta [0-9]" defaults["nigiri"]["server_shortcuts"] = "true" defaults["nigiri"]["show_debug"] = "True" defaults["nigiri"]["logfile"] = os.path.join(xdg_cache_home, "sushi", "nigiri.txt") defaults["nigiri"]["locale_dir"] = get_path("..", "locale") defaults["nigiri"]["plugin_dirs"] = escape_join( ",", (os.path.join(xdg_data_home, "nigiri", "plugins"), os.path.join(xdg_data_home, "chirashi"), get_path("plugins"), get_path("..", "chirashi"))) defaults["chatting"] = {} defaults["chatting"]["quit_message"] = "Quit." defaults["chatting"]["part_message"] = "Part." defaults["chatting"]["last_log_lines"] = "15" defaults["chatting"]["nick_separator"] = ": " defaults["colors"] = {} defaults["colors"]["messages"] = "gray" defaults["colors"]["messages_own"] = "white" defaults["colors"]["messages_highlight"] = "red" defaults["colors"]["actions"] = "gray" defaults["colors"]["actions_own"] = "white" defaults["colors"]["informative"] = "blue" defaults["templates"] = {} # misc defaults["templates"]["datestring"] = "%H:%M" # messages defaults["templates"]["action"] = "%(time)s %(nick)s %(message)s" defaults["templates"]["action_own"] = "%(time)s %(nick)s %(message)s" defaults["templates"][ "message"] = "%(time)s <%(prefix)s%(nick)s> %(message)s" defaults["templates"][ "message_own"] = "%(time)s <%(prefix)s%(nick)s> %(message)s" defaults["templates"][ "ctcp"] = "%(time)s -%(nick)s/%(target)s- %(message)s" defaults["templates"][ "ctcp_own"] = "%(time)s -%(nick)s/%(target)s- %(message)s" defaults["templates"][ "notice"] = "%(time)s *%(nick)s/%(target)s* %(message)s" defaults["templates"][ "notice_own"] = "%(time)s *%(nick)s/%(target)s* %(message)s" # actions defaults["templates"][ "invite"] = "%(time)s * %(nick)s invites %(who)s to %(channel)s" defaults["templates"][ "invite_own"] = "%(time)s * You were invited by %(nick)s to %(channel)s." defaults["templates"][ "join"] = "%(time)s * %(nick)s (%(host)s) has joined %(channel)s." defaults["templates"][ "join_own"] = "%(time)s * You have joined %(channel)s." defaults["templates"][ "kick"] = "%(time)s * %(who)s got kicked from %(channel)s by %(nick)s (%(reason)s)" defaults["templates"][ "kick_own"] = "%(time)s * You got kicked from %(channel)s by %(nick)s (%(reason)s)" defaults["templates"][ "nick"] = "%(time)s * %(nick)s is now known as %(new_nick)s." defaults["templates"][ "nick_own"] = "%(time)s * You are now known as %(new_nick)s." defaults["templates"][ "mode_list"] = "%(time)s * Modes for %(target)s: %(modes)s." defaults["templates"][ "mode_list_own"] = "%(time)s * Modes set on you: %(modes)s." defaults["templates"][ "mode"] = "%(time)s %(nick)s set %(mode)s%(param)s on %(target)s." defaults["templates"][ "mode_own"] = "%(time)s You set %(mode)s%(param)s on %(target)s." defaults["templates"]["oper"] = "%(time)s * %(nick)s is now an OPER." defaults["templates"]["oper_own"] = "%(time)s * You are now an OPER." defaults["templates"][ "part"] = "%(time)s * %(nick)s has left %(channel)s (%(reason)s)." defaults["templates"][ "part_own"] = "%(time)s * You have left %(channel)s (%(reason)s)." defaults["templates"][ "quit"] = "%(time)s * %(nick)s has quit (%(reason)s)." defaults["templates"][ "quit_own"] = "%(time)s * You have quit (%(reason)s)." defaults["templates"][ "topic"] = "%(time)s * %(nick)s has set the topic on %(channel)s to \"%(topic)s\"." defaults["templates"][ "topic_own"] = "%(time)s * You have set the topic on %(channel)s to \"%(topic)s\"." defaults["templates"][ "topic_anonymous"] = "* Topic of %(channel)s: %(topic)s" # informative defaults["templates"][ "banlist_begin"] = "%(time)s Begin of banlist on channel %(channel)s." defaults["templates"]["banlist_item"] = ">> %(who)s %(mask)s %(when)s" defaults["templates"][ "banlist_end"] = "%(time)s End of banlist. (%(channel)s)" defaults["templates"][ "cannot_join"] = "%(time)s Can't join channel %(channel)s: %(reason)s" defaults["templates"]["list_begin"] = "%(time)s Begin of list." defaults["templates"]["list_item"] = ">> %(channel)s %(user)s %(topic)s" defaults["templates"]["list_end"] = "%(time)s End of list." defaults["templates"][ "names_begin"] = "%(time)s Begin of names (%(channel)s)." defaults["templates"]["names_item"] = "[ %(row)s ]" defaults["templates"]["names_end"] = "%(time)s End of names." defaults["templates"]["no_such"] = "%(time)s No such %(type)s: %(target)s." defaults["templates"][ "whois_begin"] = "%(time)s Begin of whois (%(target)s)." defaults["templates"]["whois_item"] = ">> %(nick)s: %(message)s" defaults["templates"]["whois_end"] = "%(time)s End of whois." defaults["templates"][ "dcc_new_incoming"] = "%(time)s Incoming file transfer (ID:%(id)d) from %(sender)s: \"%(filename)s\" (%(size)d)." defaults["templates"][ "dcc_file_auto_accept"] = "%(time)s Auto accepted file transfer from %(sender)s: \"%(filename)s\" (%(size)d)." # Add default sections to config parser # so setting is easier for section in defaults.keys(): try: config_parser.add_section(section) except ConfigParser.DuplicateSectionError: continue # sections defined below are not added to the configParser and # can't be set by the set method (will raise NoSectionError) pass