Make HTML export work.
The key is the new copier script lib/scripts/ext_copy.py. Usage:
ext_copy.py [-e ext1,ext2,...] <from file> <to file>
Given a <from file> and <to file>, it will copy all files in the directory
in which from_file is found that have the extensions given in the -e option,
or all files in that directory if no such argument is given. So, for example,
we can do:
python ext_copy.py -e png,html,css /path/from/file.html /path/to/file.html
and all html, png, and css files in /path/from/ will be copied to the
(possibly new) directory /path/to/file.html.LyXconv/. The -t option determines
the extension added to the output filename passed to the script ($$o, in the
copier definition), the default being "LyXconv". If just . is given, then no
extension is added.
Other changes:
* configure.py: added appropriate copier definitions for html and wordhtml
formats, as well as for the Program pseudo-format.
* lib/Makefile.am and development/scons/scons_manifest.py: add ext_copy.py.
* lib/doc/Customization.lyx: update documentation.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18791 a592a061-630c-0410-9148-cb99ea01b6c8
2007-06-15 17:02:35 +00:00
|
|
|
#! /usr/bin/env python
|
2007-06-29 19:13:57 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
Make HTML export work.
The key is the new copier script lib/scripts/ext_copy.py. Usage:
ext_copy.py [-e ext1,ext2,...] <from file> <to file>
Given a <from file> and <to file>, it will copy all files in the directory
in which from_file is found that have the extensions given in the -e option,
or all files in that directory if no such argument is given. So, for example,
we can do:
python ext_copy.py -e png,html,css /path/from/file.html /path/to/file.html
and all html, png, and css files in /path/from/ will be copied to the
(possibly new) directory /path/to/file.html.LyXconv/. The -t option determines
the extension added to the output filename passed to the script ($$o, in the
copier definition), the default being "LyXconv". If just . is given, then no
extension is added.
Other changes:
* configure.py: added appropriate copier definitions for html and wordhtml
formats, as well as for the Program pseudo-format.
* lib/Makefile.am and development/scons/scons_manifest.py: add ext_copy.py.
* lib/doc/Customization.lyx: update documentation.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18791 a592a061-630c-0410-9148-cb99ea01b6c8
2007-06-15 17:02:35 +00:00
|
|
|
|
|
|
|
# file ext_copy.py
|
|
|
|
# This file is part of LyX, the document processor.
|
|
|
|
# Licence details can be found in the file COPYING.
|
|
|
|
|
2009-10-24 00:55:28 +00:00
|
|
|
# author Richard Heck, Alex Fernandez, Uwe Stöhr
|
Make HTML export work.
The key is the new copier script lib/scripts/ext_copy.py. Usage:
ext_copy.py [-e ext1,ext2,...] <from file> <to file>
Given a <from file> and <to file>, it will copy all files in the directory
in which from_file is found that have the extensions given in the -e option,
or all files in that directory if no such argument is given. So, for example,
we can do:
python ext_copy.py -e png,html,css /path/from/file.html /path/to/file.html
and all html, png, and css files in /path/from/ will be copied to the
(possibly new) directory /path/to/file.html.LyXconv/. The -t option determines
the extension added to the output filename passed to the script ($$o, in the
copier definition), the default being "LyXconv". If just . is given, then no
extension is added.
Other changes:
* configure.py: added appropriate copier definitions for html and wordhtml
formats, as well as for the Program pseudo-format.
* lib/Makefile.am and development/scons/scons_manifest.py: add ext_copy.py.
* lib/doc/Customization.lyx: update documentation.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18791 a592a061-630c-0410-9148-cb99ea01b6c8
2007-06-15 17:02:35 +00:00
|
|
|
|
|
|
|
# Full author contact details are available in file CREDITS
|
|
|
|
|
|
|
|
# Usage:
|
|
|
|
# ext_copy.py [-e ext1,ext2,...] <from file> <to file>
|
|
|
|
|
|
|
|
# This script is to be used as a "copier" script in the sense needed by
|
|
|
|
# the converter definitions. Given a <from file> and <to file>, it will copy
|
|
|
|
# all files in the directory in which from_file is found that have the
|
|
|
|
# extensions given in the -e argument, or all files in that directory if no
|
|
|
|
# such argument is given. So, for example, we can do:
|
|
|
|
# python ext_copy.py -e png,html,css /path/from/file.html /path/to/file.html
|
|
|
|
# and all html, png, and css files in /path/from/ will be copied to the
|
|
|
|
# (possibly new) directory /path/to/file.html.LyXconv/.
|
|
|
|
# The -t argument determines the extension added, the default being "LyXconv".
|
|
|
|
# If just . is given, no extension is added.
|
|
|
|
|
2009-10-24 00:55:28 +00:00
|
|
|
import getopt, os, shutil, sys
|
Make HTML export work.
The key is the new copier script lib/scripts/ext_copy.py. Usage:
ext_copy.py [-e ext1,ext2,...] <from file> <to file>
Given a <from file> and <to file>, it will copy all files in the directory
in which from_file is found that have the extensions given in the -e option,
or all files in that directory if no such argument is given. So, for example,
we can do:
python ext_copy.py -e png,html,css /path/from/file.html /path/to/file.html
and all html, png, and css files in /path/from/ will be copied to the
(possibly new) directory /path/to/file.html.LyXconv/. The -t option determines
the extension added to the output filename passed to the script ($$o, in the
copier definition), the default being "LyXconv". If just . is given, then no
extension is added.
Other changes:
* configure.py: added appropriate copier definitions for html and wordhtml
formats, as well as for the Program pseudo-format.
* lib/Makefile.am and development/scons/scons_manifest.py: add ext_copy.py.
* lib/doc/Customization.lyx: update documentation.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18791 a592a061-630c-0410-9148-cb99ea01b6c8
2007-06-15 17:02:35 +00:00
|
|
|
from lyxpreview_tools import error
|
|
|
|
|
|
|
|
def usage(prog_name):
|
|
|
|
return "Usage: %s [-e extensions] [-t target extension] <from file> <to file>" % prog_name
|
|
|
|
|
|
|
|
def main(argv):
|
|
|
|
progname = argv[0]
|
|
|
|
|
|
|
|
exts = [] #list of extensions for which we're checking
|
|
|
|
targext = "LyXconv" #extension for target directory
|
|
|
|
opts, args = getopt.getopt(sys.argv[1:], "e:t:")
|
|
|
|
for o, v in opts:
|
|
|
|
if o == "-e":
|
|
|
|
exts = v.split(',')
|
|
|
|
if o == "-t":
|
|
|
|
targext = v
|
|
|
|
|
|
|
|
# input directory
|
|
|
|
if len(args) != 2:
|
|
|
|
error(usage(progname))
|
|
|
|
abs_from_file = args[0]
|
|
|
|
if not os.path.isabs(abs_from_file):
|
|
|
|
error("%s is not an absolute file name.\n%s" % abs_from_file, usage(progname))
|
|
|
|
from_dir = os.path.dirname(abs_from_file)
|
|
|
|
|
|
|
|
# output directory
|
|
|
|
to_dir = args[1]
|
|
|
|
if targext != '.':
|
|
|
|
to_dir += "." + targext
|
|
|
|
if not os.path.isabs(to_dir):
|
|
|
|
error("%s is not an absolute file name.\n%s" % to_dir, usage(progname))
|
|
|
|
|
2009-10-24 12:31:59 +00:00
|
|
|
if not copy_all(from_dir, to_dir, exts):
|
|
|
|
# some kind of failure
|
|
|
|
return 1
|
|
|
|
return 0
|
Make HTML export work.
The key is the new copier script lib/scripts/ext_copy.py. Usage:
ext_copy.py [-e ext1,ext2,...] <from file> <to file>
Given a <from file> and <to file>, it will copy all files in the directory
in which from_file is found that have the extensions given in the -e option,
or all files in that directory if no such argument is given. So, for example,
we can do:
python ext_copy.py -e png,html,css /path/from/file.html /path/to/file.html
and all html, png, and css files in /path/from/ will be copied to the
(possibly new) directory /path/to/file.html.LyXconv/. The -t option determines
the extension added to the output filename passed to the script ($$o, in the
copier definition), the default being "LyXconv". If just . is given, then no
extension is added.
Other changes:
* configure.py: added appropriate copier definitions for html and wordhtml
formats, as well as for the Program pseudo-format.
* lib/Makefile.am and development/scons/scons_manifest.py: add ext_copy.py.
* lib/doc/Customization.lyx: update documentation.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18791 a592a061-630c-0410-9148-cb99ea01b6c8
2007-06-15 17:02:35 +00:00
|
|
|
|
|
|
|
|
2009-10-24 00:55:28 +00:00
|
|
|
def copy_all(from_dir, to_dir, exts):
|
|
|
|
"Copy all matching files in from_dir to to_dir"
|
Make HTML export work.
The key is the new copier script lib/scripts/ext_copy.py. Usage:
ext_copy.py [-e ext1,ext2,...] <from file> <to file>
Given a <from file> and <to file>, it will copy all files in the directory
in which from_file is found that have the extensions given in the -e option,
or all files in that directory if no such argument is given. So, for example,
we can do:
python ext_copy.py -e png,html,css /path/from/file.html /path/to/file.html
and all html, png, and css files in /path/from/ will be copied to the
(possibly new) directory /path/to/file.html.LyXconv/. The -t option determines
the extension added to the output filename passed to the script ($$o, in the
copier definition), the default being "LyXconv". If just . is given, then no
extension is added.
Other changes:
* configure.py: added appropriate copier definitions for html and wordhtml
formats, as well as for the Program pseudo-format.
* lib/Makefile.am and development/scons/scons_manifest.py: add ext_copy.py.
* lib/doc/Customization.lyx: update documentation.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18791 a592a061-630c-0410-9148-cb99ea01b6c8
2007-06-15 17:02:35 +00:00
|
|
|
for file in os.listdir(from_dir):
|
2009-10-24 00:55:28 +00:00
|
|
|
if os.path.isdir(os.path.join(from_dir, file)):
|
|
|
|
copy_all(os.path.join(from_dir, file), os.path.join(to_dir, file), exts)
|
2007-08-04 03:04:23 +00:00
|
|
|
continue
|
Make HTML export work.
The key is the new copier script lib/scripts/ext_copy.py. Usage:
ext_copy.py [-e ext1,ext2,...] <from file> <to file>
Given a <from file> and <to file>, it will copy all files in the directory
in which from_file is found that have the extensions given in the -e option,
or all files in that directory if no such argument is given. So, for example,
we can do:
python ext_copy.py -e png,html,css /path/from/file.html /path/to/file.html
and all html, png, and css files in /path/from/ will be copied to the
(possibly new) directory /path/to/file.html.LyXconv/. The -t option determines
the extension added to the output filename passed to the script ($$o, in the
copier definition), the default being "LyXconv". If just . is given, then no
extension is added.
Other changes:
* configure.py: added appropriate copier definitions for html and wordhtml
formats, as well as for the Program pseudo-format.
* lib/Makefile.am and development/scons/scons_manifest.py: add ext_copy.py.
* lib/doc/Customization.lyx: update documentation.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18791 a592a061-630c-0410-9148-cb99ea01b6c8
2007-06-15 17:02:35 +00:00
|
|
|
junk, ext = os.path.splitext(os.path.basename(file))
|
|
|
|
ext = ext.lower()[1:] #strip the leading dot
|
2009-10-24 00:55:28 +00:00
|
|
|
# only create a directory and copy files when either
|
|
|
|
# exts is empty or when ext is in the exts list
|
|
|
|
if (exts) and (ext not in exts):
|
|
|
|
continue
|
|
|
|
if not create_dir(to_dir):
|
|
|
|
return False
|
Make HTML export work.
The key is the new copier script lib/scripts/ext_copy.py. Usage:
ext_copy.py [-e ext1,ext2,...] <from file> <to file>
Given a <from file> and <to file>, it will copy all files in the directory
in which from_file is found that have the extensions given in the -e option,
or all files in that directory if no such argument is given. So, for example,
we can do:
python ext_copy.py -e png,html,css /path/from/file.html /path/to/file.html
and all html, png, and css files in /path/from/ will be copied to the
(possibly new) directory /path/to/file.html.LyXconv/. The -t option determines
the extension added to the output filename passed to the script ($$o, in the
copier definition), the default being "LyXconv". If just . is given, then no
extension is added.
Other changes:
* configure.py: added appropriate copier definitions for html and wordhtml
formats, as well as for the Program pseudo-format.
* lib/Makefile.am and development/scons/scons_manifest.py: add ext_copy.py.
* lib/doc/Customization.lyx: update documentation.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18791 a592a061-630c-0410-9148-cb99ea01b6c8
2007-06-15 17:02:35 +00:00
|
|
|
from_file = os.path.join(from_dir, file)
|
|
|
|
to_file = os.path.join(to_dir, file)
|
2007-08-04 03:04:23 +00:00
|
|
|
shutil.copyfile(from_file, to_file)
|
|
|
|
try:
|
|
|
|
shutil.copymode(from_file, to_file)
|
|
|
|
except:
|
|
|
|
pass
|
2009-10-24 12:31:59 +00:00
|
|
|
return True
|
Make HTML export work.
The key is the new copier script lib/scripts/ext_copy.py. Usage:
ext_copy.py [-e ext1,ext2,...] <from file> <to file>
Given a <from file> and <to file>, it will copy all files in the directory
in which from_file is found that have the extensions given in the -e option,
or all files in that directory if no such argument is given. So, for example,
we can do:
python ext_copy.py -e png,html,css /path/from/file.html /path/to/file.html
and all html, png, and css files in /path/from/ will be copied to the
(possibly new) directory /path/to/file.html.LyXconv/. The -t option determines
the extension added to the output filename passed to the script ($$o, in the
copier definition), the default being "LyXconv". If just . is given, then no
extension is added.
Other changes:
* configure.py: added appropriate copier definitions for html and wordhtml
formats, as well as for the Program pseudo-format.
* lib/Makefile.am and development/scons/scons_manifest.py: add ext_copy.py.
* lib/doc/Customization.lyx: update documentation.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18791 a592a061-630c-0410-9148-cb99ea01b6c8
2007-06-15 17:02:35 +00:00
|
|
|
|
2009-10-24 00:55:28 +00:00
|
|
|
|
|
|
|
def create_dir(new_dir):
|
|
|
|
"Try to create the output directory if it doesn't exist"
|
|
|
|
if not os.path.isdir(new_dir):
|
|
|
|
try:
|
|
|
|
os.makedirs(new_dir)
|
|
|
|
except:
|
|
|
|
error("Unable to create %s" % new_dir)
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
Make HTML export work.
The key is the new copier script lib/scripts/ext_copy.py. Usage:
ext_copy.py [-e ext1,ext2,...] <from file> <to file>
Given a <from file> and <to file>, it will copy all files in the directory
in which from_file is found that have the extensions given in the -e option,
or all files in that directory if no such argument is given. So, for example,
we can do:
python ext_copy.py -e png,html,css /path/from/file.html /path/to/file.html
and all html, png, and css files in /path/from/ will be copied to the
(possibly new) directory /path/to/file.html.LyXconv/. The -t option determines
the extension added to the output filename passed to the script ($$o, in the
copier definition), the default being "LyXconv". If just . is given, then no
extension is added.
Other changes:
* configure.py: added appropriate copier definitions for html and wordhtml
formats, as well as for the Program pseudo-format.
* lib/Makefile.am and development/scons/scons_manifest.py: add ext_copy.py.
* lib/doc/Customization.lyx: update documentation.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18791 a592a061-630c-0410-9148-cb99ea01b6c8
2007-06-15 17:02:35 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main(sys.argv)
|