convert docstrings comments (extra-edit)

This commit is contained in:
un-pogaz 2025-01-24 11:14:21 +01:00
parent 0ce6645f15
commit b2c90ff460
20 changed files with 225 additions and 275 deletions

View File

@ -111,13 +111,11 @@ class Bookmark: # {{{
# Switch location to start (0x08:0x0c)
start, = unpack('>I', data[eo+8:eo+12])
user_notes[start] = user_notes[end_loc]
'''
print(" %s: swapping 0x%x (%d) to 0x%x (%d)" % (user_notes[end_loc]['type'],
end_loc,
end_loc/MAGIC_MOBI_CONSTANT + 1,
start,
start//MAGIC_MOBI_CONSTANT + 1))
'''
# print(" %s: swapping 0x%x (%d) to 0x%x (%d)" % (user_notes[end_loc]['type'],
# end_loc,
# end_loc/MAGIC_MOBI_CONSTANT + 1,
# start,
# start//MAGIC_MOBI_CONSTANT + 1))
user_notes[start]['displayed_location'] = start // MAGIC_MOBI_CONSTANT + 1
user_notes.pop(end_loc)
else:
@ -225,37 +223,36 @@ class Bookmark: # {{{
e_base = 0x0d
self.pdf_page_offset = 0
while current_entry < entries:
'''
location, = unpack('>I', data[e_base+2:e_base+6])
text = None
text_len, = unpack('>I', data[e_base+0xA:e_base+0xE])
e_type, = unpack('>B', data[e_base+1])
if e_type == 0:
e_type = 'Bookmark'
elif e_type == 1:
e_type = 'Highlight'
text = get_topaz_highlight(location/MAGIC_TOPAZ_CONSTANT + 1)
elif e_type == 2:
e_type = 'Note'
text = data[e_base+0x10:e_base+0x10+text_len]
else:
e_type = 'Unknown annotation type'
# location, = unpack('>I', data[e_base+2:e_base+6])
# text = None
# text_len, = unpack('>I', data[e_base+0xA:e_base+0xE])
# e_type, = unpack('>B', data[e_base+1])
# if e_type == 0:
# e_type = 'Bookmark'
# elif e_type == 1:
# e_type = 'Highlight'
# text = get_topaz_highlight(location/MAGIC_TOPAZ_CONSTANT + 1)
# elif e_type == 2:
# e_type = 'Note'
# text = data[e_base+0x10:e_base+0x10+text_len]
# else:
# e_type = 'Unknown annotation type'
#
# if self.book_format in ['tpz','azw1']:
# displayed_location = location/MAGIC_TOPAZ_CONSTANT + 1
# elif self.book_format == 'pdf':
# # *** This needs implementation
# displayed_location = location
# user_notes[location] = dict(id=self.id,
# displayed_location=displayed_location,
# type=e_type,
# text=text)
# if text_len == 0xFFFFFFFF:
# e_base = e_base + 14
# else:
# e_base = e_base + 14 + 2 + text_len
# current_entry += 1
if self.book_format in ['tpz','azw1']:
displayed_location = location/MAGIC_TOPAZ_CONSTANT + 1
elif self.book_format == 'pdf':
# *** This needs implementation
displayed_location = location
user_notes[location] = dict(id=self.id,
displayed_location=displayed_location,
type=e_type,
text=text)
if text_len == 0xFFFFFFFF:
e_base = e_base + 14
else:
e_base = e_base + 14 + 2 + text_len
current_entry += 1
'''
# Use label as page number
pdf_location, = unpack('>I', data[e_base+1:e_base+5])
label_len, = unpack('>H', data[e_base+5:e_base+7])

View File

