gimp-help-2 r2694 - in trunk: . tools
- From: ulfehlert svn gnome org
- To: svn-commits-list gnome org
- Subject: gimp-help-2 r2694 - in trunk: . tools
- Date: Sat, 17 Jan 2009 19:42:00 +0000 (UTC)
Author: ulfehlert
Date: Sat Jan 17 19:42:00 2009
New Revision: 2694
URL: http://svn.gnome.org/viewvc/gimp-help-2?rev=2694&view=rev
Log:
2009-01-17 Ulf-D. Ehlert <ulfehlert svn gnome org>
* tools/validate_references.py: simplified verbose messages
by using Python's logging module
* Makefile.am: add target "status-LANG" for printing translation
statistics; adapted making HTML drafts to new directory structure;
use MAKEFLAGS variable on recursive make calls
* Makefile.GNU: adapted making HTML drafts to new directory structure;
fixed recursive make calls by using MAKEFLAGS variable and "-f"
option; added targets for forced updating of po files
Modified:
trunk/ChangeLog
trunk/Makefile.GNU
trunk/Makefile.am
trunk/tools/validate_references.py
Modified: trunk/Makefile.GNU
==============================================================================
--- trunk/Makefile.GNU (original)
+++ trunk/Makefile.GNU Sat Jan 17 19:42:00 2009
@@ -42,11 +42,16 @@
DOCBOOK2ODF = docbook2odf
DOCBOOK2ODFFLAGS =
+XDGOPEN = xdg-open
+
# Standard shell commands
echo_n = echo -n
mkdir_p = mkdir -p
ln_s = ln -s
+# Calling make recursively
+RMAKE = $(MAKE) -f Makefile.GNU $(MAKEFLAGS) --no-print-directory
+
# FIXME/TODO:
# make it work with srcdir != builddir
# Directories
@@ -248,7 +253,7 @@
# Targets suitable for command line
# ("make pot" will work even if pot exists)
-pot update-pot: potfiles ;
+pot: potfiles ;
potfiles: $(POT_FILES) ;
@@ -262,22 +267,16 @@
$$(cmd) $$(call make_target_dir,$$@)
$$(msg) "[PO] $$@"
$$(cmd) if test -s $$<; then $$(call pot2po,$$<,$(1),$$@); else touch $$@; fi
-# Debugging
-list-pofiles-$(1) list-po-files-$(1) list-po-$(1):
- @echo $$($(1)_PO_FILES)
po-$(1): $$($(1)_PO_FILES)
$$(cmd) if test -e messages.mo; then rm -f messages.mo; fi
endef
-
$(foreach LANG,$(PO_LANGS),$(eval $(call MAKE_PO_RULES,$(LANG))))
-# Targets suitable for command line
-update-po-%: po-%
-
# Special case 'en': do nothing :-)
po-en: ;
# Print translation statistics
+
status-%: po-status-% ;
po-status-%: po-%
$(cmd) perl tools/get_po_status.pl po/$*
@@ -288,6 +287,16 @@
perl tools/get_po_status.pl --nofiles --nosummary $${podir} || break; \
done
+# Force updating po file(s)
+update-po/%.po:
+ $(cmd) pot=`echo $* | sed -e 's|[^/]*|pot|; s/$$/.pot/'`; \
+ $(RMAKE) -W $${pot} po/$*.po
+
+force-po/%:
+ $(cmd) for po in po/$*/*.po; do \
+ $(RMAKE) update-$${po}; \
+ done
+
########################################################################
#### Make XML files: PO --> XML(non-en) ####
@@ -455,42 +464,59 @@
########################################################################
-#### HTML draft (single page preview) ####
+#### Make HTML draft (single page preview) ####
########################################################################
-%.draft: %.xml stylesheets/drafthtml.xsl
- @echo "Making draft page(s), ignore any XSLT complaints:"
+preview-xml/%.xml: xml/%.xml stylesheets/drafthtml.xsl
$(cmd) id=`sed -e 's/.*id=.//; tmatch; d; :match; s/["'"'"'].*//; q' $<`; \
- test -n "$$id" || id=noname; \
- langs="$(shell echo $@ | \
- sed -e 's,^src/.*,$(LANGUAGES),; t' \
- -e 's,^xml/\([^/]\+\)/.*,\1,')"; \
- for lang in $${langs}; do \
- destdir=html/$${lang}; \
- test -d $${destdir} && continue || \
- $(mkdir_p) $${destdir}; \
- cp -fp $(srcdir)/stylesheets/*.css \
- $(srcdir)/stylesheets/$$lang/*.css \
- $${destdir} 2>/dev/null; \
- done; \
- \
- for lang in $${langs}; do \
- destdir=html/$${lang}; \
- echo "Making $${destdir}/$${id}-draft.html ... "; \
- xmlfile="$<"; xmlfile=$${xmlfile#*/}; \
- xmlfile=xml/$${lang}/$${xmlfile#$${lang}/}; \
- if [ "$${lang}" = "no" ]; then lang="nn"; fi; \
- $(XSLTPROC) \
- $(XSLTFLAGS) $(XSLTEXTRAFLAGS) \
- --xinclude \
- --stringparam l10n.gentext.default.language $${lang} \
- --novalid \
- --output $${destdir}/$${id}-draft.html \
- $(srcdir)/stylesheets/drafthtml.xsl \
- $${xmlfile} \
- ; \
- done && \
- echo "(Remember that links won't work in a draft file.)"
+ test -n "$${id}" || id=noname; \
+ lang=$(shell echo $< | sed -e 's,^xml/,,; s,/.*,,'); \
+ destdir=html/$${lang}; \
+ $(mkdir_p) $${destdir}; \
+ cp -f $(srcdir)/stylesheets/*.css $(srcdir)/stylesheets/$${lang}/*.css\
+ $${destdir} 2>/dev/null; \
+ if [ "$${lang}" = "no" ]; then lang="nn"; fi; \
+ destfile="$${destdir}/$${id}-draft.html"; \
+ echo "Making $${destfile} (ignore any XSLT complaints) ..."; \
+ $(XSLTPROC) \
+ $(XSLTFLAGS) $(XSLTEXTRAFLAGS) \
+ --xinclude \
+ --stringparam l10n.gentext.default.language $${lang} \
+ --novalid \
+ --output $${destfile} \
+ $(srcdir)/stylesheets/drafthtml.xsl \
+ $<
+
+preview-src/%.xml: $(foreach lang,$(LANGUAGES),preview-xml/$(lang)/%.xml)
+ $(msg) "(Remember that links won't work in a draft file.)"
+
+ifeq ("$(XDGOPEN)", "")
+preview-po/%.po: preview-xml/%.xml ;
+else
+preview-po/%.po: preview-xml/%.xml
+ $(cmd) if type xdg-open >/dev/null 2>&1; then \
+ xml=$(shell echo $< | sed -e 's|preview-||'); \
+ lang=`echo $${xml} | sed -e 's,^xml/,,; s,/.*,,'`; \
+ id=`sed -e 's/.*id=.//; tmatch; d; \
+ :match; s/["'"'"'].*//; q' $${xml}`; \
+ test -n "$${id}" || id=noname; \
+ destfile="html/$${lang}/$${id}-draft.html"; \
+ test -e $${destfile} && xdg-open $${destfile}; \
+ fi
+endif
+
+
+# For backward compatibility:
+
+xml/%.draft: preview-xml/%.xml
+ $(msg) "(Remember that links won't work in a draft file.)"
+
+src/%.draft: preview-src/%.xml ;
+
+# Synonyms
+draft-xml/%.xml: preview-xml/%.xml ;
+draft-src/%.xml: preview-src/%.xml ;
+draft-po/%.po: preview-po/%.po ;
########################################################################
@@ -631,13 +657,13 @@
fi
check-images-%: FORCE
- $(cmd) $(MAKE) --no-print-directory check-image-references \
+ $(cmd) $(RMAKE) check-image-references \
VALIDATEREFERENCESFLAGS="--imgdir=images/C,images/$*"
# special case 'en':
check-images-en check-images-C: check-image-references ;
-.PHONY: checks check-svn-property check-image-references
+.PHONY: check-svn-property check-image-references
########################################################################
Modified: trunk/Makefile.am
==============================================================================
--- trunk/Makefile.am (original)
+++ trunk/Makefile.am Sat Jan 17 19:42:00 2009
@@ -44,6 +44,9 @@
## DOCBOOK2ODF = docbook2odf
DOCBOOK2ODFFLAGS =
+# Calling make recursively
+RMAKE = $(MAKE) $(MAKEFLAGS) --no-print-directory
+
# Standard shell commands
echo_n = echo $(ECHO_N)
@@ -312,6 +315,18 @@
# Special case 'en': do nothing :-)
po-en: ;
+# Print translation statistics
+
+status-%: po-status-% ;
+po-status-%: po-%
+ $(cmd) perl tools/get_po_status.pl po/$*
+
+status-all: po-status-all ;
+po-status-all:
+ $(cmd) for podir in po/*; do \
+ perl tools/get_po_status.pl --nofiles --nosummary $${podir} || break; \
+ done
+
########################################################################
#### Make XML files: PO --> XML(non-en) ####
@@ -544,42 +559,45 @@
########################################################################
-#### HTML draft (single page preview) ####
+#### Make HTML draft (single page preview) ####
########################################################################
-%.draft: %.xml stylesheets/drafthtml.xsl
- @echo "Making draft page(s), ignore any XSLT complaints:"
- $(cmd) id=`$(SED) -e 's/.*id=.//; tmatch; d; :match; s/["'"'"'].*//; q' $<`; \
- test -n "$$id" || id=noname; \
- langs="$(shell echo $@ | \
- $(SED) -e 's,^src/.*,$(LANGUAGES),; t' \
- -e 's,^xml/\([^/]\+\)/.*,\1,')"; \
- for lang in $${langs}; do \
- destdir=html/$${lang}; \
- test -d $${destdir} && continue || \
- $(MKDIR_P) $${destdir}; \
- cp -fp $(srcdir)/stylesheets/*.css \
- $(srcdir)/stylesheets/$$lang/*.css \
- $${destdir} 2>/dev/null; \
- done; \
- \
- for lang in $${langs}; do \
- destdir=html/$${lang}; \
- echo "Making $${destdir}/$${id}-draft.html ... "; \
- xmlfile="$<"; xmlfile=$${xmlfile#*/}; \
- xmlfile=xml/$${lang}/$${xmlfile#$${lang}/}; \
- if [ "$${lang}" = "no" ]; then lang="nn"; fi; \
- $(XSLTPROC) \
- $(XSLTFLAGS) $(XSLTEXTRAFLAGS) \
- --xinclude \
- --stringparam l10n.gentext.default.language $${lang} \
- --novalid \
- --output $${destdir}/$${id}-draft.html \
- $(srcdir)/stylesheets/drafthtml.xsl \
- $${xmlfile} \
- ; \
- done && \
- echo "(Remember that links won't work in a draft file.)"
+preview-xml/%.xml: xml/%.xml stylesheets/drafthtml.xsl
+ $(cmd) id=`sed -e 's/.*id=.//; tmatch; d; :match; s/["'"'"'].*//; q' $<`; \
+ test -n "$${id}" || id=noname; \
+ lang=$(shell echo $< | sed -e 's,^xml/,,; s,/.*,,'); \
+ destdir=html/$${lang}; \
+ $(mkdir_p) $${destdir}; \
+ cp -f $(srcdir)/stylesheets/*.css $(srcdir)/stylesheets/$${lang}/*.css\
+ $${destdir} 2>/dev/null; \
+ if [ "$${lang}" = "no" ]; then lang="nn"; fi; \
+ destfile="$${destdir}/$${id}-draft.html"; \
+ echo "Making $${destfile} (ignore any XSLT complaints) ..."; \
+ $(XSLTPROC) \
+ $(XSLTFLAGS) $(XSLTEXTRAFLAGS) \
+ --xinclude \
+ --stringparam l10n.gentext.default.language $${lang} \
+ --novalid \
+ --output $${destfile} \
+ $(srcdir)/stylesheets/drafthtml.xsl \
+ $<
+
+preview-po/%.po: preview-xml/%.xml ;
+
+preview-src/%.xml: $(foreach lang,$(LANGUAGES),preview-xml/$(lang)/%.xml)
+ $(msg) "(Remember that links won't work in a draft file.)"
+
+# For backward compatibility:
+
+xml/%.draft: preview-xml/%.xml
+ $(msg) "(Remember that links won't work in a draft file.)"
+
+src/%.draft: preview-src/%.xml ;
+
+# Synonyms
+draft-xml/%.xml: preview-xml/%.xml ;
+draft-src/%.xml: preview-src/%.xml ;
+draft-po/%.po: preview-po/%.po ;
########################################################################
@@ -646,7 +664,7 @@
fi
check-images-%: FORCE
- $(cmd) $(MAKE) --no-print-directory check-image-references \
+ $(cmd) $(RMAKE) check-image-references \
VALIDATEREFERENCESFLAGS="--imgdir=images/C,images/$*"
# special case 'en':
Modified: trunk/tools/validate_references.py
==============================================================================
--- trunk/tools/validate_references.py (original)
+++ trunk/tools/validate_references.py Sat Jan 17 19:42:00 2009
@@ -31,10 +31,11 @@
import getopt
import re
import xml.sax
+import logging
-# TODO: use the Python logging system(!?)
-#import logging
-
+# Configure logging
+logging.basicConfig(format="%(message)s", level=logging.WARNING)
+Logger = logging.getLogger()
# Nodes containing filereferences in a DocBook XML file
IMAGE_NODES = ["imagedata", "graphic", "inlinegraphic"]
@@ -52,9 +53,8 @@
access methods common to both derived List classes.
"""
- def __init__(self, verbose=0):
- self.verbose = verbose
- self.data = {}
+ def __init__(self):
+ self.data = {}
def __contains__(self, key):
"""Is there an entry 'key'?."""
@@ -78,12 +78,15 @@
Set the info to False rather than deleting it,
so that "removing" while iterating is possible.
"""
- if self.data.has_key(key):
- self.data[key] = False
+ #if key in self.data: self.data[key] = False
+ self.data[key] = False
+
+ def files(self):
+ return [x for x in self.data if self.data[x]]
def size(self):
"""Return the number of non-empty data entries."""
- return len([x for x in self.data if self.data[x]])
+ return len(self.files())
def __len__(self):
"""Return the number of data entries."""
@@ -98,10 +101,9 @@
def difference(self, other):
"""Remove entries common to 'self' and 'other'."""
- for key in self.data.iterkeys():
- if key in other:
- self.erase(key)
- other.erase(key)
+ for key in (k for k in self.data if k in other):
+ self.erase(key)
+ #other.erase(key)
class ImageFilesList(FileNameContainer):
@@ -111,8 +113,8 @@
in the specified 'images/' directory.
"""
- def __init__(self, verbose=0):
- super(ImageFilesList, self).__init__(verbose)
+ def __init__(self):
+ super(ImageFilesList, self).__init__()
def find(self, imageroot):
"""Search for PNG and JPG files in the image directory."""
@@ -121,48 +123,39 @@
self.imageroot = os.path.normpath(imageroot)
imageroot = self.imageroot + "/"
- if self.verbose == 1:
- sys.stderr.write("searching images in %s ... " % imageroot)
- elif self.verbose > 1:
- sys.stderr.write("searching images in %s ... \n" % imageroot)
+ Logger.info("searching images in %s ..." % imageroot)
for root, dirs, files in os.walk(self.imageroot):
- if self.verbose > 2:
- sys.stderr.write(" entering " + root + "\n")
for prune in [ 'callouts', '.svn' ]:
if prune in dirs:
dirs.remove(prune)
- # ignore images in the first level of the images dir
- if root.endswith('images'):
- if self.verbose > 2:
- sys.stderr.write(" skipping " + root + "\n")
+ # ignore images in the first level of the images dirs
+ if root == self.imageroot:
+ Logger.debug("skipping root dir %s" % root)
continue
# don't care about other files than images files
for filename in (name for name in files
if IMAGEFILE_REGEX.match(name)):
filepath = os.path.join(root, filename)
- if self.verbose > 1:
- sys.stderr.write(filepath + '\n')
+ Logger.debug(filepath)
self.add(filepath.replace(imageroot, ""))
- if self.verbose:
- sys.stderr.write("%d files\n" % len(self.data))
+ Logger.info("found %d images files" % len(self.data))
def report(self):
"""Print the list of orphaned image files, i.e. image files
which are not referred to in any XML source file.
"""
- files = [fname for fname in self.data.keys() if self.data[fname]]
- if self.verbose:
- colon, plural_s = ":", "s"
- if len(files) == 0: colon = ""
- if len(files) == 1: plural_s = ""
- sys.stderr.write("%d orphaned image file%s%s\n" % \
- (len(files), plural_s, colon))
+ files = self.files()
+ Logger.info("%d orphaned image file%s%s" % \
+ (len(files), char_if("s", len(files) != 1),
+ char_if(":", len(files) != 0)))
+ #sys.stderr.flush()
for imagefile in sorted(files):
print "ORPHANED:", os.path.join(self.imageroot, imagefile)
+ sys.stdout.flush()
class ImageReferencesList(FileNameContainer):
@@ -173,8 +166,8 @@
('image-file', 'source-file') pairs.
"""
- def __init__(self, verbose=0):
- super(ImageReferencesList, self).__init__(verbose)
+ def __init__(self):
+ super(ImageReferencesList, self).__init__()
self.cur_files = [] # stack for files in progress
self.all_files = 0 # visited files
self.handler = XMLHandler(self)
@@ -187,48 +180,46 @@
"""
parser = xml.sax.make_parser()
parser.setContentHandler(self.handler)
+ # "Optionally do not perform Namespace processing
+ # (implies namespace-prefixes)."
parser.setFeature(xml.sax.handler.feature_namespaces, 0)
+ # "Do not include external general (text) entities."
parser.setFeature(xml.sax.handler.feature_external_ges, 0)
+ # "Do not include any external parameter entities,
+ # even the external DTD subset."
parser.setFeature(xml.sax.handler.feature_external_pes, 0)
return parser
def find(self, source_file):
"""Parse XML files and extract image references."""
- if self.verbose > 1:
- sys.stderr.write("parsing XML files ... \n")
- elif self.verbose:
- sys.stderr.write("parsing XML files ... ")
-
+ Logger.info("parsing XML files ... ")
self.push_file(source_file)
+ Logger.debug("parsing %s" % source_file)
+
try:
self.parser.parse(source_file)
except xml.sax.SAXException, err:
- sys.stderr.write("ERROR parsing %s\n" % err)
+ Logger.error("ERROR parsing %s" % err)
except:
- sys.stderr.write("ERROR reading %s\n" % source_file)
- assert(len(self.cur_files) == 1)
+ Logger.error("ERROR reading %s" % source_file)
- if self.verbose > 1:
- sys.stderr.write("parsed %d files, %d references\n" % \
- (self.all_files, self.size()))
- elif self.verbose:
- sys.stderr.write("%d files, %d references\n" % \
- (self.all_files, self.size()))
+ assert(len(self.cur_files) == 1)
+ Logger.info("parsed %d files, %d references" % \
+ (self.all_files, len(self.data)))
def report(self):
"""Print the list of broken image referencess
in the XML source file(s).
"""
- files = [fname for fname in self.data.keys() if self.data[fname]]
- if self.verbose:
- colon, plural_s = ":", "s"
- if len(files) == 0: colon = ""
- if len(files) == 1: plural_s = ""
- sys.stderr.write("%d broken image reference%s%s\n" % \
- (len(files), plural_s, colon))
+ files = self.files()
+ Logger.info("%d broken image reference%s%s" % \
+ (len(files), char_if("s", len(files) != 1),
+ char_if(":", len(files) != 0)))
+ #sys.stderr.flush()
for imagefile in sorted(files):
print "BROKEN: images/%s IN %s" % (imagefile, self.data[imagefile])
+ sys.stdout.flush()
# Internal stack methods to keep track of the opened files
@@ -251,6 +242,7 @@
def __init__(self, owner):
#super(XMLHandler, self).__init__()
self.owner = owner
+
def startElement(self, name, attrs):
"""Handle image nodes."""
if name in IMAGE_NODES:
@@ -261,20 +253,18 @@
filename = os.path.join(os.path.dirname(self.owner.current_file()),
attrs.getValue('href'))
if os.path.isfile(filename):
- if self.owner.verbose > 1:
- sys.stderr.write("parsing " + str(filename) + "\n")
- self.owner.push_file(filename)
parser = self.owner.make_parser()
+ self.owner.push_file(filename)
+ Logger.debug("parsing %s" % filename)
try:
parser.parse(filename)
except xml.sax.SAXException, err:
- sys.stderr.write("ERROR parsing %s\n" % err)
+ Logger.error("ERROR parsiong %s" % err)
except:
- sys.stderr.write("ERROR reading %s\n" % filename)
+ Logger.error("ERROR reading %s" % filename)
self.owner.pop_file()
else:
- if self.owner.verbose > 1:
- sys.stderr.write("skipping " + str(filename) + "\n")
+ Logger.warn("not parsing %s" % filename)
def main():
@@ -294,7 +284,6 @@
is the set containing files in I but not in R, that is the set
of images not referenced in the XML files (orphaned images).
"""
- verbose = 0
gimp_help_root_dir = "."
xml_dir = "src"
img_dirs = "images/C"
@@ -314,7 +303,7 @@
if opt == "-h" or opt == "--help":
usage()
elif opt == "-v" or opt == "--verbose":
- verbose += 1
+ Logger.setLevel(Logger.getEffectiveLevel() - logging.DEBUG)
elif opt in ["-r", "--root"]:
gimp_help_root_dir = arg
elif opt in ["-x", "--xmldir", "-s", "--srcdir"]:
@@ -338,8 +327,7 @@
try:
os.chdir(gimp_help_root_dir)
except OSError, (errno, strerror):
- sys.stderr.write("Error: " + strerror + ": " + \
- gimp_help_root_dir +"\n")
+ Logger.error("ERROR: %s: %s" % (strerror, gimp_help_root_dir))
sys.exit(errno)
# Check for the correct directory.
@@ -363,11 +351,11 @@
find_broken_references = True
# Step 1: find all image references.
- image_refs = ImageReferencesList(verbose)
+ image_refs = ImageReferencesList()
image_refs.find(xml_root_file)
# Step 2: find all image files.
- image_files = ImageFilesList(verbose)
+ image_files = ImageFilesList()
if isinstance(img_dirs, str): img_dirs = [img_dirs]
for imgdir in img_dirs:
image_files.find(imgdir)
@@ -389,13 +377,13 @@
def usage(exitcode=0, msg=""):
"""Help the user."""
if exitcode > 0 or msg:
- sys.stderr.write("Error: " + msg + "\n")
+ sys.stderr.write("Error: %s\n" % msg)
sys.stderr.write("(try \"%s --help\")\n" % sys.argv[0])
else:
sys.stdout.write ( """\
validate_references - validates image file references in DocBook xml files
-Copyright (C) 2006-2008 RÃman Joost,
+Copyright (C) 2006-2007 RÃman Joost,
(C) 2008-2009 RÃman Joost, Ulf-D. Ehlert
Usage: validate_references.py [options]
@@ -411,5 +399,13 @@
\n""")
sys.exit(exitcode)
+
+def char_if(char, cond):
+ if cond:
+ return char
+ else:
+ return ""
+
+
if __name__ == "__main__":
main()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]