[odrs-web] Convert to Python 3



commit 3ac2179621f0986c991373b944c5d5baa625d60b
Author: Richard Hughes <richard hughsie com>
Date:   Sun Feb 10 13:25:27 2019 +0000

    Convert to Python 3

 .lgtm.yml                              |  8 ++++++++
 Dockerfile                             | 13 +++++++++++--
 app_data/README.md                     | 12 +++++++-----
 app_data/app/__init__.py               |  4 ++--
 app_data/app/db.py                     | 12 ++++++------
 app_data/app/models.py                 | 12 ++++++------
 app_data/app/views.py                  | 12 ++++++------
 app_data/app/views_admin.py            | 10 +++++-----
 app_data/cron.py                       |  2 +-
 app_data/flaskapp.py                   |  2 +-
 app_data/httpd-cfg/odrs.gnome.org.conf |  1 +
 app_data/httpd-pre-init/entrypoint.sh  |  2 +-
 app_data/requirements.txt              |  4 ++++
 app_data/wsgi-scripts/odrs.wsgi        |  2 +-
 14 files changed, 60 insertions(+), 36 deletions(-)
---
diff --git a/.lgtm.yml b/.lgtm.yml
new file mode 100644
index 0000000..b270616
--- /dev/null
+++ b/.lgtm.yml
@@ -0,0 +1,8 @@
+extraction:
+  python:
+    python_setup:
+      version: 3
+    index:
+      exclude: migrations
+queries:
+  exclude: py/test-equals-none
diff --git a/Dockerfile b/Dockerfile
index ab1ef89..b3329ed 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -2,16 +2,25 @@ FROM centos/httpd-24-centos7
 
 USER root 
 
-RUN yum install gcc make python27-python python27-python-pip python27-mod_wsgi python27-python-devel 
python2-cryptography python-flask python2-flask-wtf python2-flask-login python2-PyMySQL -y
+RUN yum install -y gcc make \
+    python36-cryptography \
+    python36-devel \
+    python36-pip \
+    python36-PyMySQL \
+    uwsgi-plugin-python36
 
 ENV ODRS_HOME=/opt/app-root/src \
     LANG=C
 
+COPY app_data/requirements.txt /tmp/requirements.txt
+
+RUN pip3 install --prefix=/usr -r /tmp/requirements.txt
+
 WORKDIR ${ODRS_HOME}
 
 COPY app_data ${ODRS_HOME}
 
-RUN python /opt/app-root/src/cron.py ratings /opt/app-root/src/app/static/ratings.json 
+RUN python36 /opt/app-root/src/cron.py ratings /opt/app-root/src/app/static/ratings.json
 
 RUN chown -R 1000310000:0 ${ODRS_HOME} && \
     chmod -R 664 ${ODRS_HOME} && \
diff --git a/app_data/README.md b/app_data/README.md
index dc722ed..662d1bb 100644
--- a/app_data/README.md
+++ b/app_data/README.md
@@ -39,14 +39,16 @@ can be used on the new instance.
 
 ## How to I use distro packages ##
 
-    pkcon install python2-PyMySQL python-flask python-flask-wtf \
-      python-flask-login
-
-...or, if you're using python3:
-
     pkcon install python3-PyMySQL python3-flask python3-flask-wtf \
       python3-flask-login
 
 ## I have a question
 
 Email me or grab me on IRC (`hughsie@freenode`).
+
+## How to build the docker image?
+
+    podman build . --build-arg ODRS_REVIEWS_SECRET=1
+    podman images
+    podman run --env-file env.cfg <image>
+    podman run --env-file env.cfg -it --entrypoint /bin/bash <image>
diff --git a/app_data/app/__init__.py b/app_data/app/__init__.py
index 5eb1947..525e41b 100644
--- a/app_data/app/__init__.py
+++ b/app_data/app/__init__.py
@@ -1,7 +1,7 @@
-#!/usr/bin/python2
+#!/usr/bin/python3
 # -*- coding: utf-8 -*-
 #
-# pylint: disable=invalid-name,missing-docstring
+# pylint: disable=invalid-name,missing-docstring,wrong-import-order,wrong-import-position
 #
 # Copyright (C) 2015-2017 Richard Hughes <richard hughsie com>
 # Licensed under the GNU General Public License Version 2
diff --git a/app_data/app/db.py b/app_data/app/db.py
index 5530a63..0df939f 100644
--- a/app_data/app/db.py
+++ b/app_data/app/db.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python3
 # -*- coding: utf-8 -*-
 #
 # pylint: disable=invalid-name,missing-docstring
