[MediaWiki-commits] [Gerrit] pywikibot...FLOSSbot[master]: license: import licenses from wikipedia

2016-10-15 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: license: import licenses from wikipedia
..


license: import licenses from wikipedia

Change-Id: Ia9f52d1a1cf60de4a2d098cfecf6e056b3ca24ba
Signed-off-by: Loic Dachary 
---
M FLOSSbot/bot.py
A FLOSSbot/license.py
A tests/test_license.py
3 files changed, 429 insertions(+), 1 deletion(-)

Approvals:
  Dachary: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/FLOSSbot/bot.py b/FLOSSbot/bot.py
index 8642759..6962b54 100644
--- a/FLOSSbot/bot.py
+++ b/FLOSSbot/bot.py
@@ -22,7 +22,7 @@
 import pywikibot
 from pywikibot import pagegenerators as pg
 
-from FLOSSbot import fsd, qa, repository
+from FLOSSbot import fsd, license, qa, repository
 from FLOSSbot.plugin import Plugin
 
 logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s')
@@ -32,6 +32,7 @@
 repository.Repository,
 qa.QA,
 fsd.FSD,
+license.License,
 ]
 
 name2plugin = dict([(p.__name__, p) for p in plugins])
diff --git a/FLOSSbot/license.py b/FLOSSbot/license.py
new file mode 100644
index 000..7f8fd09
--- /dev/null
+++ b/FLOSSbot/license.py
@@ -0,0 +1,291 @@
+#
+# Copyright (C) 2016 Loic Dachary 
+#
+#This program is free software: you can redistribute it and/or modify
+#it under the terms of the GNU General Public License as published by
+#the Free Software Foundation, either version 3 of the License, or
+#(at your option) any later version.
+#
+#This program is distributed in the hope that it will be useful,
+#but WITHOUT ANY WARRANTY; without even the implied warranty of
+#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#GNU General Public License for more details.
+#
+#You should have received a copy of the GNU General Public License
+#along with this program.  If not, see .
+#
+import argparse
+import logging
+import re
+
+import pywikibot
+from pywikibot import pagegenerators as pg
+
+from FLOSSbot import plugin
+
+log = logging.getLogger(__name__)
+
+
+class License(plugin.Plugin):
+
+def __init__(self, *args):
+super(License, self).__init__(*args)
+self.license2item = None
+self.licenses = None
+
+@staticmethod
+def get_parser():
+parser = argparse.ArgumentParser(add_help=False)
+parser.add_argument(
+'--license',
+action='append',
+default=[],
+help='only consider this license (can be repeated)')
+return parser
+
+@staticmethod
+def filter_names():
+return ['license-verify', 'no-license']
+
+def get_query(self, filter):
+format_args = {
+'license': self.P_license,
+'subclass_of': self.P_subclass_of,
+'instance_of': self.P_instance_of,
+'open_source': self.Q_open_source_license.getID(),
+'free_software': self.Q_free_software_license.getID(),
+'retrieved': self.P_retrieved,
+'delay': self.args.verification_delay,
+}
+if filter == 'license-verify':
+query = """
+SELECT DISTINCT ?item WHERE {{
+  {{
+?item p:{license} ?license .
+?license ps:{license}/wdt:{instance_of}?/wdt:{subclass_of}*
+wd:{open_source}.
+  }} Union {{
+?item p:{license} ?license .
+?license ps:{license}/wdt:{instance_of}?/wdt:{subclass_of}*
+wd:{free_software}.
+  }}
+  OPTIONAL {{
+ ?license prov:wasDerivedFrom/
+ 
+ ?retrieved
+  }}
+  FILTER (!BOUND(?retrieved) ||
+  ?retrieved < (now() - "P{delay}D"^^xsd:duration))
+}} ORDER BY ?item
+""".format(**format_args)
+elif filter == 'no-license':
+format_args.update({
+'foss': self.Q_free_and_open_source_software.getID(),
+'free_software': self.Q_free_software.getID(),
+'open_source_software': self.Q_open_source_software.getID(),
+'public_domain': self.Q_public_domain.getID(),
+'software': self.Q_software.getID(),
+})
+query = """
+SELECT DISTINCT ?item WHERE {{
+   {{
+ ?item p:{instance_of}/ps:{instance_of}/wdt:{subclass_of}*
+wd:{foss}.
+   }} Union {{
+ ?item p:{instance_of}/ps:{instance_of}/wdt:{subclass_of}*
+wd:{free_software}.
+   }} Union {{
+ ?item p:{instance_of}/ps:{instance_of}/wdt:{subclass_of}*
+wd:{open_source_software}.
+   }} Union {{
+  

[MediaWiki-commits] [Gerrit] pywikibot...FLOSSbot[master]: license: import licenses from wikipedia

2016-10-15 Thread Dachary (Code Review)
Dachary has uploaded a new change for review.

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

Change subject: license: import licenses from wikipedia
..

license: import licenses from wikipedia

Change-Id: Ia9f52d1a1cf60de4a2d098cfecf6e056b3ca24ba
Signed-off-by: Loic Dachary 
---
M FLOSSbot/bot.py
A FLOSSbot/license.py
A tests/test_license.py
3 files changed, 429 insertions(+), 1 deletion(-)


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

diff --git a/FLOSSbot/bot.py b/FLOSSbot/bot.py
index 8642759..6962b54 100644
--- a/FLOSSbot/bot.py
+++ b/FLOSSbot/bot.py
@@ -22,7 +22,7 @@
 import pywikibot
 from pywikibot import pagegenerators as pg
 
-from FLOSSbot import fsd, qa, repository
+from FLOSSbot import fsd, license, qa, repository
 from FLOSSbot.plugin import Plugin
 
 logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s')
@@ -32,6 +32,7 @@
 repository.Repository,
 qa.QA,
 fsd.FSD,
+license.License,
 ]
 
 name2plugin = dict([(p.__name__, p) for p in plugins])
diff --git a/FLOSSbot/license.py b/FLOSSbot/license.py
new file mode 100644
index 000..7f8fd09
--- /dev/null
+++ b/FLOSSbot/license.py
@@ -0,0 +1,291 @@
+#
+# Copyright (C) 2016 Loic Dachary 
+#
+#This program is free software: you can redistribute it and/or modify
+#it under the terms of the GNU General Public License as published by
+#the Free Software Foundation, either version 3 of the License, or
+#(at your option) any later version.
+#
+#This program is distributed in the hope that it will be useful,
+#but WITHOUT ANY WARRANTY; without even the implied warranty of
+#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#GNU General Public License for more details.
+#
+#You should have received a copy of the GNU General Public License
+#along with this program.  If not, see .
+#
+import argparse
+import logging
+import re
+
+import pywikibot
+from pywikibot import pagegenerators as pg
+
+from FLOSSbot import plugin
+
+log = logging.getLogger(__name__)
+
+
+class License(plugin.Plugin):
+
+def __init__(self, *args):
+super(License, self).__init__(*args)
+self.license2item = None
+self.licenses = None
+
+@staticmethod
+def get_parser():
+parser = argparse.ArgumentParser(add_help=False)
+parser.add_argument(
+'--license',
+action='append',
+default=[],
+help='only consider this license (can be repeated)')
+return parser
+
+@staticmethod
+def filter_names():
+return ['license-verify', 'no-license']
+
+def get_query(self, filter):
+format_args = {
+'license': self.P_license,
+'subclass_of': self.P_subclass_of,
+'instance_of': self.P_instance_of,
+'open_source': self.Q_open_source_license.getID(),
+'free_software': self.Q_free_software_license.getID(),
+'retrieved': self.P_retrieved,
+'delay': self.args.verification_delay,
+}
+if filter == 'license-verify':
+query = """
+SELECT DISTINCT ?item WHERE {{
+  {{
+?item p:{license} ?license .
+?license ps:{license}/wdt:{instance_of}?/wdt:{subclass_of}*
+wd:{open_source}.
+  }} Union {{
+?item p:{license} ?license .
+?license ps:{license}/wdt:{instance_of}?/wdt:{subclass_of}*
+wd:{free_software}.
+  }}
+  OPTIONAL {{
+ ?license prov:wasDerivedFrom/
+ 
+ ?retrieved
+  }}
+  FILTER (!BOUND(?retrieved) ||
+  ?retrieved < (now() - "P{delay}D"^^xsd:duration))
+}} ORDER BY ?item
+""".format(**format_args)
+elif filter == 'no-license':
+format_args.update({
+'foss': self.Q_free_and_open_source_software.getID(),
+'free_software': self.Q_free_software.getID(),
+'open_source_software': self.Q_open_source_software.getID(),
+'public_domain': self.Q_public_domain.getID(),
+'software': self.Q_software.getID(),
+})
+query = """
+SELECT DISTINCT ?item WHERE {{
+   {{
+ ?item p:{instance_of}/ps:{instance_of}/wdt:{subclass_of}*
+wd:{foss}.
+   }} Union {{
+ ?item p:{instance_of}/ps:{instance_of}/wdt:{subclass_of}*
+wd:{free_software}.
+   }} Union {{
+ ?item p:{instance_of}/ps:{instance_of}/wdt:{subclass_of}*
+