Skip to content
This repository has been archived by the owner on Dec 3, 2019. It is now read-only.

Commit

Permalink
Merge pull request #12 from kezabelle/master
Browse files Browse the repository at this point in the history
Python 3 support
  • Loading branch information
mtigas committed Oct 16, 2014
2 parents 5804e53 + 44d8205 commit d03a349
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 47 deletions.
2 changes: 1 addition & 1 deletion django_medusa/renderers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 8 additions & 11 deletions django_medusa/renderers/appengine.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
from django.conf import settings
from django.test.client import Client
from .base import BaseStaticSiteRenderer
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand Down
7 changes: 4 additions & 3 deletions django_medusa/renderers/disk.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
from django.conf import settings
from django.test.client import Client
import mimetypes
Expand Down Expand Up @@ -50,8 +51,8 @@ def _disk_render_path(args):
else:
# Default to ".html"
outpath += "index.html"
print outpath
with open(outpath, 'w') as f:
print(outpath)
with open(outpath, 'wb') as f:
f.write(resp.content)


Expand All @@ -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(
Expand Down
33 changes: 9 additions & 24 deletions django_medusa/renderers/s3.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import cStringIO

from __future__ import print_function
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
Expand Down Expand Up @@ -93,11 +96,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]

Expand Down Expand Up @@ -138,7 +141,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(
Expand Down Expand Up @@ -167,22 +170,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)
16 changes: 8 additions & 8 deletions django_medusa/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import imp
from django.conf import settings
from importlib import import_module
Expand Down Expand Up @@ -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)

0 comments on commit d03a349

Please sign in to comment.