forked from PiRSquared17/bpbible
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
222 lines (171 loc) · 6.48 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
from backend.verse_template import VerseTemplate, SmartVerseTemplate
import os
import sys
import getopt
from ConfigParser import RawConfigParser, NoSectionError, NoOptionError
paths_file = "paths.ini"
# Set defaults
data_path = "data/"
xrc_path = "xrc/"
graphics_path = "graphics/"
index_path = "./"
sword_paths_file = "./"
error_log = "error.log"
"""Attempt to override paths with settings in an INI file
The file referenced by the variable paths_file should be like this:
[BPBiblePaths]
DataPath = data
IndexPath = .
SwordPath = .
If the paths do not exist, they will be ignored.
If the paths include $DATADIR, it will be replaced with the wx user data dir
for the appropriate platform.
"""
from util import osutils
user_data_dir = osutils.get_user_data_dir()
def get_path_if_exists(path, alternate_path):
"""Expands the given path and checks if it exists.
If it is an empty path, then alternate_path will be returned.
If the path does not exist, then it will be created if possible.
"""
if "$DATADIR" in path:
path = path.replace("$DATADIR", user_data_dir)
if not path:
path = alternate_path
return path
def create_path_if_not_exists(path):
if os.path.exists(path):
return
try:
os.makedirs(path)
except OSError, e:
sys.stderr.write(str(e))
if os.path.isfile(paths_file):
try:
paths_file_parser = RawConfigParser()
paths_file_parser.read([paths_file])
data_path = get_path_if_exists(
paths_file_parser.get("BPBiblePaths", "DataPath"),
data_path
)
index_path = get_path_if_exists(
paths_file_parser.get("BPBiblePaths", "IndexPath"),
index_path
)
sword_paths_file = get_path_if_exists(
paths_file_parser.get("BPBiblePaths", "SwordPath"),
sword_paths_file
)
except (NoSectionError, NoOptionError):
pass
"""Attempt to override paths with command-line arguments
Call BPBible like this:
python bpbible.py --data-path=data --index-path=. --sword-path=.
"""
try:
opts, all = getopt.getopt(sys.argv[1:], "d", ["data-path=", "index-path=", "sword-path=", "no-splashscreen"])
except getopt.GetoptError:
opts = []
if opts:
for o, v in opts:
if o == "--data-path" and os.path.isdir(v):
data_path = v
elif o == "--index-path" and os.path.isdir(v):
index_path = v
elif o == "--sword-path" and os.path.isdir(v):
sword_paths_file = v
if data_path[-1] not in "\\/":
data_path += "/"
if index_path[-1] not in "\\/":
index_path += "/"
if sword_paths_file[-1] not in "\\/" and sword_paths_file[-1] not in "\\/":
sword_paths_file += "/"
sword_paths_file += "sword.conf"
create_path_if_not_exists(data_path)
create_path_if_not_exists(index_path)
raw = False
def name():
# Note that the string BPBible is *not* translated, since it is the
# application trade name and must be preserved in all languages in any
# place it occurs (including this one).
return "BPBible"
def MODULE_MISSING_STRING():
return _("""<b>This book is not set.</b><br>
This may be because you do not have any of this type of book installed.
<p> If you don't have any of this type of book, first download them from <a
href="http://www.crosswire.org/sword/modules/index.jsp">http://www.crosswire.org/sword/modules/index.jsp</a>.<br>
Then to install them, either drag them onto BPBible, or go <code>File >
Install Books...</code> and select the books.
<p> If you have already have SWORD books installed, go to <code>File >
Set SWORD Paths</code> and add the path where the books are installed to the book search paths.
""")
def MAX_VERSES_EXCEEDED():
return _("""<p><b>[Reference clipped as the maximum verse limit (%d verses) has been exceeded.
<br>This probably means the reference was invalid]</b>""")
def PERSONAL_COMMENTARY_UNSUPPORTED_MESSAGE():
return _("""<h4>The Personal Commentary is not supported</h4>
<p>To make notes on verses, use "Bible > Topic Management", "Bible > Tag Verses"
and "Bible > Comment on Verses".</p>
<p>For more information, see the documentation on <a href="http://code.google.com/p/bpbible/wiki/UserNotes">creating and using user notes in BPBible</a>.</p>
""")
def HARMONY_UNSUPPORTED_MESSAGE():
return _("""<h4>This harmony requires a Bible installed</h4>
<p>In order for this harmony to work, you need to have a Bible installed.</p>
""")
def CHAPTER_NOT_IN_MODULE_MESSAGE():
return _("""<p style="text-indent: 0;">%s is not in the current book.</p>""")
from util.configmgr import ConfigManager
bpbible_configuration = ConfigManager("bpbible.conf")
release_settings = bpbible_configuration.add_section("Release")
release_settings.add_item("version", "DEV", item_type=str)
release_settings.add_item("is_released", False, item_type=bool)
splashscreen_settings = bpbible_configuration.add_section("SplashScreen")
splashscreen_settings.add_item("show", True, item_type=bool)
bpbible_configuration.load()
version = release_settings["version"]
def is_release():
"""Checks if this is a released version of BPBible."""
return release_settings["is_released"]
xulrunner_version = "UNKNOWN"
def show_splashscreen():
if ("--no-splashscreen", "") in opts:
return False
return splashscreen_settings["show"]
BIBLE_VERSION_PROTOCOL = "setbibleversion"
title_str = "%(verse)s - %(name)s"
# settings
use_system_inactive_caption_colour = False
preverse = '<a name="${osisRef}_start" osisRef="$osisRef"></a>'
# templates
verse_number = u'''
<a class="vnumber $numbertype%s"
href="nbible://$internal_reference"
osisRef="$osisRef"
reference="$reference">
$versenumber</a>'''
body = (u'''%s $text $usercomments $tags
<a name="${osisRef}_end" osisRef="$osisRef"></a>''') % verse_number
bible_template = SmartVerseTemplate(body=body%'', preverse=preverse)
bible_template_without_headings = SmartVerseTemplate(body=body % '',
headings=u'', preverse=preverse)
current_verse_template = SmartVerseTemplate(body % ' currentverse',
preverse=preverse)
#, footer="<br>$range ($version)")
commentary_template = VerseTemplate(
body=u"<div class='commentary_entry'><h3>$reference</h3>$text\n</div>"
)
dictionary_template = VerseTemplate(
body=u"<div class='dictionary_entry'><h3>$reference</h3>$text\n</div>"
)
genbook_template = VerseTemplate(
body=u"<div class='genbook_entry'><div class='genbook_key' level='$level'>$breadcrumbed_reference</div>$text\n</div>"
)
compare_verse_number = (verse_number % '').replace("$numbertype", "versenumber")
verse_compare_template = VerseTemplate(
body=compare_verse_number + u" $text\n",
header=u"<p><b>(<a href=\"%s://content/$version\">$version</a>)</b>"
% BIBLE_VERSION_PROTOCOL
)
parallel_template = VerseTemplate(
body=compare_verse_number + u" $text\n",
)