Update of /cvsroot/audacity/audacity-src/scripts/mw2html_audacity
In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv22890

Modified Files:
        mw2html.py 
Log Message:
Removing all external links except licenses.

Index: mw2html.py
===================================================================
RCS file: /cvsroot/audacity/audacity-src/scripts/mw2html_audacity/mw2html.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- mw2html.py  1 Jun 2009 01:34:11 -0000       1.4
+++ mw2html.py  6 Jun 2009 12:13:32 -0000       1.5
@@ -126,30 +126,51 @@
   
   return nurl
 
-def find_tag_limits(doc, start_string, end_tag, start_tag):
+def find_tag_limits(doc, filter_string, end_tag, start_tag, start_point = 0):
 # find tag limits - start_string must be an unique identifier within doc
 
-  i1 = doc.find(start_string)
+  i1 = doc.find(filter_string, start_point)
 
-  if (i1 == -1):
+  if i1 == -1:
     return (-1,-1)
 
+  aux   = doc.rfind(start_tag, start_point, i1+len(filter_string))
+  
+  # we've found the filter_string but it has not the start_tag, so we return a 
different value
+  # telling the script to keep searching starting on the end of the 
filter_string found
+  if aux == -1:
+    return (-2, i1+len(filter_string))
+
+  i1 = aux
   sdiv = i1
-  ediv = i1 + len(start_string)
+  ediv = i1 + len(start_tag)
   while(sdiv < ediv and sdiv != -1):
       sdiv = doc.find(start_tag, sdiv+len(start_tag))
       ediv = doc.find(end_tag  , ediv+len(end_tag))
 
   return (i1, ediv)
 
+def clean_tag(doc, filter_string, end_tag, start_tag):
+  #clean tagged text function
+  start_point = 0
+  while True:
+    (start1, start2) = find_tag_limits(doc, filter_string, end_tag, start_tag, 
start_point)
+    if start1 == -1 or start2 == -1:
+      return doc
+    if start1 == -2:
+      start_point = start2
+      continue
+    end1 = doc.find('>', start1)+1;
+    end2 = start2 + len(end_tag);
+    doc = doc[:start1]+doc[end1:start2]+doc[end2:]
+  
 def remove_tag(doc, start_string, end_tag, start_tag):
   #remove tagged text function
-  ndoc = doc
   while True:
-    (i1, i2) = find_tag_limits(ndoc, start_string, end_tag, start_tag)
+    (i1, i2) = find_tag_limits(doc, start_string, end_tag, start_tag)
     if i1 == -1 or i2 == -1:
-      return ndoc
-    ndoc = ndoc[:i1]+ndoc[i2+len(end_tag):]
+      return doc
+    doc = doc[:i1]+doc[i2+len(end_tag):]
  
 def monobook_fix_html(doc, page_url):
   """
@@ -251,6 +272,9 @@
 def pos_html_transform(doc):
   global footer_text, config
   
+  # Remove empty links
+  doc = clean_tag(doc, 'href=""', '</a>', '<a ');
+  
   if config.special_mode:
     # Remove external link rel stylesheet
     doc = re.sub(r'<link rel="stylesheet" href="http://[\s\S]+?/>',r'',doc)
@@ -785,6 +809,8 @@
       new_urls += [u]
       item.url = url_to_relative(u, url)
     else:
+      if not any( license in u for license in ('creativecommons.org', 
'wxwidgets.org', 'gnu.org', 'mediawiki.org') ):
+        item.url = ''
       if config.debug:
         print 'DENIED     - ', u
 


------------------------------------------------------------------------------
OpenSolaris 2009.06 is a cutting edge operating system for enterprises 
looking to deploy the next generation of Solaris that includes the latest 
innovations from Sun and the OpenSource community. Download a copy and 
enjoy capabilities such as Networking, Storage and Virtualization. 
Go to: http://p.sf.net/sfu/opensolaris-get
_______________________________________________
Audacity-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/audacity-cvs

Reply via email to