[Pywikipedia-l] SVN: [5465] trunk/pywikipedia

russblau at svn.wikimedia.org russblau at svn.wikimedia.org
Thu May 29 14:53:41 UTC 2008


Revision: 5465
Author:   russblau
Date:     2008-05-29 14:53:40 +0000 (Thu, 29 May 2008)

Log Message:
-----------
always use wikipedia.getSite() instead of wikipedia.Site() to use caching

Modified Paths:
--------------
    trunk/pywikipedia/commons_link.py
    trunk/pywikipedia/commonsdelinker/delinker.py
    trunk/pywikipedia/commonsdelinker/image_replacer.py
    trunk/pywikipedia/cosmetic_changes.py
    trunk/pywikipedia/featured.py
    trunk/pywikipedia/featuredcount.py
    trunk/pywikipedia/imagecopy.py
    trunk/pywikipedia/interwiki.py
    trunk/pywikipedia/nowcommons.py

Modified: trunk/pywikipedia/commons_link.py
===================================================================
--- trunk/pywikipedia/commons_link.py	2008-05-29 14:15:13 UTC (rev 5464)
+++ trunk/pywikipedia/commons_link.py	2008-05-29 14:53:40 UTC (rev 5465)
@@ -60,7 +60,7 @@
         for page in self.generator:
             try:
                 wikipedia.output(u'\n>>>> %s <<<<' % page.title())
-                commons = wikipedia.Site('commons', 'commons')
+                commons = wikipedia.getSite('commons', 'commons')
                 commonspage = wikipedia.Page(commons, page.title())
                 try:
                     getcommons = commonspage.get(get_redirect=True)
@@ -104,7 +104,7 @@
         for page in self.generator:
             try:
                 wikipedia.output(u'\n>>>> %s <<<<' % page.title())
-                getCommons = wikipedia.Site('commons', 'commons')
+                getCommons = wikipedia.getSite('commons', 'commons')
                 commonsCategory = catlib.Category(getCommons,'Category:%s'%page.title())
                 try:
                     getcommonscat = commonsCategory.get(get_redirect=True)

Modified: trunk/pywikipedia/commonsdelinker/delinker.py
===================================================================
--- trunk/pywikipedia/commonsdelinker/delinker.py	2008-05-29 14:15:13 UTC (rev 5464)
+++ trunk/pywikipedia/commonsdelinker/delinker.py	2008-05-29 14:53:40 UTC (rev 5465)
@@ -747,7 +747,7 @@
 					self.sites[key][self.sites[key].index((site, False))] = (site, True)
 					return site
 			try:
-				site = wikipedia.Site(code, fam)
+				site = wikipedia.getSite(code, fam)
 			except wikipedia.NoSuchSite:
 				site = False
 			self.sites[key].append((site, True))

Modified: trunk/pywikipedia/commonsdelinker/image_replacer.py
===================================================================
--- trunk/pywikipedia/commonsdelinker/image_replacer.py	2008-05-29 14:15:13 UTC (rev 5464)
+++ trunk/pywikipedia/commonsdelinker/image_replacer.py	2008-05-29 14:53:40 UTC (rev 5465)
@@ -204,7 +204,7 @@
 
 class Reporter(threadpool.Thread):
 	def __init__(self, pool, site, config):
