From 3360711501e03f0f8ab1937d22108a6d18e2384f Mon Sep 17 00:00:00 2001 From: Daisuke Maki Date: Sat, 30 Jul 2016 18:17:10 +0900 Subject: [PATCH] Beginning of GAE port Notes: * Still unclear how we should handle secret information such as keys and tokens. * app.wsgi better be renamed to app.py * In GAE, we would have to use memcached, so Redis must be changed. * For https, certificates will have to be handled differently :/ So we still can't just migrate to GAE, but this is a start, so I will commit, and keep it. refs #37 --- Makefile | 7 ++++- appengine_config.py | 2 ++ octav.py | 4 ++- requirements.txt | 2 +- vendor.py | 71 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 appengine_config.py create mode 100644 vendor.py diff --git a/Makefile b/Makefile index 7dab126..b56daed 100644 --- a/Makefile +++ b/Makefile @@ -3,4 +3,9 @@ update-trans: pybabel update --input-file messages.pot --output-dir translations/ --locale ja --domain messages compile-trans: - pybabel compile --directory translations/ --domain messages \ No newline at end of file + pybabel compile --directory translations/ --domain messages + +appengine-deploy: + # Note: If you are on OS X, and you are using homebrew python, + # you are going to get a weird error. + pip install -r requirements.txt -t lib \ No newline at end of file diff --git a/appengine_config.py b/appengine_config.py new file mode 100644 index 0000000..56e77ad --- /dev/null +++ b/appengine_config.py @@ -0,0 +1,2 @@ +import vendor +vendor.add('lib') \ No newline at end of file diff --git a/octav.py b/octav.py index c19ef0e..011f4ac 100644 --- a/octav.py +++ b/octav.py @@ -156,7 +156,6 @@ def lookup_user_by_auth_user_id (self, auth_user_id, auth_via): def update_user (self, id, user_id, email=None, first_name=None, last_name=None, nickname=None, tshirt_size=None): try: payload = {} - hdrs = {} if id is None: raise MissingRequiredArgument('property id must be provided') payload['id'] = id @@ -807,6 +806,9 @@ def delete_conference_dates (self, conference_id, dates, user_id): uri = '%s/conference/dates/delete' % self.endpoint if self.debug: print('POST %s' % uri) + hdrs = urllib3.util.make_headers( + basic_auth='%s:%s' % (self.key, self.secret), + ) hdrs['Content-Type']= 'application/json' res = self.http.request('POST', uri, headers=hdrs, body=json.dumps(payload)) if self.debug: diff --git a/requirements.txt b/requirements.txt index 021c2a4..b4d89f4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,4 +7,4 @@ py-gfm redis urllib3 wsgi-request-logger -werkzeug \ No newline at end of file +werkzeug diff --git a/vendor.py b/vendor.py new file mode 100644 index 0000000..4609019 --- /dev/null +++ b/vendor.py @@ -0,0 +1,71 @@ +# +# Copyright 2014 Jon Wayne Parrott, [proppy], Michael R. Bernstein +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# Notes: +# - Imported from https://github.com/jonparrott/Darth-Vendor/. +# - Added license header. +# - Renamed `darth.vendor` to `vendor.add` to match upcoming SDK interface. +# - Renamed `position` param to `index` to match upcoming SDK interface. +# - Removed funny arworks docstring. + +import site +import os.path +import sys + + +def add(folder, index=1): + """ + Adds the given folder to the python path. Supports namespaced packages. + By default, packages in the given folder take precedence over site-packages + and any previous path manipulations. + + Args: + folder: Path to the folder containing packages, relative to ``os.getcwd()`` + position: Where in ``sys.path`` to insert the vendor packages. By default + this is set to 1. It is inadvisable to set it to 0 as it will override + any modules in the current working directory. + """ + + # Check if the path contains a virtualenv. + site_dir = os.path.join(folder, 'lib', 'python' + sys.version[:3], 'site-packages') + if os.path.exists(site_dir): + folder = site_dir + # Otherwise it's just a normal path, make it absolute. + else: + folder = os.path.join(os.path.dirname(__file__), folder) + + # Use site.addsitedir() because it appropriately reads .pth + # files for namespaced packages. Unfortunately, there's not an + # option to choose where addsitedir() puts its paths in sys.path + # so we have to do a little bit of magic to make it play along. + + # We're going to grab the current sys.path and split it up into + # the first entry and then the rest. Essentially turning + # ['.', '/site-packages/x', 'site-packages/y'] + # into + # ['.'] and ['/site-packages/x', 'site-packages/y'] + # The reason for this is we want '.' to remain at the top of the + # list but we want our vendor files to override everything else. + sys.path, remainder = sys.path[:1], sys.path[1:] + + # Now we call addsitedir which will append our vendor directories + # to sys.path (which was truncated by the last step.) + site.addsitedir(folder) + + # Finally, we'll add the paths we removed back. + # The final product is something like this: + # ['.', '/vendor-folder', /site-packages/x', 'site-packages/y'] + sys.path.extend(remainder) \ No newline at end of file