Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Python 3 compatibilities #60

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions fabfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""
Fabfile for managing a Python/Flask/Apache/MySQL project in MacOS/Ubuntu.
"""
from __future__ import print_function

import os

Expand Down Expand Up @@ -109,11 +110,11 @@ def syncdb():
"""Sync loacl db with remote db"""

if not REMOTE_DB_USERNAME or not REMOTE_DB_PASSWORD or not REMOTE_DB_NAME:
print "Please setup remote db configs"
print("Please setup remote db configs")
return

if not LOCAL_DB_USERNAME or not LOCAL_DB_PASSWORD or not LOCAL_DB_NAME:
print "Please setup local db configs"
print("Please setup local db configs")
return

with cd("/tmp"):
Expand Down
3 changes: 2 additions & 1 deletion fbone/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-

from app import create_app
from __future__ import absolute_import
from .app import create_app
17 changes: 9 additions & 8 deletions fbone/app.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# -*- coding: utf-8 -*-

from __future__ import absolute_import
from flask import Flask, render_template

from config import DefaultConfig
from user import User
from .config import DefaultConfig
from .user import User

from extensions import db, login_manager
from filters import format_date, pretty_date, nl2br
from utils import INSTANCE_FOLDER_PATH
from .extensions import db, login_manager
from .filters import format_date, pretty_date, nl2br
from .utils import INSTANCE_FOLDER_PATH


# For import *
Expand Down Expand Up @@ -70,9 +71,9 @@ def load_user(id):
def configure_blueprints(app):
"""Configure blueprints in views."""

from user import user
from frontend import frontend
from api import api
from .user import user
from .frontend import frontend
from .api import api

for bp in [user, frontend, api]:
app.register_blueprint(bp)
Expand Down
4 changes: 3 additions & 1 deletion fbone/config.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# -*- coding: utf-8 -*-

from __future__ import absolute_import
from builtins import object
import os

from utils import make_dir, INSTANCE_FOLDER_PATH
from .utils import make_dir, INSTANCE_FOLDER_PATH


class BaseConfig(object):
Expand Down
12 changes: 7 additions & 5 deletions fbone/filters.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-

from __future__ import division
from past.utils import old_div
import re
from datetime import datetime
from jinja2 import Markup, escape
Expand All @@ -18,12 +20,12 @@ def pretty_date(value, default="just now"):
diff = now - value

periods = (
(diff.days / 365, 'year', 'years'),
(diff.days / 30, 'month', 'months'),
(diff.days / 7, 'week', 'weeks'),
(old_div(diff.days, 365), 'year', 'years'),
(old_div(diff.days, 30), 'month', 'months'),
(old_div(diff.days, 7), 'week', 'weeks'),
(diff.days, 'day', 'days'),
(diff.seconds / 3600, 'hour', 'hours'),
(diff.seconds / 60, 'minute', 'minutes'),
(old_div(diff.seconds, 3600), 'hour', 'hours'),
(old_div(diff.seconds, 60), 'minute', 'minutes'),
(diff.seconds, 'second', 'seconds'),
)

Expand Down
3 changes: 2 additions & 1 deletion fbone/frontend/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-

from views import frontend
from __future__ import absolute_import
from .views import frontend
4 changes: 3 additions & 1 deletion fbone/frontend/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-

from __future__ import absolute_import
from builtins import str
from uuid import uuid4

from flask import Blueprint, render_template, current_app, request, flash, \
Expand All @@ -9,7 +11,7 @@

from fbone.user import User
from fbone.extensions import db, login_manager
from forms import SignupForm, LoginForm, RecoverPasswordForm, ReauthForm, \
from .forms import SignupForm, LoginForm, RecoverPasswordForm, ReauthForm, \
ChangePasswordForm


Expand Down
5 changes: 3 additions & 2 deletions fbone/user/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-

from models import User
from views import user
from __future__ import absolute_import
from .models import User
from .views import user
1 change: 1 addition & 0 deletions fbone/user/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from fbone.utils import get_current_time
from fbone.constants import USER, USER_ROLE, ADMIN, INACTIVE, USER_STATUS, \
SEX_TYPES, STRING_LEN
from functools import reduce


class User(db.Model, UserMixin):
Expand Down
3 changes: 2 additions & 1 deletion fbone/user/views.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# -*- coding: utf-8 -*-

from __future__ import absolute_import
import os

from flask import Blueprint, render_template, send_from_directory, request, \
current_app, flash
from flask_login import login_required, current_user

from forms import ProfileForm, PasswordForm
from .forms import ProfileForm, PasswordForm

from fbone.extensions import db
from fbone.utils import get_current_time
Expand Down
3 changes: 2 additions & 1 deletion fbone/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Utils has nothing to do with models and views.
"""

from builtins import range
import string
import random
import os
Expand Down Expand Up @@ -35,5 +36,5 @@ def make_dir(dir_path):
try:
if not os.path.exists(dir_path):
os.mkdir(dir_path)
except Exception, e:
except Exception as e:
raise e
14 changes: 10 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Fabric
Fabric; python_version < '3.0'
Fabric3; python_version >= '3.0'
Flask
Flask-Login
Flask-RESTful
Expand All @@ -7,7 +8,8 @@ Flask-Testing
Flask-WTF
Jinja2
MarkupSafe
MySQL-python
MySQL-python; python_version < '3.0'
mysqlclient; python_version >= '3.0'
SQLAlchemy
WTForms
Werkzeug
Expand All @@ -31,6 +33,10 @@ python-dateutil
pytz
requests
six
speaklater
speaklater; python_version < '3.0'
speaklater3; python_version >= '3.0'
wrapt
wsgiref
wsgiref; python_version < '3.0'
future
six

1 change: 1 addition & 0 deletions wsgi.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-

from past.builtins import execfile
import sys, os, pwd

project = "fbone"
Expand Down