@ -319,36 +319,34 @@ class NEXTBOOK(USBMS):
SUPPORTS_SUB_DIRS = True
THUMBNAIL_HEIGHT = 120
'''
def upload_cover(self, path, filename, metadata, filepath):
if metadata.thumbnail and metadata.thumbnail[-1]:
path = path.replace('/', os.sep)
is_main = path.startswith(self._main_prefix)
prefix = None
if is_main:
prefix = self._main_prefix
else:
if self._card_a_prefix and \
path.startswith(self._card_a_prefix):
prefix = self._card_a_prefix
elif self._card_b_prefix and \
path.startswith(self._card_b_prefix):
prefix = self._card_b_prefix
if prefix is None:
prints('WARNING: Failed to find prefix for:', filepath)
return
thumbnail_dir = os.path.join(prefix, '.Cover')
relpath = os.path.relpath(filepath, prefix)
if relpath.startswith('..\\'):
relpath = relpath[3:]
thumbnail_dir = os.path.join(thumbnail_dir, relpath)
if not os.path.exists(thumbnail_dir):
os.makedirs(thumbnail_dir)
with open(os.path.join(thumbnail_dir, filename+'.jpg'), 'wb') as f:
f.write(metadata.thumbnail[-1])
fsync(f)
'''
# def upload_cover(self, path, filename, metadata, filepath):
# if metadata.thumbnail and metadata.thumbnail[-1]:
# path = path.replace('/', os.sep)
# is_main = path.startswith(self._main_prefix)
# prefix = None
# if is_main:
# prefix = self._main_prefix
# else:
# if self._card_a_prefix and \
# path.startswith(self._card_a_prefix):
# prefix = self._card_a_prefix
# elif self._card_b_prefix and \
# path.startswith(self._card_b_prefix):
# prefix = self._card_b_prefix
# if prefix is None:
# prints('WARNING: Failed to find prefix for:', filepath)
# return
# thumbnail_dir = os.path.join(prefix, '.Cover')
#
# relpath = os.path.relpath(filepath, prefix)
# if relpath.startswith('..\\'):
# relpath = relpath[3:]
# thumbnail_dir = os.path.join(thumbnail_dir, relpath)
# if not os.path.exists(thumbnail_dir):
# os.makedirs(thumbnail_dir)
# with open(os.path.join(thumbnail_dir, filename+'.jpg'), 'wb') as f:
# f.write(metadata.thumbnail[-1])
# fsync(f)
class MOOVYBOOK(USBMS):

View File

@ -161,15 +161,13 @@ class Delegator:
for m in methods:
setattr(self, m, getattr(d, m))
'''
for setting in d.getSettings():
if isinstance(setting, string_or_bytes):
setting = (d, setting)
delegates = \
self.delegatedSettingsDict.setdefault(setting[1], [])
delegates.append(setting[0])
self.delegatedSettings.append(setting)
'''
# for setting in d.getSettings():
# if isinstance(setting, string_or_bytes):
# setting = (d, setting)
# delegates = \
# self.delegatedSettingsDict.setdefault(setting[1], [])
# delegates.append(setting[0])
# self.delegatedSettings.append(setting)
def applySetting(self, name, value, testValid=False):
applied = False
@ -193,13 +191,11 @@ class Delegator:
def applySettings(self, settings, testValid=False):
for (setting, value) in settings.items():
self.applySetting(setting, value, testValid)
'''
if setting not in self.delegatedSettingsDict:
raise LrsError("setting %s not valid" % setting)
delegates = self.delegatedSettingsDict[setting]
for d in delegates:
setattr(d, setting, value)
'''
# if setting not in self.delegatedSettingsDict:
# raise LrsError("setting %s not valid" % setting)
# delegates = self.delegatedSettingsDict[setting]
# for d in delegates:
# setattr(d, setting, value)
def appendDelegates(self, element, sourceEncoding):
for d in self.delegates:

View File

@ -166,28 +166,26 @@ class Colors:
if the_index > -1:
line = re.sub(self.__line_color_exp, self.__sub_from_line_color, line)
self.__write_obj.write(line)
'''
if num == 0:
hex_num = 'false'
else:
hex_num = self.__color_dict.get(num)
if hex_num == None:
if self.__run_level > 0:
sys.stderr.write(
'module is colors.py\n'
'function is self.__after_color_func\n'
'no value in self.__color_dict for key %s\n' % num
)
if self.__run_level > 3:
sys.stderr.write(
'run level is %s\n'
'Script will now quit\n'
% self.__run_level)
else:
self.__write_obj.write(
'cw<ci<font-color<nu<%s\n' % hex_num
)
'''
# if num == 0:
# hex_num = 'false'
# else:
# hex_num = self.__color_dict.get(num)
# if hex_num == None:
# if self.__run_level > 0:
# sys.stderr.write(
# 'module is colors.py\n'
# 'function is self.__after_color_func\n'
# 'no value in self.__color_dict for key %s\n' % num
# )
# if self.__run_level > 3:
# sys.stderr.write(
# 'run level is %s\n'
# 'Script will now quit\n'
# % self.__run_level)
# else:
# self.__write_obj.write(
# 'cw<ci<font-color<nu<%s\n' % hex_num
# )
else:
self.__write_obj.write(line)
# cw<bd<bor-par-to<nu<bdr-hair__|bdr-li-wid:0.50|bdr-sp-wid:1.00|bdr-color_:2

