Author: kfogel
Date: Thu Aug 23 16:29:02 2007
New Revision: 1080

Log:
* tools/make-ad-sense.py
  (__doc__): Update for below.
  (adsense_id): New variable.
  (adsense_in_file): New function.
  (main): Don't add adsense to a file that already has it.

* lang-makefile
  (www): Restore adsense generation, now that it's safe, reverting r1078.


Modified:
   trunk/lang-makefile
   trunk/tools/make-ad-sense.py

Modified: trunk/lang-makefile
==============================================================================
--- trunk/lang-makefile (original)
+++ trunk/lang-makefile Thu Aug 23 16:29:02 2007
@@ -14,7 +14,7 @@
 all: html html-chunk pdf ps
 
 # The web site post-commit hook runs 'make www'.
-www: all-html
+www: all-html adsense
 
 adsense:
        ../tools/make-ad-sense.py producingoss.html

Modified: trunk/tools/make-ad-sense.py
==============================================================================
--- trunk/tools/make-ad-sense.py        (original)
+++ trunk/tools/make-ad-sense.py        Thu Aug 23 16:29:02 2007
@@ -2,18 +2,20 @@
 
 """Usage: 'make-ad-sense.py HTML-DIR_or_HTML-FILE'
 
-Add AdSense bits to HTML-DIR/*.html or to HTML-FILE.  Note that if you
-run this twice, it will dumbly add the bits again, resulting in weirdness."""
+Add AdSense bits to HTML-DIR/*.html or to HTML-FILE, but only if the
+bits are not already there."""
 
 import sys
 import os
 import os.path
 import re
 
+adsense_id = "pub-5862978179091956"
+
 adsense_left_data = """
 <div id="adsense_left">
 <script type="text/javascript"><!--
-google_ad_client = "pub-5862978179091956";
+google_ad_client = "%s";
 google_ad_width = 120;
 google_ad_height = 600;
 google_ad_format = "120x600_as";
@@ -25,12 +27,12 @@
 </script>
 </div>
 
-"""
+""" % adsense_id
 
 adsense_bottom_data = """
 <div id="adsense_bottom">
 <script type="text/javascript"><!--
-google_ad_client = "pub-5862978179091956";
+google_ad_client = "%s";
 google_ad_width = 728;
 google_ad_height = 90;
 google_ad_format = "728x90_as";
@@ -42,7 +44,7 @@
 </script>
 </div>
 
-"""
+""" % adsense_id
 
 adsense_css = """
 /* Added for AdSense Support */
@@ -68,6 +70,16 @@
     sys.stderr.write(msg + "\n")
     sys.exit(1)
 
+def adsense_in_file(fname):
+    """Return non-False iff file FNAME already contains adsense bits."""
+    # Just scan the whole file, this doesn't need to be efficient.
+    found = False
+    f = file(fname)
+    for line in f:
+        if (line.find(adsense_id) >= 0):
+            found = True
+    return found
+
 def add_adsense_left_html(file):
     lines = open(file, 'r').readlines()
     for i in range(len(lines)):
@@ -124,7 +136,7 @@
       targets = os.listdir(book_dir)
 
     for child in targets:
-        if child[-5:] == '.html':
+        if child[-5:] == '.html' and not adsense_in_file(child):
             try:
                 add_adsense_left_html(os.path.join(book_dir, child))
             except:

_______________________________________________
Producingoss-translators mailing list
[email protected]
http://www.red-bean.com/mailman/listinfo/producingoss-translators

Reply via email to