Skip to content

Commit 24a9a0c

Browse files
authored
Merge pull request #3514 from cclauss/modernize-python2-code
Modernize Python 2 code to get ready for Python 3
2 parents fbc8aa9 + 040ac06 commit 24a9a0c

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

deploy/delete_stale_projects.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
import shutil
23
import os
34

@@ -11,11 +12,11 @@
1112
if slug not in slugs and slug.replace('_', '-') not in slugs:
1213
final.append(slug)
1314

14-
print "To delete: %s" % len(final)
15+
print("To delete: %s" % len(final))
1516

1617
for to_del in final:
1718
root = '/home/docs/checkouts/readthedocs.org'
18-
print "Deleting " + to_del
19+
print("Deleting " + to_del)
1920
shutil.rmtree('{root}/user_builds/{slug}'.format(root=root, slug=to_del), ignore_errors=True)
2021
shutil.rmtree('{root}/media/pdf/{slug}'.format(root=root, slug=to_del), ignore_errors=True)
2122
shutil.rmtree('{root}/media/epub/{slug}'.format(root=root, slug=to_del), ignore_errors=True)

deploy/flask-redirects.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""A Flask app for redirecting documentation from the root / URL."""
2+
from __future__ import print_function
23

34
import json
45

@@ -17,7 +18,7 @@ def redirect_front():
1718

1819
SUBDOMAIN = CNAME = False
1920

20-
print "Got request {host}".format(host=request.host)
21+
print("Got request {host}".format(host=request.host))
2122
if PRODUCTION_DOMAIN in request.host:
2223
SUBDOMAIN = True
2324
slug = request.host.split('.')[0]
@@ -31,23 +32,23 @@ def redirect_front():
3132
path = "/home/docs/checkouts/readthedocs.org/public_cname_project/{cname}/metadata.json".format(cname=cname)
3233

3334
try:
34-
json_obj = json.load(file(path))
35+
json_obj = json.load(open(path))
3536
version = json_obj['version']
3637
language = json_obj['language']
3738
single_version = json_obj['single_version']
38-
except Exception, e:
39-
print e
39+
except Exception as e:
40+
print(e)
4041

4142
if single_version:
4243
if SUBDOMAIN:
4344
sendfile = "/user_builds/{slug}/translations/{language}/{version}/".format(slug=slug, language=language, version=version)
4445
elif CNAME:
4546
sendfile = "/public_cname_root/{cname}/".format(cname=cname, language=language, version=version)
46-
print "Redirecting {host} to {sendfile}".format(host=request.host, sendfile=sendfile)
47+
print("Redirecting {host} to {sendfile}".format(host=request.host, sendfile=sendfile))
4748
return make_response('', 303, {'X-Accel-Redirect': sendfile})
4849
else:
4950
url = '/{language}/{version}/'.format(language=language, version=version)
50-
print "Redirecting {host} to {url}".format(host=request.host, url=url)
51+
print("Redirecting {host} to {url}".format(host=request.host, url=url))
5152
return redirect(url)
5253

5354

deploy/nginx-smoke-test.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python
22

33
"""Check Nginx config on readthedocs.org."""
4+
from __future__ import print_function
45

56
import sys
67
import requests
@@ -66,15 +67,15 @@ def run_test(fn, *args):
6667
ret_value = fn(*args)
6768
result = 'ok' if ret_value else 'ERROR'
6869
url = args[0]
69-
print "{url: <65} ... {result}".format(url=url, result=result)
70+
print("{url: <65} ... {result}".format(url=url, result=result))
7071
return ret_value
7172

7273

7374
def header(msg):
7475
"""Give each test a sexy header."""
75-
print
76-
print msg
77-
print "-----------------------------"
76+
print()
77+
print(msg)
78+
print("-----------------------------")
7879

7980

8081
def summary_results(num_tests, num_fails):
@@ -115,7 +116,7 @@ def main():
115116
for url, redirect in redirected_urls:
116117
run_test(redirected, url, redirect)
117118

118-
print summary_results(TESTS, FAILS)
119+
print(summary_results(TESTS, FAILS))
119120

120121
exit_code = 1 if (FAILS > 0) else 0
121122
return exit_code

0 commit comments

Comments
 (0)