예제 #1
0
    def get_container(self, remote_path, username=""):
        try:
            from hbp_archive import Container
        except ImportError:
            print("Please install the following package: hbp_archive")
            return

        name_parts = remote_path.split("swift://cscs.ch/")[1].split("/")
        if name_parts[0].startswith(
                "bp00sp"):  # presuming all project names start like this
            prj_name = name_parts[0]
            ind = 1
        else:
            prj_name = None
            ind = 0
        cont_name = name_parts[ind]
        entity_path = "/".join(name_parts[ind + 1:])
        pre_path = None
        if not "." in name_parts[-1]:
            dirname = name_parts[-1]
            pre_path = entity_path.replace(dirname, "", 1)

        print("----------------------------------------------------")
        print("NOTE: The target location is inside a CSCS container")
        print("----------------------------------------------------")
        if not username:
            username = raw_input("Please enter your CSCS username: ")
        container = Container(cont_name, username, project=prj_name)
        if prj_name:
            container.project._get_container_info()
        return container, entity_path, pre_path
예제 #2
0
    def upload_data(self,
                    file_paths,
                    username="",
                    container="",
                    project=None,
                    remote_directory="",
                    overwrite=False):
        try:
            from hbp_archive import Container
        except ImportError:
            print("Please install the following package: hbp_archive")
            return

        print("----------------------------------------------------")
        print("NOTE: The target location is inside a CSCS container")
        print("----------------------------------------------------")
        if not username:
            username = raw_input("Please enter your CSCS username: "******"Please enter target container name: ")
        container_obj = Container(container, username, project=project)
        remote_paths = container_obj.upload(file_paths,
                                            remote_directory=remote_directory,
                                            overwrite=overwrite)
        return remote_paths
    def upload_data(self,
                    file_paths,
                    username="",
                    container="",
                    project=None,
                    remote_directory="",
                    overwrite=False):
        try:
            from hbp_archive import Container
        except ImportError:
            print("Please install the following package: hbp_archive")
            return

        print("----------------------------------------------------")
        print("NOTE: The target location is inside a CSCS container")
        print("----------------------------------------------------")
        if not username:
            username = input("Please enter your CSCS username: "******"Please enter target container name: ")
        if isinstance(file_paths, str):
            file_paths = [file_paths]
        container_obj = Container(container, username, project=project)
        url_prefix = ""
        if container_obj.public_url:
            url_prefix = container_obj.public_url + "/"
        remote_paths = container_obj.upload(file_paths,
                                            remote_directory=remote_directory,
                                            overwrite=overwrite)
        uploaded_file_paths = []
        for ind, f in enumerate(file_paths):
            uploaded_file_paths.append({
                "filepath":
                url_prefix + remote_paths[ind],
                "filesize":
                os.path.getsize(f)
            })
        return uploaded_file_paths
예제 #4
0
 def setUpClass(cls, getpw):
     getpw.return_value = os.environ["HBP_ARCHIVE_PASSWORD"]
     username = os.environ["HBP_ARCHIVE_USERNAME"]
     cls.container = Container("sp6_validation_data", username)
예제 #5
0
 def test_instantiate_with_project_name(self, getpw):
     # see issue #8
     getpw.return_value = os.environ["HBP_ARCHIVE_PASSWORD"]
     username = os.environ["HBP_ARCHIVE_USERNAME"]
     container2 = Container("sp6_validation_data", username, project="bp00sp06")
     container2.list()