View File

@ -150,10 +150,7 @@ file.
self.__state = 'body'
type = 'bookmark-%s' % self.__type_of_bookmark
# change here
'''
my_string = self.__string_obj.process_string(
self.__text_string, type)
'''
# my_string = self.__string_obj.process_string(self.__text_string, type)
my_string = self.__parse_bookmark_func(
self.__text_string, type)
self.__write_obj.write(self.__marker)

View File

@ -107,11 +107,8 @@ class GetOptions:
return_options['out-file'] = options['output']
else:
pass
'''
sys.stderr.write(
'You must provide an output file with the \'o\' option\n')
return_options['valid'] = 0
'''
# sys.stderr.write("You must provide an output file with the 'o' option\n")
# return_options['valid'] = 0
if 'level' in the_keys:
return_options['level'] = options['level']
the_level = return_options.get('level')
@ -225,14 +222,12 @@ class GetOptions:
else:
return_options['out-file'] = '%s.xml' % the_file_name
if not smart_output and not return_options['out-file']:
'''
sys.stderr.write(
'Please provide and file to output with the -o option.\n'
'Or set \'<smart-output value = "true"/>\'.\n'
'in the configuration file.\n'
)
return_options['valid'] = 0
'''
# sys.stderr.write(
# 'Please provide and file to output with the -o option.\n'
# 'Or set \'<smart-output value = "true"/>\'.\n'
# 'in the configuration file.\n'
# )
# return_options['valid'] = 0
pass
if 'indent' in the_keys:
try:
@ -242,28 +237,26 @@ class GetOptions:
sys.stderr.write('--indent must take an integer')
return_options['valid'] = 0
# check for format and pyxml
'''
the_format = return_options.get('format')
if the_format != 'raw':
no_pyxml = return_options.get('no-pyxml')
if no_pyxml:
sys.stderr.write('You want to convert your file to "%s".\n'
'Sorry, but you must have pyxml installed\n'
'in order to convert your document to anything but raw XML.\n'
'Please do not use the --format option.\n\n'
% the_format
)
return_options['valid'] = 0
xslt_proc = return_options.get('xslt-processor')
if xslt_proc == None and not no_pyxml:
sys.stderr.write('You want to convert your file to "%s".\n'
'Sorry, but you must have an xslt processor set up\n'
'in order to conevert your document to anything but raw XML.\n'
'Please use --format raw.\n\n'
% the_format
)
return_options['valid'] = 0
'''
# the_format = return_options.get('format')
# if the_format != 'raw':
# no_pyxml = return_options.get('no-pyxml')
# if no_pyxml:
# sys.stderr.write('You want to convert your file to "%s".\n'
# 'Sorry, but you must have pyxml installed\n'
# 'in order to convert your document to anything but raw XML.\n'
# 'Please do not use the --format option.\n\n'
# % the_format
# )
# return_options['valid'] = 0
# xslt_proc = return_options.get('xslt-processor')
# if xslt_proc == None and not no_pyxml:
# sys.stderr.write('You want to convert your file to "%s".\n'
# 'Sorry, but you must have an xslt processor set up\n'
# 'in order to conevert your document to anything but raw XML.\n'
# 'Please use --format raw.\n\n'
# % the_format
# )
# return_options['valid'] = 0
return return_options
def __get_config_options(self):

View File

