jenkins-bot has submitted this change and it was merged.
Change subject: [PEP8] changes ......................................................................
[PEP8] changes
Change-Id: I8d9d934b242c96796d56ecfd61169133dc76d328 --- M imagetransfer.py M lonelypages.py 2 files changed, 90 insertions(+), 86 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/imagetransfer.py b/imagetransfer.py index a950d48..f5979d1 100644 --- a/imagetransfer.py +++ b/imagetransfer.py @@ -26,34 +26,37 @@ """ # # (C) Andre Engels, 2004 -# (C) Pywikipedia bot team, 2004-2012 +# (C) Pywikibot team, 2004-2013 # # Distributed under the terms of the MIT license. # -__version__='$Id$' +__version__ = '$Id$'
-import re, sys -import wikipedia as pywikibot -import upload, config, pagegenerators +import re +import sys +import pywikibot +import upload +import config +import pagegenerators
copy_message = { - 'ar':u"هذه الصورة تم نقلها من %s. الوصف الأصلي كان:\r\n\r\n%s", - 'en':u"This image was copied from %s. The original description was:\r\n\r\n%s", - 'fa':u"تصویر از %s کپی شدهاست.توضیحات اصلی ان این بود::\r\n\r\n%s", - 'de':u"Dieses Bild wurde von %s kopiert. Die dortige Beschreibung lautete:\r\n\r\n%s", - 'fr':u"Cette image est copiée de %s. La description originale était:\r\n\r\n%s", - 'he':u"תמונה זו הועתקה מהאתר %s. תיאור הקובץ המקורי היה:\r\n\r\n%s", - 'hu':u"Kép másolása innen: %s. Az eredeti leírás:\r\n\r\n%s", - 'ia':u"Iste imagine esseva copiate de %s. Le description original esseva:\r\n\r\n%s", - 'it':u"Questa immagine è stata copiata da %s. La descrizione originale era:\r\n\r\n%s", - 'kk':u"Бұл сурет %s дегеннен көшірілді. Түпнұсқа сипатттамасы былай болды:\r\n\r\n%s", - 'lt':u"Šis paveikslėlis buvo įkeltas iš %s. Originalus aprašymas buvo:\r\n\r\n%s", - 'nl':u"Afbeelding gekopieerd vanaf %s. De beschrijving daar was:\r\n\r\n%s", - 'pl':u"Ten obraz został skopiowany z %s. Oryginalny opis to:\r\n\r\n%s", - 'pt':u"Esta imagem foi copiada de %s. A descrição original foi:\r\n\r\n%s", - 'ru':u"Изображение было скопировано с %s. Оригинальное описание содержало:\r\n\r\n%s", - 'sr':u"Ова слика је копирана са %s. Оригинални опис је:\r\n\r\n%s", - 'zh':u"本圖像從 %s 複製,原始說明資料:\r\n\r\n%s", + 'ar': u"هذه الصورة تم نقلها من %s. الوصف الأصلي كان:\r\n\r\n%s", + 'en': u"This image was copied from %s. The original description was:\r\n\r\n%s", + 'fa': u"تصویر از %s کپی شدهاست.توضیحات اصلی ان این بود::\r\n\r\n%s", + 'de': u"Dieses Bild wurde von %s kopiert. Die dortige Beschreibung lautete:\r\n\r\n%s", + 'fr': u"Cette image est copiée de %s. La description originale était:\r\n\r\n%s", + 'he': u"תמונה זו הועתקה מהאתר %s. תיאור הקובץ המקורי היה:\r\n\r\n%s", + 'hu': u"Kép másolása innen: %s. Az eredeti leírás:\r\n\r\n%s", + 'ia': u"Iste imagine esseva copiate de %s. Le description original esseva:\r\n\r\n%s", + 'it': u"Questa immagine è stata copiata da %s. La descrizione originale era:\r\n\r\n%s", + 'kk': u"Бұл сурет %s дегеннен көшірілді. Түпнұсқа сипатттамасы былай болды:\r\n\r\n%s", + 'lt': u"Šis paveikslėlis buvo įkeltas iš %s. Originalus aprašymas buvo:\r\n\r\n%s", + 'nl': u"Afbeelding gekopieerd vanaf %s. De beschrijving daar was:\r\n\r\n%s", + 'pl': u"Ten obraz został skopiowany z %s. Oryginalny opis to:\r\n\r\n%s", + 'pt': u"Esta imagem foi copiada de %s. A descrição original foi:\r\n\r\n%s", + 'ru': u"Изображение было скопировано с %s. Оригинальное описание содержало:\r\n\r\n%s", + 'sr': u"Ова слика је копирана са %s. Оригинални опис је:\r\n\r\n%s", + 'zh': u"本圖像從 %s 複製,原始說明資料:\r\n\r\n%s", }
nowCommonsTemplate = { @@ -70,20 +73,13 @@ 'kk': u'{{NowCommons|Image:%s}}', 'li': u'{{NowCommons|%s}}', 'lt': u'{{NowCommons|Image:%s}}', - 'nds-nl' : u'{{NoenCommons|File:%s}}', + 'nds-nl': u'{{NoenCommons|File:%s}}', 'nl': u'{{NuCommons|Image:%s}}', 'pl': u'{{NowCommons|%s}}', 'pt': u'{{NowCommons|%s}}', 'sr': u'{{NowCommons|%s}}', 'zh': u'{{NowCommons|Image:%s}}', } - -#nowCommonsThis = { - #'en': u'{{NowCommonsThis|%s}}', - #'it': u'{{NowCommons omonima|%s}}', - #'kk': u'{{NowCommonsThis|%s}}', - #'pt': u'{{NowCommonsThis|%s}}', -#}
nowCommonsMessage = { 'ar': u'الملف الآن متوفر في ويكيميديا كومنز.', @@ -105,15 +101,6 @@ 'sr': u'Слика је сада доступна и на Викимедија Остави.', 'zh': u'檔案已存在於維基共享資源。', } - -#nowCommonsThisMessage = { - #'ar': u'الملف الآن متوفر في كومنز بنفس الاسم.', - #'en': u'File is now available on Commons with the same name.', - #'he': u'הקובץ זמין כעת בוויקישיתוף בשם זהה.', - #'it': u'L'immagine è adesso disponibile su Wikimedia Commons con lo stesso nome.', - #'kk': u'Файлды дәл сол атауымен енді Ортаққордан қатынауға болады.', - #'pt': u'Esta imagem está agora no Commons com o mesmo nome.', -#}
# Translations for license templates. # Must only be given when they are in fact different. @@ -165,6 +152,7 @@
class ImageTransferBot: + def __init__(self, generator, targetSite=None, interwiki=False, keep_name=False): self.generator = generator @@ -182,7 +170,7 @@ sourceSite = sourceImagePage.site() if debug: print "-" * 50 - print "Found image: %s"% imageTitle + print "Found image: %s" % imageTitle url = sourceImagePage.fileUrl().encode('utf-8') pywikibot.output(u"URL should be: %s" % url) # localize the text that should be printed on the image description page @@ -215,7 +203,7 @@ targetSite=self.targetSite, urlEncoding=sourceSite.encoding(), keepFilename=self.keep_name, - verifyDescription = not self.keep_name) + verifyDescription=not self.keep_name) # try to upload targetFilename = bot.run() if targetFilename and self.targetSite.family.name == 'commons' and \ @@ -272,7 +260,7 @@
except pywikibot.NoPage: break - print "="*60 + print "=" * 60
def run(self): for page in self.generator: @@ -284,9 +272,9 @@ imagePage = pywikibot.ImagePage(page.site(), page.title()) imagelist = [imagePage] else: - imagelist = page.imagelinks(followRedirects = True) + imagelist = page.imagelinks(followRedirects=True)
- while len(imagelist)>0: + while imagelist: self.showImageList(imagelist) if len(imagelist) == 1: # no need to query the user, only one possibility @@ -303,7 +291,7 @@ pywikibot.output( u'The image is already on Wikimedia Commons.') else: - self.transferImage(imagelist[todo], debug = False) + self.transferImage(imagelist[todo], debug=False) # remove the selected image from the list imagelist = imagelist[:todo] + imagelist[todo + 1:] else: diff --git a/lonelypages.py b/lonelypages.py index 3f5675b..859bab8 100644 --- a/lonelypages.py +++ b/lonelypages.py @@ -40,14 +40,14 @@ # # (C) Pietrodn, it.wiki 2006-2007 # (C) Filnik, it.wiki 2007 -# (C) Pywikipedia bot team, 2008-2012 +# (C) Pywikibot team, 2008-2013 # # Distributed under the terms of the MIT license. # __version__ = '$Id$' #
-import wikipedia as pywikibot +import pywikibot import pagegenerators import re
@@ -108,41 +108,52 @@
# ************* Modify only above! ************* #
+ def main(): # Load the configurations in the function namespace - global commento; global Template; global disambigPage; global commenttodisambig + global commento + global Template + global disambigPage + global commenttodisambig global exception
- enablePage = None # Check if someone set an enablePage or not - limit = 50000 # All the pages! (I hope that there aren't so many lonely pages in a project..) - generator = None # Check if the bot should use the default generator or not - genFactory = pagegenerators.GeneratorFactory() # Load all the default generators! - nwpages = False # Check variable for newpages - always = False # Check variable for always - disambigPage = None # If no disambigPage given, not use it. + enablePage = None # Check if someone set an enablePage or not + # All the pages! (I hope that there aren't so many lonely pages in a + # project..) + limit = 50000 + # Check if the bot should use the default generator or not + generator = None + # Load all the default generators! + genFactory = pagegenerators.GeneratorFactory() + nwpages = False # Check variable for newpages + always = False # Check variable for always + disambigPage = None # If no disambigPage given, not use it. # Arguments! for arg in pywikibot.handleArgs(): if arg.startswith('-enable'): if len(arg) == 7: - enablePage = pywikibot.input(u'Would you like to check if the bot should run or not?') + enablePage = pywikibot.input( + u'Would you like to check if the bot should run or not?') else: enablePage = arg[8:] if arg.startswith('-disambig'): if len(arg) == 9: - disambigPage = pywikibot.input(u'In which page should the bot save the disambig pages?') + disambigPage = pywikibot.input( + u'In which page should the bot save the disambig pages?') else: disambigPage = arg[10:] elif arg.startswith('-limit'): if len(arg) == 6: - limit = int(pywikibot.input(u'How many pages do you want to check?')) + limit = int(pywikibot.input( + u'How many pages do you want to check?')) else: limit = int(arg[7:]) elif arg.startswith('-newpages'): if len(arg) == 9: - nwlimit = 50 # Default: 50 pages + nwlimit = 50 # Default: 50 pages else: nwlimit = int(arg[10:]) - generator = pywikibot.getSite().newpages(number = nwlimit) + generator = pywikibot.getSite().newpages(number=nwlimit) nwpages = True elif arg == '-always': always = True @@ -156,21 +167,23 @@
# If the generator is not given, use the default one if not generator: - generator = wikiSite.lonelypages(repeat = True, number = limit) + generator = wikiSite.lonelypages(repeat=True, number=limit) # Take the configurations according to our project comment = pywikibot.translate(wikiSite, commento) commentdisambig = pywikibot.translate(wikiSite, commenttodisambig) template = pywikibot.translate(wikiSite, Template) exception = pywikibot.translate(wikiSite, exception) # EnablePage part - if enablePage != None: + if enablePage: # Define the Page Object enable = pywikibot.Page(wikiSite, enablePage) # Loading the page's data try: getenable = enable.get() except pywikibot.NoPage: - pywikibot.output(u"%s doesn't esist, I use the page as if it was blank!" % enable.title()) + pywikibot.output( + u"%s doesn't esist, I use the page as if it was blank!" + % enable.title()) getenable = '' except wikiepedia.IsRedirect: pywikibot.output(u"%s is a redirect, skip!" % enable.title()) @@ -181,7 +194,7 @@ pywikibot.output('The bot is disabled') return # DisambigPage part - if disambigPage != None: + if disambigPage is not None: disambigpage = pywikibot.Page(wikiSite, disambigPage) try: disambigtext = disambigpage.get() @@ -189,24 +202,23 @@ pywikibot.output(u"%s doesn't esist, skip!" % disambigpage.title()) disambigtext = '' except wikiepedia.IsRedirect: - pywikibot.output(u"%s is a redirect, don't use it!" % disambigpage.title()) + pywikibot.output(u"%s is a redirect, don't use it!" + % disambigpage.title()) disambigPage = None # Main Loop for page in generator: - if nwpages == True: - page = page[0] # The newpages generator returns a tuple, not a Page object. + if nwpages: + # newpages generator returns a tuple, not a Page object. + page = page[0] pywikibot.output(u"Checking %s..." % page.title()) - # Used to skip the first pages in test phase... - #if page.title()[0] in ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q']: - #continue - if page.isRedirectPage(): # If redirect, skip! + if page.isRedirectPage(): # If redirect, skip! pywikibot.output(u'%s is a redirect! Skip...' % page.title()) continue # refs is not a list, it's a generator while resList... is a list, yes. refs = page.getReferences() refsList = list() for j in refs: - if j == None: + if j is None: # We have to find out why the function returns that value pywikibot.error(u'1 --> Skip page') continue @@ -216,12 +228,13 @@ pywikibot.output(u"%s isn't orphan! Skip..." % page.title()) continue # Never understood how a list can turn in "None", but it happened :-S - elif refsList == None: + elif refsList is None: # We have to find out why the function returns that value pywikibot.error(u'2 --> Skip page') continue else: - # Ok, no refs, no redirect... let's check if there's already the template + # Ok, no refs, no redirect... + # let's check if there's already the template try: oldtxt = page.get() except pywikibot.NoPage: @@ -237,29 +250,32 @@ res = re.findall(regexp, oldtxt.lower()) # Found a template! Let's skip the page! if res != []: - pywikibot.output(u'Your regex has found something in %s, skipping...' % page.title()) + pywikibot.output( + u'Your regex has found something in %s, skipping...' + % page.title()) Find = True break - # Skip the page.. if Find: - continue - # Is the page a disambig? - if page.isDisambig() and disambigPage != None: - pywikibot.output(u'%s is a disambig page, report..' % page.title()) + continue # Skip the page.. + if page.isDisambig() and disambigPage: + pywikibot.output(u'%s is a disambig page, report..' + % page.title()) if not page.title().lower() in disambigtext.lower(): disambigtext = u"%s\n*[[%s]]" % (disambigtext, page.title()) disambigpage.put(disambigtext, commentdisambig) continue # Is the page a disambig but there's not disambigPage? Skip! elif page.isDisambig(): - pywikibot.output(u'%s is a disambig page, skip...' % page.title()) - continue + pywikibot.output(u'%s is a disambig page, skip...' + % page.title()) + continue else: # Ok, the page need the template. Let's put it there! - newtxt = u"%s\n%s" % (template, oldtxt) # Adding the template in the text - pywikibot.output(u"\t\t>>> %s <<<" % page.title()) # Showing the title - pywikibot.showDiff(oldtxt, newtxt) # Showing the changes - choice = 'y' # Default answer + # Adding the template in the text + newtxt = u"%s\n%s" % (template, oldtxt) + pywikibot.output(u"\t\t>>> %s <<<" % page.title()) + pywikibot.showDiff(oldtxt, newtxt) + choice = 'y' if not always: choice = pywikibot.inputChoice(u'Orphan page found, shall I add the template?', ['Yes', 'No', 'All'], ['y', 'n', 'a']) if choice == 'a':
pywikibot-commits@lists.wikimedia.org