3 # Author: A. S. Budden <abudden _at_ gmail _dot_ com>
4 # Copyright: Copyright (C) 2009-2011 A. S. Budden
5 # Permission is hereby granted to use and distribute this code,
6 # with or without modifications, provided that this copyright
7 # notice is copied with it. Like anything else that's free,
8 # the TagHighlight plugin is provided *as is* and comes with no
9 # warranty of any kind, either expressed or implied. By using
10 # this plugin, you agree that in no event will the copyright
11 # holder be liable for any damages resulting from the use
14 # ---------------------------------------------------------------------
18 from optparse import Values
19 from .utilities import TagHighlightOptionDict
20 from .loaddata import LoadFile, LoadDataFile, SetLoadDataDirectory
21 from .debug import SetDebugLogFile, SetDebugLogLevel, Debug
23 config = TagHighlightOptionDict()
25 def SetDataDirectories():
27 if hasattr(sys, 'frozen'):
28 # Compiled variant, executable should be in
29 # plugin/TagHighlight/Compiled/Win32, so data
30 # is in ../../data relative to executable
31 config['data_directory'] = os.path.abspath(
32 os.path.join(os.path.dirname(sys.executable),
34 config['version_info_dir'] = os.path.abspath(os.path.dirname(sys.executable))
36 # Script variant: this file in
37 # plugin/TagHighlight/module, so data is in
38 # ../data relative to this file
39 config['data_directory'] = os.path.abspath(
40 os.path.join(os.path.dirname(__file__),
42 config['version_info_dir'] = config['data_directory']
44 SetLoadDataDirectory(config['data_directory'])
46 if not os.path.exists(config['data_directory']):
47 raise IOError("Data directory doesn't exist, have you installed the main distribution?")
49 def LoadVersionInfo():
51 data = LoadDataFile('release.txt')
52 config['release'] = data['release']
55 config['version'] = LoadFile(os.path.join(config['version_info_dir'],'version_info.txt'))
58 'clean': 'Unreleased',
60 'revision_id': 'Unreleased',
63 def SetInitialOptions(new_options):
65 for key in new_options:
66 config[key] = new_options[key]
67 if 'debug_level' in config:
68 SetDebugLogLevel(config['debug_level'])
69 if 'debug_file' in config:
70 SetDebugLogFile(config['debug_file'])
74 if 'language_handler' in config:
76 from .languages import Languages
77 config['language_handler'] = Languages(config)
79 full_language_list = config['language_handler'].GetAllLanguages()
80 if len(config['languages']) == 0:
81 # Include all languages
82 config['language_list'] = full_language_list
84 config['language_list'] = [i for i in full_language_list if i in config['languages']]
85 Debug("Languages:\n\t{0!r}\n\t{1!r}".format(full_language_list, config['language_list']), "Information")