def load_profile_parser(api, opts): """ Load and add user profile description :param api: API Rest api object :param opts: command-line parser opts :type opts: Namespace object with opts attribute """ profile = json.loads(helpers.read_file(opts.path_file)) return _add_profile(api, profile)
def load_profile_parser(api, opts): """ Load and add user profile description :param api: API Rest api object :param opts: command-line parser opts :type opts: Namespace object with opts attribute """ try: profile = json.loads(helpers.read_file(opts.path_file)) return _add_profile(api, profile['profilename'], profile) except KeyError: # pragma: no cover raise ValueError("'profilename' required in profile JSON file: %r" % opts.path_file)
def load_profile_parser(api, opts): """ Load and add user profile description :param api: API Rest api object :param opts: command-line parser opts :type opts: Namespace object with opts attribute """ try: profile = json.loads(helpers.read_file(opts.path_file)) return _add_profile(api, profile['profilename'], profile) except KeyError: # pragma: no cover raise ValueError( "'profilename' required in profile JSON file: %r" % opts.path_file)
def load_experiment(api, exp_desc_path, firmware_list=()): """ Load and submit user experiment description with firmware(s) Firmwares required for experiment will be loaded from current directory, except if their path is given in firmware_list :param api: API Rest api object :param exp_desc_path: path to experiment json description file :param firmware_list: list of firmware path """ # 1. load experiment description exp_dict = json.loads(helpers.read_file(exp_desc_path)) exp_files = helpers.FilesDict() # 2. Add experiment description exp_files[EXP_FILENAME] = helpers.json_dumps(exp_dict) # 3. Add firmwares files to the experiment files using # firmware_list and experiment firmwareassociations # extract firmwares names _fw_association = exp_dict['firmwareassociations'] or [] firmwares = set([assoc['firmwarename'] for assoc in _fw_association]) try: # replace firwmare name by firmware_path from firmware_list for _fw_path in firmware_list: firmwares.remove(basename(_fw_path)) firmwares.add(_fw_path) except KeyError as err: raise ValueError("Firmware {!s} is not in experiment: {}".format( err, exp_desc_path)) else: # Add all firmwares to the experiment files for _fw_path in firmwares: exp_files.add_firmware(_fw_path) return api.submit_experiment(exp_files)
def load_experiment(api, exp_desc_path, files_list=()): """ Load and submit user experiment description with firmware(s) Firmwares and scripts required for experiment will be loaded from current directory, except if their path is given in files_list :param api: API Rest api object :param exp_desc_path: path to experiment json description file :param files_list: list of files path """ # 1. load experiment description exp_dict = json.loads(helpers.read_file(exp_desc_path)) experiment = _Experiment.from_dict(exp_dict) # 2. List files and update path with provided path files = _files_with_filespath(experiment.filenames(), files_list) # Construct experiment files exp_files = helpers.FilesDict() exp_files[EXP_FILENAME] = helpers.json_dumps(experiment) for exp_file in files: exp_files.add_file(exp_file) return api.submit_experiment(exp_files)