[odrs-web/oscp] Get the latest badword list when building
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [odrs-web/oscp] Get the latest badword list when building
- Date: Sun, 7 Jul 2019 18:47:48 +0000 (UTC)
commit 9cf3be334324c4f80b2b181f23f9f72fb034524e
Author: Richard Hughes <richard hughsie com>
Date: Sun Jul 7 18:47:21 2019 +0100
Get the latest badword list when building
Dockerfile | 4 ++++
app_data/cron.py | 50 +++++++++++++++++++++++++++++++++++++-------------
2 files changed, 41 insertions(+), 13 deletions(-)
---
diff --git a/Dockerfile b/Dockerfile
index f1b2149..144144e 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -41,6 +41,10 @@ RUN curl https://flathub.org/repo/appstream/x86_64/appstream.xml.gz -o /tmp/apps
RUN python36 /opt/app-root/src/cron.py appstream-import /tmp/appstream.xml.gz
+RUN curl https://raw.githubusercontent.com/hughsie/badwords/master/badwords.csv -o /tmp/badwords.csv
+
+RUN LANG=en_US.utf8 python36 /opt/app-root/src/cron.py taboo-import /tmp/badwords.csv
+
RUN python36 /opt/app-root/src/cron.py ratings /opt/app-root/src/odrs/static/ratings.json
RUN chown -R 1000310000:0 ${ODRS_HOME} && \
diff --git a/app_data/cron.py b/app_data/cron.py
index 891edbb..465cc7a 100755
--- a/app_data/cron.py
+++ b/app_data/cron.py
@@ -96,6 +96,36 @@ def _appstream_import(fn):
parent.adopt(child)
db.session.commit()
+def _taboo_import_item(taboos, locale, value, description, severity):
+ key = locale + ':' + value
+ if key in taboos:
+ taboo = taboos[key]
+ is_dirty = False
+ if taboo.description != description:
+ print('Modifying {} description from "{}" to "{}"'.format(key,
+ taboo.description,
+ description))
+ taboo.description = description
+ is_dirty = True
+ if taboo.severity != severity:
+ print('Modifying {} severity from "{}" to "{}"'.format(key,
+ taboo.severity,
+ severity))
+ taboo.severity = severity
+ is_dirty = True
+ return is_dirty
+ if value.find(' ') != -1:
+ print('Ignoring', locale, value)
+ return False
+ if value.lower() != value:
+ print('Ignoring', locale, value)
+ return False
+ taboo = Taboo(locale, value, description, severity=severity)
+ taboos[key] = taboo
+ print('Adding {}'.format(key))
+ db.session.add(taboo)
+ return True
+
def _taboo_import(fn):
# get all the taboos in one database call
@@ -105,27 +135,21 @@ def _taboo_import(fn):
taboos[key] = taboo
# add any new ones
+ is_dirty = False
with open(fn, newline='') as csvfile:
for locale, values, description, severity in csv.reader(csvfile):
locale = locale.strip()
description = description.strip()
+ severity = int(severity)
for value in values.split('/'):
value = value.strip()
- key = locale + ':' + value
- if key in taboos:
- continue
- if value.find(' ') != -1:
- print('Ignoring', locale, value)
- continue
- if value.lower() != value:
- print('Ignoring', locale, value)
- continue
- taboo = Taboo(locale, value, description, severity=int(severity))
- taboos[key] = taboo
- print('Adding', locale, value)
- db.session.add(taboo)
+ is_dirty = _taboo_import_item(taboos, locale, value, description, severity) or is_dirty
db.session.commit()
+ # if dirty, check all the existing reviews
+ if is_dirty:
+ _taboo_check()
+
if __name__ == '__main__':
if len(sys.argv) < 2:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]