@@ -87,7 +87,7 @@ def _password_hash(value):
 def _get_datestr_from_dt(when):
     return int("%04i%02i%02i" % (when.year, when.month, when.day))
 
-class Database(object):
+class Database():
 
     def __init__(self, app):
         """ Constructor for object """
@@ -311,7 +311,7 @@ class Database(object):
             data.append((en[0], en[1]))
         return data
 
-class DatabaseEventlog(object):
+class DatabaseEventlog():
 
     def __init__(self, db):
         """ Constructor for object """
@@ -337,7 +337,7 @@ class DatabaseEventlog(object):
         """ Adds an info item to the event log """
         self.warn(user_addr, user_hash, app_id, message, False)
 
-class DatabaseReviews(object):
+class DatabaseReviews():
 
     def __init__(self, db):
         """ Constructor for object """
@@ -553,7 +553,7 @@ class DatabaseReviews(object):
             data.append(en[0])
         return data
 
-class DatabaseModerators(object):
+class DatabaseModerators():
 
     def __init__(self, db):
         """ Constructor for object """
@@ -668,7 +668,7 @@ class DatabaseModerators(object):
         except mdb.Error as e:
             raise CursorError(cur, e)
 
-class DatabaseUsers(object):
+class DatabaseUsers():
 
     def __init__(self, db):
         """ Constructor for object """
diff --git a/app_data/app/models.py b/app_data/app/models.py
index a687a82..57e59ca 100644
--- a/app_data/app/models.py
+++ b/app_data/app/models.py
@@ -1,12 +1,12 @@
-#!/usr/bin/python2
+#!/usr/bin/python3
 # -*- coding: utf-8 -*-
 #
-# pylint: disable=invalid-name,missing-docstring,too-few-public-methods
+# pylint: disable=invalid-name,missing-docstring,too-few-public-methods,too-many-instance-attributes
 #
 # Copyright (C) 2015-2017 Richard Hughes <richard hughsie com>
 # Licensed under the GNU General Public License Version 2
 
-class User(object):
+class User():
     def __init__(self):
         self.id = None
         self.karma = 0
@@ -14,7 +14,7 @@ class User(object):
         self.user_hash = 0
         self.is_banned = 0
 
-class Review(object):
+class Review():
     def __init__(self):
         self.review_id = 0
         self.date_created = 0
@@ -32,7 +32,7 @@ class Review(object):
         self.date_deleted = None
         self.reported = None
 
-class Event(object):
+class Event():
     def __init__(self):
         self.eventlog_id = 0
         self.date_created = 0
@@ -42,7 +42,7 @@ class Event(object):
         self.app_id = None
         self.important = False
 
-class Moderator(object):
+class Moderator():
     def __init__(self):
         self.moderator_id = 0
         self.username = None
diff --git a/app_data/app/views.py b/app_data/app/views.py
index 7abb3df..237f488 100644
--- a/app_data/app/views.py
+++ b/app_data/app/views.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python2
+#!/usr/bin/python3
 # -*- coding: utf-8 -*-
 #
 # pylint: disable=invalid-name,missing-docstring
@@ -607,8 +607,8 @@ def ratings():
                     mimetype="application/json")
 
 if __name__ == '__main__':
-    print ">>>%s<<<" % _sanitised_version("16.12.3")
-    print ">>>%s<<<" % _sanitised_version("4:16.12.3+p16.04+git20170325.0519-0")
-    print ">>>%s<<<" % _sanitised_version("16.11.0~ds0")
-    print ">>>%s<<<" % _sanitised_summary("   not sure why people include.   ")
-    print ">>>%s<<<" % _sanitised_description("   this is awesome :) !!!   ")
+    print(">>>%s<<<" % _sanitised_version("16.12.3"))
+    print(">>>%s<<<" % _sanitised_version("4:16.12.3+p16.04+git20170325.0519-0"))
+    print(">>>%s<<<" % _sanitised_version("16.11.0~ds0"))
+    print(">>>%s<<<" % _sanitised_summary("   not sure why people include.   "))
+    print(">>>%s<<<" % _sanitised_description("   this is awesome :) !!!   "))
diff --git a/app_data/app/views_admin.py b/app_data/app/views_admin.py
index bd8dc86..327a6c9 100644
--- a/app_data/app/views_admin.py
+++ b/app_data/app/views_admin.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python2
+#!/usr/bin/python3
 # -*- coding: utf-8 -*-
 #
 # pylint: disable=invalid-name,missing-docstring
