("1_4", range(222,246), minor_versions("1.4" , 5)),
("1_5", range(246,277), minor_versions("1.5" , 7)),
("1_6", range(277,346), minor_versions("1.6" , 0)),
- ]
-# ("2_0", [], minor_versions("2.0", 0))]
+ ("2_0", [], minor_versions("2.0", 0))]
####################################################################
# This is useful just for development versions #
" Emits a warning and exits if not in try_hard mode."
self.warning(message)
if not self.try_hard:
- self.warning("Quiting.")
+ self.warning("Quitting.")
sys.exit(1)
self.status = 2
def convert(self):
"Convert from current (self.format) to self.end_format."
- mode, convertion_chain = self.chain()
- self.warning("convertion chain: " + str(convertion_chain), 3)
+ mode, conversion_chain = self.chain()
+ self.warning("conversion chain: " + str(conversion_chain), 3)
- for step in convertion_chain:
+ for step in conversion_chain:
steps = getattr(__import__("lyx_" + step), mode)
self.warning("Convertion step: %s - %s" % (step, mode),
default_debug__ + 1)
if not steps:
- self.error("The convertion to an older "
+ self.error("The conversion to an older "
"format (%s) is not implemented." % self.format)
multi_conv = len(steps) != 1
def chain(self):
""" This is where all the decisions related with the
- convertion are taken. It returns a list of modules needed to
+ conversion are taken. It returns a list of modules needed to
convert the LyX file from self.format to self.end_format"""
self.start = self.format
return mode, steps
- def get_toc(self, depth = 4):
- " Returns the TOC of this LyX document."
- paragraphs_filter = {'Title' : 0,'Chapter' : 1, 'Section' : 2,
- 'Subsection' : 3, 'Subsubsection': 4}
- allowed_insets = ['Quotes']
- allowed_parameters = ('\\paragraph_spacing', '\\noindent',
- '\\align', '\\labelwidthstring',
- "\\start_of_appendix", "\\leftindent")
- sections = []
- for section in paragraphs_filter.keys():
- sections.append('\\begin_layout %s' % section)
-
- toc_par = []
- i = 0
- while 1:
- i = find_tokens(self.body, sections, i)
- if i == -1:
- break
-
- j = find_end_of(self.body, i + 1, '\\begin_layout', '\\end_layout')
- if j == -1:
- self.warning('Incomplete file.', 0)
- break
-
- section = self.body[i].split()[1]
- if section[-1] == '*':
- section = section[:-1]
-
- par = []
-
- k = i + 1
- # skip paragraph parameters
- while not self.body[k].strip() or self.body[k].split()[0] \
- in allowed_parameters:
- k += 1
-
- while k < j:
- if check_token(self.body[k], '\\begin_inset'):
- inset = self.body[k].split()[1]
- end = find_end_of_inset(self.body, k)
- if end == -1 or end > j:
- self.warning('Malformed file.', 0)
-
- if inset in allowed_insets:
- par.extend(self.body[k: end+1])
- k = end + 1
- else:
- par.append(self.body[k])
- k += 1
-
- # trim empty lines in the end.
- while par and par[-1].strip() == '':
- par.pop()
-
- toc_par.append(Paragraph(section, par))
-
- i = j + 1
-
- return toc_par
+# Part of an unfinished attempt to make lyx2lyx gave a more
+# structured view of the document.
+# def get_toc(self, depth = 4):
+# " Returns the TOC of this LyX document."
+# paragraphs_filter = {'Title' : 0,'Chapter' : 1, 'Section' : 2,
+# 'Subsection' : 3, 'Subsubsection': 4}
+# allowed_insets = ['Quotes']
+# allowed_parameters = ('\\paragraph_spacing', '\\noindent',
+# '\\align', '\\labelwidthstring',
+# "\\start_of_appendix", "\\leftindent")
+# sections = []
+# for section in paragraphs_filter.keys():
+# sections.append('\\begin_layout %s' % section)
+
+# toc_par = []
+# i = 0
+# while 1:
+# i = find_tokens(self.body, sections, i)
+# if i == -1:
+# break
+
+# j = find_end_of(self.body, i + 1, '\\begin_layout', '\\end_layout')
+# if j == -1:
+# self.warning('Incomplete file.', 0)
+# break
+
+# section = self.body[i].split()[1]
+# if section[-1] == '*':
+# section = section[:-1]
+
+# par = []
+
+# k = i + 1
+# # skip paragraph parameters
+# while not self.body[k].strip() or self.body[k].split()[0] \
+# in allowed_parameters:
+# k += 1
+
+# while k < j:
+# if check_token(self.body[k], '\\begin_inset'):
+# inset = self.body[k].split()[1]
+# end = find_end_of_inset(self.body, k)
+# if end == -1 or end > j:
+# self.warning('Malformed file.', 0)
+
+# if inset in allowed_insets:
+# par.extend(self.body[k: end+1])
+# k = end + 1
+# else:
+# par.append(self.body[k])
+# k += 1
+
+# # trim empty lines in the end.
+# while par and par[-1].strip() == '':
+# par.pop()
+
+# toc_par.append(Paragraph(section, par))
+
+# i = j + 1
+
+# return toc_par
class File(LyX_base):
self.read()
-class NewFile(LyX_base):
- " This class is to create new LyX files."
- def set_header(self, **params):
- # set default values
- self.header.extend([
- "#LyX xxxx created this file."
- "For more info see http://www.lyx.org/",
- "\\lyxformat xxx",
- "\\begin_document",
- "\\begin_header",
- "\\textclass article",
- "\\language english",
- "\\inputencoding auto",
- "\\font_roman default",
- "\\font_sans default",
- "\\font_typewriter default",
- "\\font_default_family default",
- "\\font_sc false",
- "\\font_osf false",
- "\\font_sf_scale 100",
- "\\font_tt_scale 100",
- "\\graphics default",
- "\\paperfontsize default",
- "\\papersize default",
- "\\use_geometry false",
- "\\use_amsmath 1",
- "\\cite_engine basic",
- "\\use_bibtopic false",
- "\\paperorientation portrait",
- "\\secnumdepth 3",
- "\\tocdepth 3",
- "\\paragraph_separation indent",
- "\\defskip medskip",
- "\\quotes_language english",
- "\\papercolumns 1",
- "\\papersides 1",
- "\\paperpagestyle default",
- "\\tracking_changes false",
- "\\end_header"])
-
- self.format = get_end_format()
- for param in params:
- self.set_parameter(param, params[param])
-
-
- def set_body(self, paragraphs):
- self.body.extend(['\\begin_body',''])
-
- for par in paragraphs:
- self.body.extend(par.asLines())
-
- self.body.extend(['','\\end_body', '\\end_document'])
-
-
-class Paragraph:
- # unfinished implementation, it is missing the Text and Insets
- # representation.
- " This class represents the LyX paragraphs."
- def __init__(self, name, body=[], settings = [], child = []):
- """ Parameters:
- name: paragraph name.
- body: list of lines of body text.
- child: list of paragraphs that descend from this paragraph.
- """
- self.name = name
- self.body = body
- self.settings = settings
- self.child = child
-
- def asLines(self):
- """ Converts the paragraph to a list of strings, representing
- it in the LyX file."""
-
- result = ['','\\begin_layout %s' % self.name]
- result.extend(self.settings)
- result.append('')
- result.extend(self.body)
- result.append('\\end_layout')
-
- if not self.child:
- return result
-
- result.append('\\begin_deeper')
- for node in self.child:
- result.extend(node.asLines())
- result.append('\\end_deeper')
-
- return result
+#class NewFile(LyX_base):
+# " This class is to create new LyX files."
+# def set_header(self, **params):
+# # set default values
+# self.header.extend([
+# "#LyX xxxx created this file."
+# "For more info see http://www.lyx.org/",
+# "\\lyxformat xxx",
+# "\\begin_document",
+# "\\begin_header",
+# "\\textclass article",
+# "\\language english",
+# "\\inputencoding auto",
+# "\\font_roman default",
+# "\\font_sans default",
+# "\\font_typewriter default",
+# "\\font_default_family default",
+# "\\font_sc false",
+# "\\font_osf false",
+# "\\font_sf_scale 100",
+# "\\font_tt_scale 100",
+# "\\graphics default",
+# "\\paperfontsize default",
+# "\\papersize default",
+# "\\use_geometry false",
+# "\\use_amsmath 1",
+# "\\cite_engine basic",
+# "\\use_bibtopic false",
+# "\\paperorientation portrait",
+# "\\secnumdepth 3",
+# "\\tocdepth 3",
+# "\\paragraph_separation indent",
+# "\\defskip medskip",
+# "\\quotes_language english",
+# "\\papercolumns 1",
+# "\\papersides 1",
+# "\\paperpagestyle default",
+# "\\tracking_changes false",
+# "\\end_header"])
+
+# self.format = get_end_format()
+# for param in params:
+# self.set_parameter(param, params[param])
+
+
+# def set_body(self, paragraphs):
+# self.body.extend(['\\begin_body',''])
+
+# for par in paragraphs:
+# self.body.extend(par.asLines())
+
+# self.body.extend(['','\\end_body', '\\end_document'])
+
+
+# Part of an unfinished attempt to make lyx2lyx gave a more
+# structured view of the document.
+#class Paragraph:
+# # unfinished implementation, it is missing the Text and Insets
+# # representation.
+# " This class represents the LyX paragraphs."
+# def __init__(self, name, body=[], settings = [], child = []):
+# """ Parameters:
+# name: paragraph name.
+# body: list of lines of body text.
+# child: list of paragraphs that descend from this paragraph.
+# """
+# self.name = name
+# self.body = body
+# self.settings = settings
+# self.child = child
+
+# def asLines(self):
+# """ Converts the paragraph to a list of strings, representing
+# it in the LyX file."""
+
+# result = ['','\\begin_layout %s' % self.name]
+# result.extend(self.settings)
+# result.append('')
+# result.extend(self.body)
+# result.append('\\end_layout')
+
+# if not self.child:
+# return result
+
+# result.append('\\begin_deeper')
+# for node in self.child:
+# result.extend(node.asLines())
+# result.append('\\end_deeper')
+
+# return result