Explorar el Código

Support Python 3 for running the app

pull/2/head
Noah Petherbridge hace 4 años
padre
commit
e38ccc7190

+ 8
- 2
rophako/app.py Ver fichero

@@ -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":

+ 2
- 3
rophako/jsondb.py Ver fichero

@@ -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
- 7
rophako/log.py Ver fichero

@@ -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
- 1
rophako/model/blog.py Ver fichero

@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import unicode_literals, absolute_import

"""Blog models."""


+ 1
- 1
rophako/model/comment.py Ver fichero

@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import unicode_literals, absolute_import

"""Commenting models."""


+ 1
- 1
rophako/model/emoticons.py Ver fichero

@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import unicode_literals, absolute_import

"""Emoticon models."""


+ 1
- 1
rophako/model/photo.py Ver fichero

@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import unicode_literals, absolute_import

"""Photo album models."""


+ 1
- 1
rophako/model/tracking.py Ver fichero

@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import unicode_literals, absolute_import

"""Visitor tracking models."""


+ 1
- 1
rophako/model/user.py Ver fichero

@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import unicode_literals, absolute_import

"""User account models."""


+ 1
- 1
rophako/model/wiki.py Ver fichero

@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import unicode_literals, absolute_import

"""Wiki models."""


+ 1
- 1
rophako/modules/account/__init__.py Ver fichero

@@ -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
- 1
rophako/modules/admin/__init__.py Ver fichero

@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import unicode_literals, absolute_import

"""Endpoints for admin functions."""


+ 1
- 1
rophako/modules/blog/__init__.py Ver fichero

@@ -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
- 0
rophako/modules/comment/__init__.py Ver fichero

@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, absolute_import

"""Endpoints for the commenting subsystem."""


+ 1
- 1
rophako/modules/contact/__init__.py Ver fichero

@@ -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
- 1
rophako/modules/emoticons/__init__.py Ver fichero

@@ -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
- 1
rophako/modules/photo/__init__.py Ver fichero

@@ -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
- 1
rophako/modules/tracking/__init__.py Ver fichero

@@ -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
- 1
rophako/modules/wiki/__init__.py Ver fichero

@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import unicode_literals, absolute_import

"""Endpoints for the wiki."""


+ 2
- 2
rophako/plugin.py Ver fichero

@@ -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")

+ 2
- 2
rophako/settings.py Ver fichero

@@ -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."""

+ 6
- 3
rophako/utils.py Ver fichero

@@ -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
import urlparse
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
- 3
runserver.py Ver fichero

@@ -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)


+ 6
- 3
scripts/orphaned-photos.py Ver fichero

@@ -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()

Cargando…
Cancelar
Guardar