Permalink
Browse files

Updated scripts and tests to Python 3.

  • Loading branch information...
1 parent ae451d6 commit 5c338172d15ca2a2fea323319b25730dedbc8f8c @ehmatthes committed Nov 21, 2013
Showing with 27 additions and 30 deletions.
  1. +6 −9 scripts/add_bootstrap.py
  2. +4 −4 scripts/modify_facebook_urls.py
  3. +5 −5 scripts/show_hide_output.py
  4. +12 −12 tests/test_links.py
@@ -60,15 +60,12 @@
f = open(path_to_notebooks + filename, 'wb')
for line in lines:
if '<body>' in line:
- f.write(line)
- f.write(navbar_string)
- f.write("\n\n")
+ f.write(line.encode('utf-8'))
+ f.write(navbar_string.encode('utf-8'))
+ f.write("\n\n".encode('utf-8'))
elif '</body>' in line:
- f.write(final_js_string)
- f.write(line)
+ f.write(final_js_string.encode('utf-8'))
+ f.write(line.encode('utf-8'))
else:
- f.write(line)
+ f.write(line.encode('utf-8'))
f.close()
-
-
-
@@ -5,7 +5,7 @@
import os
import sys
-print "Modifying facebook urls..."
+print("Modifying facebook urls...")
# Find all files to work with.
path_to_notebooks = '/srv/projects/intro_programming/intro_programming/notebooks/'
@@ -31,12 +31,12 @@
for line in lines:
if old_fb_url in line:
new_line = line.replace(old_fb_url, new_fb_url)
- f.write(new_line)
+ f.write(new_line.encode('utf-8'))
else:
- f.write(line)
+ f.write(line.encode('utf-8'))
f.close()
-print "Modified facebook urls.\n"
+print("Modified facebook urls.\n")
@@ -65,20 +65,20 @@ def generate_show_hide_all_buttons():
if "<div class='container'>" in line or '<div class="container">' in line:
# Add show_all hide_all buttons in second container.
container_number += 1
- f.write(line)
+ f.write(line.encode('utf-8'))
if container_number == 2:
- f.write(generate_show_hide_all_buttons())
+ f.write(generate_show_hide_all_buttons().encode('utf-8'))
elif target_string in line:
# If this line has a div.output, add an id
replacement_string = '<div id="output_%d" class="output ' % replacement_num
# Add a pair of show/ hide buttons right before div.output
- f.write(generate_button(replacement_num))
- f.write(line.replace(target_string, replacement_string))
+ f.write(generate_button(replacement_num).encode('utf-8'))
+ f.write(line.replace(target_string, replacement_string).encode('utf-8'))
replacement_num += 1
else:
# Otherwise, rewrite the line.
- f.write(line)
+ f.write(line.encode('utf-8'))
View
@@ -26,7 +26,7 @@
for opt, arg in opts:
if opt in ('--root', '-r'):
root = arg + '/'
-print "Using root: ", root
+print("Using root: ", root)
def get_links_in_line(line):
@@ -61,9 +61,9 @@ def get_links_in_file(root_dir, filename):
def check_links(filename, links, bad_links, links_tested):
# Checks all links given, and adds bad links to bad_links.
- print "links to check: ", links
+ print("links to check: ", links)
for link in links:
- print "Checking link: %s..." % link
+ print("Checking link: %s..." % link)
# Only check links that haven't already been checked:
if link in links_tested:
@@ -74,9 +74,9 @@ def check_links(filename, links, bad_links, links_tested):
url = link
else:
url = root + link
- print 'checking url: ', url
+ print('checking url: ', url)
r = requests.get(url)
- print 'Status code: ', r.status_code
+ print('Status code: ', r.status_code)
if r.status_code != 200:
bad_links[filename + '---' + link] = r.status_code
else:
@@ -95,7 +95,7 @@ def check_links(filename, links, bad_links, links_tested):
# Start a server locally, in the notebooks directory.
-print "Starting server..."
+print("Starting server...")
cmd = 'chdir /srv/projects/intro_programming/intro_programming/notebooks/ && '
cmd += 'python -m SimpleHTTPServer'
pro = subprocess.Popen(cmd, shell=True, preexec_fn=os.setsid)
@@ -123,13 +123,13 @@ def check_links(filename, links, bad_links, links_tested):
os.killpg(pro.pid, signal.SIGTERM)
# Report on bad links.
-print "\n\n*** Bad Links ***"
+print("\n\n*** Bad Links ***")
if bad_links:
for link in bad_links:
- print '\n', bad_links[link], link
+ print('\n', bad_links[link], link)
else:
- print "Congratulations, all links are working."
-print "\n"
+ print("Congratulations, all links are working.")
+print("\n")
-print "Checked %d links." % num_links_checked
-print "Tested %d unique links." % len(links_tested)
+print("Checked %d links." % num_links_checked)
+print("Tested %d unique links." % len(links_tested))

0 comments on commit 5c33817

Please sign in to comment.