-		self.site = wikipedia.Site(site.lang, site.family,
+		self.site = wikipedia.getSite(site.lang, site.family,
 			site.user, True)
 		self.config = config
 		

Modified: trunk/pywikipedia/cosmetic_changes.py
===================================================================
--- trunk/pywikipedia/cosmetic_changes.py	2008-05-29 14:15:13 UTC (rev 5464)
+++ trunk/pywikipedia/cosmetic_changes.py	2008-05-29 14:53:40 UTC (rev 5465)
@@ -143,7 +143,7 @@
         does not sort them.
         """
         # The PyWikipediaBot is no longer allowed to touch categories on the German Wikipedia. See http://de.wikipedia.org/wiki/Hilfe_Diskussion:Personendaten/Archiv/bis_2006#Position_der_Personendaten_am_.22Artikelende.22
-        if self.site != wikipedia.Site('de', 'wikipedia'):
+        if self.site != wikipedia.getSite('de', 'wikipedia'):
             categories = wikipedia.getCategoryLinks(text, site = self.site)
             text = wikipedia.replaceCategoryLinks(text, categories, site = self.site)
         return text

Modified: trunk/pywikipedia/featured.py
===================================================================
--- trunk/pywikipedia/featured.py	2008-05-29 14:15:13 UTC (rev 5464)
+++ trunk/pywikipedia/featured.py	2008-05-29 14:53:40 UTC (rev 5465)
@@ -363,9 +363,10 @@
     fromlang.sort()
     try:
         for ll in fromlang:
-            fromsite=wikipedia.Site(ll)
-            if not fromsite==wikipedia.getSite():
-                featuredWithInterwiki(fromsite, wikipedia.getSite(), template_on_top)
+            fromsite = wikipedia.getSite(ll)
+            if  fromsite != wikipedia.getSite():
+                featuredWithInterwiki(fromsite, wikipedia.getSite(),
+                                      template_on_top)
     finally:
         wikipedia.stopme()
         if not nocache:

Modified: trunk/pywikipedia/featuredcount.py
===================================================================
--- trunk/pywikipedia/featuredcount.py	2008-05-29 14:15:13 UTC (rev 5464)
+++ trunk/pywikipedia/featuredcount.py	2008-05-29 14:53:40 UTC (rev 5465)
@@ -30,14 +30,14 @@
     wikipedia.output('\03{lightred}** wikipedia:%s has %i featured articles\03{default}' % (site.lang, len(arts)))
     
 if __name__=="__main__":
-    mysite=wikipedia.getSite()
-    fromlang=featured_name.keys()
+    mysite = wikipedia.getSite()
+    fromlang = featured_name.keys()
     fromlang.sort()
     try:
         for ll in fromlang:
-            fromsite=wikipedia.Site(ll)
-            if not fromsite==wikipedia.getSite():
-                arts=featuredArticles(fromsite)
-        arts_mysite=featuredArticles(mysite)
+            fromsite = wikipedia.getSite(ll)
+            if fromsite != mysite:
+                arts = featuredArticles(fromsite)
+        arts_mysite = featuredArticles(mysite)
     finally:
         wikipedia.stopme()

Modified: trunk/pywikipedia/imagecopy.py
===================================================================
--- trunk/pywikipedia/imagecopy.py	2008-05-29 14:15:13 UTC (rev 5464)
+++ trunk/pywikipedia/imagecopy.py	2008-05-29 14:53:40 UTC (rev 5465)
@@ -89,7 +89,7 @@
 import pagegenerators, add_text
 from upload import *
 NL=''
-                
+
 def pageTextPost(url,postinfo):
     print url
     m=re.search(ur'http://(.*?)(/.*)',url)
@@ -98,7 +98,7 @@
     else:
             domain=m.group(1)
             path=m.group(2)
-            
+
     h = httplib.HTTP(domain)
     h.putrequest('POST', path)
     h.putheader('Host', domain)
@@ -118,7 +118,7 @@
         self.imagePage = imagePage
         self.newname = newname
         threading.Thread.__init__ ( self )
-        
+
     def run(self):
         tosend={'language':str(self.imagePage.site().language()),
                 'image':self.imagePage.titleWithoutNamespace().encode('utf-8'),
@@ -143,7 +143,7 @@
         #urlEncoding='utf-8'
         bot = UploadRobot(url=self.imagePage.fileUrl(), description=CH, useFilename=self.newname, keepFilename=True, verifyDescription=False, ignoreWarning = True, targetSite = wikipedia.getSite('commons', 'commons'))
         bot.run()
-    
+
         #add {{NowCommons}}, first force to get the page so we dont run into edit conflicts
         imtxt=self.imagePage.get(force=True)
         if self.newname!=self.imagePage.titleWithoutNamespace():
@@ -153,7 +153,7 @@
             self.imagePage.put(imtxt+u'\n\n{{NowCommons}}', u'{{NowCommons}}')
             print 'Nowcommons.\n'
         return
-        
+
 #-label ok skip view
 #textarea
 archivo=wikipedia.config.datafilepath("Uploadbot.localskips.txt")
@@ -163,7 +163,7 @@
     tocreate=open(archivo, 'w')
     tocreate.write("{{NowCommons")
     tocreate.close()
-    
+
 def getautoskip():
     '''
     Get a list of templates to skip.
@@ -173,7 +173,7 @@
     f.close()
     toreturn=txt.split('{{')[1:]
     return toreturn
-    
+
 class Tkdialog:
     def __init__(self, image_title, content, uploader, url, templates, commonsconflict=0):
         self.root=Tk()
@@ -195,50 +195,51 @@
         textarea.config(state=DISABLED, height=8, width=40, padx=0, pady=0, wrap=WORD, yscrollcommand=scrollbar.set)
         scrollbar.config(command=textarea.yview)
         self.entry=Entry(self.root)
-        
+
         self.templatelist=Listbox(self.root, bg="white", height=5)
-                
+
         for template in templates:
             self.templatelist.insert(END, template)
         autoskipButton=Button(self.root, text="Add to AutoSkip", command=self.add2autoskip)
         browserButton=Button(self.root, text='View in browser', command=self.openInBrowser)
         skipButton=Button(self.root, text="Skip", command=self.skipFile)
         okButton=Button(self.root, text="OK", command=self.okFile)
-        
+
         ##Start grid
         label.grid(row=0)
         okButton.grid(row=0, column=1, rowspan=2)
         skipButton.grid(row=0, column=2, rowspan=2)
         browserButton.grid(row=0, column=3, rowspan=2)
-        
+
         self.entry.grid(row=1)
 
-        
         textarea.grid(row=2, column=1, columnspan=3)
         scrollbar.grid(row=2, column=5)
         self.templatelist.grid(row=2, column=0)
-        
+
         autoskipButton.grid(row=3, column=0)
         imageinfo.grid(row=3, column=1, columnspan=4)
 
-        
     def okFile(self):
         '''
         The user pressed the OK button.
         '''
         self.changename=self.entry.get()
         self.root.destroy()
+        
     def skipFile(self):
         '''
         The user pressed the Skip button.
         '''
         self.skip=1
         self.root.destroy()
+        
     def openInBrowser(self):
         '''
         The user pressed the View in browser button.
         '''
         webbrowser.open(self.url)
+        
     def add2autoskip(self):
         '''
         The user pressed the Add to AutoSkip button.
@@ -249,7 +250,7 @@
         toadd.write('{{'+template)
         toadd.close()
         self.skipFile()
-        
+
     def getnewname(self):
         '''
         Activate the dialog and return the new name and if the image is skipped.
@@ -257,6 +258,7 @@
         self.root.mainloop()
         return (self.changename, self.skip)
 
+
 def doiskip(pagetext):
     '''
     Skip this image or not.
@@ -271,6 +273,7 @@
             return True
     return False
 
+
 def main(args):
     generator = None;
     #newname = "";
@@ -296,7 +299,7 @@
     for page in pregenerator:        
         if page.exists() and (page.namespace() == 6) and (not page.isRedirectPage()) :
             imagepage = wikipedia.ImagePage(page.site(), page.title())
-            
+
             #First do autoskip.         
             if doiskip(imagepage.get()):
                 wikipedia.output("Skipping " + page.title())
@@ -312,19 +315,20 @@
 
                     # Do the Tkdialog to accept/reject and change te name        
                     (newname, skip)=Tkdialog(imagepage.titleWithoutNamespace(), imagepage.get(), username, imagepage.permalink(), imagepage.templates()).getnewname()
-                
+
                     if skip:
                         wikipedia.output('Skipping this image')
                         break
-                   
+
                     # Did we enter a new name?
                     if len(newname)==0:                
                         #Take the old name
                         newname=imagepage.titleWithoutNamespace()
-                           
+
                     # Check if the image already exists
-                    CommonsPage=wikipedia.Page(wikipedia.Site('commons', 'commons'), 'Image:'+newname)
-                    
+                    CommonsPage=wikipedia.Page(
+                                   wikipedia.getSite('commons', 'commons'),
+                                   'Image:'+newname)
                     if not CommonsPage.exists():
                         break
                     else:
@@ -333,7 +337,7 @@
 
             if not skip:
                 imageTransfer(imagepage, newname).start()
-                     
+
     wikipedia.output(u'Still ' + str(threading.activeCount()) + u' active threads, lets wait')    
     for openthread in threading.enumerate():
         if openthread != threading.currentThread():

Modified: trunk/pywikipedia/interwiki.py
===================================================================
--- trunk/pywikipedia/interwiki.py	2008-05-29 14:15:13 UTC (rev 5464)
+++ trunk/pywikipedia/interwiki.py	2008-05-29 14:53:40 UTC (rev 5465)
@@ -1120,7 +1120,7 @@
                     # temporary hard-coded special case to get rid of thousands of broken links to the Lombard Wikipedia,
                     # where useless bot-created articles were mass-deleted. See for example:
                     # http://meta.wikimedia.org/wiki/Proposals_for_closing_projects/Closure_of_Lombard_Wikipedia#Road_Map
-                    if rmPage.site() == wikipedia.Site('lmo', 'wikipedia'):
+                    if rmPage.site() == wikipedia.getSite('lmo', 'wikipedia'):
                         wikipedia.output('Found bad link to %s. As many lmo pages were deleted, it is assumed that it can be safely removed.' % rmPage.aslink())
                     else:
                     ##########
@@ -1147,7 +1147,7 @@
                     # temporary hard-coded special case to get rid of thousands of broken links to the Lombard Wikipedia,
                     # where useless bot-created articles were mass-deleted. See for example:
                     # http://meta.wikimedia.org/wiki/Proposals_for_closing_projects/Closure_of_Lombard_Wikipedia#Road_Map
-                    if len(removing) == 1 and removing[0].site() == wikipedia.Site('lmo', 'wikipedia'):
+                    if len(removing) == 1 and removing[0].site() == wikipedia.getSite('lmo', 'wikipedia'):
                         wikipedia.output('Found bad link to %s. As many lmo pages were deleted, it is assumed that it can be safely removed.' % removing[0].aslink())
                     else:
                     ##########

Modified: trunk/pywikipedia/nowcommons.py
===================================================================
--- trunk/pywikipedia/nowcommons.py	2008-05-29 14:15:13 UTC (rev 5464)
+++ trunk/pywikipedia/nowcommons.py	2008-05-29 14:53:40 UTC (rev 5465)
@@ -167,7 +167,7 @@
                 return filenameOnCommons
 
     def run(self):
-        commons = wikipedia.Site('commons', 'commons')
+        commons = wikipedia.getSite('commons', 'commons')
         comment = wikipedia.translate(self.site, nowCommonsMessage)
 
         for page in self.getPageGenerator():





More information about the Pywikipedia-l mailing list