@ -568,22 +568,20 @@ class Hex2Utf8:
self.__convert_body()
'''
how to swap case for non-capitals
my_string.swapcase()
An example of how to use a hash for the caps function
(but I shouldn't need this, since utf text is separate
from regular text?)
sub_dict = {
"&#x0430;" : "some other value"
}
def my_sub_func(matchobj):
info = matchobj.group(0)
value = sub_dict.get(info)
return value
return "f"
line = "&#x0430; more text"
reg_exp = re.compile(r'(?P<name>&#x0430;|&#x0431;)')
line2 = re.sub(reg_exp, my_sub_func, line)
print line2
'''
# how to swap case for non-capitals
# my_string.swapcase()
# An example of how to use a hash for the caps function
# (but I shouldn't need this, since utf text is separate
# from regular text?)
# sub_dict = {
# "&#x0430;" : "some other value"
# }
# def my_sub_func(matchobj):
# info = matchobj.group(0)
# value = sub_dict.get(info)
# return value
# return "f"
# line = "&#x0430; more text"
# reg_exp = re.compile(r'(?P<name>&#x0430;|&#x0431;)')
# line2 = re.sub(reg_exp, my_sub_func, line)
# print line2

View File

@ -209,15 +209,13 @@ class Inline:
if name:
self.__inline_list[-1]['contains_inline'] = 1
self.__inline_list[-1][name] = char_value
'''
if name == 'font-style':
if char_value == 'Symbol':
self.__write_obj.write('mi<mk<font-symbo\n')
elif char_value == 'Wingdings':
self.__write_obj.write('mi<mk<font-wingd\n')
elif char_value == 'Zapf Dingbats':
self.__write_obj.write('mi<mk<font-dingb\n')
'''
# if name == 'font-style':
# if char_value == 'Symbol':
# self.__write_obj.write('mi<mk<font-symbo\n')
# elif char_value == 'Wingdings':
# self.__write_obj.write('mi<mk<font-wingd\n')
# elif char_value == 'Zapf Dingbats':
# self.__write_obj.write('mi<mk<font-dingb\n')
def __close_bracket_func(self, line):
'''

View File

@ -119,11 +119,9 @@ class ListNumbers:
text_string = text_string.replace(')', '')
if text_string.isdigit():
return 'ordered'
'''
sys.stderr.write('module is list_numbers\n')
sys.stderr.write('method is __determine type\n')
sys.stderr.write('Couldn\'t get type of list\n')
'''
# sys.stderr.write('module is list_numbers\n')
# sys.stderr.write('method is __determine type\n')
# sys.stderr.write('Couldn\'t get type of list\n')
# must be some type of ordered list -- just a guess!
return 'unordered'

View File

@ -68,14 +68,12 @@ class ListTable:
'cw<ci<bold______' : 'bold',
'cw<ss<para-style' : 'paragraph-style-name',
}
'''
all_lists =
[{anything here?}
[{list-templateid = ""}
[{level-indent}],[{level-indent}]
]
],
'''
# all_lists =
# [{anything here?}
# [{list-templateid = ""}
# [{level-indent}],[{level-indent}]
# ]
# ],
def __parse_lines(self, line):
'''
@ -229,14 +227,12 @@ class ListTable:
self.__level_numbers_string += '\\&#x0027;%s' % line[18:]
elif self.__token_info == 'tx<nu<__________':
self.__level_numbers_string += line[17:]
'''
num = line[18:]
num = int(num, 16)
level = str(round((num - 1)/2, 0))
level = level[:-2]
level = 'level%s-show-level' % level
self.__all_lists[-1][-1][0][level] = 'true'
'''
# num = line[18:]
# num = int(num, 16)
# level = str(round((num - 1)/2, 0))
# level = level[:-2]
# level = 'level%s-show-level' % level
# self.__all_lists[-1][-1][0][level] = 'true'
def __level_text_func(self, line):
'''

View File

@ -282,7 +282,5 @@ if __name__ == '__main__':
)
options, the_args = test_obj.parse_options()
print(options, the_args)
'''
this_options = ['--foo', '-o']
this_opt_with_args = ['--foo']
'''
# this_options = ['--foo', '-o']
# this_opt_with_args = ['--foo']

View File

@ -674,15 +674,12 @@ if another paragraph_def is found, the state changes to collect_tokens.
self.__write_obj.write('mi<tg<open-att__<paragraph-definition')
self.__write_obj.write('<name>%s' % self.__att_val_dict['name'])
self.__write_obj.write('<style-number>%s' % self.__att_val_dict['style-num'])
tabs_list = ['tabs-left', 'tabs-right', 'tabs-decimal', 'tabs-center',
'tabs-bar', 'tabs']
'''
for tab_item in tabs_list:
if self.__att_val_dict[tab_item] != '':
the_value = self.__att_val_dict[tab_item]
the_value = the_value[:-1]
self.__write_obj.write('<%s>%s' % (tab_item, the_value))
'''
tabs_list = ['tabs-left', 'tabs-right', 'tabs-decimal', 'tabs-center', 'tabs-bar', 'tabs']
# for tab_item in tabs_list:
# if self.__att_val_dict[tab_item] != '':
# the_value = self.__att_val_dict[tab_item]
# the_value = the_value[:-1]
# self.__write_obj.write('<%s>%s' % (tab_item, the_value))
if self.__att_val_dict['tabs'] != '':
the_value = self.__att_val_dict['tabs']
# the_value = the_value[:-1]

View File

@ -115,11 +115,9 @@ class Pict:
has not already been created.) Set the self.__in_pict flag to true.
If the line does not contain pict data, return 1
'''
'''
$pict_count++;
$pict_count = sprintf("%03d", $pict_count);
print OUTPUT "dv<xx<em<nu<pict<at<num>$pict_count\n";
'''
# $pict_count++;
# $pict_count = sprintf("%03d", $pict_count);
# print OUTPUT "dv<xx<em<nu<pict<at<num>$pict_count\n";
if self.__token_info == 'cw<gr<picture___':
self.__pict_count += 1
# write_obj.write("mi<tg<em<at<pict<num>%03d\n" % self.__pict_count)

