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

Updates for Python 3 #722

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion .buildkite/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ services:
aliases:
- mltshp.dev
mysql:
image: mysql:5
image: mysql:latest
ports:
- "3306:3306"
environment:
Expand Down
4 changes: 2 additions & 2 deletions .buildkite/steps/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ docker pull mltshp/mltshp-web:build-${BUILDKITE_BUILD_NUMBER}
docker tag mltshp/mltshp-web:build-${BUILDKITE_BUILD_NUMBER} mltshp/mltshp-web:latest

# launch fakes3/mysql/web app
docker-compose -f .buildkite/docker-compose.yml up -d
docker compose -f .buildkite/docker-compose.yml up -d

# let's wait and allow mysql/fakes3 to spin up
#wait_for localhost 3306
Expand All @@ -25,6 +25,6 @@ docker exec -t buildkite_mltshp_1 ./run-tests.sh
docker exec -t -e BUILDKITE -e BUILDKITE_JOB_ID -e BUILDKITE_BRANCH -e COVERALLS_REPO_TOKEN buildkite_mltshp_1 ./coveralls-report.sh

# tear down containers
docker-compose -f .buildkite/docker-compose.yml down
docker compose -f .buildkite/docker-compose.yml down

docker container prune -f
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pip-log.txt
.DS_Store
*.swp
env
env3
mounts
.env
.deploy.env
Expand Down
20 changes: 7 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:16.04
FROM ubuntu:22.04
LABEL maintainer "[email protected]"
ENV PYTHONUNBUFFERED 1

