Anonymous avatar Anonymous committed 2fe429a

a2x: Added a new stytax to the --resource option specifier which allows the
destination path to be specified.

Comments (0)

Files changed (2)

             for r in open(self.resource_manifest):
                 self.resources.append(r.strip())
         for r in self.resources:
-            if os.path.isfile(r):
-                self.resource_files.append(r)
-            elif os.path.isdir(r):
+            if os.path.isdir(r):
                 self.resource_dirs.append(r)
             else:
-                die('missing resource: %s' % r)
+                self.resource_files.append(r)
         # Lastly search among images and stylesheets distributed with asciidoc.
         for p in (os.path.dirname(self.asciidoc), CONF_DIR):
             for d in ('images','stylesheets'):
         '''
         Search html_files for images and CSS resource URIs (html_files can be a
         list of file names or a single file name).
-        If the URIs are relative then copy them from the src_dir to the
-        dst_dir.
+        Copy them from the src_dir to the dst_dir.
         If not found in src_dir then recursively search all specified
-        resources for the file name.
-        Optional additional resources URIs can be passed in the resources list.
-        Does not copy absolute URIs.
+        resource directories.
+        Optional additional resources files can be passed in the resources list.
         '''
         resources = resources[:]
         resources += find_resources(html_files, 'link', 'href',
         resources = list(set(resources))    # Drop duplicates.
         resources.sort()
         for f in resources:
-            f = os.path.normpath(f)
-            if os.path.isabs(f):
-                if not os.path.isfile(f):
-                    warning('missing resource: %s' % f)
-                continue
-            src = os.path.join(src_dir, f)
-            dst = os.path.join(dst_dir, f)
+            if '=' in f:
+                src, dst = f.split('=')
+                if not dst:
+                    dst = src
+            else:
+                src = dst = f
+            src = os.path.normpath(src)
+            dst = os.path.normpath(dst)
+            if os.path.isabs(dst):
+                die('absolute resource file name: %s' % dst)
+            if dst.startswith('..'):
+                die('resource file outside destination directory: %s' % dst)
+            src = os.path.join(src_dir, src)
+            dst = os.path.join(dst_dir, dst)
             if not os.path.isfile(src):
                 for d in self.resource_dirs:
-                    src = find_files(d, os.path.basename(f))
-                    if src:
-                        src = src[0]
+                    d = os.path.join(src_dir, d)
+                    found = find_files(d, os.path.basename(src))
+                    if found:
+                        src = found[0]
                         break
                 else:
                     if not os.path.isfile(dst):
-                        warning('missing resource: %s' % f)
-                    continue    # Continues outer for loop.
-            # Arrive here if relative resource file has been found.
+                        die('missing resource: %s' % src)
+                    continue
+            # Arrive here if resource file has been found.
             if os.path.normpath(src) != os.path.normpath(dst):
                 dstdir = os.path.dirname(dst)
                 shell_makedirs(dstdir)
         for (p,dirs,files) in os.walk(os.path.dirname(opf_file)):
             for f in files:
                 f = os.path.join(p,f)
-                if f.startswith(opf_dir):
+                if os.path.isfile(f):
+                    assert f.startswith(opf_dir)
                     f = '.' + f[len(opf_dir):]
-                f = os.path.normpath(f)
-                if os.path.isfile(f):
-                    resource_files.append(f)
+                    f = os.path.normpath(f)
+                    if f not in ['content.opf']:
+                        resource_files.append(f)
         opf = xml.dom.minidom.parseString(open(opf_file).read())
         manifest_files = []
         manifest = opf.getElementsByTagName('manifest')[0]
                 mimetype = mimetypes.guess_type(f)[0]
                 if mimetype is None:
                     warning('unknown mimetype: %s' % f)
-                    continue
+                    mimetype = 'application/xhtml+xml'
                 item.setAttribute('media-type', mimetype)
                 manifest.appendChild(item)
         if count > 0:
 *--conf-file*='CONF_FILE'::
   Load configuration file. See <<X2,CONF FILES section>>.
 
-*-D, --destination-dir*='PATH'::
+*-D, --destination-dir*='DESTINATION_DIR'::
   Output directory. Defaults to 'SOURCE_FILE' directory.
 
 *-d, --doctype*='DOCTYPE'::
 *-n, --dry-run*::
   Do not do anything just print what would have been done.
 
-*-r, --resource*='PATH'::
-  If 'PATH' refers to a directory recursively search it for required
-  <<X3,resource files>>. If 'PATH' refers to a file add it to the list
-  of required resource files. This option may be specified more than
-  once.
+*-r, --resource*='RESOURCE_SPEC'::
+  Specify a resouce.  This option may be specified more than once.
+  See the <<X3,*RESOURCES*>> section for more details.
 
 *-m, --resource-manifest*='FILE'::
   'FILE' contains a list resources (one per line). Manifest 'FILE'
   //    a2x: --dblatex-opts "-P latex.output.revhistory=0"
 
 
+[[X4]]
 OUTPUT FILES
 ------------
 Output files are written to the directory specified by the
 Resources are files (typically CSS and images) that are required by
 HTML based outputs ('xhtml', 'epub', 'chunked', 'htmlhelp' formats).
 'a2x' scans the generated HTML files and builds a list of required CSS
-and image file. Additional resource files can be specified explicitly
+and image files. Additional resource files can be specified explicitly
 using the *--resource* option.
 
-'a2x' searches for resources in the following locations in the
+'a2x' searches for resource files in the following locations in the
 following order:
 
 . The 'SOURCE_FILE' directory.
-. Directories specified by *--resource* and *--resource-manifest*
-  options (recursively).
+. Resource directories (specified by *--resource* and
+  *--resource-manifest* options) are searched recursively.
 . The 'asciidoc(1)' `images` and `stylesheets` configuration file
-  directories (recursively).
+  directories are searched recursively.
 . The destination directory.
 
 When a resource is found it is copied to the correct relative
-destination directory.  Missing destination sub-directories are
-created automatically.
+destination directory. Destination sub-directories are created
+automatically.
+
+A resource specifier (*--resource* option 'RESOURCE_SPEC') can specify
+a single resource file or a directory to be recursively searched for
+resource files. A resource specifier can be either of the following
+two formats:
+
+  <resource_dir>
+  <resource_file>[=<destination_file>]
+
+Where:
+
+`<resource_dir>`::
+  Specifies a directory (absolute or relative to the 'SOURCE_FILE')
+  which is searched recursively for resource files.
+
+`<resource_file>`::
+  Specifies a resource file (absolute or relative to the
+  'SOURCE_FILE') which is copied to `<destination_file>`. If
+  `<destination_file>` is not specified then it is the same as the
+  `<resource_file>`.
+
+`<destination_file>`::
+  Specifies the destination of the copied source file. The
+  `<destination_file>` path is relative to the destination directory
+  (absolute paths are not allowed). The destination directory is
+  format dependent (see the <<X4,*OUTPUT FILES*>> section for
+  details):
+
+  chunked, htmlhelp;; The chunked directory.
+  epub;;              The archived `OEBPS` directory.
+  xhtml;;             The *DESTINATION_DIR*.
+
+Resource specifier examples:
+
+  ../images
+  doc/README.txt=README.txt
+  /home/srackham/images/tiger.png=images/tiger.png
 
 
 EXAMPLES
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.