From 116914a949b373fa91a5dd3644b690727dac9a25 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Wed, 22 Jun 2016 20:58:19 -0700 Subject: [PATCH] Remove unused scripts --- support/download.py | 46 --------------------------------------------- support/timer.py | 35 ---------------------------------- 2 files changed, 81 deletions(-) delete mode 100644 support/download.py delete mode 100644 support/timer.py diff --git a/support/download.py b/support/download.py deleted file mode 100644 index faa71bce..00000000 --- a/support/download.py +++ /dev/null @@ -1,46 +0,0 @@ -# A file downloader. - -import contextlib, os, tempfile, timer, urllib2, urlparse - -class Downloader: - def __init__(self, dir=None): - self.dir = dir - - # Downloads a file and removes it when exiting a block. - # Usage: - # d = Downloader() - # with d.download(url) as f: - # use_file(f) - def download(self, url, cookie=None): - suffix = os.path.splitext(urlparse.urlsplit(url)[2])[1] - fd, filename = tempfile.mkstemp(suffix=suffix, dir=self.dir) - os.close(fd) - with timer.print_time('Downloading', url, 'to', filename): - opener = urllib2.build_opener() - if cookie: - opener.addheaders.append(('Cookie', cookie)) - num_tries = 2 - for i in range(num_tries): - try: - f = opener.open(url) - except urllib2.URLError, e: - print('Failed to open url', url) - continue - length = f.headers.get('content-length') - if not length: - print('Failed to get content-length') - continue - length = int(length) - with open(filename, 'wb') as out: - count = 0 - while count < length: - data = f.read(1024 * 1024) - count += len(data) - out.write(data) - @contextlib.contextmanager - def remove(filename): - try: - yield filename - finally: - os.remove(filename) - return remove(filename) diff --git a/support/timer.py b/support/timer.py deleted file mode 100644 index bf938d62..00000000 --- a/support/timer.py +++ /dev/null @@ -1,35 +0,0 @@ -# A with statement based timer. - -from __future__ import print_function -from contextlib import contextmanager -import timeit - -class Timer: - """ - A with statement based timer. - Usage: - t = Timer() - with t: - do_something() - time = t.time - """ - - def __enter__(self): - self.start = timeit.default_timer() - - def __exit__(self, type, value, traceback): - finish = timeit.default_timer() - self.time = finish - self.start - -@contextmanager -def print_time(*args): - """ - Measures and prints the time taken to execute nested code. - args: Additional arguments to print. - """ - t = Timer() - print(*args) - with t: - yield - print(*args, end=' ') - print('finished in {0:.2f} second(s)'.format(t.time))