If it is not broken then break it:

* Fix lyx2lyx default debug level
* Fix lyx2lyx verbose mode
* Use stderr consistently
* Update default version when running from src directory
* Output prettier and more useful information
* Allow to specify the target version, the format will be accordingly
* Have a more reliable chain of dependencies (fixes corner cases < 2.15)
* Add placeholder for future file format changes



git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@27506 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
José Matox 2008-11-15 22:55:53 +00:00
parent 0685dfef74
commit 32f469b851
3 changed files with 118 additions and 19 deletions

View File

@ -32,7 +32,7 @@ try:
import lyx2lyx_version
version__ = lyx2lyx_version.version
except: # we are running from build directory so assume the last version
version__ = '1.6.0svn'
version__ = '2.0.0svn'
default_debug__ = 2
@ -73,14 +73,16 @@ format_relation = [("0_06", [200], minor_versions("0.6" , 4)),
("0_12", [215], minor_versions("0.12", 1) + ["0.11"]),
("1_0", [215], minor_versions("1.0" , 4)),
("1_1", [215], minor_versions("1.1" , 4)),
("1_1_5", [216], ["1.1.5","1.1.5.1","1.1.5.2","1.1"]),
("1_1_6_0", [217], ["1.1.6","1.1.6.1","1.1.6.2","1.1"]),
("1_1_6_3", [218], ["1.1.6.3","1.1.6.4","1.1"]),
("1_1_5", [216], ["1.1", "1.1.5","1.1.5.1","1.1.5.2"]),
("1_1_6_0", [217], ["1.1", "1.1.6","1.1.6.1","1.1.6.2"]),
("1_1_6_3", [218], ["1.1", "1.1.6.3","1.1.6.4"]),
("1_2", [220], minor_versions("1.2" , 4)),
("1_3", [221], minor_versions("1.3" , 7)),
("1_4", range(222,246), minor_versions("1.4" , 5)),
("1_5", range(246,277), minor_versions("1.5" , 6)),
("1_6", range(277,346), minor_versions("1.6" , 0))]
("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))]
####################################################################
# This is useful just for development versions #
@ -104,6 +106,23 @@ def formats_list():
return formats
def format_info():
" Returns a list with supported file formats."
out = """Major version:
minor versions
formats
"""
for version in format_relation:
major = str(version[2][0])
versions = str(version[2][1:])
if len(version[1]) == 1:
formats = str(version[1][0])
else:
formats = "%s - %s" % (version[1][-1], version[1][0])
out += "%s\n\t%s\n\t%s\n\n" % (major, versions, formats)
return out + '\n'
def get_end_format():
" Returns the more recent file format available."
return format_relation[-1][1][-1]
@ -158,7 +177,7 @@ class LyX_base:
def __init__(self, end_format = 0, input = "", output = "", error = "",
debug = default_debug__, try_hard = 0, cjk_encoding = '',
language = "english", encoding = "auto"):
final_version = "", language = "english", encoding = "auto"):
"""Arguments:
end_format: final format that the file should be converted. (integer)
@ -180,9 +199,37 @@ class LyX_base:
if end_format:
self.end_format = self.lyxformat(end_format)
# In case the target version and format are both specified
# verify that they are compatible. If not send a warning
# and ignore the version.
if final_version:
message = "Incompatible version %s for specified format %d" % (
final_version, self.end_format)
for version in format_relation:
if self.end_format in version[1]:
if final_version not in version[2]:
self.warning(message)
final_version = ""
elif final_version:
for version in format_relation:
if final_version in version[2]:
# set the last format for that version
self.end_format = version[1][-1]
break
else:
final_version = ""
else:
self.end_format = get_end_format()
if not final_version:
for step in format_relation:
if self.end_format in step[1]:
final_version = step[2][1]
self.final_version = final_version
self.warning("Final version: %s" % self.final_version, 10)
self.warning("Final format: %d" % self.end_format, 10)
self.backend = "latex"
self.textclass = "article"
# This is a hack: We use '' since we don't know the default
@ -556,13 +603,14 @@ class LyX_base:
steps = []
if (initial_step, self.start) < (final_step, self.end_format):
mode = "convert"
first_step = 1
full_steps = []
for step in format_relation:
if initial_step <= step[0] <= final_step:
if first_step and len(step[1]) == 1:
first_step = 0
continue
steps.append(step[0])
if initial_step <= step[0] <= final_step and step[2][0] <= self.final_version:
full_steps.append(step)
if full_steps[0][1][-1] == self.format:
full_steps = full_steps[1:]
for step in full_steps:
steps.append(step[0])
else:
mode = "revert"
relation_format = format_relation[:]
@ -646,9 +694,10 @@ class File(LyX_base):
" This class reads existing LyX files."
def __init__(self, end_format = 0, input = "", output = "", error = "",
debug = default_debug__, try_hard = 0, cjk_encoding = ''):
debug = default_debug__, try_hard = 0, cjk_encoding = '',
final_version = ''):
LyX_base.__init__(self, end_format, input, output, error,
debug, try_hard, cjk_encoding)
debug, try_hard, cjk_encoding, final_version)
self.read()

View File

@ -38,13 +38,13 @@ Copyright (C) 2007 José Matos and Dekel Tsur""" % LyX.version__
parser.set_defaults(debug=LyX.default_debug__, cjk_encoding = '')
parser.add_option("-d", "--debug", type="int",
help="level=0..2 (O_ quiet, 2_verbose) default: 1")
help="level=0..2 (O_ quiet, 10_verbose) default: 2")
parser.add_option("-q", "--quiet",
action="store_const", const=0, dest="debug")
parser.add_option("-v", "--verbose",
action="store_const", const=1, dest="debug")
parser.add_option("--noisy",
action="store_const", const=2, dest="debug")
action="store_const", const=10, dest="debug")
parser.add_option("-c", "--encoding", dest="cjk_encoding",
help="files in format 248 and lower are read and"
" written in the format of CJK-LyX."
@ -56,8 +56,10 @@ Copyright (C) 2007 José Matos and Dekel Tsur""" % LyX.version__
help= "name of the output file else goes to stdout")
parser.add_option("-t", "--to", dest= "end_format",
help= "destination file format, default (latest)")
parser.add_option("-V", "--final_version", dest= "final_version",
help= "destination version, default (latest)")
parser.add_option("-l", "--list", action="store_true",
help = "list all available formats")
help = "list all available formats and supported versions")
parser.add_option("-n", "--try-hard", action="store_true",
help = "try hard (ignore any convertion errors)")
@ -68,7 +70,7 @@ Copyright (C) 2007 José Matos and Dekel Tsur""" % LyX.version__
options.input = None
if options.list:
print LyX.formats_list()
sys.stderr.write(LyX.format_info())
sys.exit()
else:
del options.list

48
lib/lyx2lyx/lyx_2_0.py Normal file
View File

@ -0,0 +1,48 @@
# This file is part of lyx2lyx
# -*- coding: utf-8 -*-
# Copyright (C) 2008 José Matos <jamatos@lyx.org>
#
# 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 2
# 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, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
""" Convert files to the file format generated by lyx 2.0"""
from parser_tools import find_token, find_end_of, find_tokens, get_value, get_value_string
####################################################################
# Private helper functions
def find_end_of_inset(lines, i):
" Find end of inset, where lines[i] is included."
return find_end_of(lines, i, "\\begin_inset", "\\end_inset")
####################################################################
def dummy(document):
pass
##
# Conversion hub
#
supported_versions = ["2.2.0","2.0"]
convert = [[346, [dummy]]
]
revert = [[345, []]
]
if __name__ == "__main__":
pass