@@ -73,7 +73,7 @@ def _email_check(value):
         return False
     return True
 
-class Pagination(object):
+class Pagination():
 
     def __init__(self, page, per_page, total_count):
         self.page = page
@@ -211,15 +211,15 @@ def utility_processor():
         nr_stars = int(rating / 20)
         tmp = ''
         for _ in range(0, nr_stars):
-            tmp += u'★'
+            tmp += '★'
         for _ in range(0, 5 - nr_stars):
-            tmp += u'☆'
+            tmp += '☆'
         return tmp
 
     def format_truncate(tmp, length):
         if len(tmp) <= length:
             return tmp
-        return tmp[:length] + u'…'
+        return tmp[:length] + '…'
 
     def format_timestamp(tmp):
         if not tmp:
diff --git a/app_data/cron.py b/app_data/cron.py
index 9554da3..a13fcdf 100755
--- a/app_data/cron.py
+++ b/app_data/cron.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python2
+#!/usr/bin/python3
 # -*- coding: utf-8 -*-
 #
 # Copyright (C) 2016-2018 Richard Hughes <richard hughsie com>
diff --git a/app_data/flaskapp.py b/app_data/flaskapp.py
index f9c087b..c6d851b 100755
--- a/app_data/flaskapp.py
+++ b/app_data/flaskapp.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python2
+#!/usr/bin/python3
 # -*- coding: utf-8 -*-
 #
 # Copyright (C) 2016-2017 Richard Hughes <richard hughsie com>
diff --git a/app_data/httpd-cfg/odrs.gnome.org.conf b/app_data/httpd-cfg/odrs.gnome.org.conf
index d7376df..67bd749 100644
--- a/app_data/httpd-cfg/odrs.gnome.org.conf
+++ b/app_data/httpd-cfg/odrs.gnome.org.conf
@@ -14,6 +14,7 @@
     WSGIProcessGroup odrs.gnome.org
 
     WSGIScriptAlias / /opt/app-root/src/wsgi-scripts/odrs.wsgi
+    WSGIPythonPath /usr/lib/python3.6/site-packages:/usr/lib64/python3.6/site-packages
 
     SetEnv ODRS_REVIEWS_SECRET replace_odrs_secret
     SetEnv MYSQL_DB_USERNAME replace_odrs_username
diff --git a/app_data/httpd-pre-init/entrypoint.sh b/app_data/httpd-pre-init/entrypoint.sh
index 8e7f936..d04587b 100755
--- a/app_data/httpd-pre-init/entrypoint.sh
+++ b/app_data/httpd-pre-init/entrypoint.sh
@@ -5,4 +5,4 @@ sed -i "s/replace_odrs_username/${MYSQL_DB_USERNAME}/" ${HTTPD_CONFIGURATION_PAT
 sed -i "s/replace_odrs_password/${MYSQL_DB_PASSWORD}/" ${HTTPD_CONFIGURATION_PATH}/odrs.gnome.org.conf
 sed -i "s/replace_odrs_host/${MYSQL_DB_HOST}/" ${HTTPD_CONFIGURATION_PATH}/odrs.gnome.org.conf
 
-while true; do python /opt/app-root/src/cron.py ratings /opt/app-root/src/app/static/ratings.json ; sleep 
43200 ; done &
+while true; do python36 /opt/app-root/src/cron.py ratings /opt/app-root/src/app/static/ratings.json ; sleep 
43200 ; done &
diff --git a/app_data/requirements.txt b/app_data/requirements.txt
new file mode 100644
index 0000000..10d7eeb
--- /dev/null
+++ b/app_data/requirements.txt
@@ -0,0 +1,4 @@
+flask-wtf
+flask-login
+markupsafe
+PyMySQL
diff --git a/app_data/wsgi-scripts/odrs.wsgi b/app_data/wsgi-scripts/odrs.wsgi
index 3f97df7..e1ede3f 100644
--- a/app_data/wsgi-scripts/odrs.wsgi
+++ b/app_data/wsgi-scripts/odrs.wsgi
@@ -1,4 +1,4 @@
-#!/usr/bin/python2
+#!/usr/bin/python3
 # -*- coding: utf-8 -*-
 #
 # Copyright (C) 2016 Richard Hughes <richard hughsie com>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]