![]() |
#91 | |
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 8,761
Karma: 5706256
Join Date: Nov 2009
Device: many
|
Hi BeckyEbook,
I will look into that. I did add a new Sigil Error box that allows full expansion to see any python exceptions and debug output if a runtime error happens. But if no runtime error happens, then no output will be shown. You should always be able to redirect all python print output to a file at a fixed path no matter what. Have you tried redirecting python std out to a file? Is the file empty? Did you use a hard coded path? I may be able to create a log ability of some sort stored in the python function context that the C++ side creates. I will try playing around with it a bit to see. Kevin Quote:
|
|
![]() |
![]() |
![]() |
#92 |
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 839
Karma: 2657572
Join Date: Jan 2017
Location: Poland
Device: Various
|
I tried something like this:
Code:
debug_file_name = "function_debug" home = os.path.expanduser('~') if os.path.isdir(os.path.join(home, 'Desktop\\Becky')): log_file_name = os.path.join(home, 'Desktop\\Becky', debug_file_name + '.log') else: log_file_name = os.path.join(home, debug_file_name + '_' + '.log') def log_message(message): print(message) with open(log_file_name, "a", encoding="utf-8") as f: f.write(message + "\n") |
![]() |
![]() |
Advert | |
|
![]() |
#93 |
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 8,761
Karma: 5706256
Join Date: Nov 2009
Device: many
|
That should work. Did it create the proper log file?
|
![]() |
![]() |
![]() |
#94 |
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 839
Karma: 2657572
Join Date: Jan 2017
Location: Poland
Device: Various
|
No file is created. Absolutely nothing. I checked all drives by the way, including all TEMP folders.
|
![]() |
![]() |
![]() |
#95 | |
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 8,761
Karma: 5706256
Join Date: Nov 2009
Device: many
|
Quote:
Once I get something working, I will push it to master so you can test. |
|
![]() |
![]() |
Advert | |
|
![]() |
#96 |
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 8,761
Karma: 5706256
Join Date: Nov 2009
Device: many
|
@BeckyEbook
Here is a proof of concept adapting your approach to using just an environment variable to determine the full absolute path to the desired log file. Code:
diff --git a/src/Resource_Files/python3lib/functionrep.py b/src/Resource_Files/python3lib/functionrep.py index 3a0aca2ca..d61f85e3a 100644 --- a/src/Resource_Files/python3lib/functionrep.py +++ b/src/Resource_Files/python3lib/functionrep.py @@ -1,4 +1,5 @@ import re +import os from fr_utils import unescapeit, toUpper, toLower, swapcase, capitalize @@ -114,3 +115,10 @@ def replace_titlecase_ignore_tags(match, number, file_name, metadata, data, *arg def replace_swapcase_ignore_tags(match, number, file_name, metadata, data, *args, **kwargs): '''Swap the case of the matched text, ignoring the text inside tag definitions.''' return apply_func_to_html_text(match, swapcase) + + +def replace_debug_log(message): + logfile = os.environ.get('SIGIL_FUNCTION_REPLACE_LOG_FILE', None); + if logfile: + with open(logfile, "a", encoding="utf-8") as f: + f.write(message) diff --git a/src/Resource_Files/python3lib/functionsearch.py b/src/Resource_Files/python3lib/functionsearch.py index 958b0787f..104211341 100644 --- a/src/Resource_Files/python3lib/functionsearch.py +++ b/src/Resource_Files/python3lib/functionsearch.py @@ -124,6 +124,7 @@ class FunctionSearch(object): global replace_capitalize_ignore_tags global replace_titlecase_ignore_tags global replace_swapcase_ignore_tags + global replace_debug_log self.metadataxml = metadataxml self.function_name = function_name @@ -157,6 +158,7 @@ class FunctionSearch(object): try: result=self.replace(match,self.number,self.bookpath,self.metadataxml,self.funcData) except Exception as e: + replace_debug_log(str(e)) print(e) return result @@ -175,6 +177,7 @@ class FunctionSearch(object): try: result=self.replace(match,self.number,self.bookpath,self.metadataxml,self.funcData) except Exception as e: + replace_debug_log(str(e)) print(e) return result Then to use it inside your replace function first set the environment variable: export SIGIL_FUNCTION_REPLACE_LOG_FILE=/Users/kbhend/Desktop/junk.txt Then in your replace routine you can now use the replace_debug_log routine. Code:
def replace(match, number, file_name, metadata, data): if match: replace_debug_log("I am here with number " + str(number) + "\n") return match.group(0) Please give this a try in your own build of Sigil. If that works, I will try to refine this approach using redirecting of sys.stdout and sys.stderr behind the scenes if I can. |
![]() |
![]() |
![]() |
#97 |
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 839
Karma: 2657572
Join Date: Jan 2017
Location: Poland
Device: Various
|
It works! Thank you!
|
![]() |
![]() |
![]() |
#98 |
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 8,761
Karma: 5706256
Join Date: Nov 2009
Device: many
|
Great! I tried to redirect stdout but it fails since there is no way to know when the last replacement is being done by the user in advance so there is no way to put stdout back where it belongs (using the python __del__ method will not always work since it waits until garbage collection happens).
So I will push this version to master. |
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Improvements/bugs/features | dontcrash | KOReader | 10 | 10-23-2019 10:05 AM |
Touch HD, Future features or dead features? | ElWorm | PocketBook | 4 | 02-07-2018 11:36 AM |
[FREE]Innovative Ideas to Ignite Your Mind: Business Ideas to Start Entrepreneurship | amazon author | Self-Promotions by Authors and Publishers | 0 | 04-01-2015 04:09 AM |
How many 'improvements' do we really need? | Fozzybear | General Discussions | 61 | 04-15-2012 12:38 PM |
ideas for calibre features | smarties86 | Recipes | 3 | 07-01-2011 10:23 AM |