forked from Freely-Given-org/BibleOrgSys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyBibleBible.py
executable file
·1566 lines (1381 loc) · 86.8 KB
/
MyBibleBible.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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# MyBibleBible.py
#
# Module handling "MyBible" Bible module files
#
# Copyright (C) 2016-2019 Robert Hunt
# Author: Robert Hunt <Freely.Given.org@gmail.com>
# License: See gpl-3.0.txt
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
Module reading and loading MyBible Bible databases.
These can be downloaded from: http://mybible.zone/b-eng.php?q=mybible&k=bibles&qq=2&q=bbl
The format can be found from: http://mybible.zone/creat-eng.php
and was here: https://docs.google.com/document/d/12rf4Pqy13qhnAW31uKkaWNTBDTtRbNW0s7cM0vcimlA/edit?pref=2&pli=1
The filename.SQLite3 is the module abbreviation.
A MyBible Bible module file has three tables
TABLE info (name TEXT, value TEXT);
TABLE "books" ("book_color" TEXT, "book_number" NUMERIC, "short_name" TEXT, "long_name" TEXT);
TABLE "verses" ("book_number" NUMERIC, "chapter" NUMERIC, "verse" NUMERIC, "text" TEXT);
UNIQUE INDEX verses_index on "verses" (book_number, chapter, verse);
Here is a typical info table:
PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE info (name TEXT, value TEXT);
INSERT INTO "info" VALUES('description','International Standard Version');
INSERT INTO "info" VALUES('chapter_string','Chapter');
INSERT INTO "info" VALUES('language','en');
INSERT INTO "info" VALUES('language_iso639-2b','eng');
INSERT INTO "info" VALUES('russian_numbering','false');
INSERT INTO "info" VALUES('strong_numbers','false');
INSERT INTO "info" VALUES('right_to_left','false');
COMMIT;
Should look for books_all table first.
Here is a typical books table:
PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE "books" ("book_color" TEXT, "book_number" NUMERIC, "short_name" TEXT, "long_name" TEXT);
INSERT INTO "books" VALUES('#ccccff',10,'Gen','Genesis');
INSERT INTO "books" VALUES('#ccccff',20,'Exo','Exodus');
INSERT INTO "books" VALUES('#ccccff',30,'Lev','Leviticus');
INSERT INTO "books" VALUES('#ccccff',40,'Num','Numbers');
INSERT INTO "books" VALUES('#ccccff',50,'Deu','Deuteronomy');
INSERT INTO "books" VALUES('#ffcc99',60,'Josh','Joshua');
…
INSERT INTO "books" VALUES('#00ff00',710,'3Jn','3 John');
INSERT INTO "books" VALUES('#00ff00',720,'Jud','Jude');
INSERT INTO "books" VALUES('#ff7c80',730,'Rev','Revelation');
COMMIT;
Here is a typical verses table segment (one verse per SQLite3 table row):
…
INSERT INTO "verses" VALUES(730,22,17,'<n>{Concluding Invitation}</n> d The Spirit and the bride say, "Come!" Let everyone who hears this say, "Come!" Let everyone who is thirsty come! Let anyone who wants the water of life take it as a gift! ');
INSERT INTO "verses" VALUES(730,22,18,'<n>{Concluding Warning}</n> d I warn everyone who hears the words of the prophecy in this book: If anyone adds anything to them, God will strike him with the plagues that are written in this book. ');
INSERT INTO "verses" VALUES(730,22,19,'If anyone takes away any words from the book of this prophecy, God will take away his portion of the tree of life and the holy city that are described in this book. ');
INSERT INTO "verses" VALUES(730,22,20,'<n>{Epilogue}</n> d The one who is testifying to these things says, "Yes, I am coming soon!" Amen! Come, Lord Jesus! ');
INSERT INTO "verses" VALUES(730,22,21,'May the grace of the Lord Jesus be with all the saints. Amen. <n>{Other mss. lack Amen}</n> ');
CREATE UNIQUE INDEX verses_index on "verses" (book_number, chapter, verse);
COMMIT;
NOTE that MyBible can put different parts of the translation into different databases/files,
e.g., a main (plain) text module, plus having footnotes, subheadings, and cross-references in separate modules.
This code does not (yet?) handle combining multiple MyBible databases into one InternalBible,
i.e., you can only have the text module OR the footnote module, but not both together.
"""
from gettext import gettext as _
LastModifiedDate = '2019-02-04' # by RJH
ShortProgName = "MyBibleBible"
ProgName = "MyBible Bible format handler"
ProgVersion = '0.20'
ProgNameVersion = '{} v{}'.format( ShortProgName, ProgVersion )
ProgNameVersionDate = '{} {} {}'.format( ProgNameVersion, _("last modified"), LastModifiedDate )
debuggingThisModule = False
import logging, os
import sqlite3, re
import multiprocessing
from collections import OrderedDict
from random import randrange
import BibleOrgSysGlobals
from Bible import Bible, BibleBook
from BibleOrganisationalSystems import BibleOrganisationalSystem
FILENAME_ENDINGS_TO_ACCEPT = ( '.SQLITE3', ) # Must be UPPERCASE
BIBLE_FILENAME_ENDINGS_TO_ACCEPT = ( '.SQLITE3', '.COMMENTARIES.SQLITE3', ) # Must be UPPERCASE
FILENAME_PARTS_TO_REJECT = ( '.DICTIONARY.', '.CROSSREFERENCES.', ) # Must be UPPERCASE
KNOWN_INFO_FIELD_NAMES = ( 'description',
'chapter_string', 'chapter_string_ot', 'chapter_string_nt', 'chapter_string_ps',
'language', 'language_iso639-2b', 'region', 'russian_numbering',
'strong_numbers', 'strong_numbers_prefix',
'right_to_left', 'right_to_left_ot', 'right_to_left_nt',
'localized_book_abbreviations', 'contains_accents',
'detailed_info', 'introduction_string', 'Introduction',
'is_footnotes', )
# NOTE that color values can vary between modules
BOOK_TABLE = {
'GEN': ( '#ccccff', 10, 'Быт', 'Бытие', 'Gen', 'Genesis'),
'EXO': ( '#ccccff', 20, 'Исх', 'Исход', 'Exo', 'Exodus'),
'LEV': ( '#ccccff', 30, 'Лев', 'Левит', 'Lev', 'Leviticus'),
'NUM': ( '#ccccff', 40, 'Чис', 'Числа', 'Num', 'Numbers'),
'DEU': ( '#ccccff', 50, 'Втор', 'Второзаконие', 'Deu', 'Deuteronomy'),
'JOS': ( '#ffcc99', 60, 'Нав', 'Иисус Навин', 'Josh', 'Joshua'),
'JDG': ( '#ffcc99', 70, 'Суд', 'Судьи', 'Judg', 'Judges'),
'RUT': ( '#ffcc99', 80, 'Руфь', 'Руфь', 'Ruth', 'Ruth'),
'SA1': ( '#ffcc99', 90, '1Цар', '1-я Царств', '1Sam', '1 Samuel'),
'SA2': ( '#ffcc99', 100, '2Цар', '2-я Царств', '2Sam', '2 Samuel'),
'KI1': ( '#ffcc99', 110, '3Цар', '3-я Царств', '1Kin', '1 Kings'),
'KI2': ( '#ffcc99', 120, '4Цар', '4-я Царств', '2Kin', '2 Kings'),
'JDT': ( '#ffcc99', 180, 'Иудф', 'Иудифь', 'Jdth', 'Judith'),
'CH1': ( '#ffcc99', 130, '1Пар', '1-я Паралипоменон', '1Chr', '1 Chronicles'),
'CH2': ( '#ffcc99', 140, '2Пар', '2-я Паралипоменон', '2Chr', '2 Chronicles'),
'EZR': ( '#ffcc99', 150, 'Ездр', 'Ездра', 'Ezr', 'Ezra'),
'NEH': ( '#ffcc99', 160, 'Неем', 'Неемия', 'Neh', 'Nehemiah'),
'LES': ( '#ffcc99', 165, '2Езд', '2-я Ездры', '2Esd', '2 Esdras'), # Was 740 -- NOT SURE ABOUT THIS ONE -- 2nd Ezra
'TOB': ( '#ffcc99', 170, 'Тов', 'Товит', 'Tob', 'Tobit'),
'EST': ( '#ffcc99', 190, 'Есф', 'Есфирь', 'Esth', 'Esther'),
'JOB': ( '#66ff99', 220, 'Иов', 'Иов', 'Job', 'Job'),
'PSA': ( '#66ff99', 230, 'Пс', 'Псалтирь', 'Ps', 'Psalms'),
'PRO': ( '#66ff99', 240, 'Прит', 'Притчи', 'Prov', 'Proverbs'),
'ECC': ( '#66ff99', 250, 'Еккл', 'Екклесиаст', 'Eccl', 'Ecclesiastes'),
'SNG': ( '#66ff99', 260, 'Песн', 'Песня Песней', 'Song', 'Song of Solomon'),
'WIS': ( '#66ff99', 270, 'Прем', 'Премудрость Соломона', 'Wis', 'Wisdom of Solomon'),
'SIR': ( '#66ff99', 280, 'Сир', 'Сирах', 'Sir', 'Sirach'),
'ISA': ( '#ff9fb4', 290, 'Ис', 'Исаия', 'Isa', 'Isaiah'),
'JER': ( '#ff9fb4', 300, 'Иер', 'Иеремия', 'Jer', 'Jeremiah'),
'PAZ': ( '#ff9fb4', 305, '???', '???', 'Azar', 'Azariah'),
'LAM': ( '#ff9fb4', 310, 'Плач', 'Плач Иеремии', 'Lam', 'Lamentations'),
'LJE': ( '#ff9fb4', 315, 'Посл', 'Послание Иеремии', 'Let', 'Letter of Jeremiah'),
'BAR': ( '#ff9fb4', 320, 'Вар', 'Варух', 'Bar', 'Baruch'),
'SUS': ( '#ff9fb4', 325, '???', '???', 'Sus', 'Susanna'),
'EZE': ( '#ff9fb4', 330, 'Иез', 'Иезекииль', 'Ezek', 'Ezekiel'),
'DAN': ( '#ff9fb4', 340, 'Дан', 'Даниил', 'Dan', 'Daniel'),
'BEL': ( '#ff9fb4', 345, '???', '???', 'Bel', 'Bel and Dragon'),
'HOS': ( '#ffff99', 350, 'Ос', 'Осия', 'Hos', 'Hosea'),
'JOL': ( '#ffff99', 360, 'Иоил', 'Иоиль', 'Joel', 'Joel'),
'AMO': ( '#ffff99', 370, 'Ам', 'Амос', 'Am', 'Amos'),
'OBA': ( '#ffff99', 380, 'Авд', 'Авдий', 'Oba', 'Obadiah'),
'JNA': ( '#ffff99', 390, 'Ион', 'Иона', 'Jona', 'Jonah'),
'MIC': ( '#ffff99', 400, 'Мих', 'Михей', 'Mic', 'Micah'),
'NAH': ( '#ffff99', 410, 'Наум', 'Наум', 'Nah', 'Nahum'),
'HAB': ( '#ffff99', 420, 'Авв', 'Аввакум', 'Hab', 'Habakkuk'),
'ZEP': ( '#ffff99', 430, 'Соф', 'Софония', 'Zeph', 'Zephaniah'),
'HAG': ( '#ffff99', 440, 'Агг', 'Аггей', 'Hag', 'Haggai'),
'ZEC': ( '#ffff99', 450, 'Зах', 'Захария', 'Zech', 'Zechariah'),
'MAL': ( '#ffff99', 460, 'Мал', 'Малахия', 'Mal', 'Malachi'),
'MA1': ( '#d3d3d3', 462, '1Мак', '1-я Маккавейская', '1Mac', '1 Maccabees'), # Was 200
'MA2': ( '#d3d3d3', 464, '2Мак', '2-я Маккавейская', '2Mac', '2 Maccabees'), # Was 210
'MA3': ( '#d3d3d3', 466, '3Мак', '3-я Маккавейская', '3Mac', '3 Maccabees'), # MAN appears at 466 in KJ-1769
'EZ5': ( '#d3d3d3', 468, '3Езд', '3-я Ездры', '3Esd', '3 Esdras'), # Was 750 -- NOT SURE ABOUT THIS ONE -- 3rd Ezra
'MAT': ( '#ff6600', 470, 'Мат', 'От Матфея', 'Mat', 'Matthew'),
'MRK': ( '#ff6600', 480, 'Мар', 'От Марка', 'Mar', 'Mark'),
'LUK': ( '#ff6600', 490, 'Лук', 'От Луки', 'Luk', 'Luke'),
'JHN': ( '#ff6600', 500, 'Ин', 'От Иоанна', 'John', 'John'),
'ACT': ( '#00ffff', 510, 'Деян', 'Деяния', 'Acts', 'Acts'),
'JAM': ( '#00ff00', 660, 'Иак', 'Иакова', 'Jam', 'James'),
'PE1': ( '#00ff00', 670, '1Пет', '1-е Петра', '1Pet', '1 Peter'),
'PE2': ( '#00ff00', 680, '2Пет', '2-е Петра', '2Pet', '2 Peter'),
'JN1': ( '#00ff00', 690, '1Ин', '1-е Иоанна', '1Jn', '1 John'),
'JN2': ( '#00ff00', 700, '2Ин', '2-е Иоанна', '2Jn', '2 John'),
'JN3': ( '#00ff00', 710, '3Ин', '3-е Иоанна', '3Jn', '3 John'),
'JDE': ( '#00ff00', 720, 'Иуд', 'Иуды', 'Jud', 'Jude'),
'ROM': ( '#ffff00', 520, 'Рим', 'К Римлянам', 'Rom', 'Romans'),
'CO1': ( '#ffff00', 530, '1Кор', '1-е Коринфянам', '1Cor', '1 Corinthians'),
'CO2': ( '#ffff00', 540, '2Кор', '2-е Коринфянам', '2Cor', '2 Corinthians'),
'GAL': ( '#ffff00', 550, 'Гал', 'К Галатам', 'Gal', 'Galatians'),
'EPH': ( '#ffff00', 560, 'Еф', 'К Ефесянам', 'Eph', 'Ephesians'),
'PHP': ( '#ffff00', 570, 'Флп', 'К Филиппийцам', 'Phil', 'Philippians'),
'COL': ( '#ffff00', 580, 'Кол', 'К Колоссянам', 'Col', 'Colossians'),
'TH1': ( '#ffff00', 590, '1Фес', '1-е Фессалоникийцам', '1Ths', '1 Thessalonians'),
'TH2': ( '#ffff00', 600, '2Фес', '2-е Фессалоникийцам', '2Ths', '2 Thessalonians'),
'TI1': ( '#ffff00', 610, '1Тим', '1-е Тимофею', '1Tim', '1 Timothy'),
'TI2': ( '#ffff00', 620, '2Тим', '2-е Тимофею', '2Tim', '2 Timothy'),
'TIT': ( '#ffff00', 630, 'Тит', 'К Титу', 'Tit', 'Titus'),
'PHM': ( '#ffff00', 640, 'Флм', 'К Филимону', 'Phlm', 'Philemon'),
'HEB': ( '#ffff00', 650, 'Евр', 'К Евреям', 'Heb', 'Hebrews'),
'REV': ( '#ff7c80', 730, 'Откр', 'Откровение', 'Rev', 'Revelation'),
'LAO': ( '#00ff00', 780, 'Лаод', 'К Лаодикийцам', 'Lao', 'Letter to the Laodiceans'),
'MAN': ( '#66ff99', 790, 'Мол', 'Молитва Манассии', 'Man', 'Prayer of Manasseh'), # Can also appear at 466
}
# Create a pivot table by book number
BOOKNUMBER_TABLE = {}
# Check the table
for bBBB,bStuff in BOOK_TABLE.items():
#print( bBBB, bStuff )
assert len(bStuff) == 6
for someField in bStuff: assert someField # shouldn't be blank
if debuggingThisModule: assert BibleOrgSysGlobals.BibleBooksCodes.getReferenceNumber(bBBB)
bkColor, bkNumber, rusAbbrev, rusName, engAbbrev, engName = bStuff
assert bkNumber not in BOOKNUMBER_TABLE
BOOKNUMBER_TABLE[bkNumber] = (bBBB,bkColor,rusAbbrev,rusName,engAbbrev,engName)
assert len(BOOKNUMBER_TABLE) == len(BOOK_TABLE)
# We only use the BOOKNUMBER_TABLE for CREATING modules -- not for reading
def exp( messageString ):
"""
Expands the message string in debug mode.
Prepends the module name to a error or warning message string
if we are in debug mode.
Returns the new string.
"""
try: nameBit, errorBit = messageString.split( ': ', 1 )
except ValueError: nameBit, errorBit = '', messageString
if BibleOrgSysGlobals.debugFlag or debuggingThisModule:
nameBit = '{}{}{}'.format( ShortProgName, '.' if nameBit else '', nameBit )
return '{}{}'.format( nameBit+': ' if nameBit else '', errorBit )
# end of exp
def MyBibleBibleFileCheck( givenFolderName, strictCheck=True, autoLoad=False, autoLoadBooks=False ):
"""
Given a folder, search for MyBible Bible files or folders in the folder and in the next level down.
Returns False if an error is found.
if autoLoad is false (default)
returns None, or the number of Bibles found.
if autoLoad is true and exactly one MyBible Bible is found,
returns the loaded MyBibleBible object.
"""
if BibleOrgSysGlobals.verbosityLevel > 2: print( "MyBibleBibleFileCheck( {}, {}, {}, {} )".format( givenFolderName, strictCheck, autoLoad, autoLoadBooks ) )
if BibleOrgSysGlobals.debugFlag:
assert givenFolderName and isinstance( givenFolderName, str )
assert autoLoad in (True,False,)
# Check that the given folder is readable
if not os.access( givenFolderName, os.R_OK ):
logging.critical( _("MyBibleBibleFileCheck: Given {!r} folder is unreadable").format( givenFolderName ) )
return False
if not os.path.isdir( givenFolderName ):
logging.critical( _("MyBibleBibleFileCheck: Given {!r} path is not a folder").format( givenFolderName ) )
return False
# Find all the files and folders in this folder
if BibleOrgSysGlobals.verbosityLevel > 3: print( " MyBibleBibleFileCheck: Looking for files in given {}".format( givenFolderName ) )
foundFolders, foundFiles = [], []
for something in os.listdir( givenFolderName ):
somepath = os.path.join( givenFolderName, something )
if os.path.isdir( somepath ):
if something in BibleOrgSysGlobals.COMMONLY_IGNORED_FOLDERS:
continue # don't visit these directories
foundFolders.append( something )
elif os.path.isfile( somepath ):
somethingUpper = something.upper()
somethingUpperProper, somethingUpperExt = os.path.splitext( somethingUpper )
ignore = False
for stuff in FILENAME_PARTS_TO_REJECT:
if stuff in somethingUpper: ignore=True; break
if ignore: continue
#if not somethingUpperExt[1:] in extensionsToIgnore: # Compare without the first dot
if somethingUpperExt in FILENAME_ENDINGS_TO_ACCEPT:
foundFiles.append( something )
# See if there's an MyBibleBible project here in this given folder
numFound = 0
looksHopeful = False
lastFilenameFound = None
for thisFilename in sorted( foundFiles ):
lastFilenameFound = thisFilename
numFound += 1
if numFound:
if BibleOrgSysGlobals.verbosityLevel > 2: print( "MyBibleBibleFileCheck got", numFound, givenFolderName, lastFilenameFound )
if numFound == 1 and (autoLoad or autoLoadBooks):
MyBB = MyBibleBible( givenFolderName, lastFilenameFound )
if autoLoad or autoLoadBooks: MyBB.preload()
if autoLoadBooks: MyBB.loadBooks() # Load and process the database
return MyBB
return numFound
elif looksHopeful and BibleOrgSysGlobals.verbosityLevel > 2: print( " Looked hopeful but no actual files found" )
# Look one level down
numFound = 0
foundProjects = []
for thisFolderName in sorted( foundFolders ):
tryFolderName = os.path.join( givenFolderName, thisFolderName+'/' )
if not os.access( tryFolderName, os.R_OK ): # The subfolder is not readable
logging.warning( _("MyBibleBibleFileCheck: {!r} subfolder is unreadable").format( tryFolderName ) )
continue
if BibleOrgSysGlobals.verbosityLevel > 3: print( " MyBibleBibleFileCheck: Looking for files in {}".format( tryFolderName ) )
foundSubfolders, foundSubfiles = [], []
for something in os.listdir( tryFolderName ):
somepath = os.path.join( givenFolderName, thisFolderName, something )
if os.path.isdir( somepath ): foundSubfolders.append( something )
elif os.path.isfile( somepath ):
somethingUpper = something.upper()
somethingUpperProper, somethingUpperExt = os.path.splitext( somethingUpper )
ignore = False
for stuff in FILENAME_PARTS_TO_REJECT:
if stuff in somethingUpper: ignore=True; break
if ignore: continue
#if not somethingUpperExt[1:] in extensionsToIgnore: # Compare without the first dot
if somethingUpperExt in FILENAME_ENDINGS_TO_ACCEPT:
foundSubfiles.append( something )
# See if there's an MyBible project here in this folder
for thisFilename in sorted( foundSubfiles ):
foundProjects.append( (tryFolderName, thisFilename,) )
lastFilenameFound = thisFilename
numFound += 1
if numFound:
if BibleOrgSysGlobals.verbosityLevel > 2: print( "MyBibleBibleFileCheck foundProjects", numFound, foundProjects )
if numFound == 1 and (autoLoad or autoLoadBooks):
if BibleOrgSysGlobals.debugFlag: assert len(foundProjects) == 1
MyBB = MyBibleBible( foundProjects[0][0], foundProjects[0][1] )
if autoLoad or autoLoadBooks: MyBB.preload()
if autoLoadBooks: MyBB.loadBooks() # Load and process the database
return MyBB
return numFound
# end of MyBibleBibleFileCheck
class MyBibleBible( Bible ):
"""
Class for reading, validating, and converting MyBibleBible files.
"""
def __init__( self, sourceFolder, givenFilename, encoding='utf-8' ):
"""
Constructor: just sets up the Bible object.
"""
# Setup and initialise the base class first
Bible.__init__( self )
self.objectNameString = 'MyBible Bible object'
self.objectTypeString = 'MyBible'
# Now we can set our object variables
self.sourceFolder, self.sourceFilename, self.encoding = sourceFolder, givenFilename, encoding
self.sourceFilepath = os.path.join( self.sourceFolder, self.sourceFilename )
# Do a preliminary check on the readability of our file
if not os.access( self.sourceFilepath, os.R_OK ):
logging.critical( _("MyBibleBible: File {!r} is unreadable").format( self.sourceFilepath ) )
filenameBits = os.path.splitext( self.sourceFilename )
self.name = self.abbreviation = filenameBits[0]
self.fileExtension = filenameBits[1]
#if self.fileExtension.upper().endswith('X'):
#logging.warning( _("MyBibleBible: File {!r} is encrypted").format( self.sourceFilepath ) )
# end of MyBibleBible.__init__
def preload( self ):
"""
Load the metadata from the SQLite3 database.
"""
if BibleOrgSysGlobals.debugFlag and debuggingThisModule:
print( exp("preload()") )
if BibleOrgSysGlobals.verbosityLevel > 2: print( _("Preloading {}…").format( self.sourceFilepath ) )
fileExtensionUpper = self.fileExtension.upper()
if fileExtensionUpper not in FILENAME_ENDINGS_TO_ACCEPT:
logging.critical( "{} doesn't appear to be a MyBible file".format( self.sourceFilename ) )
elif not self.sourceFilename.upper().endswith( BIBLE_FILENAME_ENDINGS_TO_ACCEPT[0] ):
logging.critical( "{} doesn't appear to be a MyBible Bible file".format( self.sourceFilename ) )
connection = sqlite3.connect( self.sourceFilepath )
connection.row_factory = sqlite3.Row # Enable row names
self.cursor = connection.cursor()
# First get the settings
if self.suppliedMetadata is None: self.suppliedMetadata = {}
self.suppliedMetadata['MyBible'] = {}
self.cursor.execute( 'select * from info' )
rows = self.cursor.fetchall()
for row in rows:
assert len(row) == 2 # name, value
name, value = row
if debuggingThisModule: print( ' INFO', name, repr(value) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag:
assert name in KNOWN_INFO_FIELD_NAMES
# NOTE: detailed_info may contain HTML formatting
if value == 'false': value = False
elif value == 'true': value = True
self.suppliedMetadata['MyBible'][name] = value
#print( self.suppliedMetadata['MyBible'] ); halt
if self.getSetting('language') in ('ru','rus',) \
or self.getSetting('Language') in ('ru','rus',) \
or self.getSetting('LanguageName') in ('Russian',) \
or self.getSetting('ISOLanguageCode') in ('rus',) \
or self.getSetting('language_iso639-2b') in ('rus',):
self.BibleOrganisationalSystem = BibleOrganisationalSystem( 'GENERIC-80-RUS' )
else: self.BibleOrganisationalSystem = BibleOrganisationalSystem( 'GENERIC-ENG' ) # All possible books
# Now get the book info -- try the books_all table first to see if it exists
self.suppliedMetadata['MyBible']['BookInfo'] = OrderedDict()
loadedBookInfo = False
try:
self.cursor.execute( 'select * from books_all' )
rows = self.cursor.fetchall()
#print( " BOOKS_ALL rows", len(rows) )
isPresent = True
for j, row in enumerate( rows ):
assert len(row) == 5
bookColor, bookNumber, shortName, longName, isPresent = row
#print( bookColor, bookNumber, shortName, longName, isPresent )
if BibleOrgSysGlobals.debugFlag: assert bookNumber in BOOKNUMBER_TABLE
if len(rows) == 66: BBB = BibleOrgSysGlobals.BibleBooksCodes.getBBBFromReferenceNumber( j+1 )
else:
BBB = self.BibleOrganisationalSystem.getBBBFromText( longName ) # Might not work for other languages
if BBB is None: BBB = self.BibleOrganisationalSystem.getBBBFromText( shortName ) # Might not work for other languages
#print( " Got1 BBB", BBB, repr(longName) )
assert BBB
self.suppliedMetadata['MyBible']['BookInfo'][BBB] = { 'bookNumber':bookNumber, 'longName':longName,
'shortName':shortName, 'isPresent':isPresent, 'bookColor':bookColor }
if BibleOrgSysGlobals.verbosityLevel > 1:
print( " Loaded book info ({}) from BOOKS_ALL table".format( len(rows) ) )
loadedBookInfo = True
except sqlite3.OperationalError: pass # Table is not in older module versions
if not loadedBookInfo: # from newer books_all table
try:
self.cursor.execute( 'select * from books' )
rows = self.cursor.fetchall()
#print( " BOOKS rows", len(rows) )
isPresent = True
for j, row in enumerate( rows ):
try: bookColor, bookNumber, shortName, longName = row
except ValueError: bookColor, bookNumber, shortName, longName, isPresent = row
#print( bookColor, bookNumber, shortName, longName, isPresent )
if BibleOrgSysGlobals.debugFlag: assert bookNumber in BOOKNUMBER_TABLE
longName = longName.strip() # Why do some have a \n at the end???
if len(rows) == 66: BBB = BibleOrgSysGlobals.BibleBooksCodes.getBBBFromReferenceNumber( j+1 )
else:
BBB = self.BibleOrganisationalSystem.getBBBFromText( longName ) # Might not work for other languages
if BBB is None: BBB = self.BibleOrganisationalSystem.getBBBFromText( shortName ) # Might not work for other languages
if BBB is None and shortName=='3Ма': BBB = 'MA3' # Cant't track down why this fails ???
#print( " Got2 BBB", BBB, repr(longName), repr(shortName) )
assert BBB
self.suppliedMetadata['MyBible']['BookInfo'][BBB] = { 'bookNumber':bookNumber, 'longName':longName,
'shortName':shortName, 'isPresent':isPresent, 'bookColor':bookColor }
if BibleOrgSysGlobals.verbosityLevel > 1:
print( " Loaded book info ({}) from (old) BOOKS table".format( len(rows) ) )
loadedBookInfo = True
except sqlite3.OperationalError: pass # Table is not in older module versions
if loadedBookInfo:
self.availableBBBs.update( self.suppliedMetadata['MyBible']['BookInfo'].keys() )
else: # no book info loaded
if '.commentaries.' not in self.sourceFilename:
logging.critical( "MyBibleBible.preload for {} had no books table".format( self.sourceFilename ) )
#print( self.suppliedMetadata['MyBible'] ); halt
self.preloadDone = True
# end of MyBibleBible.preload
def loadBooks( self ):
"""
Load all the books out of the SQLite3 database.
"""
if BibleOrgSysGlobals.debugFlag and debuggingThisModule:
print( exp("loadBooks()") )
assert self.preloadDone
if BibleOrgSysGlobals.verbosityLevel > 2: print( _("Loading {}…").format( self.sourceFilepath ) )
for BBB in self.suppliedMetadata['MyBible']['BookInfo']:
#print( 'isPresent', self.suppliedMetadata['MyBible']['BookInfo'][BBB]['isPresent'] )
if self.suppliedMetadata['MyBible']['BookInfo'][BBB]['isPresent']:
self.loadBook( BBB )
elif BibleOrgSysGlobals.verbosityLevel > 1:
print( " {} is not present in this Bible".format( BBB ) )
self.cursor.close()
del self.cursor
self.applySuppliedMetadata( 'MyBible' ) # Copy some to self.settingsDict
self.doPostLoadProcessing()
# end of MyBibleBible.loadBooks
def loadBook( self, BBB ):
"""
Load the requested book out of the SQLite3 database.
"""
if BibleOrgSysGlobals.debugFlag and debuggingThisModule:
print( exp("loadBook( {} )").format( BBB ) )
assert self.preloadDone
if BBB in self.books:
if BibleOrgSysGlobals.debugFlag: print( " {} is already loaded -- returning".format( BBB ) )
return # Already loaded
if BBB in self.triedLoadingBook:
logging.warning( "We had already tried loading MyBibleBible {} for {}".format( BBB, self.name ) )
return # We've already attempted to load this book
self.triedLoadingBook[BBB] = True
self.bookNeedsReloading[BBB] = False
if BibleOrgSysGlobals.verbosityLevel > 2 or BibleOrgSysGlobals.debugFlag: print( _("MyBibleBible: Loading {} from {}…").format( BBB, self.sourceFilepath ) )
if '.commentaries.' in self.sourceFilename: self.__loadBibleCommentaryBook( BBB )
else: self.__loadBibleBook( BBB )
# end of MyBibleBible.loadBook
def __loadBibleBook( self, BBB ):
"""
Load the requested Bible book out of the SQLite3 database.
"""
if BibleOrgSysGlobals.debugFlag and debuggingThisModule:
print( exp("__loadBibleBook( {} )").format( BBB ) )
lastC = None
def importVerseLine( name, BBB, C, V, originalLine, bookObject ):
"""
Change MyBible format codes to our codes
and then add the line to the given bookObject
"""
nonlocal lastC
#if BibleOrgSysGlobals.debugFlag and debuggingThisModule:
#print( exp("importVerseLine( {!r}, {} {}:{}, {!r}, … )").format( name, BBB, C, V, originalLine ) )
if originalLine is None: # We don't have an entry for this C:V
return
while originalLine and originalLine[-1] in '\r\n': # RHB
originalLine = originalLine[:-1]
assert '\n' not in originalLine and '\r' not in originalLine
line = originalLine
if line.endswith( '<BR>' ): line = line[:-4] # CSLU
# Change MyBible format codes
line = line.replace( '<n>{', '\\f ' ).replace( '}</n>', '\\f*' ) # ISV
line = line.replace( '<n>', '\\f ' ).replace( '</n>', '\\f*' )
line = line.replace( '<f>', '\\fn ' ).replace( '</f>', '\\fn*' ) # BTI
line = line.replace( '<i>', '\\add ' ).replace( '</i>', '\\add*' )
line = line.replace( '<b>', '\\bd ' ).replace( '</b>', '\\bd*' ) # RHB
line = line.replace( '<e>', '\\em ' ).replace( '</e>', '\\em*' )
line = line.replace( '<J>', '\\wj ' ).replace( '</J>', '\\wj*' ).replace( '<J/>', '\\wj*' ) # ¥£¥
line = line.replace( '<S>', '\\str ' ).replace( '</S>', '\\str*' )
line = line.replace( '<t>', '\\qm ' ).replace( '</t>', '\\m ' )
line = line.replace( '<br/>', '\\m ' )
line = line.replace( '<pb/>', '\\p ' )
line = line.replace( '<p>', '\\p ' ) # KJ-1769
line = line.replace( '<br>', '\\m ' ) # RHB
# Check for left-overs
if '<' in line or '>' in line: # or '{' in line or '}' in line: RSTI has braces
print( exp("importVerseLine( {!r} failed at {} {}:{} {!r} from {!r} )").format( name, BBB, C, V, line, originalLine ) )
if debuggingThisModule: halt
# Ok, use the adjusted info
if C!=lastC:
bookObject.addLine( 'c', str(C) )
lastC = C
#print( BBB, C, V, repr(line) )
bookObject.addLine( 'v', '{} {}'.format( V, line ) )
# end of importVerseLine
# Main code for loadBook()
if BBB not in self.suppliedMetadata['MyBible']['BookInfo'] \
or not self.suppliedMetadata['MyBible']['BookInfo'][BBB]['isPresent']:
return
# Create the empty book
thisBook = BibleBook( self, BBB )
thisBook.objectNameString = 'MyBible Bible Book object'
thisBook.objectTypeString = 'MyBible'
C = V = 1
#ourGlobals = {}
#continued = ourGlobals['haveParagraph'] = False
haveLines = False
mbBookNumber = self.suppliedMetadata['MyBible']['BookInfo'][BBB]['bookNumber']
#print( repr(mbBookNumber) )
self.cursor.execute('select chapter,verse,text from verses where book_number=?', (mbBookNumber,) )
for row in self.cursor.fetchall():
C, V, line = row
#try:
#row = self.cursor.fetchone()
#C, V, line = row
#except TypeError: # This reference is missing (row is None)
##print( "something wrong at", BBB, C, V )
##if BibleOrgSysGlobals.debugFlag: halt
##print( row )
#line = None
#print ( mbBookNumber, BBB, C, V, "MyBib file line is", repr(line) )
if line is None: logging.warning( "MyBibleBible.loadBibleBook: Have missing verse line at {} {}:{}".format( BBB, C, V ) )
else: # line is not None
if not line: logging.warning( "MyBibleBible.loadBibleBook: Found blank verse line at {} {}:{}".format( BBB, C, V ) )
else:
haveLines = True
## Some modules end lines with \r\n or have it in the middle!
## (We just ignore these for now)
#while line and line[-1] in '\r\n': line = line[:-1]
#if '\r' in line or '\n' in line: # (in the middle)
#logging.warning( "MyBibleBible.load: Found CR or LF characters in verse line at {} {}:{}".format( BBB, C, V ) )
#line = line.replace( '\r\n', ' ' ).replace( '\r', ' ' ).replace( '\n', ' ' )
importVerseLine( self.name, BBB, C, V, line, thisBook ) # handle any formatting and save the line
if haveLines:
if BibleOrgSysGlobals.verbosityLevel > 2: print( " MyBible loadBibleBook saving", BBB )
self.stashBook( thisBook )
#else: print( "Not saving", BBB )
#if ourGlobals['haveParagraph']:
#thisBook.addLine( 'p', '' )
#ourGlobals['haveParagraph'] = False
# end of MyBibleBible.__loadBibleBook
def __loadBibleCommentaryBook( self, BBB ):
"""
Load the requested Bible book out of the SQLite3 database.
"""
if BibleOrgSysGlobals.debugFlag and debuggingThisModule:
print( exp("__loadBibleCommentaryBook( {} )").format( BBB ) )
lastC = None
def importCommentaryLine( name, BBB, C, V, footnoteNumber, originalLine, bookObject ):
"""
Change MyBible format codes to our codes
and then add the line to the given bookObject
"""
nonlocal lastC
#if BibleOrgSysGlobals.debugFlag and debuggingThisModule:
#print( exp("importCommentaryLine( {!r}, {} {}:{}, {!r},{!r}, … )").format( name, BBB, C, V, footnoteNumber, originalLine ) )
if originalLine is None: # We don't have an entry for this C:V
return
assert '\n' not in originalLine and '\r' not in originalLine
line = originalLine
# Change MyBible format codes
line = line.replace( '<n>{', '\\f ' ).replace( '}</n>', '\\f*' ) # ISV
line = line.replace( '<n>', '\\f ' ).replace( '</n>', '\\f*' )
line = line.replace( '<i>', '\\add ' ).replace( '</i>', '\\add*' )
line = line.replace( '<e>', '\\em ' ).replace( '</e>', '\\em*' )
line = line.replace( '<J>', '\\wj ' ).replace( '</J>', '\\wj*' )
line = line.replace( '<S>', '\\str ' ).replace( '</S>', '\\str*' )
line = line.replace( '<t>', '\\qm ' ).replace( '</t>', '\\m ' )
line = line.replace( '<br/>', '\\m ' ).replace( '<pb/>', '\\p ' )
# Check for left-overs
if '<' in line or '>' in line or '=' in line or '{' in line or '}' in line:
if '<a ' not in line:
print( exp("importCommentaryLine( {!r} failed at {} {}:{} {!r} from {!r} )").format( name, BBB, C, V, line, originalLine ) )
if debuggingThisModule:
halt
# Ok, use the adjusted info
if C!=lastC:
bookObject.addLine( 'c', str(C) )
lastC = C
#print( BBB, C, V, repr(line) )
bookObject.addLine( 'v', '{} {}'.format( V, line ) )
# end of importCommentaryLine
# Main code for loadBook()
#if BBB not in self.suppliedMetadata['MyBible']['BookInfo'] \
#or not self.suppliedMetadata['MyBible']['BookInfo'][BBB]['isPresent']:
#return
# Create the empty book
thisBook = BibleBook( self, BBB )
thisBook.objectNameString = 'MyBible Bible Book object'
thisBook.objectTypeString = 'MyBible'
C = V = 1
#ourGlobals = {}
#continued = ourGlobals['haveParagraph'] = False
haveLines = False
footnoteMarker = None
mbBookNumber = BOOK_TABLE[BBB][1]
#print( repr(mbBookNumber) )
if self.suppliedMetadata['MyBible']['is_footnotes']:
self.cursor.execute('select chapter_number_from,verse_number_from,chapter_number_to,verse_number_to,marker,text from commentaries where book_number=?', (mbBookNumber,) )
else:
self.cursor.execute('select chapter_number_from,verse_number_from,chapter_number_to,verse_number_to,text from commentaries where book_number=?', (mbBookNumber,) )
for row in self.cursor.fetchall():
if self.suppliedMetadata['MyBible']['is_footnotes']:
C, V, C2, V2, footnoteMarker, line = row
#print( '{!r}:{!r}-{!r}:{!r} {!r}:{!r}'.format( C, V, C2, V2, footnoteMarker, line ) )
else: # not footnotes
C, V, C2, V2, line = row
#print( '{!r}:{!r}-{!r}:{!r} {!r}'.format( C, V, C2, V2, line ) )
if C2 is not None or V2 is not None:
if C2 is None or C2==C:
assert V2 > V
V = '{}-{}'.format( V, V2 ) # Make a verse bridge
else: halt # it's across a chapter boundary -- not finished
#try:
#row = self.cursor.fetchone()
#C, V, line = row
#except TypeError: # This reference is missing (row is None)
##print( "something wrong at", BBB, C, V )
##if BibleOrgSysGlobals.debugFlag: halt
##print( row )
#line = None
#print ( mbBookNumber, BBB, C, V, "MyBib file line is", repr(line) )
if line is None: logging.warning( "MyBibleBible.loadBibleCommentaryBook: Have missing commentary line at {} {}:{}".format( BBB, C, V ) )
else: # line is not None
if not line: logging.warning( "MyBibleBible.loadBibleCommentaryBook: Found blank commentary line at {} {}:{}".format( BBB, C, V ) )
else:
haveLines = True
## Some modules end lines with \r\n or have it in the middle!
## (We just ignore these for now)
#while line and line[-1] in '\r\n': line = line[:-1]
#if '\r' in line or '\n' in line: # (in the middle)
#logging.warning( "MyBibleBible.load: Found CR or LF characters in verse line at {} {}:{}".format( BBB, C, V ) )
#line = line.replace( '\r\n', ' ' ).replace( '\r', ' ' ).replace( '\n', ' ' )
importCommentaryLine( self.name, BBB, C, V, footnoteMarker, line, thisBook ) # handle any formatting and save the line
if haveLines:
if BibleOrgSysGlobals.verbosityLevel > 2: print( " MyBible loadBibleCommentaryBook saving", BBB )
self.stashBook( thisBook )
#else: print( "Not saving", BBB )
#if ourGlobals['haveParagraph']:
#thisBook.addLine( 'p', '' )
#ourGlobals['haveParagraph'] = False
# end of MyBibleBible.__loadBibleCommentaryBook
# end of MyBibleBible class
def createMyBibleModule( self, outputFolder, controlDict ):
"""
Create a SQLite3 database module for the Android program MyBible.
self here is a Bible object with _processedLines
"""
import zipfile
from USFM3Markers import OFTEN_IGNORED_USFM_HEADER_MARKERS, USFM_ALL_INTRODUCTION_MARKERS, USFM_BIBLE_PARAGRAPH_MARKERS, removeUSFMCharacterField, replaceUSFMCharacterFields
from InternalBibleInternals import BOS_ADDED_NESTING_MARKERS, BOS_NESTING_MARKERS
from theWordBible import theWordOTBookLines, theWordNTBookLines, theWordBookLines, theWordIgnoredIntroMarkers
def adjustLine( BBB, C, V, originalLine ):
"""
Handle pseudo-USFM markers within the line (cross-references, footnotes, and character formatting).
Parameters are the Scripture reference (for error messsages)
and the line (string) containing the backslash codes.
Returns a string with the backslash codes replaced by MyBible RTF formatting codes.
"""
line = originalLine # Keep a copy of the original line for error messages
if '\\x' in line: # Remove cross-references completely (why???)
#line = line.replace('\\x ','<RX>').replace('\\x*','<Rx>')
line = removeUSFMCharacterField( 'x', line, closedFlag=True ).lstrip() # Remove superfluous spaces
if '\\f' in line: # Handle footnotes
#print( "originalLine", repr(originalLine) )
while True: # fix internal footnote formatting
match = re.search( r"\\f (.+?)\\f\*", line )
if not match: break
#print( "line1", repr(line) )
#print( "1", match.group(1) )
adjNote = match.group(1).replace('\\fqa*','\\ft ').replace('\\nd*','\\ft ').replace('\\add*','\\ft ')
if '\\' in adjNote:
noteBits = adjNote.split( '\\' )
#print( "noteBits", noteBits )
newNote = ''
for noteBit in noteBits:
if noteBit in ( '+ ', '- ', '* ', '* ', ): pass # Just ignore these -- '* ' is for WEB
elif noteBit.startswith( '+ ' ): newNote += (' ' if newNote else '') + noteBit[2:]
elif noteBit.rstrip().isdigit(): pass # Just ignore footnote digits
elif noteBit.startswith( 'fr ' ): pass # Just ignore the origin markers (since we'll see the footnotes inline anyway)
elif noteBit.startswith( 'ft ' ): newNote += (' ' if newNote else '') + noteBit[3:]
elif noteBit.startswith( 'fq ' ): newNote += '<i>' + noteBit[3:] + '</i>'
elif noteBit.startswith( 'fqa ' ): newNote += '<i>' + noteBit[4:] + '</i>'
elif noteBit.startswith( 'nd ' ): newNote += noteBit[3:]
elif noteBit.startswith( 'add ' ): newNote += noteBit[4:]
elif noteBit.startswith( '+wj ' ): newNote += '<J>' + noteBit[4:]
elif noteBit.startswith( '+wj*' ): newNote += '</J>' + noteBit[4:]
else:
logging.error( "MyBible adjustLine: {} {!r} footnote field not handled properly yet.".format( self.abbreviation if self.abbreviation else self.name, noteBit[:3] ) )
newNote += '[[' + noteBit[3:] + ']]'
if BibleOrgSysGlobals.debuggingThisModule and debuggingThisModule: halt
else: newNote = adjNote # No backslash fields inside note
line = line[:match.start()] + '<n>' + newNote + '</n>' + line[match.end():]
#print( "line2", repr(line) )
#line = removeUSFMCharacterField( 'f', line, closedFlag=True ).lstrip() # Remove superfluous spaces
##for marker in ( 'fr', 'fm', ): # simply remove these whole field
##line = removeUSFMCharacterField( marker, line, closedFlag=None )
##for marker in ( 'fq', 'fqa', 'fl', 'fk', ): # italicise these ones
##while '\\'+marker+' ' in line:
###print( BBB, C, V, marker, line.count('\\'+marker+' '), line )
###print( "was", "'"+line+"'" )
##ix = line.find( '\\'+marker+' ' )
##assert ix != -1
##ixEnd = line.find( '\\', ix+len(marker)+2 )
##if ixEnd == -1: # no following marker so assume field stops at the end of the line
##line = line.replace( '\\'+marker+' ', '<i>' ) + '</i>'
##elif line[ixEnd:].startswith( '\\'+marker+'*' ): # replace the end marker also
##line = line.replace( '\\'+marker+' ', '<i>' ).replace( '\\'+marker+'*', '</i>' )
##else: # leave the next marker in place
##line = line[:ixEnd].replace( '\\'+marker+' ', '<i>' ) + '</i>' + line[ixEnd:]
##for marker in ( 'ft', ): # simply remove these markers (but leave behind the text field)
##line = line.replace( '\\'+marker+' ', '' ).replace( '\\'+marker+'*', '' )
###for caller in '+*abcdefghijklmnopqrstuvwxyz': line.replace('\\f '+caller+' ','<RF>') # Handle single-character callers
##line = re.sub( r'(\\f [a-z+*]{1,4} )', '<RF>', line ) # Handle one to three character callers
##line = line.replace('\\f ','<RF>').replace('\\f*','<Rf>') # Must be after the italicisation
###if '\\f' in originalLine:
###print( "o", originalLine )
###print( "n", line )
###halt
if '\\' in line: # Handle character formatting fields
line = removeUSFMCharacterField( 'fig', line, closedFlag=True ) # Remove figures
#line = removeUSFMCharacterField( 'str', line, closedFlag=True ) # Remove Strong's numbers
line = removeUSFMCharacterField( 'sem', line, closedFlag=True ) # Remove semantic tagging
replacements = (
( ('add',), '<i>','</i>' ),
( ('qt',), '','' ),
( ('wj',), '<J>','</J>' ),
( ('ca','va',), '(',')' ),
( ('bdit',), '<b><i>','</i></b>' ),
( ('bd','em','k',), '<b>','</b>' ),
( ('it','rq','bk','dc','qs','sig','sls','tl',), '<i>','</i>' ),
( ('nd','sc',), '','' ),
#( ('f',), '<n>','</n>' ),
( ('str',), '<S>','</S>' ),
)
line = replaceUSFMCharacterFields( replacements, line ) # This function also handles USFM 2.4 nested character markers
if '\\nd' not in originalLine and '\\+nd' not in originalLine:
line = line.replace('LORD', '<font size=-1>LORD</font>')
#line = line.replace('\\nd ','<font size=-1>',).replace('\\nd*','</font>').replace('\\+nd ','<font size=-1>',).replace('\\+nd*','</font>')
#else:
#line = line.replace('LORD', '<font size=-1>LORD</font>')
#line = line.replace('\\add ','<FI>').replace('\\add*','<Fi>').replace('\\+add ','<FI>').replace('\\+add*','<Fi>')
#line = line.replace('\\qt ','<FO>').replace('\\qt*','<Fo>').replace('\\+qt ','<FO>').replace('\\+qt*','<Fo>')
#line = line.replace('\\wj ','<FR>').replace('\\wj*','<Fr>').replace('\\+wj ','<FR>').replace('\\+wj*','<Fr>')
#if '\\' in line: # Output simple HTML tags (with no semantic info)
#line = line.replace('\\bdit ','<b><i>').replace('\\bdit*','</i></b>').replace('\\+bdit ','<b><i>').replace('\\+bdit*','</i></b>')
#for marker in ( 'it', 'rq', 'bk', 'dc', 'qs', 'sig', 'sls', 'tl', ): # All these markers are just italicised
#line = line.replace('\\'+marker+' ','<i>').replace('\\'+marker+'*','</i>').replace('\\+'+marker+' ','<i>').replace('\\+'+marker+'*','</i>')
#for marker in ( 'bd', 'em', 'k', ): # All these markers are just bolded
#line = line.replace('\\'+marker+' ','<b>').replace('\\'+marker+'*','</b>').replace('\\+'+marker+' ','<b>').replace('\\+'+marker+'*','</b>')
#line = line.replace('\\sc ','<font size=-1>',).replace('\\sc*','</font>').replace('\\+sc ','<font size=-1>',).replace('\\+sc*','</font>')
# Check what's left at the end
if '\\' in line:
logging.warning( "toMyBible.adjustLine: Doesn't handle formatted line yet: {} {}:{} {!r}".format( BBB, C, V, line ) )
if BibleOrgSysGlobals.debugFlag and debuggingThisModule:
print( "toMyBible.adjustLine: Doesn't handle formatted line yet: {} {}:{} {!r}".format( BBB, C, V, line ) )
halt
return line
# end of toMyBible.adjustLine
#def handleIntroduction( BBB, bookData, ourGlobals ):
#"""
#Go through the book introduction (if any) and extract main titles for MyBible export.
#Parameters are BBB (for error messages),
#the actual book data, and
#ourGlobals dictionary for persistent variables.
#Returns the information in a composed line string.
#"""
#C = V = 0
#composedLine = ''
#while True:
##print( "toMyBible.handleIntroduction", BBB, C, V )
#try: result = bookData.getContextVerseData( (BBB,'0',str(V),) ) # Currently this only gets one line
#except KeyError: break # Reached the end of the introduction
#verseData, context = result
#assert len(verseData ) == 1 # in the introductory section
#marker, text = verseData[0].getMarker(), verseData[0].getFullText()
#if marker not in theWordIgnoredIntroMarkers and '¬' not in marker and marker not in BOS_ADDED_NESTING_MARKERS: # don't need added markers here either
#if marker in ('mt1','mte1',): composedLine += '<TS1>'+adjustLine(BBB,C,V,text)+'<Ts><pb/>'
#elif marker in ('mt2','mte2',): composedLine += '<TS2>'+adjustLine(BBB,C,V,text)+'<Ts><pb/>'
#elif marker in ('mt3','mte3',): composedLine += '<TS3>'+adjustLine(BBB,C,V,text)+'<Ts><pb/>'
#elif marker in ('mt4','mte4',): composedLine += '<TS3>'+adjustLine(BBB,C,V,text)+'<Ts><pb/>'
#elif marker=='ms1': composedLine += '<TS2>'+adjustLine(BBB,C,V,text)+'<Ts><pb/>'
#elif marker in ('ms2','ms3','ms4'): composedLine += '<TS3>'+adjustLine(BBB,C,V,text)+'<Ts><pb/>'
#elif marker=='mr': composedLine += '<TS3>'+adjustLine(BBB,C,V,text)+'<Ts><pb/>'
#else:
#logging.warning( "toMyBible.handleIntroduction: doesn't handle {} {!r} yet".format( BBB, marker ) )
#if BibleOrgSysGlobals.debugFlag and debuggingThisModule:
#print( "toMyBible.handleIntroduction: doesn't handle {} {!r} yet".format( BBB, marker ) )
#halt
#ourGlobals['unhandledMarkers'].add( marker + ' (in intro)' )
#V += 1 # Step to the next introductory section "verse"
## Check what's left at the end
#if '\\' in composedLine:
#logging.warning( "toMyBible.handleIntroduction: Doesn't handle formatted line yet: {} {!r}".format( BBB, composedLine ) )
#if BibleOrgSysGlobals.debugFlag and debuggingThisModule:
#print( "toMyBible.handleIntroduction: Doesn't handle formatted line yet: {} {!r}".format( BBB, composedLine ) )
#halt
#return composedLine.replace( '~^~', '\\' )
## end of toMyBible.handleIntroduction
def composeVerseLine( BBB, C, V, verseData, ourGlobals ):
"""
Composes a single line representing a verse.
Parameters are the Scripture reference (for error messages),
the verseData (a list of InternalBibleEntries: pseudo-USFM markers and their contents),
and a ourGlobals dictionary for holding persistent variables (between calls).
This function handles the paragraph/new-line markers;
adjustLine (above) is called to handle internal/character markers.
Returns the composed line.
"""
#if BibleOrgSysGlobals.debugFlag and debuggingThisModule:
#print( "toMyBible.composeVerseLine( {} {}:{} {} {}".format( BBB, C, V, verseData, ourGlobals ) )
composedLine = ourGlobals['line'] # We might already have some book headings to precede the text for this verse
ourGlobals['line'] = '' # We've used them so we don't need them any more
#marker = text = None
vCount = 0
lastMarker = gotVP = None
#if BBB=='MAT' and C==4 and 14<V<18: print( BBB, C, V, ourGlobals, verseData )
for verseDataEntry in verseData:
marker, text = verseDataEntry.getMarker(), verseDataEntry.getFullText()
if '¬' in marker or marker in BOS_ADDED_NESTING_MARKERS: continue # Just ignore added markers -- not needed here
if marker in ('c','c#','cl','cp','rem',): lastMarker = marker; continue # ignore all of these for this
if marker == 'vp#': # This precedes a v field and has the verse number to be printed
gotVP = text # Just remember it for now
elif marker == 'v': # handle versification differences here
vCount += 1
if vCount == 1: # Handle verse bridges
if text != str(V):
composedLine += '<sup>('+adjustLine(BBB,C,V,text)+')</sup> ' # Put the additional verse number into the text in parenthesis
elif vCount > 1: # We have an additional verse number
if BibleOrgSysGlobals.debugFlag and debuggingThisModule: assert text != str(V)
composedLine += ' <sup>('+adjustLine(BBB,C,V,text)+')</sup>' # Put the additional verse number into the text in parenthesis
lastMarker = marker
continue
#print( "toMyBible.composeVerseLine:", BBB, C, V, marker, text )
if marker in theWordIgnoredIntroMarkers:
logging.error( "toMyBible.composeVerseLine: Found unexpected {} introduction marker at {} {}:{} {}".format( marker, BBB, C, V, repr(text) ) )
print( "toMyBible.composeVerseLine:", BBB, C, V, marker, text, verseData )
if BibleOrgSysGlobals.debugFlag and debuggingThisModule:
assert marker not in theWordIgnoredIntroMarkers # these markers shouldn't occur in verses
if marker == 'ms1':
pass #composedLine += '<TS2>'+adjustLine(BBB,C,V,text)+'<Ts><pb/>'
elif marker in ('ms2','ms3','ms4'):
pass #composedLine += '<TS3>'+adjustLine(BBB,C,V,text)+'<Ts><pb/>'
elif marker == 's1':
if ourGlobals['lastLine'] is not None and not composedLine: # i.e., don't do it for the very first line
ourGlobals['lastLine'] = ourGlobals['lastLine'].rstrip() + '<pb/>' # append the new paragraph marker to the previous line
composedLine += '<br/><t>'+adjustLine(BBB,C,V,text)+'</t><br/>'
#elif marker == 's2': composedLine += '~^~b~^~i~^~f0 '+adjustLine(BBB,C,V,text)+'~^~cf0~^~b0~^~i0<pb/>'
elif marker in ( 's2', 's3','s4', 'sr','mr', 'd', ): composedLine += '<t>'+adjustLine(BBB,C,V,text)+'</t>'
elif marker in ( 'qa', 'r', ):
if marker=='r' and text and text[0]!='(' and text[-1]!=')': # Put parenthesis around this if not already there
text = '(' + text + ')'
composedLine += '<br/><t>'+adjustLine(BBB,C,V,text)+'</t><br/>'
elif marker in ( 'm', ):
assert not text
if ourGlobals['lastLine'] is not None and not composedLine: # i.e., don't do it for the very first line
ourGlobals['lastLine'] = ourGlobals['lastLine'].rstrip() + '<pb/>' # append the new paragraph marker to the previous line
#if text: