[csw-devel] SF.net SVN: opencsw:[388] utilities/mirror_check.py

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Tue Jul 12 15:25:13 CEST 2011


Revision: 388
          http://opencsw.svn.sourceforge.net/opencsw/?rev=388&view=rev
Author:   wahwah
Date:     2011-07-12 13:25:13 +0000 (Tue, 12 Jul 2011)

Log Message:
-----------
mirror_check: Allow to specify the mirror index

Modified Paths:
--------------
    utilities/mirror_check.py

Modified: utilities/mirror_check.py
===================================================================
--- utilities/mirror_check.py	2011-07-12 13:25:01 UTC (rev 387)
+++ utilities/mirror_check.py	2011-07-12 13:25:13 UTC (rev 388)
@@ -21,13 +21,14 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 import logging
+import optparse
 import re
 import threading
 import urllib2
 
 logging.basicConfig(level=logging.INFO)
 
-MIRRORS_URL = "http://www.opencsw.org/mirrors"
+DEFAULT_MIRRORS_URL = "http://www.opencsw.org/mirrors"
 URL_RE_STR = r"^(?P<url>(ht|f)tp://\w+(\.\w+)*.*)$"
 URL_OPENCSW, URL_BLASTWAVE, URL_UNKNOWN, URL_NOTFOUND = (
         "OpenCSW", "Blastwave", "Unknown", "Not found")
@@ -47,9 +48,11 @@
 
     url_re = re.compile(URL_RE_STR)
 
-    def __init__(self):
+    def __init__(self, mirror_url):
+        self.mirror_url = mirror_url
         self.urls_by_identification = {}
         self.identifications_by_url = {}
+        logging.info("mirror_url=%s", self.mirror_url)
 
     def RemoveHtmlComments(self, html):
         """Removes HTML comments from the HTML code.
@@ -65,14 +68,14 @@
                 yield word
 
     def GetUrls(self):
-        url_d = urllib2.urlopen(MIRRORS_URL)
+        url_d = urllib2.urlopen(self.mirror_url)
         mirrors_html = url_d.read()
         return self.ExtractUrls(mirrors_html)
 
     def IdentifyUrls(self, urls):
 
         class UrlIdentifier(threading.Thread):
-            
+
             def __init__(self, url, callback):
                 super(UrlIdentifier, self).__init__()
                 self.url = url
@@ -138,7 +141,12 @@
 
 
 def main():
-    cmc = OpencswMirrorChecker()
+    parser = optparse.OptionParser()
+    parser.add_option("-m", "--mirror", dest="mirror",
+                      help="Mirror URL, by default %s" % DEFAULT_MIRRORS_URL,
+                      default=DEFAULT_MIRRORS_URL)
+    options, args = parser.parse_args()
+    cmc = OpencswMirrorChecker(options.mirror)
     cmc.Run()
 
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.


More information about the devel mailing list