View File

@ -191,15 +191,13 @@ class PreambleDiv:
'''
If not font table is found, make a string for a default one
'''
'''
self.__style_sheet_final = 'mi<tg<open______<style-table\n'
self.__style_sheet_final +=
self.__style_sheet_final +=
self.__style_sheet_final +=
self.__style_sheet_final +=
self.__style_sheet_final +=
self.__style_sheet_final += 'mi<tg<close_____<style-table\n'
'''
# self.__style_sheet_final = 'mi<tg<open______<style-table\n'
# self.__style_sheet_final +=
# self.__style_sheet_final +=
# self.__style_sheet_final +=
# self.__style_sheet_final +=
# self.__style_sheet_final +=
# self.__style_sheet_final += 'mi<tg<close_____<style-table\n'
self.__style_sheet_final = '''mi<tg<open______<style-table
mi<mk<styles-beg
mi<mk<stylei-beg

View File

@ -585,31 +585,29 @@ class ProcessTokens:
1024 : 'Unkown',
255 : 'Unkown',
}
'''
# unknown
# These must get passed on because they occurred after \\*
'do' : ('un', 'unknown___', self.default_func),
'company' : ('un', 'company___', self.default_func),
'shpinst' : ('un', 'unknown___', self.default_func),
'panose' : ('un', 'unknown___', self.default_func),
'falt' : ('un', 'unknown___', self.default_func),
'listoverridetable' : ('un', 'unknown___', self.default_func),
'category' : ('un', 'unknown___', self.default_func),
'template' : ('un', 'unknown___', self.default_func),
'ud' : ('un', 'unknown___', self.default_func),
'formfield' : ('un', 'unknown___', self.default_func),
'ts' : ('un', 'unknown___', self.default_func),
'rsidtbl' : ('un', 'unknown___', self.default_func),
'generator' : ('un', 'unknown___', self.default_func),
'ftnsep' : ('un', 'unknown___', self.default_func),
'aftnsep' : ('un', 'unknown___', self.default_func),
'aftnsepc' : ('un', 'unknown___', self.default_func),
'aftncn' : ('un', 'unknown___', self.default_func),
'objclass' : ('un', 'unknown___', self.default_func),
'objdata' : ('un', 'unknown___', self.default_func),
'picprop' : ('un', 'unknown___', self.default_func),
'blipuid' : ('un', 'unknown___', self.default_func),
'''
# 'do' : ('un', 'unknown___', self.default_func),
# 'company' : ('un', 'company___', self.default_func),
# 'shpinst' : ('un', 'unknown___', self.default_func),
# 'panose' : ('un', 'unknown___', self.default_func),
# 'falt' : ('un', 'unknown___', self.default_func),
# 'listoverridetable' : ('un', 'unknown___', self.default_func),
# 'category' : ('un', 'unknown___', self.default_func),
# 'template' : ('un', 'unknown___', self.default_func),
# 'ud' : ('un', 'unknown___', self.default_func),
# 'formfield' : ('un', 'unknown___', self.default_func),
# 'ts' : ('un', 'unknown___', self.default_func),
# 'rsidtbl' : ('un', 'unknown___', self.default_func),
# 'generator' : ('un', 'unknown___', self.default_func),
# 'ftnsep' : ('un', 'unknown___', self.default_func),
# 'aftnsep' : ('un', 'unknown___', self.default_func),
# 'aftnsepc' : ('un', 'unknown___', self.default_func),
# 'aftncn' : ('un', 'unknown___', self.default_func),
# 'objclass' : ('un', 'unknown___', self.default_func),
# 'objdata' : ('un', 'unknown___', self.default_func),
# 'picprop' : ('un', 'unknown___', self.default_func),
# 'blipuid' : ('un', 'unknown___', self.default_func),
def __ms_hex_func(self, pre, token, num):
num = num[1:] # chop off leading 0, which I added

View File

@ -427,12 +427,12 @@ class Sections:
'''
# change this 2004-04-26
# Don't do anything
'''
self.__sec_in_field_string += line
self.__print_field_sec_attributes()
self.__write_obj.write(self.__sec_in_field_string)
self.__print_field_sec_attributes()
'''
#
# self.__sec_in_field_string += line
# self.__print_field_sec_attributes()
# self.__write_obj.write(self.__sec_in_field_string)
# self.__print_field_sec_attributes()
self.__state = 'body'
self.__in_field = 0
# this is changed too

