def set_up_project_experiment(self, apikey, project_name, experiment_name):
     project_list = get_all_projects(apikey=apikey)
     for proj in project_list:
         if proj.name == project_name:
             self.project = proj
     if not self.project:
         print("Can not find project with name = " + str(project_name) +
               ". Quiting.")
         return False
     experiment_list = self.project.get_all_experiments()
     found = []
     for exp in experiment_list:
         if exp.name == experiment_name:
             found.append(exp)
     if not found:
         print("Can not find Experiment with name = " +
               str(experiment_name) + ". Quiting.")
         return False
     if len(found) > 1:
         print("Found more the one Experiment with name = " +
               str(experiment_name) + ";")
         print("Rename experiment so that '" + str(experiment_name) +
               "' is unique.")
         print("Quiting.")
         return False
     self.experiment = found[0]
     return True
Exemple #2
0
    def setUpClass(cls):
        cls.apikey = os.environ['MC_API_KEY']
        print("MC_API_KEY = {}".format(cls.apikey))
        cls.project = None

        if USER_TEST_PROJECT:
            all_projects = get_all_projects()
            for project in all_projects:
                if project.name == TEST_PROJECT_NAME:
                    cls.project = project
                    cls.project_name = project.name
                    cls.project_id = project.id
                    break
        else:
            cls.project_name = fake_name("TestForETL-")
            description = "Test project generated by automated test"
            cls.project = create_project(cls.project_name, description)
            cls.project_id = cls.project.id

        cls.data_dir_path = os.path.abspath(os.environ['TEST_DATA_DIR'])
        print("TEST_DATA_DIR = {}".format(cls.data_dir_path))

        project = cls.project

        project.local_path = cls.data_dir_path
        local_dir_path = os.path.join(cls.data_dir_path, TEST_DIR)
        project.add_directory_tree_by_local_path(local_dir_path)
        print("project {} ({})".format(project.name, project.id))
        print("project.local_path = {}".format(project.local_path))
        print("local_dir_path = {}".format(local_dir_path))
 def get_project_for_test(self, name):
     projects = get_all_projects(self.apikey)
     project = None
     for probe in projects:
         if probe.name == name:
             project = probe
     if not project:
         print("Can not find project {}".format(name))
         exit(-1)
     print("got project for test{}".format(project.name))
     return project
def test(project_name, apikey):
    project_list = get_all_projects(apikey=apikey)
    project = None
    for proj in project_list:
        if proj.name == project_name:
            project = proj
    if not project:
        print("Can not find project with name = " + str(project_name) + ". Quiting.")
        return
    print("Found project: " + project.name + " (" + project.id + ")")
    print("------")
    table = make_project_file_id_path_table(project)
    print("------")
    for key in table:
        print(key + " --> " + table[key]['file'].name + ", " + table[key]['path'])
 def set_up_project_experiment_metadata(self, project_name,
                                        experiment_name):
     project_list = get_all_projects(apikey=self.apikey)
     for proj in project_list:
         if proj.name == project_name:
             self.project = proj
     if not self.project:
         print("Can not find project with name = " + str(project_name) +
               ". Quiting.")
         return False
     experiment_list = self.project.get_all_experiments()
     found = []
     for exp in experiment_list:
         if exp.name == experiment_name:
             found.append(exp)
     if not found:
         print("Can not find Experiment with name = " +
               str(experiment_name) + ". Quiting.")
         return False
     if len(found) > 1:
         print("Found more the one Experiment with name = " +
               str(experiment_name) + ";")
         print("Rename experiment so that '" + str(experiment_name) +
               "' is unique.")
         print("Quiting.")
         return False
     self.experiment = found[0]
     ok = self.metadata.read(self.experiment.id)
     if not ok:
         print("There was no ETL metadata for the experiment '" +
               str(experiment_name) + "';")
         print(
             "This experiment does not appear to have been created using ETL input."
         )
         print("Quiting.")
         return False
     metadata = MetadataVerification().verify(
         self.metadata)  # Adds metadata.process_table !
     if not metadata:
         print("Metadata verification failed.")
         return False
     self.metadata = metadata
     return True
        print("You must specify a Materials Commons apikey. Argument not found.")
        parser.print_help()
        exit(-1)

    if not args.user:
        print("You must specify a Materials Commons user id. Argument not found.")
        parser.print_help()
        exit(-1)

    if not args.name:
        print("You must specify a Project name. Argument not found.")
        parser.print_help()
        exit(-1)

    local_log.info("Searching for project with name-match = {}".format(args.name))
    project_list = get_all_projects(apikey=args.apikey)
    local_log.info("Found {} projects".format(len(project_list)))

    project_selected = None
    for probe in project_list:
        local_log.info("Compareing with {}".format(probe.name))
        if args.name in probe.name:
            if project_selected:
                local_log.info("Found multiple matches for {}".format(args.name))
                local_log.info("You must specify a unique project name, or name substring.")
                parser.print_help()
                exit(-1)
            project_selected = probe

    if not project_selected:
        local_log.info("Found no matches for {}".format(args.name))
Exemple #7
0
#import sys

import materials_commons.api as mcapi

project_list = mcapi.get_all_projects()

for project in project_list:
    if project.name == 'PRISMS-PF API Test':
        current_project = project

experiment_list = current_project.get_all_experiments()

for experiment in experiment_list:
    if experiment.name == 'Experiment 0':
        print(experiment.name)
        current_experiment = experiment


template_list = mcapi.get_all_templates()
for template in template_list:
    print(template.name, template.id)

#experiment = project.create_experiment("Experiment 0", "Creating and modifying experiments using the API")