Support Python 3 for running the app
This commit is contained in:
parent
9b890a1cf8
commit
e38ccc7190
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/env python
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
"""Flask app for Rophako."""
|
||||
|
||||
|
@ -35,8 +35,14 @@ from rophako.log import logger
|
|||
#import rophako.model.tracking as Tracking
|
||||
import rophako.utils
|
||||
|
||||
# String escaping for the secret key (processes \ escapes properly), the
|
||||
# escape encoding name varies between Python 2 and 3.
|
||||
string_escape = "string_escape" if sys.version_info[0] == 2 \
|
||||
else "unicode_escape"
|
||||
|
||||
app.DEBUG = Config.site.debug == "true"
|
||||
app.secret_key = Config.security.secret_key.decode("string_escape")
|
||||
app.secret_key = bytes(Config.security.secret_key.encode("utf-8")) \
|
||||
.decode(string_escape)
|
||||
|
||||
# Security?
|
||||
if Config.security.force_ssl == "true":
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import unicode_literals, print_function, absolute_import
|
||||
|
||||
"""JSON flat file database system."""
|
||||
|
||||
import codecs
|
||||
import os
|
||||
import os.path
|
||||
import glob
|
||||
import re
|
||||
from fcntl import flock, LOCK_EX, LOCK_SH, LOCK_UN
|
||||
import redis
|
||||
|
@ -215,7 +214,7 @@ def get_redis():
|
|||
)
|
||||
redis_client.ping()
|
||||
except Exception as e:
|
||||
logger.error("Couldn't connect to Redis; memory caching will be disabled! {}".format(e.message))
|
||||
logger.error("Couldn't connect to Redis; memory caching will be disabled! {}".format(e))
|
||||
redis_client = None
|
||||
disable_redis = True
|
||||
return redis_client
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import unicode_literals, print_function, absolute_import
|
||||
|
||||
"""Debug and logging functions."""
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
from flask import g, request
|
||||
import logging
|
||||
|
||||
from rophako.settings import Config
|
||||
|
@ -17,9 +14,6 @@ class LogHandler(logging.Handler):
|
|||
# The initial log line, which has the $prefix$ in it.
|
||||
line = self.format(record)
|
||||
|
||||
# Is the user logged in?
|
||||
name = "-nobody-"
|
||||
|
||||
line = line.replace('$prefix$', '')
|
||||
print(line)
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
"""Blog models."""
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
"""Commenting models."""
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
"""Emoticon models."""
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
"""Photo album models."""
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
"""Visitor tracking models."""
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
"""User account models."""
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
"""Wiki models."""
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
"""Endpoints for user login and out."""
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
"""Endpoints for admin functions."""
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
"""Endpoints for the web blog."""
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
"""Endpoints for the commenting subsystem."""
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
"""Endpoints for contacting the site owner."""
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
"""Endpoints for the commenting subsystem."""
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
"""Endpoints for the photo albums."""
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
"""Endpoints for visitor tracking functions."""
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
"""Endpoints for the wiki."""
|
||||
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
#!/usr/bin/env python
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
"""Dynamic CMS plugin loader."""
|
||||
|
||||
import os
|
||||
from importlib import import_module
|
||||
from rophako.app import app, BLUEPRINT_PATHS
|
||||
|
||||
def load_plugin(name, as_blueprint=True, template_path=None):
|
||||
"""Load a Rophako CMS plugin.
|
||||
|
@ -17,6 +16,7 @@ def load_plugin(name, as_blueprint=True, template_path=None):
|
|||
* `template_path` is a filesystem path where the blueprint's templates
|
||||
can be found. If not provided, the path is automatically determined
|
||||
based on the module name, which is suitable for the built-in plugins."""
|
||||
from rophako.app import app, BLUEPRINT_PATHS
|
||||
module = import_module(name)
|
||||
if as_blueprint:
|
||||
mod = getattr(module, "mod")
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import unicode_literals, print_function, absolute_import
|
||||
|
||||
import os
|
||||
import datetime
|
||||
|
@ -33,7 +33,7 @@ class ConfigHandler(object):
|
|||
|
||||
def print_settings(self):
|
||||
"""Pretty-print the contents of the configuration."""
|
||||
print self.settings
|
||||
print(self.settings)
|
||||
|
||||
def load_plugins(self):
|
||||
"""Load all the plugins specified by the config file."""
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import unicode_literals, print_function, absolute_import
|
||||
|
||||
from flask import (g, session, request, render_template, flash, redirect,
|
||||
url_for, current_app)
|
||||
|
@ -14,7 +14,10 @@ import importlib
|
|||
import smtplib
|
||||
import markdown
|
||||
import json
|
||||
try:
|
||||
import urlparse
|
||||
except ImportError:
|
||||
from urllib import parse as urlparse
|
||||
import traceback
|
||||
from email.mime.multipart import MIMEMultipart
|
||||
from email.mime.text import MIMEText
|
||||
|
@ -207,7 +210,7 @@ def send_email(to, subject, message, sender=None, reply_to=None):
|
|||
def handle_exception(error):
|
||||
"""Send an e-mail to the site admin when an exception occurs."""
|
||||
if current_app.config.get("DEBUG"):
|
||||
print traceback.format_exc()
|
||||
print(traceback.format_exc())
|
||||
raise
|
||||
|
||||
import rophako.jsondb as JsonDB
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
import sys
|
||||
import argparse
|
||||
|
||||
from rophako.app import app
|
||||
|
@ -49,4 +48,3 @@ if __name__ == '__main__':
|
|||
flask_options["ssl_context"] = context
|
||||
|
||||
app.run(**flask_options)
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/env python
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import unicode_literals, print_function, absolute_import
|
||||
|
||||
"""Locate any orphaned photos.
|
||||
|
||||
|
@ -12,11 +12,14 @@ import json
|
|||
import glob
|
||||
|
||||
sys.path.append(".")
|
||||
from rophako.settings import Config
|
||||
Config.load_settings()
|
||||
|
||||
import rophako.jsondb as JsonDB
|
||||
|
||||
def main():
|
||||
if len(sys.argv) == 1:
|
||||
print "Usage: {} <path/to/static/photos>".format(__file__)
|
||||
print("Usage: {} <path/to/static/photos>".format(__file__))
|
||||
sys.exit(1)
|
||||
|
||||
photo_root = sys.argv[1]
|
||||
|
@ -32,7 +35,7 @@ def main():
|
|||
for img in glob.glob("{}/*.*".format(photo_root)):
|
||||
fname = img.split("/")[-1]
|
||||
if not fname in photos:
|
||||
print "Orphan:", fname
|
||||
print("Orphan:", fname)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
Loading…
Reference in New Issue
Block a user