Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Sigil

Notices

Reply
 
Thread Tools Search this Thread
Old 04-07-2025, 04:58 PM   #91
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
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:
Originally Posted by BeckyEbook View Post
The functions have potential, but I have trouble debugging them.
"print" or trying to save information to an external debug file does not work.

If I need any "output" I am helpless.
What can I do?

I checked in Calibre and there is a special window with results, so that such a function works.

There are certainly people who are able to write a working function right away. I like to test my solutions, so "print" is my friend.
KevinH is online now   Reply With Quote
Old 04-08-2025, 02:11 AM   #92
BeckyEbook
Guru
BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.
 
BeckyEbook's Avatar
 
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")
BeckyEbook is offline   Reply With Quote
Advert
Old 04-08-2025, 08:33 AM   #93
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 8,761
Karma: 5706256
Join Date: Nov 2009
Device: many
That should work. Did it create the proper log file?
KevinH is online now   Reply With Quote
Old 04-08-2025, 08:52 AM   #94
BeckyEbook
Guru
BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.
 
BeckyEbook's Avatar
 
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.
BeckyEbook is offline   Reply With Quote
Old 04-08-2025, 09:15 AM   #95
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 8,761
Karma: 5706256
Join Date: Nov 2009
Device: many
Quote:
Originally Posted by BeckyEbook View Post
No file is created. Absolutely nothing. I checked all drives by the way, including all TEMP folders.
Okay I will take what you wrote and make it a library function where the path to the log file to be created is set by an environment variable. That way it is invokable more easily from within a user's replace function.

Once I get something working, I will push it to master so you can test.
KevinH is online now   Reply With Quote
Advert
Old 04-08-2025, 12:44 PM   #96
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
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.
KevinH is online now   Reply With Quote
Old 04-08-2025, 01:30 PM   #97
BeckyEbook
Guru
BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.
 
BeckyEbook's Avatar
 
Posts: 839
Karma: 2657572
Join Date: Jan 2017
Location: Poland
Device: Various
It works! Thank you!
BeckyEbook is offline   Reply With Quote
Old 04-09-2025, 09:45 AM   #98
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 8,761
Karma: 5706256
Join Date: Nov 2009
Device: many
Quote:
Originally Posted by BeckyEbook View Post
It works! Thank you!
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.
KevinH is online now   Reply With Quote
Reply


Forum Jump

Similar Threads
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


All times are GMT -4. The time now is 08:30 AM.


MobileRead.com is a privately owned, operated and funded community.