On 12/19/2009 06:58 AM, Ben M. wrote:
On Fri, Dec 18, 2009 at 5:42 PM, Enrico Forestieri<for...@lyx.org>  wrote:
Yep, as I said, in development/tools there is a shell script (lyxeditor)
that parses the preferences file and lyxrc.dist for the lyxpipe definition.
It works on Linux, MacOS, and Cygwin. It would be easy to extend it to
also work on native Windows, but then you would need a Bourne-like shell
to execute it. So, it would be better to convert it to Python. This should
be a rather simple task.
Okay, here's a very rough draft.  This is the first thing I've written
in Python, so some things are very ugly.  It works for me under Win32,
but I haven't tested under anything else.

Not so bad, but a few comments.


import os, re, string, sys, subprocess

version_suffix = "16"

In general, it's a good idea to do this sort of thing for trunk first.

def parse_serverpipe(PREFERENCES):
    print "Parsing " + PREFERENCES
    fh = open(PREFERENCES, "r")
    lines = fh.readlines()
serverpipe = r"\serverpipe " # Want to find lines starting with \serverpipe
    for line in lines:
        # Remove extra whitespace
        line = line.strip()
        # Does line start with \serverpipe?
        if line.startswith(serverpipe):
            # Remove \serverpipe
            line = line[len(serverpipe):].strip()

Just for clarity, I'd do:
                spipe = line[len(serverpipe):].strip()
and then use spipe.

            # Get rid of any quotation marks
            if line[0] == line[-1] == '"':
                line = line[1:-1].strip()
            # Substitute $HOME for ~/
            if line.startswith("~/"):
                line = HOME + line[2:]
            if not line == "":
                return line
    # Nothing found
    return ""

if not len(sys.argv) == 3:
    print "Usage: " + sys.argv[0] + " <latexfile> <lineno>"
    sys.exit(1)

if OSTYPE == "macos":
    LYXSYSDIRS = ["/Applications/LyX.app/Contents/Resources"]
    LYXBASEDIR = ["LyX" + version_suffix]
    old_dir = os.getcwd()
    os.chdir(HOME + "/Library/Application Support")
elif OSTYPE == "win32":
    LYXSYSDIRS = [r"..\Resources"]
    LYXBASEDIR = [r"lyx" + version_suffix]
    old_dir = os.getcwd()
    os.chdir(os.environ["APPDATA"])
else:
LYXSYSDIRS = ["/usr/share/lyx", "/usr/local/share/lyx", "/opt/share/lyx"]

This will be hard to get right, since you can install LyX anywhere.

    LYXBASEDIR = [".lyx" + version_suffix]

This again will be hard to get right. (For trunk, I use ~/dev/lyxdirs/lyxsvn/.) Perhaps the script should take optional arguments for these. (Argument processing is done with getopt.)

rh

Reply via email to