def do_test(workingdir): zipname = os.path.join(workingdir, 'foo') target_path = os.path.join(workingdir, 'boo') errors = [] unpack_zip(zipname, target_path, errors) assert [('Failed to unzip %s: File is not a zip file' % zipname) ] == errors
def do_test(zipname, workingdir): target_path = os.path.join(workingdir, 'foo') # same name as what's in the zip errors = [] unpack_zip(zipname, target_path, errors) assert [] == errors assert os.path.isfile(target_path) assert codecs.open(target_path, 'r', 'utf-8').read() == "hello world\n"
def do_test(zipname, workingdir): target_path = os.path.join(workingdir, 'foo') # same name with codecs.open(target_path, 'w', 'utf-8') as f: f.write("\n") errors = [] unpack_zip(zipname, target_path, errors) assert [] == errors assert os.path.isfile(target_path) assert codecs.open(target_path, 'r', 'utf-8').read() == "hello world\n"
def do_test(zipname, workingdir): target_path = os.path.join(workingdir, 'boo') with codecs.open(target_path, 'w', 'utf-8') as f: f.write("\n") errors = [] unpack_zip(zipname, target_path, errors) assert [( "%s exists and isn't a directory, not unzipping a directory over it." % target_path)] == errors
def do_test(zipname, workingdir): target_path = os.path.join( workingdir, 'boo') # different name from what's in the zip errors = [] unpack_zip(zipname, target_path, errors) assert [] == errors assert os.path.isdir(target_path) assert codecs.open(os.path.join(target_path, 'foo'), 'r', 'utf-8').read() == "hello world\n"
def do_test(zipname, workingdir): target_path = os.path.join(workingdir, 'boo') errors = [] unpack_zip(zipname, target_path, errors) assert [] == errors assert os.path.isdir(target_path) assert codecs.open(os.path.join(target_path, 'foo'), 'r', 'utf-8').read() == "hello world\n" assert codecs.open(os.path.join(target_path, 'bar'), 'r', 'utf-8').read() == "goodbye world\n"
def do_test(zipname, workingdir): target_path = os.path.join(workingdir, 'foo') # same name as file in zip os.makedirs(target_path) errors = [] unpack_zip(zipname, target_path, errors) assert os.path.isdir(target_path) assert [ "%s exists and is a directory, not unzipping a plain file over it." % target_path ] == errors
def do_test(zipname, workingdir): target_path = os.path.join(workingdir, 'boo') # different from the file in the zip with codecs.open(target_path, 'w', 'utf-8') as f: f.write("original\n") errors = [] unpack_zip(zipname, target_path, errors) assert [( "%s exists and isn't a directory, not unzipping a directory over it." % target_path)] == errors assert os.path.isfile(target_path) assert codecs.open(target_path, 'r', 'utf-8').read() == "original\n"
def _provide_download(self, requirement, context, frontend): filename = context.status.analysis.existing_filename if filename is not None: frontend.info( "Previously downloaded file located at {}".format(filename)) return filename filename = os.path.abspath( os.path.join(context.environ['PROJECT_DIR'], requirement.filename)) if requirement.unzip: download_filename = filename + ".zip" else: download_filename = filename download = FileDownloader(url=requirement.url, filename=download_filename, hash_algorithm=requirement.hash_algorithm) try: _ioloop = IOLoop(make_current=False) response = _ioloop.run_sync(download.run) if response is None: for error in download.errors: frontend.error(error) return None elif response.code == 200: if requirement.hash_value is not None and requirement.hash_value != download.hash: frontend.error( "Error downloading {}: mismatched hashes. Expected: {}, calculated: {}" .format(requirement.url, requirement.hash_value, download.hash)) return None if requirement.unzip: unzip_errors = [] if unpack_zip(download_filename, filename, unzip_errors): os.remove(download_filename) return filename else: for error in unzip_errors: frontend.error(error) return None return filename else: frontend.error("Error downloading {}: response code {}".format( requirement.url, response.code)) return None except Exception as e: frontend.error("Error downloading {}: {}".format( requirement.url, str(e))) return None finally: _ioloop.close()
def do_test(zipname, workingdir): target_path = os.path.join(workingdir, 'boo') errors = [] unpack_zip(zipname, target_path, errors) assert ['Zip archive was empty.'] == errors assert not os.path.isdir(target_path)