]> git.parisson.com Git - pdf.js.git/commitdiff
Move downloading code into separate function for readability.
authorRob Sayre <sayrer@gmail.com>
Sun, 26 Jun 2011 19:05:02 +0000 (12:05 -0700)
committerRob Sayre <sayrer@gmail.com>
Sun, 26 Jun 2011 19:05:02 +0000 (12:05 -0700)
test/test.py

index b867251ee0a7560d900d9e3baf8137a3995e743d..c6723ada485877d936920f05320dc7d02fc718da 100644 (file)
@@ -204,6 +204,23 @@ def makeBrowserCommands(browserManifestFile):
         browsers = [BrowserCommand(browser) for browser in json.load(bmf)]
     return browsers
 
+def downloadLinkedPDFs(manifestList):
+    for item in manifestList:
+        f, isLink = item['file'], item.get('link', False)
+        if isLink and not os.access(f, os.R_OK):
+            linkFile = open(f +'.link')
+            link = linkFile.read()
+            linkFile.close()
+
+            sys.stdout.write('Downloading '+ link +' to '+ f +' ...')
+            sys.stdout.flush()
+            response = urllib2.urlopen(link)
+
+            with open(f, 'w') as out:
+                out.write(response.read())
+
+            print 'done'
+
 def setUp(options):
     # Only serve files from a pdf.js clone
     assert not ANAL or os.path.isfile('../pdf.js') and os.path.isdir('../.git')
@@ -227,22 +244,7 @@ def setUp(options):
     with open(options.manifestFile) as mf:
         manifestList = json.load(mf)
 
-    for item in manifestList:
-        f, isLink = item['file'], item.get('link', False)
-        if isLink and not os.access(f, os.R_OK):
-            linkFile = open(f +'.link')
-            link = linkFile.read()
-            linkFile.close()
-
-            sys.stdout.write('Downloading '+ link +' to '+ f +' ...')
-            sys.stdout.flush()
-            response = urllib2.urlopen(link)
-
-            out = open(f, 'w')
-            out.write(response.read())
-            out.close()
-
-            print 'done'
+    downloadLinkedPDFs(manifestList)
 
     for b in testBrowsers:
         State.taskResults[b.name] = { }