Hello xqt!
Hello all!

Sorry I was not able to attach a file to [1] or change 'Assigned' or
something else. This is the reason why I post this patch here.
Could you please commit it? This would be nice... :)

Thanks a lot and Greetings
Dr. Trigon

[1]
https://sourceforge.net/tracker/?func=detail&aid=3108403&group_id=93107&atid=603141
Index: clean_sandbox.py
===================================================================
--- clean_sandbox.py    (Revision 40)
+++ clean_sandbox.py    (Arbeitskopie)
@@ -21,7 +21,11 @@
 # (C) Andre Engels, 2007
 # (C) Siebrand Mazeland, 2007
 # (C) xqt, 2009
+# (C) Dr. Trigon, 2011
 #
+# DrTrigonBot: http://de.wikipedia.org/wiki/Benutzer:DrTrigonBot
+# Clean User Sandbox Robot (clean_user_sandbox.py)
+#
 # Distributed under the terms of the MIT license.
 #
 __version__ = '$Id: clean_sandbox.py 8564 2010-09-15 17:16:53Z xqt $'
@@ -148,24 +152,37 @@
             wait = False
             now = time.strftime("%d %b %Y %H:%M:%S (UTC)", time.gmtime())
             localSandboxTitle = pywikibot.translate(mySite, sandboxTitle)
+            IsUserSandbox = hasattr(self, '_user_list')  # DrTrigonBot (Clean 
User Sandbox Robot)
+            if IsUserSandbox:
+                localSandboxTitle = [localSandboxTitle % user.name() for user 
in self._user_list]
             if type(localSandboxTitle) is list:
                 titles = localSandboxTitle
             else:
                 titles = [localSandboxTitle,]
             for title in titles:
                 sandboxPage = pywikibot.Page(mySite, title)
+                pywikibot.output(u'Preparing to process sandbox page %s' % 
sandboxPage.title(asLink=True))
                 try:
                     text = sandboxPage.get()
                     translatedContent = pywikibot.translate(mySite, content)
                     translatedMsg = pywikibot.translate(mySite, msg)
                     subst = 'subst:' in translatedContent
+                    pos = text.find(translatedContent.strip())
                     if text.strip() == translatedContent.strip():
                         pywikibot.output(u'The sandbox is still clean, no 
change necessary.')
                     elif subst and sandboxPage.userName() == 
mySite.loggedInAs():
                         pywikibot.output(u'The sandbox might be clean, no 
change necessary.')
-                    elif text.find(translatedContent.strip()) <> 0 and not 
subst:
-                        sandboxPage.put(translatedContent, translatedMsg)
-                        pywikibot.output(u'Standard content was changed, 
sandbox cleaned.')
+                    elif pos <> 0 and not subst:
+                        if IsUserSandbox:
+                            endpos = pos + len(translatedContent.strip())
+                            if (pos < 0) or (endpos == len(text)):
+                                pywikibot.output(u'The user sandbox is still 
clean or not set up, no change necessary.')
+                            else:
+                                sandboxPage.put(text[:endpos], translatedMsg)
+                                pywikibot.output(u'Standard content was 
changed, user sandbox cleaned.')
+                        else:
+                            sandboxPage.put(translatedContent, translatedMsg)
+                            pywikibot.output(u'Standard content was changed, 
sandbox cleaned.')
                     else:
                         diff = minutesDiff(sandboxPage.editTime(), 
time.strftime("%Y%m%d%H%M%S", time.gmtime()))
                         if pywikibot.verbose:
@@ -179,6 +196,9 @@
                             wait = True
                 except pywikibot.EditConflict:
                     pywikibot.output(u'*** Loading again because of edit 
conflict.\n')
+                except pywikibot.NoPage:
+                    pywikibot.output(u'*** The sandbox is not existent, 
skipping.')
+                    continue
             if self.no_repeat:
                 pywikibot.output(u'\nDone.')
                 return
_______________________________________________
Pywikipedia-l mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikipedia-l

Reply via email to