def test_local_upload(self): """Tests whether uploading to a local file works.""" dst = tempfile.NamedTemporaryFile() dstUri = "file://"+dst.name stager = DataStager(self.source_path, dstUri) stager.perform(asynchronous=False) tmpdata = dst.read() self.assertEqual(self.data, tmpdata)
def test_local_retrieve(self): """Tests whether retrieving a local file works.""" dst_fd, dst_path = tempfile.mkstemp(text=True) stager = DataStager("file://" + self.source_path, dst_path) stager.perform(asynchronous=False) tmpdata = open(dst_path).read() os.unlink(dst_path) os.close(dst_fd) self.assertEqual(self.data, tmpdata)
def handle_upload(self, file_name, uri, mount_point): log.debug("uploading: %s -> %s" % (file_name, uri)) # make file relative to image mount_point file_name = os.path.join(mount_point, file_name.lstrip("/")) stager = DataStager(file_name, uri) rv = stager.perform_upload() log.debug("uploaded to %s" % (uri)) return rv
def handle(self, location, target_dir, target_file_name=None): """Handle a Location entry with an URI as its source. The URI is retrieved and according to additional elements validated (hash validation) and decompressed. """ uri = location["URI"] if uri.startswith("cache://"): uri = self.__transform_cache_uri_hack(uri) # retrieve log.debug("retrieving: %s" % (uri)) if target_file_name is None: filename = uri.split("/")[-1] else: filename = target_file_name dst = os.path.join(target_dir, filename) ds = DataStager(uri, dst) rv = ds.perform_download() log.debug("retrieved to %s" % (dst)) # verify the hash value hash_validator = location.get("Hash") if hash_validator is not None: log.debug("validating data") if not hash_validator.validate(open(dst).read()): raise ValidationError("the retrieved file did not match the hash-value", uri, hash_validator.algorithm(), hash_validator.hexdigest() ) # decompress the file if necessary compression = location.get("Compression") if compression is not None: log.debug("decompressing %s" % (dst)) compression.decompress(file_name=dst, remove_original=True)
def __retrieveFile(self, uri, dst): from xbe.util.staging import DataStager ds = DataStager(uri, dst) return ds.perform()
def test_remote_retrieve(self): remoteSource = "http://www.heise.de/index.html" dst = tempfile.NamedTemporaryFile() stager = DataStager(remoteSource, dst.name) stager.perform(asynchronous=False)