From f9656ae3b392058478659721b21ac3218c414a57 Mon Sep 17 00:00:00 2001 From: Keryn Knight Date: Sun, 5 Jan 2014 17:19:03 +0000 Subject: [PATCH 1/4] without configuring the `MEDUSA_RENDERER_CLASS`, the staticsitegen command will fail with an ImportError, rather than the NotImplementedError we expect. --- django_medusa/renderers/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django_medusa/renderers/__init__.py b/django_medusa/renderers/__init__.py index 928aae9..2200369 100644 --- a/django_medusa/renderers/__init__.py +++ b/django_medusa/renderers/__init__.py @@ -16,7 +16,7 @@ def get_cls(renderer_name): return getattr(mod, cls_name) -DEFAULT_RENDERER = 'medusa.renderers.BaseStaticSiteRenderer' +DEFAULT_RENDERER = 'django_medusa.renderers.BaseStaticSiteRenderer' # Define the default "django_medusa.renderers.StaticSiteRenderer" class as # whatever class we have chosen in settings (defaulting to Base which will From 0d2e5fa9d7193a2bc56b4cf243a8e4ce8f0952b9 Mon Sep 17 00:00:00 2001 From: Keryn Knight Date: Sun, 5 Jan 2014 15:42:06 +0000 Subject: [PATCH 2/4] convert print usage to use the print function for py3 compatibility. --- django_medusa/renderers/appengine.py | 19 ++++++++----------- django_medusa/renderers/disk.py | 5 +++-- django_medusa/renderers/s3.py | 27 +++++---------------------- django_medusa/utils.py | 16 ++++++++-------- 4 files changed, 24 insertions(+), 43 deletions(-) diff --git a/django_medusa/renderers/appengine.py b/django_medusa/renderers/appengine.py index f3191c0..59c1675 100644 --- a/django_medusa/renderers/appengine.py +++ b/django_medusa/renderers/appengine.py @@ -1,3 +1,4 @@ +from __future__ import print_function from django.conf import settings from django.test.client import Client from .base import BaseStaticSiteRenderer @@ -46,7 +47,7 @@ def _gae_render_path(args): if needs_ext: outpath += "index.html" - print outpath + print(outpath) with open(outpath, 'w') as f: f.write(resp.content) @@ -82,8 +83,7 @@ def render_path(self, path=None, view=None): @classmethod def initialize_output(cls): - print "Initializing output directory with `app.yaml`." - print + print("Initializing output directory with `app.yaml`.") # Initialize the MEDUSA_DEPLOY_DIR with an `app.yaml` and `deploy` # directory which stores the static files on disk. @@ -113,9 +113,7 @@ def initialize_output(cls): @classmethod def finalize_output(cls): - print - print "Finalizing `app.yaml`." - print + print("Finalizing `app.yaml`.") DEPLOY_DIR = settings.MEDUSA_DEPLOY_DIR app_yaml = os.path.abspath(os.path.join( @@ -158,10 +156,9 @@ def finalize_output(cls): ) app_yaml_f.close() - print "You should now be able to deploy this to Google App Engine" - print "by performing the following command:" - print "appcfg.py update %s" % os.path.abspath(DEPLOY_DIR) - print + print("You should now be able to deploy this to Google App Engine") + print("by performing the following command:") + print("appcfg.py update %s" % os.path.abspath(DEPLOY_DIR)) def generate(self): DEPLOY_DIR = settings.MEDUSA_DEPLOY_DIR @@ -171,7 +168,7 @@ def generate(self): # Upload up to ten items at once via `multiprocessing`. from multiprocessing import Pool - print "Uploading with up to 10 upload processes..." + print("Uploading with up to 10 upload processes...") pool = Pool(10) handlers = pool.map( diff --git a/django_medusa/renderers/disk.py b/django_medusa/renderers/disk.py index 4deeedb..a7153f2 100644 --- a/django_medusa/renderers/disk.py +++ b/django_medusa/renderers/disk.py @@ -1,3 +1,4 @@ +from __future__ import print_function from django.conf import settings from django.test.client import Client import mimetypes @@ -50,7 +51,7 @@ def _disk_render_path(args): else: # Default to ".html" outpath += "index.html" - print outpath + print(outpath) with open(outpath, 'w') as f: f.write(resp.content) @@ -65,7 +66,7 @@ def generate(self): # Upload up to ten items at once via `multiprocessing`. from multiprocessing import Pool, cpu_count - print "Generating with up to %d processes..." % cpu_count() + print("Generating with up to %d processes..." % cpu_count()) pool = Pool(cpu_count()) pool.map_async( diff --git a/django_medusa/renderers/s3.py b/django_medusa/renderers/s3.py index 555fb50..b1ff9e5 100644 --- a/django_medusa/renderers/s3.py +++ b/django_medusa/renderers/s3.py @@ -1,3 +1,4 @@ +from __future__ import print_function import cStringIO from datetime import timedelta, datetime @@ -93,11 +94,11 @@ def _s3_render_path(args): else: message = "Skipping" - print "%s http://%s%s" % ( + print("%s http://%s%s" % ( message, bucket.get_website_endpoint(), path - ) + )) temp_file.close() return [path, outpath] @@ -138,7 +139,7 @@ def generate(self): from multiprocessing import Pool import itertools - print "Uploading with up to 10 upload processes..." + print("Uploading with up to 10 upload processes...") pool = Pool(10) path_tuples = pool.map( @@ -167,22 +168,4 @@ def finalize_output(cls): settings.AWS_DISTRIBUTION_ID, cls.all_generated_paths ) - print req.id - #import time - #while True: - # status = cf.invalidation_request_status( - # settings.AWS_DISTRIBUTION_ID, - # req.id - # ).status - # if status != "InProgress": - # print - # print "Complete:" - # if dist.config.cnames: - # print "Site deployed to http://%s/" % dist.config.cnames[0] - # else: - # print "Site deployed to http://%s/" % dist.domain_name - # print - # break - # else: - # print "In progress..." - # time.sleep(5) + print(req.id) diff --git a/django_medusa/utils.py b/django_medusa/utils.py index e949abc..e276d12 100644 --- a/django_medusa/utils.py +++ b/django_medusa/utils.py @@ -1,3 +1,4 @@ +from __future__ import print_function import imp from django.conf import settings from importlib import import_module @@ -32,25 +33,24 @@ def get_static_renderers(): import_module(app) app_path = sys.modules[app].__path__ except AttributeError: - print "Skipping app '%s'... (Not found)" % app + print("Skipping app '%s'... (Not found)" % app) continue try: imp.find_module(module_name, app_path) except ImportError: - print "Skipping app '%s'... (No 'renderers.py')" % app + print("Skipping app '%s'... (No 'renderers.py')" % app) continue try: app_render_module = import_module('%s.%s' % (app, module_name)) if hasattr(app_render_module, "renderers"): renderers += getattr(app_render_module, module_name) else: - print "Skipping app '%s'... ('%s.renderers' does not contain "\ - "'renderers' var (list of render classes)" % (app, app) + print("Skipping app '%s'... ('%s.renderers' does not contain "\ + "'renderers' var (list of render classes)" % (app, app)) except AttributeError: - print "Skipping app '%s'... (Error importing '%s.renderers')" % ( + print("Skipping app '%s'... (Error importing '%s.renderers')" % ( app, app - ) + )) continue - print "Found renderers for '%s'..." % app - print + print ("Found renderers for '%s'..." % app) return tuple(renderers) From 7217cfec356bfff683f305aebeae7b43346033c9 Mon Sep 17 00:00:00 2001 From: Keryn Knight Date: Sun, 5 Jan 2014 15:43:05 +0000 Subject: [PATCH 3/4] =?UTF-8?q?assume=20py2=20by=20default,=20but=20if=20i?= =?UTF-8?q?t=20fails,=20import=20the=20py3=20stringIO=20and=20hope=20for?= =?UTF-8?q?=20the=20best.=20doesn=E2=80=99t=20rely=20on=20six,=20or=20djan?= =?UTF-8?q?go=E2=80=99s=20vendored=20version=20of=20it.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- django_medusa/renderers/s3.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/django_medusa/renderers/s3.py b/django_medusa/renderers/s3.py index b1ff9e5..f5c98d8 100644 --- a/django_medusa/renderers/s3.py +++ b/django_medusa/renderers/s3.py @@ -1,6 +1,8 @@ from __future__ import print_function -import cStringIO - +try: + import cStringIO +except ImportError: # >=Python 3. + from io import StringIO as cStringIO from datetime import timedelta, datetime from django.conf import settings from django.test.client import Client From 649392fdd1dffbce492fa9766f48e77fe1e081f4 Mon Sep 17 00:00:00 2001 From: Keryn Knight Date: Sun, 5 Jan 2014 17:25:12 +0000 Subject: [PATCH 4/4] =?UTF-8?q?open()=20needs=20to=20use=20=E2=80=98wb?= =?UTF-8?q?=E2=80=99=20under=20py3=20to=20avoid=20raising=20a=20TypeError?= =?UTF-8?q?=20about=20receiving=20bytes=20rather=20than=20str.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- django_medusa/renderers/disk.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django_medusa/renderers/disk.py b/django_medusa/renderers/disk.py index a7153f2..76821e5 100644 --- a/django_medusa/renderers/disk.py +++ b/django_medusa/renderers/disk.py @@ -52,7 +52,7 @@ def _disk_render_path(args): # Default to ".html" outpath += "index.html" print(outpath) - with open(outpath, 'w') as f: + with open(outpath, 'wb') as f: f.write(resp.content)