Skip to content

Commit

Permalink
Python 3: print is now a function
Browse files Browse the repository at this point in the history
  • Loading branch information
Tenzer committed Oct 4, 2018
1 parent c5cc80f commit 49a2aae
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions render.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,18 @@ def render(data_file, template_file, destination_file):
"""Build the HTML content from scraped data"""
lookup = mako.lookup.TemplateLookup(directories=['.'])
template = mako.template.Template(filename=template_file, lookup=lookup)
print "Loading data from %s..." % data_file
print("Loading data from %s..." % data_file)
with open(data_file) as f:
instances = json.load(f)
for i in instances:
add_render_info(i)
print "Rendering to %s..." % destination_file
print("Rendering to %s..." % destination_file)
generated_at = datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S UTC')
with io.open(destination_file, 'w', encoding="utf-8") as fh:
try:
fh.write(template.render(instances=instances, generated_at=generated_at))
except:
print mako.exceptions.text_error_template().render()
print(mako.exceptions.text_error_template().render())

if __name__ == '__main__':
render('www/instances.json', 'in/index.html.mako', 'www/index.html')
18 changes: 9 additions & 9 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ def scrape_ec2(c):
try:
scrape(ec2_file)
except Exception as e:
print "ERROR: Unable to scrape data: %s" % e
print traceback.print_exc()
print("ERROR: Unable to scrape data: %s" % e)
print(traceback.print_exc())


@task
Expand All @@ -57,16 +57,16 @@ def scrape_rds(c):
try:
rds_scrape(rds_file)
except Exception as e:
print "ERROR: Unable to scrape RDS data: %s" % e
print traceback.print_exc()
print("ERROR: Unable to scrape RDS data: %s" % e)
print(traceback.print_exc())


@task
def serve(c):
"""Serve site contents locally for development"""
os.chdir("www/")
httpd = SocketServer.TCPServer((HTTP_HOST, int(HTTP_PORT)), SimpleHTTPServer.SimpleHTTPRequestHandler)
print "Serving on http://{}:{}".format(httpd.socket.getsockname()[0], httpd.socket.getsockname()[1])
print("Serving on http://{}:{}".format(httpd.socket.getsockname()[0], httpd.socket.getsockname()[1]))
httpd.serve_forever()


Expand All @@ -83,18 +83,18 @@ def bucket_create(c):
conn = connect_s3(calling_format=BUCKET_CALLING_FORMAT)
bucket = conn.create_bucket(BUCKET_NAME, policy='public-read')
bucket.configure_website('index.html', 'error.html')
print 'Bucket %r created.' % BUCKET_NAME
print('Bucket %r created.' % BUCKET_NAME)


@task
def bucket_delete(c):
"""Deletes the S3 bucket used to host the site"""
if not confirm("Are you sure you want to delete the bucket %r?" % BUCKET_NAME):
print 'Aborting at user request.'
print('Aborting at user request.')
exit(1)
conn = connect_s3(calling_format=BUCKET_CALLING_FORMAT)
conn.delete_bucket(BUCKET_NAME)
print 'Bucket %r deleted.' % BUCKET_NAME
print('Bucket %r deleted.' % BUCKET_NAME)


@task
Expand All @@ -109,7 +109,7 @@ def deploy(c, root_dir='www'):
continue
local_path = os.path.join(root, name)
remote_path = local_path[len(root_dir) + 1:]
print '%s -> %s/%s' % (local_path, BUCKET_NAME, remote_path)
print('%s -> %s/%s' % (local_path, BUCKET_NAME, remote_path))
k = Key(bucket)
k.key = remote_path
k.set_contents_from_filename(local_path, policy='public-read')
Expand Down

0 comments on commit 49a2aae

Please sign in to comment.