Expand All @@ -9,7 +9,7 @@ RUN apt-get -y update && apt-get install -y \
supervisor \
libmysqlclient-dev \
mysql-client \
python-dev \
python3-dev \
libjpeg-dev \
libcurl4-openssl-dev \
curl \
Expand All @@ -20,20 +20,14 @@ RUN apt-get -y update && apt-get install -y \
libpcre3-dev \
libssl-dev \
libffi-dev \
python-pip && \
python3-pip && \
rm -rf /var/lib/apt/lists/* && \
\
pip install -U 'pip==20.3.4' 'setuptools==44.0.0' distribute && \
# fixes a weird issue where distribute complains about setuptools "0.7"
# (incorrectly matching version "20.7.0" which ubuntu 16.04 has preinstalled)
rm -rf /usr/lib/python2.7/dist-packages/setuptools-20.7.0.egg-info && \
\
# install nginx + upload module
mkdir -p /tmp/install && \
cd /tmp/install && \
wget http://nginx.org/download/nginx-0.8.55.tar.gz && tar zxf nginx-0.8.55.tar.gz && \
wget https://github.com/fdintino/nginx-upload-module/archive/2.2.0.tar.gz && tar zxf 2.2.0.tar.gz && \
cd /tmp/install/nginx-0.8.55 && \
wget http://nginx.org/download/nginx-1.25.1.tar.gz && tar zxf nginx-1.25.1.tar.gz && \
wget https://github.com/fdintino/nginx-upload-module/archive/2.3.0.tar.gz && tar zxf 2.3.0.tar.gz && \
cd /tmp/install/nginx-1.25.1 && \
./configure \
--with-http_ssl_module \
--with-http_stub_status_module \
Expand All @@ -43,7 +37,7 @@ RUN apt-get -y update && apt-get install -y \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/srv/mltshp.com/nginx-error.log \
--http-log-path=/srv/mltshp.com/nginx-access.log \
--add-module=/tmp/install/nginx-upload-module-2.2.0 && \
--add-module=/tmp/install/nginx-upload-module-2.3.0 && \
make && make install && \
mkdir -p /etc/nginx && \
rm -rf /tmp/install && \
Expand Down
12 changes: 3 additions & 9 deletions Dockerfile.worker
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:16.04
FROM ubuntu:22.04
LABEL maintainer "[email protected]"
ENV PYTHONUNBUFFERED 1

Expand All @@ -10,7 +10,7 @@ RUN apt-get -y update && \
cron \
libmysqlclient-dev \
mysql-client \
python-dev \
python3-dev \
libjpeg-dev \
libcurl4-openssl-dev \
curl \
Expand All @@ -22,14 +22,8 @@ RUN apt-get -y update && \
libpcre3-dev \
libssl-dev \
libffi-dev \
python-pip && \
python3-pip && \
rm -rf /var/lib/apt/lists/* && \
pip install -U 'pip==20.3.4' 'setuptools==44.0.0' distribute && \
# Fix for a really weird issue when installing postmark library
# distribute fails to run since it sees a setuptools with "0.7"
# in the name, even though ubuntu:16.04 has pre-installed "20.7.0"
# https://github.com/pypa/setuptools/issues/543
rm -rf /usr/lib/python2.7/dist-packages/setuptools-20.7.0.egg-info && \
groupadd ubuntu --gid=1010 && \
useradd ubuntu --create-home --home-dir=/home/ubuntu \
--uid=1010 --gid=1010 && \
Expand Down
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@ init-dev:
mkdir -p mounts/mysql mounts/logs mounts/fakes3 mounts/uploaded

run:
docker-compose --env-file .env up -d
docker compose --env-file .env up -d

stop:
docker-compose --env-file .env down
docker compose --env-file .env down

build:
docker build -t mltshp/mltshp-web:latest .

shell:
docker-compose --env-file .env exec mltshp bash
docker compose --env-file .env exec mltshp bash

test:
docker-compose --env-file .env exec mltshp su ubuntu -c "cd /srv/mltshp.com/mltshp; python test.py $(TEST)"
docker compose --env-file .env exec mltshp su ubuntu -c "cd /srv/mltshp.com/mltshp; python3 test.py $(TEST)"

destroy:
docker-compose down
docker compose down
rm -rf mounts

migrate:
docker-compose --env-file .env exec mltshp su ubuntu -c "cd /srv/mltshp.com/mltshp; python migrate.py"
docker compose --env-file .env exec mltshp su ubuntu -c "cd /srv/mltshp.com/mltshp; python3 migrate.py"

mysql:
docker-compose --env-file .env exec mltshp su ubuntu -c "cd /srv/mltshp.com/mltshp; mysql -u root --host mysql mltshp"
docker compose --env-file .env exec mltshp su ubuntu -c "cd /srv/mltshp.com/mltshp; mysql -u root --host mysql mltshp"
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

[![Build status](https://badge.buildkite.com/a86854c6272f21c9b46b8b6aafd3a4fb99bcfabe6e611bc370.svg)](https://buildkite.com/mltshp-inc/mltshp-web-service) [![Coverage Status](https://coveralls.io/repos/github/MLTSHP/mltshp/badge.svg?branch=master)](https://coveralls.io/github/MLTSHP/mltshp?branch=master)

## Project Description

This project is the codebase for running [mltshp.com](https://mltshp.com).
It's a Python 3 application, utilizing a MySQL database, Amazon S3 for
asset storage, and RabbitMQ for background jobs.

## Development Environment

MLTSHP is a Dockerized application. This greatly simplifies running the
Expand Down Expand Up @@ -59,7 +65,7 @@ When you run the application, it launches it into a background process.
But if you want to watch the realtime logs emitted by each service,
just use this command:

$ docker-compose logs -f
$ docker compose logs -f

In addition to that, the web app produces some log files that are
captured under the "mounts/logs" folder of your git repository.
Expand Down Expand Up @@ -141,7 +147,7 @@ containers, just use this command:
If you just wish to rebuild the Docker container, use the Docker
compose command:

$ docker-compose down
$ docker compose down

Then, run another `make run`.

Expand All @@ -155,6 +161,6 @@ update from the pattern library.

## About

MLTSHP is open-source software, ©2017 the MLTSHP team and released to the public under the terms of the Mozilla Public License. A copy of the MPL can be found in the LICENSE file.
MLTSHP is open-source software, ©2023 the MLTSHP team and released to the public under the terms of the Mozilla Public License. A copy of the MPL can be found in the LICENSE file.

[![Fastly logo](/static/images/fastly-logo.png)](https://www.fastly.com) MLTSHP is proudly powered by Fastly.
12 changes: 6 additions & 6 deletions developerdocs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
master_doc = 'docindex'

# General information about the project.
project = u'mltshp'
copyright = u'2017 MLTSHP, Inc.'
project = 'mltshp'
copyright = '2023 MLTSHP, Inc.'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down Expand Up @@ -180,8 +180,8 @@
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('docindex', 'mltshp-api.tex', u'mltshp-api Documentation',
u'MLTSHP, LLC', 'manual'),
('docindex', 'mltshp-api.tex', 'mltshp-api Documentation',
'MLTSHP, LLC', 'manual'),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -213,6 +213,6 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('docindex', 'mltshp-api', u'mltshp-api Documentation',
[u'MLTSHP, LLC'], 1)
('docindex', 'mltshp-api', 'mltshp-api Documentation',
['MLTSHP, LLC'], 1)
]
38 changes: 19 additions & 19 deletions handlers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#handlers
import base
import account
import admin
import image
import home
import misc
import tools
import upload
import incoming
import friends
import api
import developers
import conversations
import error
import popular
import shake
import tag
import stripe_hooks
import search
from . import base
from . import account
from . import admin
from . import image
from . import home
from . import misc
from . import tools
from . import upload
from . import incoming
from . import friends
from . import api
from . import developers
from . import conversations
from . import error
from . import popular
from . import shake
from . import tag
from . import stripe_hooks
from . import search
14 changes: 7 additions & 7 deletions handlers/account.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import datetime
import re
import json
from urllib import urlencode
from urllib.parse import urlencode
import logging

import tornado.httpclient
Expand All @@ -12,7 +12,7 @@
import postmark
import requests

from base import BaseHandler, require_membership
from .base import BaseHandler, require_membership
from models import User, Invitation, Shake, Notification, Conversation, Invitation,\
App, PaymentLog, Voucher, Promotion, MigrationState
from lib.utilities import email_re, base36decode, is_valid_voucher_key,\
Expand Down Expand Up @@ -348,9 +348,9 @@ def post(self, app_id=None):
user = self.get_current_user_object()
app = App.get("id = %s", app_id)
if not app:
return {'error' : 'Invalid request.'}
return self.write({'error' : 'Invalid request.'})
app.disconnect_for_user(user)
return {'result' : 'ok'}
return self.write({'result' : 'ok'})


class ForgotPasswordHandler(BaseHandler):
Expand Down Expand Up @@ -843,7 +843,7 @@ def get(self, page=None):
"""
current_user_obj = self.get_current_user_object()

if self.get_arguments('agree', None):
if self.get_argument('agree', None):
current_user_obj.tou_agreed = True
current_user_obj.save()
return self.redirect("/")
Expand Down Expand Up @@ -929,7 +929,7 @@ def post(self):
if plan_id == "mltshp-double":
quantity = int(float(self.get_argument("quantity")))
if quantity < 24 or quantity > 500:
raise "Invalid request"
raise Exception("Invalid request")

customer = None
sub = None
Expand All @@ -946,7 +946,7 @@ def post(self):
if customer is None:
if token_id is None:
# FIXME: handle this more gracefully...
raise "Invalid request"
raise Exception("Invalid request")

# create a new customer object for this subscription
customer = stripe.Customer.create(
Expand Down
2 changes: 1 addition & 1 deletion handlers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import tornado.web
import postmark

from base import BaseHandler
from .base import BaseHandler
from models import Sharedfile, User, Shake, Shakesharedfile, Invitation, Waitlist, ShakeCategory
from lib.utilities import send_slack_notification

Expand Down
12 changes: 6 additions & 6 deletions handlers/api.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from datetime import datetime
import time
from urllib import urlencode
from urlparse import urlparse, urlunparse, urljoin
from urllib.parse import urlencode
from urllib.parse import urlparse, urlunparse
from hashlib import sha1
import hmac
import base64
import functools

import tornado.web
from tornado.options import define, options
from tornado.options import options

from base import BaseHandler
from .base import BaseHandler
from lib.utilities import normalize_string, base36decode
from models import Accesstoken, Apihit, Apilog, App, Authorizationcode, \
Favorite, Magicfile, Sharedfile, User, Shake, Comment
Expand Down Expand Up @@ -102,8 +102,8 @@ def wrapper(self, *args, **kwargs):
parsed_url.path,
query_array)

digest = hmac.new(access_token.consumer_secret.encode('ascii'), normalized_string, sha1).digest()
signature = base64.encodestring(digest).strip()
digest = hmac.new(access_token.consumer_secret.encode('ascii'), normalized_string.encode('ascii'), sha1).digest()
signature = base64.encodebytes(digest).strip().decode('ascii')

if signature == auth_items['signature']:
self.oauth2_user_id = access_token.user_id
Expand Down
2 changes: 1 addition & 1 deletion handlers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def add_error(self, key, message):
self._errors[key] = message

def add_errors(self, errors_dict):
for error_key in errors_dict.keys():
for error_key in list(errors_dict.keys()):
self.add_error(error_key, errors_dict[error_key])

def log_user_in(self, user):
Expand Down
2 changes: 1 addition & 1 deletion handlers/conversations.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import tornado.web

from base import BaseHandler, require_membership
from .base import BaseHandler, require_membership
from models import Conversation, Notification, Comment, Sharedfile

class IndexHandler(BaseHandler):
Expand Down
2 changes: 1 addition & 1 deletion handlers/developers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import tornado.web

from base import BaseHandler
from .base import BaseHandler

from models import App

Expand Down
2 changes: 1 addition & 1 deletion handlers/error.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import tornado
import base
from . import base

class NotFoundHandler(base.BaseHandler):
def check_xsrf_cookie(self):
Expand Down
2 changes: 1 addition & 1 deletion handlers/friends.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import tornado.web
from base import BaseHandler, require_membership
from .base import BaseHandler, require_membership


class FriendHandler(BaseHandler):
Expand Down
Loading