diff options
author | Tommy Reynolds <Tommy.Reynolds@MegaCoder.com> | 2005-12-11 03:26:10 +0000 |
---|---|---|
committer | Tommy Reynolds <Tommy.Reynolds@MegaCoder.com> | 2005-12-11 03:26:10 +0000 |
commit | c4c0161f570cc0f8ded83b24755f156a6bfccc80 (patch) | |
tree | d50981f43450714a772cd6e0e13d91b3e9c6f577 | |
parent | cb6039e7a61128a2477ad18324015f5ba7e0ff7f (diff) | |
download | fedora-doc-utils-c4c0161f570cc0f8ded83b24755f156a6bfccc80.tar.gz fedora-doc-utils-c4c0161f570cc0f8ded83b24755f156a6bfccc80.tar.xz fedora-doc-utils-c4c0161f570cc0f8ded83b24755f156a6bfccc80.zip |
Allow a document 'figs/' directory to contain its own subdirectory
structure. Copy the directory tree, but only populate it with files
which pass the '-f glob' filter(s). If no filters are given, "*" is
used as a default.
-rw-r--r-- | Makefile.common | 15 | ||||
-rwxr-xr-x | bin/copy-figs | 170 |
2 files changed, 174 insertions, 11 deletions
diff --git a/Makefile.common b/Makefile.common index 4fe83f0..cfba08e 100644 --- a/Makefile.common +++ b/Makefile.common @@ -73,11 +73,8 @@ ${TARGETS}:: # cp ${HTMLCSS} mydoc-en/fedora.css # cp ${HTMLCSSEXTRA} mydoc-en/watermark.png # cp ${FDPDIR}/docs-common/images/watermark.png mydoc-en/ -# mkdir -p mydoc-en/figs -# cp -p figs/*-${LANG}.* mydoc-en/figs +# ${FDPDIR}/docs-common/bin/copy-figs -f '*.png' figs mydoc-en/ # but we do avoid copying EPS files since they are nonsense to the HTML world. -# Also, we create the figs directory only if the document dir has a "figs/". -# I don't think we need to do this for a nochunks output, though. # define HTML_template ${DOCBASE}-$(1)/index.html:: ${DOCBASE}-$(1).xml $$(XMLEXTRAFILES-$(1)) @@ -87,13 +84,9 @@ ${DOCBASE}-$(1)/index.html:: ${DOCBASE}-$(1).xml $$(XMLEXTRAFILES-$(1)) cp ${HTMLCSS} $(DOCBASE)-$(1)/fedora.css [ -z "${HTMLCSSEXTRA}" ] || \ cp ${HTMLCSSEXTRA} $(DOCBASE)-$(1)/watermark.png - [ ! -d figs ] || ( \ - mkdir -p ${DOCBASE}-$(1)/figs; \ - find figs -type f -iname '*.*' -print | \ - egrep -vi '*.eps' | \ - egrep '(.*-$(1)..*)|([^-]*[.][^-]*)' | \ - while read x; do cp -f $$$${x} ${DOCBASE}-$(1)/figs; done \ - ) && exit 0 + [ ! -d figs ] || \ + ${FDPDIR}/docs-common/bin/copy-figs -v -f '*.png' \ + figs $(DOCBASE)-$(1) endef # html:: $(foreach LANG,${LANGUAGES},$(DOCBASE)-$(LANG)/index.html) diff --git a/bin/copy-figs b/bin/copy-figs new file mode 100755 index 0000000..fe066ec --- /dev/null +++ b/bin/copy-figs @@ -0,0 +1,170 @@ +#!/bin/bash +######################################################################## +# Copy a file system hierarchy to a destination tree, copying only +# files that are either: language neutral, or specific to a particular +# language. +######################################################################## +# We assume the following naming convention, because that is what the +# docs currently seem to use. +# +# <filename>-<locale>.<ext> is a language-specific file, such as +# "foo-en.png". +# +# <filename>.<ext> is a language-neutral file, such as "foo.png". +# +# What makes this complicated is that some files already have embedded +# dashes that have nothing to do with locales, thus we have an ambiguous +# filename grammar. +######################################################################## + +targetLang=en +bnFilter= +DEBUG=no +VERBOSE=no + +die() { + printf "${ME}: %s\n" "$@" >&2 + exit 1 +} + +glob2sed() { + s="" + i=1 + while true + do + c=$(echo "${1}" | cut -c$i) + if [ -z "${c}" ]; then + break + fi + case "${c}" in + '.' ) + s="${s}[.]" + ;; + '*' ) + s="${s}.*" + ;; + '?' ) + s="${s}." + ;; + * ) + s="${s}${c}" + ;; + esac + i=$(expr $i + 1) + done + echo "${s}" +} + +ME=$(/bin/basename $0) +USAGE="usage: ${ME} [-D] [-f glob] [-l lang] [-V] /path/to/source/dir /path/to/dest/dir" + +while getopts Df:l:v c +do + case "${c}" in + D) DEBUG='';; + f) + sedFilter=$(glob2sed "${OPTARG}") + bnFilter="${bnFilter} -e /^${sedFilter}$/p" + ;; + l) targetLang="${OPTARG}";; + v) VERBOSE='';; + *) echo "${USAGE}" >&2; exit 1;; + esac +done + +shift $(expr ${OPTIND} - 1) + +if [ $# -ne 2 ]; then + echo "${USAGE}" >&2 + exit 1 +fi + +SRC="$1" +DST="$2" + +shift 2 + +case "${SRC}" in +/* ) + ;; +~/* ) + SRC=${HOME}/$(echo "${SRC}" | cut -c2,-) + ;; +* ) + SRC="$(/bin/pwd)/${SRC}" + ;; +esac + +case "${DST}" in +/* ) + ;; +~/* ) + DST=${HOME}/$(echo "${DST}" | cut -c2,-) + ;; +* ) + DST="$(/bin/pwd)/${DST}" + ;; +esac + +if [ -z "${bnFilter}" ]; then + bnFilter="-e /^.*$/p" +fi +[ "${DEBUG}" ] || echo >&2 "bnFilter=|${bnFilter}|" + +leadin=$(/usr/bin/dirname "${SRC}") +[ "${DEBUG}" ] || echo >&2 "leadin=|${leadin}|" + +find "${SRC}" -print | +while read fn +do + # Skip anything that even looks like CVS or SVN + case "${fn}" in + *CVS* | *svn* ) + continue + ;; + esac + # Figure out the relative path for this pathname chunk + rp=$( + echo $(/usr/bin/dirname "${fn}")/$(/bin/basename "${fn}") | + /bin/sed "s;^${leadin}/*;;" + ) + [ "${DEBUG}" ] || echo >&2 "rp=|${rp}|" + # Copy directories, even if they are going to be empty. + # Inodes are cheap, as long as you have enough. + if [ -d "${fn}" ]; then + [ "${VERBOSE}" ] || echo >&2 "Creating ${rp}" + /bin/mkdir -p "${DST}"/"${rp}" + continue + fi + # May not want this file under any circumstances + bn=$(/bin/basename "${rp}") + filteredBn=$(echo "${bn}" | sed -n ${bnFilter}) + if [ -z "${filteredBn}" ]; then + [ "${DEBUG}" ] || echo >&2 "Filter rejects |${fn}|" + continue + fi + # We want this file if the language matches or if it is + # language neutral + copyIt=no + case "${bn}" in + *-${LANG}.* ) + # Has matching language + copyIt=yes + ;; + *-* ) + # Doesn't match target language + ;; + * ) + # Assume language neutral file + copyIt=yes + ;; + esac + [ "${DEBUG}" ] || echo >&2 "copyIt=${copyIt}" + # Copy file if we like it + if [ "${copyIt}" = "yes" ]; then + [ "${VERBOSE}" ] || echo >&2 "Copying file |$fn|" + cp "${fn}" "${DST}/${rp}" + else + [ "${VERBOSE}" ] || echo >&2 "Rejecting file |$fn|" + fi +done |