X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=lib%2Fscripts%2Fext_copy.py;h=3022d30139642fd2367b84a9ba27893157a61860;hb=fa38ae3fc0f6e957f9b7115d04e72c121b39cf92;hp=1d842f9060f0a539d0efe5898fb485c550f768a9;hpb=adaeffec5a222777ab3db119694780ed2898341c;p=lyx.git diff --git a/lib/scripts/ext_copy.py b/lib/scripts/ext_copy.py index 1d842f9060..3022d30139 100644 --- a/lib/scripts/ext_copy.py +++ b/lib/scripts/ext_copy.py @@ -1,4 +1,3 @@ -#! /usr/bin/env python # -*- coding: utf-8 -*- # file ext_copy.py @@ -10,36 +9,44 @@ # Full author contact details are available in file CREDITS # Usage: -# ext_copy.py [-e ext1,ext2,...] +# ext_copy.py [-d] [-e ext1,ext2,...] [-t target_ext] from_file to_file # This script is to be used as a "copier" script in the sense needed by -# the converter definitions. Given a and , 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 +# 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 +# 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. +# If the -d option is given then the document directory /path/to/ will be used +# to copy the files no subdirectory will be created/used. import getopt, os, shutil, sys from lyxpreview_tools import error + def usage(prog_name): - return "Usage: %s [-e extensions] [-t target extension] " % prog_name + msg = "Usage: %s [-d] [-e extensions] [-t target extension] from_file to_file" + return msg % prog_name + def main(argv): progname = argv[0] exts = [] #list of extensions for which we're checking + use_doc_dir = False targext = "LyXconv" #extension for target directory - opts, args = getopt.getopt(sys.argv[1:], "e:t:") + opts, args = getopt.getopt(sys.argv[1:], "de:t:") for o, v in opts: if o == "-e": exts = v.split(',') if o == "-t": targext = v + if o == "-d": + use_doc_dir = True # input directory if len(args) != 2: @@ -50,13 +57,19 @@ def main(argv): 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)) - - return copy_all(from_dir, to_dir, exts) != True + if use_doc_dir: + to_dir = os.path.dirname(args[1]) + else: + 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)) + + if not copy_all(from_dir, to_dir, exts): + # some kind of failure + return 1 + return 0 def copy_all(from_dir, to_dir, exts): @@ -80,7 +93,7 @@ def copy_all(from_dir, to_dir, exts): shutil.copymode(from_file, to_file) except: pass - return 0 + return True def create_dir(new_dir):