def test_untar(self, mockMkDir, mockIsDir): with patch.object(tarfile, 'open', autospec=True) as mockOpen: with patch.object(mockOpen.return_value, 'extractall', autospec=True) as mockExtract: FileUtils.untar('some/zip/path', 'some/dir/path') mockOpen.assert_called_once_with('some/zip/path', 'r') mockIsDir.assert_called_once_with('some/dir/path') mockMkDir.assert_called_once_with('some/dir/path') mockExtract.assert_called_once_with('some/dir/path')
def retrieve(self, job_bundle): if not job_bundle.local_path or not os.path.isdir(job_bundle.local_path): # configure bundle with information about who is processing it where job_bundle.local_path = 'tmp/%s' % (job_bundle.scene_entity_id,) zip_path = '%s.tar.gz' % (job_bundle.local_path,) job_bundle.hostname = platform.uname().node job_bundle.save() # get the compressed scene data if we don't have it if not os.path.isfile(zip_path): urllib.request.urlretrieve(job_bundle.requested_scene.scene_url, zip_path) FileUtils.untar(zip_path, job_bundle.local_path)
def get_metadata(self, bundle, field_name): if not self.xml_helper: relative_filename = '%s.xml' % (bundle.scene_entity_id,) absolute_filename = FileUtils.absolutize(bundle=bundle, filename=relative_filename) self.xml_helper = XmlHelper(absolute_filename) return self.xml_helper.retrieve(field_name)
def _resolve_name(adapter, stage, bundle, semantic_name): try: semantic_name.index('*') literal_name = semantic_name absolute_filenames = glob.glob( FileUtils.absolutize(bundle=bundle, filename=literal_name)) except ValueError: literal_name = adapter.resolve_relative_image(bundle, semantic_name) absolute_filenames = [ FileUtils.absolutize(bundle=bundle, filename=literal_name) ] versioned_filenames = [ FileUtils.locate_latest_version(filename, stage.sort_order) for filename in absolute_filenames ] return versioned_filenames
def output_directory(self): return FileUtils.absolutize(bundle=self.bundle, filename=self.config['output_directory'])
def get_new_filename(self, filename): return self.get_new_version( FileUtils.absolutize(bundle=self.bundle, filename=self.adapter.construct_filename( self.bundle, filename)))
def get_new_version(self, filename): filename = FileUtils.version_filename(filename, self.sort_order) if self.output_extension: filename = splitext(filename)[0] + '.' + self.output_extension return filename
def test__version(self): assert (FileUtils._version('foo.bar', 7) == 'foo_stage_07.bar')
def test_locate_latest_version_exists(self, *args): assert (FileUtils.locate_latest_version('foo.bar', 3) == 'foo_stage_01.bar')
def test_locate_latest_version_new(self, *args): assert (FileUtils.locate_latest_version('foo.bar', 3) == 'foo.bar')
def test_version_filename(self, mockUn, mockRe): assert (FileUtils.version_filename('foo_stage_8.bar', 2) == 'reversioned') mockUn.assert_called_once_with('foo_stage_8.bar', new_extension=None) mockRe.assert_called_once_with('unversioned', 2)
def test__unversion(self): assert (FileUtils._unversion('foo.bar') == 'foo.bar') assert (FileUtils._unversion('foo_stage_03.bar') == 'foo.bar')
def manifest_directory(self): manifest_directory_name = self.pipeline_stage.interstitial_product_location return FileUtils.absolutize(bundle=self.bundle, filename=manifest_directory_name)
def output_directory(self): output_directory_name = self.pipeline_stage.output_filename return FileUtils.absolutize(bundle=self.bundle, filename=output_directory_name)