def _get_target_path(source):
    # to extract a human-readable suffix from the source path, split by
    # both backslash (to handle windows filesystem) and forward slash
    # (to handle URLs and unix filesystem)
    suffix = re.split(r'\\|/', source)[-1]
    return tempfile.mktemp(suffix='-{0}'.format(suffix),
                           dir=create_temp_folder())
 def test_download_resource_to_specific_file(self):
     target_path = "{0}/for_test_custom.log".format(create_temp_folder())
     resource_path = self.context.download_resource(
         resource_path='for_test.log',
         target_path=target_path)
     self.assertEqual(target_path, resource_path)
     self.assertTrue(os.path.exists(resource_path))
Esempio n. 3
0
 def test_download_resource_to_specific_file(self, _):
     target_path = "{0}/for_test_custom.log".format(create_temp_folder())
     resource_path = self.context.download_resource(
         resource_path='for_test.txt',
         target_path=target_path)
     self.assertEqual(target_path, resource_path)
     self.assertTrue(os.path.exists(resource_path))
Esempio n. 4
0
 def test_download_resource_to_specific_file(self, _):
     target_path = "{0}/for_test_custom.log".format(create_temp_folder())
     with patch('requests.get', return_value=Mock(ok=True, content=b'')):
         resource_path = self.context.download_resource(
             resource_path='for_test.txt', target_path=target_path)
     self.assertEqual(target_path, resource_path)
     self.assertTrue(os.path.exists(resource_path))
Esempio n. 5
0
    def download_directory(self,
                           blueprint_id,
                           deployment_id,
                           resource_path,
                           logger,
                           target_path=None,
                           preview_only=False):
        resource_files = manager.get_resource_directory_index(
            blueprint_id, deployment_id, self.ctx.tenant_name, resource_path)
        resource_files = [os.path.join(resource_path, fp)
                          for fp in resource_files]

        logger.debug(">> Collected %s", resource_files)
        if preview_only:
            return resource_files

        top_dir = None
        target_dir = utils.create_temp_folder()
        for file_path in resource_files:
            top_dir = top_dir or file_path.split(os.sep)[0]
            target_path = os.path.join(target_dir,
                                       os.path.relpath(file_path, top_dir))
            os.makedirs(os.path.dirname(target_path), exist_ok=True)
            self.download_resource(
                blueprint_id,
                deployment_id,
                file_path,
                logger,
                target_path=target_path)
        return target_dir
Esempio n. 6
0
def _get_target_path(source):
    # to extract a human-readable suffix from the source path, split by
    # both backslash (to handle windows filesystem) and forward slash
    # (to handle URLs and unix filesystem)
    suffix = re.split(r'\\|/', source)[-1]
    return tempfile.mktemp(suffix='-{0}'.format(suffix),
                           dir=create_temp_folder())
Esempio n. 7
0
def _save_resource(logger, resource, resource_path, target_path):
    if not target_path:
        target_path = os.path.join(utils.create_temp_folder(),
                                   os.path.basename(resource_path))
    with open(target_path, 'wb') as f:
        f.write(resource)
    logger.info("Downloaded %s to %s" % (resource_path, target_path))
    return target_path
Esempio n. 8
0
def _get_target_path(source):
    # to extract a human-readable suffix from the source path, split by
    # both backslash (to handle windows filesystem) and forward slash
    # (to handle URLs and unix filesystem)
    suffix = re.split(r'\\|/', source)[-1]
    return os.path.join(create_temp_folder(), suffix)
def _get_target_path(source):
    # to extract a human-readable suffix from the source path, split by
    # both backslash (to handle windows filesystem) and forward slash
    # (to handle URLs and unix filesystem)
    suffix = re.split(r'\\|/', source)[-1]
    return os.path.join(create_temp_folder(), suffix)