]> thyrsus.com Git - imgsizer.git/commitdiff
Ready to ship.
authorEric S. Raymond <esr@thyrsus.com>
Mon, 30 Jul 2001 04:51:43 +0000 (04:51 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Mon, 30 Jul 2001 04:51:43 +0000 (04:51 +0000)
Makefile
imgsizer

index cce463df66daa8f2eaa239528ef5bcb850af2846..944ffc5454874a10743f75340816499408a3299f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,9 +1,9 @@
 # Makefile for the imgsizer distribution
-VERS=2.0
+VERS=2.1
 
 # These choices are correct for Linux.  Season to taste.
 BINDIR = /usr/bin
-MANDIR = /usr/man/man1
+MANDIR = /usr/share/man/man1
 
 install:
        cp imgsizer $(BINDIR)
index 8b22a35028f80c274a039ca64b707dcf2d925157..f94d109fd764e0d1599e32426eb6d9ac9bcb476d 100755 (executable)
--- a/imgsizer
+++ b/imgsizer
@@ -5,8 +5,7 @@
 # 
 # Fix up IMG tags in given documents to contain correct sizes.  No longer
 # requires the identify(1) program from the ImageMagick suite if you have
-# a decent file(1) and rdjpgcom(1).  To fix up sizes for non-local images
-# it requires the httpget(1) script.
+# a decent file(1) and rdjpgcom(1).
 # 
 # Works with Python 1.5.2
 #
@@ -54,9 +53,9 @@
 #    try commands in least to most expensive order, and notice when a command
 #    returns not to try it again.
 #
-import sys, os, getopt, filecmp, string, re, urllib, commands
+import sys, os, getopt, cmp, string, re, urllib, commands
 
-version = "2.0, 11 July 2001";
+version = "2.1, 26 July 2001";
 
 splash = """imgsizer version %s, Eric S. Raymond <esr@thyrsus.com>
 See <http://www.tuxedo.org/~esr/software.html> for updates."""
@@ -80,7 +79,7 @@ Options:
 
     -n, --no-overwrite
 
-        Don't overwrite existing width and heigbt tags if both are present.
+        Don't overwrite existing width and height tags if both are present.
 
 """
 
@@ -106,7 +105,7 @@ def sizefix(infp, outfp):
             if ch == '':
                 return
             outfp.write(lead)
-            if lead.find('>') > -1:
+            if string.find(lead, '>') > -1:
                 continue
             if not lead in ("img", "IMG"):
                 continue
@@ -150,7 +149,7 @@ def imgsize(src):
                 return (sizes.group(1), sizes.group(2))
             elif status == 127:
                 rdjpgcom = 0
-    # Next try identify(1), more expensive nut bulletproof
+    # Next try identify(1), more expensive but bulletproof
     if magick:
         (status, output) = commands.getstatusoutput("identify " + filename)
         if status == 0:
@@ -158,9 +157,10 @@ def imgsize(src):
             if sizes:
                 return (sizes.group(1), sizes.group(2))
         elif status == 127:
+            sys.stderr.write("imgsizer: giving up on ImageMagick\n")
             magick = 0
     # All attempts failed
-    sys.stderr.write("imgsizer: couldn't analyze " + src)
+    sys.stderr.write("imgsizer: couldn't analyze %s\n" % src)
 
 source  = re.compile('SRC="?([^" \t\n]*)"?', re.I)
 awidth  = re.compile(' *WIDTH="?[0-9]*"?', re.I)
@@ -201,7 +201,7 @@ quotes = 1
 root = "."
 
 out = "imgsizer-out$$"
-dir = "."      # NOTE: if you are doing <yourfile , make sure that pwd is correct! 
+dir = "."      # NOTE: if you are doing <yourfile make sure that pwd is correct! 
 
 # Optimization latches -- if an attempt  to invoke a command returns 127
 # "not found" there will turn off and that command won't be tried again.
@@ -239,8 +239,6 @@ if not arguments:
     sizefix(sys.stdin, sys.stdout)
 else:
     for file in arguments:
-        base = os.path.basename(file) 
-        dir  = os.path.dirname(file) 
         try:
             infp = open(file)
         except:
@@ -248,12 +246,12 @@ else:
             raise SystemExit, 1
         tempfile = file + ".~imgsizer-%d~" % os.getpid()
         try:
-            outfp = open(tempfile)
+            outfp = open(tempfile, "w")
         except OSError:
             print "imgsizer: can't open tempfile"
             raise SystemExit, 1
         sizefix(infp, outfp)
-        if filecmp.cmp(file, tempfile):
+        if cmp.cmp(file, tempfile):
             os.remove(tempfile)
         else:
             try: