#! /usr/bin/env python
# -*- coding: utf-8 -*-
-# file prefs2prefs-lfuns.py
+# file prefs2prefs-prefs.py
# This file is part of LyX, the document processor.
# Licence details can be found in the file COPYING.
# Add use_qimage option.
# No conversion necessary.
-import re
+# Incremented to format 7, r40789 by gb
+# Add mime type to file format
+
+# Incremented to format 8, 288c1e0f by rgh
+# Add "nice" flag for converters
+# No conversion necessary.
+
+# Incremented to format 9, a18af620 by spitz
+# Remove default_language rc.
+
+# Incremented to format 10, 4985015 by tommaso
+# Add close_buffer_with_last_view in preferences.
+# No conversion necessary.
+import re
###########################################################
#
# Conversion chain
+def get_format(line):
+ entries = []
+ i = 0
+ while i < len(line):
+ if line[i] == '"':
+ beg = i + 1
+ i = i + 1
+ while i < len(line) and line[i] != '"':
+ if line[i] == '\\' and i < len(line) - 1 and line[i+1] == '"':
+ # convert \" to "
+ i = i + 1
+ i = i + 1
+ end = i
+ entries.append(line[beg:end].replace('\\"', '"'))
+ elif line[i] == '#':
+ return entries
+ elif not line[i].isspace():
+ beg = i
+ while not line[i].isspace():
+ i = i + 1
+ end = i
+ entries.append(line[beg:end])
+ i = i + 1
+ return entries
+
+
def simple_renaming(line, old, new):
i = line.lower().find(old.lower())
if i == -1:
no_match = (False, [])
-########################
-### Format 1 conversions
+######################################
+### Format 1 conversions (for LyX 2.0)
def remove_obsolete(line):
tags = ("\\use_tempdir", "\\spell_command", "\\personal_dictionary",
return (True, "")
return no_match
+
def language_use_babel(line):
if not line.lower().startswith("\language_use_babel"):
return no_match
newline = "\\language_package_selection " + newval
return (True, newline)
+
def language_package(line):
return simple_renaming(line, "\\language_package", "\\language_custom_package")
+
lfre = re.compile(r'^\\converter\s+"?(\w+)"?\s+"?(\w+)"?\s+"([^"]*?)"\s+"latex"', re.IGNORECASE)
def latex_flavor(line):
if not line.lower().startswith("\\converter"):
return (True,
"\\converter \"%s\" \"%s\" \"%s\" \"latex=%s\"" % (conv, fmat, args, flavor))
+
emre = re.compile(r'^\\format\s+(.*)\s+"(document[^"]*?)"', re.IGNORECASE)
def export_menu(line):
if not line.lower().startswith("\\format"):
return (True,
"\\Format %s \"%s,menu=export\"" % (fmat, opts))
+# End format 1 conversions (for LyX 2.0)
+########################################
+
+#################################
+# Conversions from LyX 2.0 to 2.1
zipre = re.compile(r'^\\format\s+("?dia"?\s+.*)\s+"([^"]*?)"', re.IGNORECASE)
def zipped_native(line):
if not line.lower().startswith("\\format"):
return no_match
return (True, "")
+def add_mime_types(line):
+ if not line.lower().startswith("\\format"):
+ return no_match
+ entries = get_format(line)
+ converted = line
+ i = len(entries)
+ while i < 7:
+ converted = converted + ' ""'
+ i = i + 1
+ formats = {'tgif':'application/x-tgif', \
+ 'fig':'application/x-xfig', \
+ 'dia':'application/x-dia-diagram', \
+ 'odg':'application/vnd.oasis.opendocument.graphics', \
+ 'svg':'image/svg+xml', \
+ 'bmp':'image/x-bmp', \
+ 'gif':'image/gif', \
+ 'jpg':'image/jpeg', \
+ 'pbm':'image/x-portable-bitmap', \
+ 'pgm':'image/x-portable-graymap', \
+ 'png':'image/x-png', \
+ 'ppm':'image/x-portable-pixmap', \
+ 'tiff':'image/tiff', \
+ 'xbm':'image/x-xbitmap', \
+ 'xpm':'image/x-xpixmap', \
+ 'docbook-xml':'application/docbook+xml', \
+ 'dot':'text/vnd.graphviz', \
+ 'ly':'text/x-lilypond', \
+ 'latex':'text/x-tex', \
+ 'text':'text/plain', \
+ 'gnumeric':'application/x-gnumeric', \
+ 'excel':'application/vnd.ms-excel', \
+ 'oocalc':'application/vnd.oasis.opendocument.spreadsheet', \
+ 'xhtml':'application/xhtml+xml', \
+ 'bib':'text/x-bibtex', \
+ 'eps':'image/x-eps', \
+ 'ps':'application/postscript', \
+ 'pdf':'application/pdf', \
+ 'dvi':'application/x-dvi', \
+ 'html':'text/html', \
+ 'odt':'application/vnd.oasis.opendocument.text', \
+ 'sxw':'application/vnd.sun.xml.writer', \
+ 'rtf':'application/rtf', \
+ 'doc':'application/msword', \
+ 'csv':'text/csv', \
+ 'lyx':'application/x-lyx', \
+ 'wmf':'image/x-wmf', \
+ 'emf':'image/x-emf'}
+ if entries[1] in formats.keys():
+ converted = converted + ' "' + formats[entries[1]] + '"'
+ else:
+ converted = converted + ' ""'
+ return (True, converted)
+
+def remove_default_language(line):
+ if not line.lower().startswith("\\default_language"):
+ return no_match
+ return (True, "")
+
-########################
+# End conversions for LyX 2.0 to 2.1
+####################################
conversions = [
- [ 1, [ # this will be a long list of conversions to format 1
+ [ 1, [ # there were several conversions for format 1
export_menu,
latex_flavor,
remove_obsolete,
language_use_babel,
language_package
]],
- [ 2, []],
- [ 3, [ zipped_native ]],
- [ 4, [ remove_default_papersize ]],
- [ 5, []],
- [ 6, []],
+ [ 2, []],
+ [ 3, [ zipped_native ]],
+ [ 4, [ remove_default_papersize ]],
+ [ 5, []],
+ [ 6, []],
+ [ 7, [add_mime_types]],
+ [ 8, []],
+ [ 9, [ remove_default_language ]],
+ [ 10, []]
]