Dachary has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/310790

Change subject: repository: do not display anything if nothing done
......................................................................

repository: do not display anything if nothing done

Prefix all messages with the URL of the time so they are self
contained. Make it so nothing is displayed when nothing is done, unless
--verbose is specified.

Change-Id: If8ae0c1708ba373317687f2dffab90fde805a60d
Signed-off-by: Loic Dachary <l...@dachary.org>
---
M FLOSSbot/repository.py
1 file changed, 26 insertions(+), 17 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/bots/FLOSSbot 
refs/changes/90/310790/1

diff --git a/FLOSSbot/repository.py b/FLOSSbot/repository.py
index e43b614..8bd6ad8 100644
--- a/FLOSSbot/repository.py
+++ b/FLOSSbot/repository.py
@@ -170,6 +170,18 @@
         Repository.Q_ftp = pywikibot.ItemPage(site, "Q42283", 0)
         Repository.cache = True
 
+    def debug(self, item, message):
+        self.log(log.debug, item, message)
+
+    def info(self, item, message):
+        self.log(log.info, item, message)
+
+    def error(self, item, message):
+        self.log(log.error, item, message)
+
+    def log(self, fun, item, message):
+        fun("http://wikidata.org/wiki/"; + item.getID() + " " + message)
+
     def run(self):
         if self.args.filter == 'no-protocol':
             query = """
@@ -205,8 +217,6 @@
         for item in pg.WikidataSPARQLPageGenerator(query,
                                                    site=site,
                                                    result_type=list):
-            log.info("WORKING ON https://www.wikidata.org/wiki/"; +
-                     item.getID())
             self.fixup_protocol(site, item)
             self.fixup_rank(site, item)
 
@@ -218,13 +228,14 @@
             return False
 
         if len(clm_dict['P1324']) != 2:
-            log.debug("SKIP more than two URLs is too difficult to fix")
+            self.debug(item, "SKIP more than two URLs is too difficult to fix")
             return False
 
         http = []
         for claim in clm_dict['P1324']:
             if claim.getRank() == 'preferred':
-                log.debug("SKIP because there already is a preferred URL")
+                self.debug(item,
+                           "SKIP because there already is a preferred URL")
                 return False
             if P_protocol not in claim.qualifiers:
                 continue
@@ -232,12 +243,12 @@
                 if protocol.getTarget() == Repository.Q_http:
                     http.append(claim)
         if len(http) != 1:
-            log.debug("SKIP because there are " + str(len(http)) +
-                      " URLs with the http protocol")
+            self.debug(item, "SKIP because there are " + str(len(http)) +
+                       " URLs with the http protocol")
             return False
         if not self.args.dry_run:
             http[0].changeRank('preferred')
-        log.info("PREFERRED set to " + http[0].getTarget())
+        self.info(item, "PREFERRED set to " + http[0].getTarget())
         return True
 
     def fixup_protocol(self, site, item):
@@ -253,8 +264,8 @@
             url = claim.getTarget()
             extracted = Repository.extract_repository(url)
             if extracted and extracted not in urls:
-                log.info("ADDING " + extracted +
-                         " as a source repository discovered in " + url)
+                self.debug(item, "ADDING " + extracted +
+                           " as a source repository discovered in " + url)
                 source_code_repository = pywikibot.Claim(
                     site, P_source_code_repository, 0)
                 source_code_repository.setTarget(extracted)
@@ -264,25 +275,26 @@
                 if claim.getRank() == 'normal':
                     if not self.args.dry_run:
                         claim.changeRank('preferred')
-                    log.info("PREFERRED set to " + url)
+                    self.info(item, "PREFERRED set to " + url)
 
         for claim in clm_dict['P1324']:
             Repository.fixup_url(claim)
 
         for claim in clm_dict['P1324']:
             if P_protocol in claim.qualifiers:
-                log.info("IGNORE " + claim.getTarget() +
-                         " because it already has a protocol")
+                self.debug(item, "IGNORE " + claim.getTarget() +
+                           " because it already has a protocol")
                 continue
             target_protocol = Repository.guess_protocol(claim)
             if not target_protocol:
-                log.error(claim.getTarget())
+                self.error(item,
+                           claim.getTarget() + " misses a protocol qualifier")
                 continue
             protocol = pywikibot.Claim(site, P_protocol, 0)
             protocol.setTarget(target_protocol)
             if not self.args.dry_run:
                 claim.addQualifier(protocol, bot=True)
-            log.info("SET protocol of " + claim.getTarget())
+            self.info(item, "SET protocol of " + claim.getTarget())
 
     @staticmethod
     def guess_protocol_from_url(url):
@@ -394,7 +406,6 @@
 
     @staticmethod
     def try_protocol(url, credentials):
-        log.debug("trying all known protocols on " + url)
         if Repository.verify_git(url):
             return Repository.Q_git
         elif Repository.verify_hg(url):
@@ -418,8 +429,6 @@
         protocol = Repository.guess_protocol_from_url(url)
         if protocol:
             if not Repository.verify_protocol(url, protocol, credentials):
-                log.error(url + " does not obey the expected protocol " +
-                          str(protocol))
                 return None
             else:
                 return protocol

-- 
To view, visit https://gerrit.wikimedia.org/r/310790
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If8ae0c1708ba373317687f2dffab90fde805a60d
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/bots/FLOSSbot
Gerrit-Branch: master
Gerrit-Owner: Dachary <l...@dachary.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to