diff options
author | Justus Winter <4winter@informatik.uni-hamburg.de> | 2011-09-22 12:52:28 +0200 |
---|---|---|
committer | Justus Winter <4winter@informatik.uni-hamburg.de> | 2011-09-22 12:52:28 +0200 |
commit | 5add434c57d8e41582eb8f9804c3716ef5ba41e8 (patch) | |
tree | dcebf2e4b9e4ae0701f5cd6bcd380c2b861ff28c /alot | |
parent | 661c4f255f86e9ac56eea0cf7e37b51b4d94ac2a (diff) |
Read defaults from default config file
Read the configuration defaults from a file instead of hardcoding them in
settings.py. This also simplifies the option lookup.
Diffstat (limited to 'alot')
-rw-r--r-- | alot/defaults/alot.rc | 289 | ||||
-rw-r--r-- | alot/defaults/notmuch.rc | 3 | ||||
-rw-r--r-- | alot/settings.py | 295 |
3 files changed, 302 insertions, 285 deletions
diff --git a/alot/defaults/alot.rc b/alot/defaults/alot.rc new file mode 100644 index 00000000..fbe2b318 --- /dev/null +++ b/alot/defaults/alot.rc @@ -0,0 +1,289 @@ +[general] + +# ask for subject when compose +ask_subject = True + +# max length of authors line in thread widgets +authors_maxlength = 30 + +# confirm exit +bug_on_exit = False + +# number of colours your terminal supports +colourmode = 256 + +# fill threadline with message content +display_content_in_threadline = False + +# headers that get displayed by default +displayed_headers = From,To,Cc,Bcc,Subject + +# editor command +editor_cmd = /usr/bin/vim -f -c 'set filetype=mail' + +editor_writes_encoding' = UTF-8 + +# timeout in secs after a failed attempt to flush is repeated +flush_retry_timeout = 5 + +# where to look up hooks +hooksfile = ~/.alot.py + +# time in secs to display status messages +notify_timeout = 2 + +# display statusline? +show_statusbar = True + +spawn_editor = False +# set terminal for asynchronous editing +terminal_cmd = x-terminal-emulator -e + +# strftime format for timestamps. Note: you must escape % here: +# use '%%' instead of '%'. otherwise see +# http://docs.python.org/library/datetime.html#strftime-strptime-behavior +timestamp_format = '' + +# how to print messages: +# this specifies a shellcommand used pro printing. +# threads/messages are piped to this as plaintext. +# muttprint/a2ps works nicely +print_cmd = + +#initial searchstring when none is given as argument: +initial_searchstring = tag:inbox AND NOT tag:killed + +# in case more than one account has an addressbook: +# Set this to True to make tabcompletion for recipients during compose only +# look in the abook of the account matching the sender address +complete_matching_abook_only = False + +[global-maps] +@ = refresh +I = search tag:inbox AND NOT tag:killed +L = taglist +shift tab = bprevious +U = search tag:unread +tab = bnext +\ = 'prompt search ' +d = bclose +$ = flush +m = compose +o = 'prompt search ' +q = exit +';' = bufferlist +':' = prompt + +[bufferlist-maps] +x = closefocussed +enter = openfocussed + +[search-maps] +a = toggletag inbox +& = toggletag killed +l = retagprompt +O = refineprompt +enter = openthread +| = refineprompt + +[envelope-maps] +a = prompt attach ~/ +y = send +s = 'prompt subject ' +t = 'prompt to ' +enter = reedit + +[taglist-maps] +enter = select + +[thread-maps] +C = fold --all +E = unfold --all +H = toggleheaders +P = print --thread +S = save --all +a = toggletag inbox +g = groupreply +f = forward +p = print +s = save +r = reply +enter = select +| = 'prompt pipeto ' + +[command-aliases] +quit = exit +bn = bnext +clo = close +bp = bprevious +ls = bufferlist + +[16c-theme] +bufferlist_focus_fg = white +threadline_mailcount_focus_bg = dark cyan +bufferlist_focus_bg = dark gray +tag_bg = black +message_attachment_fg = light gray +threadline_authors_focus_fg = black,bold +threadline_bg = default +notify_error_fg = white +bufferlist_results_even_bg = black +threadline_subject_fg = light gray +message_header_value_bg = dark gray +messagesummary_even_fg = white +threadline_authors_focus_bg = dark cyan +footer_fg = light green +bufferlist_results_odd_fg = light gray +threadline_date_fg = light gray +bufferlist_results_even_fg = light gray +message_header_value_fg = light gray +threadline_subject_bg = default +messagesummary_odd_fg = white +message_header_key_fg = white +threadline_tags_focus_bg = dark cyan +tag_focus_fg = white +bufferlist_results_odd_bg = black +threadline_fg = default +prompt_fg = light gray +header_bg = dark blue +threadline_subject_focus_bg = dark cyan +message_body_fg = light gray +message_header_key_bg = dark gray +threadline_date_bg = default +tag_focus_bg = dark cyan +messagesummary_odd_bg = dark blue +threadline_subject_focus_fg = black +threadline_date_focus_fg = black +messagesummary_even_bg = light blue +message_header_fg = white +threadline_focus_fg = white +messagesummary_focus_bg = dark cyan +threadline_date_focus_bg = dark cyan +threadline_content_bg = default +threadline_tags_bg = default +threadline_mailcount_bg = default +messagesummary_focus_fg = white +message_body_bg = default +threadline_mailcount_focus_fg = black +prompt_bg = black +header_fg = white +threadline_content_fg = dark gray +threadline_focus_bg = dark cyan +threadline_mailcount_fg = light gray +threadline_content_focus_bg = dark cyan +tag_fg = brown +notify_normal_fg = default +message_attachment_focussed_bg = light green +threadline_tags_fg = brown +notify_error_bg = dark red +threadline_content_focus_fg = dark gray +footer_bg = dark blue +threadline_authors_bg = default +threadline_tags_focus_fg = yellow,bold +message_attachment_bg = dark gray +notify_normal_bg = default +message_attachment_focussed_fg = light gray +threadline_authors_fg = dark green +message_header_bg = dark gray + +[256c-theme] +bufferlist_focus_fg = #ffa +threadline_mailcount_focus_bg = g58 +bufferlist_focus_bg = g38 +tag_bg = default +message_attachment_fg = light gray +threadline_authors_focus_fg = #8f6 +threadline_bg = default +notify_error_fg = white +bufferlist_results_even_bg = g3 +threadline_subject_fg = g58 +message_header_value_bg = dark gray +messagesummary_even_fg = white +threadline_authors_focus_bg = g58 +footer_fg = white +bufferlist_results_odd_fg = default +threadline_date_fg = g58 +bufferlist_results_even_fg = default +message_header_value_fg = light gray +threadline_subject_bg = default +messagesummary_odd_fg = white +message_header_key_fg = white +threadline_tags_focus_bg = g58 +tag_focus_fg = #ffa +bufferlist_results_odd_bg = default +threadline_fg = default +prompt_fg = light gray +header_bg = dark blue +threadline_subject_focus_bg = g58 +message_body_fg = light gray +message_header_key_bg = dark gray +threadline_date_bg = default +tag_focus_bg = g58 +messagesummary_odd_bg = #006 +threadline_subject_focus_fg = g89 +threadline_date_focus_fg = g89 +messagesummary_even_bg = #068 +message_header_fg = white +threadline_focus_fg = white +messagesummary_focus_bg = g58 +threadline_date_focus_bg = g58 +threadline_content_bg = default +threadline_tags_bg = default +threadline_mailcount_bg = default +messagesummary_focus_fg = #ff8 +message_body_bg = default +threadline_mailcount_focus_fg = g89 +prompt_bg = default +header_fg = white +threadline_content_fg = #866 +threadline_focus_bg = g58 +threadline_mailcount_fg = light gray +threadline_content_focus_bg = g58 +tag_fg = brown +notify_normal_fg = default +message_attachment_focussed_bg = light green +threadline_tags_fg = #a86 +notify_error_bg = dark red +threadline_content_focus_fg = #866 +footer_bg = #006 +threadline_authors_bg = default +threadline_tags_focus_fg = #ff8 +message_attachment_bg = dark gray +notify_normal_bg = default +message_attachment_focussed_fg = light gray +threadline_authors_fg = #6d6 +message_header_bg = dark gray + +[1c-theme] +message_body = default +message_header = default +prompt = +message_attachment = default +notify_normal = default +messagesummary_odd = +threadline_content = default +threadline_subject_focus = standout +bufferlist_results_odd = default +messagesummary_focus = standout +message_attachment_focussed = underline +tag_focus = standout +header = standout +tag = default +threadline_content_focus = standout +message_header_value = default +threadline_mailcount_focus = standout +threadline_date_focus = standout +message_header_key = default +threadline_subject = default +threadline_authors = default,underline +bufferlist_results_even = default +threadline_authors_focus = standout +footer = standout +notify_error = standout +messagesummary_even = +threadline_tags_focus = standout +threadline = default +threadline_date = default +threadline_mailcount = default +threadline_focus = standout +threadline_tags = bold +bufferlist_focus = standout diff --git a/alot/defaults/notmuch.rc b/alot/defaults/notmuch.rc new file mode 100644 index 00000000..f03fcda1 --- /dev/null +++ b/alot/defaults/notmuch.rc @@ -0,0 +1,3 @@ +[maildir] +synchronize_flags = False + diff --git a/alot/settings.py b/alot/settings.py index 1aa7b682..39783ba2 100644 --- a/alot/settings.py +++ b/alot/settings.py @@ -23,301 +23,24 @@ import codecs from ConfigParser import SafeConfigParser - -DEFAULTS = { - 'general': { - 'ask_subject': 'True', - 'authors_maxlength': '30', - 'bug_on_exit': 'False', - 'colourmode': '256', - 'complete_matching_abook_only': 'False', - 'display_content_in_threadline': 'False', - 'displayed_headers': 'From,To,Cc,Bcc,Subject', - 'editor_cmd': "/usr/bin/vim -f -c 'set filetype=mail' +", - 'editor_writes_encoding': 'UTF-8', - 'flush_retry_timeout': '5', - 'hooksfile': '~/.alot.py', - 'initial_searchstring': 'tag:inbox AND NOT tag:killed', - 'notify_timeout': '2', - 'print_cmd': '', - 'show_statusbar': 'True', - 'spawn_editor': 'False', - 'terminal_cmd': 'x-terminal-emulator -e', - 'timestamp_format': '', - }, - '16c-theme': { - 'bufferlist_focus_bg': 'dark gray', - 'bufferlist_focus_fg': 'white', - 'bufferlist_results_even_bg': 'black', - 'bufferlist_results_even_fg': 'light gray', - 'bufferlist_results_odd_bg': 'black', - 'bufferlist_results_odd_fg': 'light gray', - 'footer_bg': 'dark blue', - 'footer_fg': 'light green', - 'header_bg': 'dark blue', - 'header_fg': 'white', - 'message_attachment_bg': 'dark gray', - 'message_attachment_fg': 'light gray', - 'message_attachment_focussed_bg': 'light green', - 'message_attachment_focussed_fg': 'light gray', - 'message_body_bg': 'default', - 'message_body_fg': 'light gray', - 'message_header_bg': 'dark gray', - 'message_header_fg': 'white', - 'message_header_key_bg': 'dark gray', - 'message_header_key_fg': 'white', - 'message_header_value_bg': 'dark gray', - 'message_header_value_fg': 'light gray', - 'messagesummary_even_bg': 'light blue', - 'messagesummary_even_fg': 'white', - 'messagesummary_focus_bg': 'dark cyan', - 'messagesummary_focus_fg': 'white', - 'messagesummary_odd_bg': 'dark blue', - 'messagesummary_odd_fg': 'white', - 'notify_error_bg': 'dark red', - 'notify_error_fg': 'white', - 'notify_normal_bg': 'default', - 'notify_normal_fg': 'default', - 'prompt_bg': 'black', - 'prompt_fg': 'light gray', - 'tag_focus_bg': 'dark cyan', - 'tag_focus_fg': 'white', - 'tag_bg': 'black', - 'tag_fg': 'brown', - 'threadline_authors_bg': 'default', - 'threadline_authors_fg': 'dark green', - 'threadline_authors_focus_bg': 'dark cyan', - 'threadline_authors_focus_fg': 'black,bold', - 'threadline_bg': 'default', - 'threadline_content_bg': 'default', - 'threadline_content_fg': 'dark gray', - 'threadline_content_focus_bg': 'dark cyan', - 'threadline_content_focus_fg': 'dark gray', - 'threadline_date_bg': 'default', - 'threadline_date_fg': 'light gray', - 'threadline_date_focus_bg': 'dark cyan', - 'threadline_date_focus_fg': 'black', - 'threadline_fg': 'default', - 'threadline_focus_bg': 'dark cyan', - 'threadline_focus_fg': 'white', - 'threadline_mailcount_bg': 'default', - 'threadline_mailcount_fg': 'light gray', - 'threadline_mailcount_focus_bg': 'dark cyan', - 'threadline_mailcount_focus_fg': 'black', - 'threadline_subject_bg': 'default', - 'threadline_subject_fg': 'light gray', - 'threadline_subject_focus_bg': 'dark cyan', - 'threadline_subject_focus_fg': 'black', - 'threadline_tags_bg': 'default', - 'threadline_tags_fg': 'brown', - 'threadline_tags_focus_bg': 'dark cyan', - 'threadline_tags_focus_fg': 'yellow,bold', - }, - '1c-theme': { - 'bufferlist_focus': 'standout', - 'bufferlist_results_even': 'default', - 'bufferlist_results_odd': 'default', - 'footer': 'standout', - 'header': 'standout', - 'message_attachment': 'default', - 'message_attachment_focussed': 'underline', - 'message_body': 'default', - 'message_header': 'default', - 'message_header_key': 'default', - 'message_header_value': 'default', - 'messagesummary_even': '', - 'messagesummary_focus': 'standout', - 'messagesummary_odd': '', - 'notify_error': 'standout', - 'notify_normal': 'default', - 'prompt': '', - 'tag_focus': 'standout', - 'tag': 'default', - 'threadline': 'default', - 'threadline_authors': 'default,underline', - 'threadline_authors_focus': 'standout', - 'threadline_content': 'default', - 'threadline_content_focus': 'standout', - 'threadline_date': 'default', - 'threadline_date_focus': 'standout', - 'threadline_focus': 'standout', - 'threadline_mailcount': 'default', - 'threadline_mailcount_focus': 'standout', - 'threadline_subject': 'default', - 'threadline_subject_focus': 'standout', - 'threadline_tags': 'bold', - 'threadline_tags_focus': 'standout', - }, - '256c-theme': { - 'bufferlist_focus_bg': 'g38', - 'bufferlist_focus_fg': '#ffa', - 'bufferlist_results_even_bg': 'g3', - 'bufferlist_results_even_fg': 'default', - 'bufferlist_results_odd_bg': 'default', - 'bufferlist_results_odd_fg': 'default', - 'footer_bg': '#006', - 'footer_fg': 'white', - 'header_bg': 'dark blue', - 'header_fg': 'white', - 'message_attachment_bg': 'dark gray', - 'message_attachment_fg': 'light gray', - 'message_attachment_focussed_bg': 'light green', - 'message_attachment_focussed_fg': 'light gray', - 'message_body_bg': 'default', - 'message_body_fg': 'light gray', - 'message_header_bg': 'dark gray', - 'message_header_fg': 'white', - 'message_header_key_bg': 'dark gray', - 'message_header_key_fg': 'white', - 'message_header_value_bg': 'dark gray', - 'message_header_value_fg': 'light gray', - 'messagesummary_even_bg': '#068', - 'messagesummary_even_fg': 'white', - 'messagesummary_focus_bg': 'g58', - 'messagesummary_focus_fg': '#ff8', - 'messagesummary_odd_bg': '#006', - 'messagesummary_odd_fg': 'white', - 'notify_error_bg': 'dark red', - 'notify_error_fg': 'white', - 'notify_normal_bg': 'default', - 'notify_normal_fg': 'default', - 'prompt_bg': 'default', - 'prompt_fg': 'light gray', - 'tag_focus_bg': 'g58', - 'tag_focus_fg': '#ffa', - 'tag_bg': 'default', - 'tag_fg': 'brown', - 'threadline_authors_bg': 'default', - 'threadline_authors_fg': '#6d6', - 'threadline_authors_focus_bg': 'g58', - 'threadline_authors_focus_fg': '#8f6', - 'threadline_bg': 'default', - 'threadline_content_bg': 'default', - 'threadline_content_fg': '#866', - 'threadline_content_focus_bg': 'g58', - 'threadline_content_focus_fg': '#866', - 'threadline_date_bg': 'default', - 'threadline_date_fg': 'g58', - 'threadline_date_focus_bg': 'g58', - 'threadline_date_focus_fg': 'g89', - 'threadline_fg': 'default', - 'threadline_focus_bg': 'g58', - 'threadline_focus_fg': 'white', - 'threadline_mailcount_bg': 'default', - 'threadline_mailcount_fg': 'light gray', - 'threadline_mailcount_focus_bg': 'g58', - 'threadline_mailcount_focus_fg': 'g89', - 'threadline_subject_bg': 'default', - 'threadline_subject_fg': 'g58', - 'threadline_subject_focus_bg': 'g58', - 'threadline_subject_focus_fg': 'g89', - 'threadline_tags_bg': 'default', - 'threadline_tags_fg': '#a86', - 'threadline_tags_focus_bg': 'g58', - 'threadline_tags_focus_fg': '#ff8', - }, - 'global-maps': { - '$': 'flush', - ':': 'prompt', - ';': 'bufferlist', - '@': 'refresh', - '@': 'refresh', - 'I': 'search tag:inbox AND NOT tag:killed', - 'L': 'taglist', - 'U': 'search tag:unread', - '\\': 'prompt search ', - 'm': 'compose', - 'o': 'prompt search ', - 'q': 'exit', - 'shift tab': 'bprevious', - 'tab': 'bnext', - 'd': 'bclose', - }, - 'search-maps': { - '&': 'toggletag killed', - 'O': 'refineprompt', - 'a': 'toggletag inbox', - 'enter': 'openthread', - 'l': 'retagprompt', - '|': 'refineprompt', - }, - 'thread-maps': { - 'C': 'fold --all', - 'E': 'unfold --all', - 'H': 'toggleheaders', - 'P': 'print --thread', - 'a': 'toggletag inbox', - 'enter': 'select', - 'f': 'forward', - 'g': 'groupreply', - 'p': 'print', - 'r': 'reply', - 's': 'save', - 'S': 'save --all', - '|': 'prompt pipeto ', - }, - 'taglist-maps': { - 'enter': 'select', - }, - 'envelope-maps': { - 'a': 'prompt attach ~/', - 'y': 'send', - 'enter': 'reedit', - 't': 'prompt to ', - 's': 'prompt subject ', - }, - 'bufferlist-maps': { - 'x': 'closefocussed', - 'enter': 'openfocussed', - }, - 'command-aliases': { - 'clo': 'close', - 'bn': 'bnext', - 'bp': 'bprevious', - 'ls': 'bufferlist', - 'quit': 'exit', - } -} - -NOTMUCH_DEFAULTS = { - 'maildir': { - 'synchronize_flags': 'False', - }, -} - - -class DefaultsConfigParser(SafeConfigParser): - def __init__(self, defaults): - self.defaults = defaults +class FallbackConfigParser(SafeConfigParser): + def __init__(self): SafeConfigParser.__init__(self) self.optionxform = lambda x: x - for sec in defaults.keys(): - self.add_section(sec) def get(self, section, option, fallback=None, *args, **kwargs): if SafeConfigParser.has_option(self, section, option): return SafeConfigParser.get(self, section, option, *args, **kwargs) - elif section in self.defaults: - if option in self.defaults[section]: - return self.defaults[section][option] return fallback - def has_option(self, section, option, *args, **kwargs): - if SafeConfigParser.has_option(self, section, option): - return True - elif section in self.defaults: - if option in self.defaults[section]: - return True - return False - def getstringlist(self, section, option, **kwargs): value = self.get(section, option, **kwargs) return [s.strip() for s in value.split(',')] -class AlotConfigParser(DefaultsConfigParser): - def __init__(self, defaults): - DefaultsConfigParser.__init__(self, defaults) +class AlotConfigParser(FallbackConfigParser): + def __init__(self): + FallbackConfigParser.__init__(self) self.hooks = None def read(self, file): @@ -336,7 +59,7 @@ class AlotConfigParser(DefaultsConfigParser): def get_palette(self): mode = self.getint('general', 'colourmode') ms = "%dc-theme" % mode - names = self.options(ms) + DEFAULTS[ms].keys() + names = self.options(ms) if mode > 2: names = set([s[:-3] for s in names]) p = list() @@ -406,8 +129,10 @@ class HookManager(object): return None -config = AlotConfigParser(DEFAULTS) -notmuchconfig = DefaultsConfigParser(NOTMUCH_DEFAULTS) +config = AlotConfigParser() +config.read(os.path.join(os.path.dirname(__file__), 'defaults', 'alot.rc')) +notmuchconfig = FallbackConfigParser() +notmuchconfig.read(os.path.join(os.path.dirname(__file__), 'defaults', 'notmuch.rc')) hooks = HookManager() mailcaps = mailcap.getcaps() |