View File

@ -460,13 +460,11 @@ class Styles:
'''
self.__type_of_style = 'par'
self.__styles_num = line[20:-1]
'''
self.__enter_dict_entry('tabs-left', '')
self.__enter_dict_entry('tabs-right', '')
self.__enter_dict_entry('tabs-center', '')
self.__enter_dict_entry('tabs-decimal', '')
self.__enter_dict_entry('tabs-bar', '')
'''
# self.__enter_dict_entry('tabs-left', '')
# self.__enter_dict_entry('tabs-right', '')
# self.__enter_dict_entry('tabs-center', '')
# self.__enter_dict_entry('tabs-decimal', '')
# self.__enter_dict_entry('tabs-bar', '')
def __char_style_func(self, line):
'''

View File

@ -468,16 +468,14 @@ class Table:
if action:
action(line)
self.__write_obj.write(line)
'''
elif self.__token_info == 'mi<mk<pard-start':
self.__start_cell_func(line)
self.__write_obj.write(line)
elif self.__token_info == 'cw<tb<row_______':
self.__end_row_func(line)
self.__write_obj.write(line)
else:
self.__write_obj.write(line)
'''
# elif self.__token_info == 'mi<mk<pard-start':
# self.__start_cell_func(line)
# self.__write_obj.write(line)
# elif self.__token_info == 'cw<tb<row_______':
# self.__end_row_func(line)
# self.__write_obj.write(line)
# else:
# self.__write_obj.write(line)
def __end_row_func(self, line):
'''

View File

@ -419,9 +419,7 @@ class EPUB_MOBI(CatalogPlugin):
OptionRecommendation.HIGH))
recommendations.append(('comments', '', OptionRecommendation.HIGH))
'''
>>> Use to debug generated catalog code before pipeline conversion <<<
'''
# >>> Use to debug generated catalog code before pipeline conversion <<<
GENERATE_DEBUG_EPUB = False
if GENERATE_DEBUG_EPUB:
catalog_debug_path = os.path.join(os.path.expanduser('~'), 'Desktop', 'Catalog debug')

View File

@ -3072,12 +3072,10 @@ class CatalogBuilder:
# Don't include Author for Kindle
title_str = self.format_ncx_text('%s' % (book['title']), dest='title')
if self.opts.connected_kindle and book['id'] in self.bookmarked_books:
'''
dots = int((book['percent_read'] + 5)/10)
dot_string = '+' * dots
empty_dots = '-' * (10 - dots)
title_str += ' %s%s' % (dot_string,empty_dots)
'''
# dots = int((book['percent_read'] + 5)/10)
# dot_string = '+' * dots
# empty_dots = '-' * (10 - dots)
# title_str += ' %s%s' % (dot_string,empty_dots)
title_str += '*'
sec_text = title_str
else: