[Pywikipedia-l] SVN: [5951] trunk/pywikipedia/checkimages.py

filnik at svn.wikimedia.org filnik at svn.wikimedia.org
Fri Oct 10 15:28:22 UTC 2008


Revision: 5951
Author:   filnik
Date:     2008-10-10 15:28:22 +0000 (Fri, 10 Oct 2008)

Log Message:
-----------
Testing phase on commons gives a lot of things to think about.. continuing with the fixing phase

Modified Paths:
--------------
    trunk/pywikipedia/checkimages.py

Modified: trunk/pywikipedia/checkimages.py
===================================================================
--- trunk/pywikipedia/checkimages.py	2008-10-10 14:33:40 UTC (rev 5950)
+++ trunk/pywikipedia/checkimages.py	2008-10-10 15:28:22 UTC (rev 5951)
@@ -1017,6 +1017,17 @@
                     list_licenses.append(pageLicense) # the list has wiki-pages
         return list_licenses
 
+    def giveMeTheTemplate(self, license_selected):
+        #print template.exists()
+        template = wikipedia.Page(self.site, 'Template:%s' % license_selected)
+        if not template.exists():
+            template = wikipedia.Page(self.site, license_selected)
+            if not template.exists():
+                return None # break and exit
+        if template.isRedirectPage():
+            template = template.getRedirectTarget()
+        return template
+
     def smartDetection(self, image_text):
         seems_ok = False
         license_found = None
@@ -1030,16 +1041,13 @@
                 break
             if licenses_found != []:
                 for license_selected in licenses_found:
-                    #print template.exists()
-                    template = wikipedia.Page(self.site, 'Template:%s' % license_selected)
-                    if not template.exists():
-                        template = wikipedia.Page(self.site, license_selected)
-                        if not template.exists():
-                            exit_cicle = True
-                            break # break and report
+                    # put the first, if there is problem, this will be reported in the log
+                    if license_found == None:
+                        license_found = license_selected
                     try:
-                        if template.isRedirectPage():
-                            template = template.getRedirectTarget()
+                        template = self.giveMeTheTemplate(license_selected)
+                        if template == None:
+                            continue
                     except wikipedia.BadTitle:
                         # Template with wrong name, no need to report, simply skip
                         continue
@@ -1047,16 +1055,21 @@
                         if template in self.list_licenses: # the list_licenses are loaded in the __init__ (not to load them multimple times)
                             seems_ok = True
                             exit_cicle = True
+                            license_found = license_selected # let the last "fake" license normally detected
                             break
-                license_found = license_selected # let the last "fake" license normally detected
                 # previous block was unsuccessful? Try with the next one
                 for license_selected in licenses_found:
                     try:
+                        template = self.giveMeTheTemplate(license_selected)
+                    except wikipedia.BadTitle:
+                        # Template with wrong name, no need to report, simply skip
+                        continue                          
+                    try:
                         template_text = template.get()
+                        if template == None:
+                            continue # ok, this template it's not ok, continue..               
                     except wikipedia.NoPage:
-                        seems_ok = False # Empty template (maybe deleted while the script's running)
-                        exit_cicle = True
-                        break
+                        continue # ok, this template it's not ok, continue..
                     regex_noinclude = re.compile(r'<noinclude>(.*?)</noinclude>', re.DOTALL)
                     template_text = regex_noinclude.sub('', template_text)
                     if second_round == False:
@@ -1065,7 +1078,6 @@
                         break # only exit from the for, not from the while
                     else:
                         exit_cicle = True
-                        license_found = license_selected # A good license? Ok, let's use it instead
                         break
         if not seems_ok:
             rep_text_license_fake = "\n*[[:Image:%s]] seems to have a ''fake license'', license detected: {{tl|%s}}." % (self.image, license_found)





More information about the Pywikipedia-l mailing list