Clean up the lyxpak script a bit, towards possible inclusion.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37496 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Richard Heck 2011-02-04 19:43:52 +00:00
parent 7357a577de
commit a621204d57

View File

@ -24,7 +24,7 @@ from sets import Set
lyx2lyx = None
# Pre-compiled regular expressions.
re_lyxfile = re.compile("\.lyx$")
re_extn = re.compile("\.[^.]*$")
re_input = re.compile(r'^(.*)\\(input|include){(\s*)(\S+)(\s*)}.*$')
re_package = re.compile(r'^(.*)\\(usepackage){(\s*)(\S+)(\s*)}.*$')
re_class = re.compile(r'^(\\)(textclass)(\s+)(\S+)$')
@ -71,7 +71,7 @@ def abspath(name):
def gather_files(curfile, incfiles):
" Recursively gather files."
curdir = os.path.dirname(abspath(curfile))
is_lyxfile = re_lyxfile.search(curfile)
is_lyxfile = re_extn.search(curfile)
if is_lyxfile:
lyx2lyx_cmd = 'python "%s" "%s"' % (lyx2lyx, curfile)
l2l_status, l2l_stdout = run_cmd(lyx2lyx_cmd)
@ -156,11 +156,18 @@ def gather_files(curfile, incfiles):
def main(argv):
if len(argv) >= 2 and len(argv) <= 3:
if len(argv) < 2 and len(argv) > 3:
error(usage(argv[0]))
lyxfile = argv[1]
if not os.path.exists(lyxfile):
error('File "%s" not found.' % lyxfile)
if len(argv) == 3:
outdir = argv[2]
if not os.path.isdir(outdir):
error('Error: "%s" is not a directory.' % outdir)
# Check that it actually is a LyX document
input = open(lyxfile, 'rU')
line = input.readline()
@ -177,7 +184,7 @@ def main(argv):
if archiver == "tar":
ar_cmd = "tar cf"
ar_name = re_lyxfile.sub(".tar", abspath(lyxfile))
ar_name = re_extn.sub(".tar", abspath(lyxfile))
# Archive will be compressed if either gzip or bzip2 are available
compress, full_path = find_exe(["gzip", "bzip2"], extlist, path)
if compress == "gzip":
@ -186,18 +193,13 @@ def main(argv):
ext = ".bz2"
elif archiver == "zip":
ar_cmd = "zip"
ar_name = re_lyxfile.sub(".zip", abspath(lyxfile))
ar_name = re_extn.sub(".zip", abspath(lyxfile))
compress = None
else:
error("Unable to find neither tar nor zip.")
error("Unable to find either tar or zip.")
if len(argv) == 3:
outdir = argv[2]
if not os.path.isdir(outdir):
error('Error: "%s" is not a directory.' % outdir)
if outdir:
ar_name = os.path.join(abspath(outdir), os.path.basename(ar_name))
else:
error(usage(argv[0]))
# Try to find the location of the lyx2lyx script
global lyx2lyx
@ -205,7 +207,6 @@ def main(argv):
lyx_exe, full_path = find_exe(["lyxc", "lyx"], extlist, path)
if lyx_exe == None:
error('Cannot find the LyX executable in the path.')
else:
cmd_status, cmd_stdout = run_cmd("%s -version 2>&1" % lyx_exe)
if cmd_status != None:
error('Cannot query LyX about the lyx2lyx script.')
@ -251,7 +252,7 @@ def main(argv):
# Build the archive command
ar_cmd = '%s "%s"' % (ar_cmd, ar_name)
for file in incfiles:
print file
#print file
ar_cmd = ar_cmd + ' "' + file + '"'
# Create the archive