def get_options_from_file(options): """ read webdav client option from configuation file. Expects presence of an authentication file with user/pwd details :param options: filepath of configuration file """ args = get_args_from_configfile(options) if 'authenticationfile' in args.keys(): check_file_exists(args['authenticationfile'], should_exist=True) authentication = get_args_from_configfile(args['authenticationfile']) args.pop('authenticationfile', None) args.update(authentication) return args
def get_wdclient(options): """ get webdav :param options: specification of options for the client. Either as path to configuration file (str) or a dict """ if isinstance(options, str): check_file_exists(options, should_exist=True) options = get_options_from_file(options) elif isinstance(options, dict): pass else: raise TypeError('unrecognized type {} for client \ options'.format(type(options))) check_options(options) wdclient = wd3client(options) return wdclient
def _get_output_file_dict(path, file_handle='point_cloud', features=[], multi_band_files=True, format='.ply', overwrite=False, **kwargs): p = pathlib.Path(path) if not p.suffix: # expected dir check_dir_exists(p, should_exist=True) if features and not multi_band_files: files = {} for feature in features: sub_path = p / feature check_dir_exists(sub_path, should_exist=True, mkdir=True) file_path = (sub_path / file_handle).with_suffix(format) files.update({file_path.as_posix(): [feature]}) else: file_path = (p / file_handle).with_suffix(format).as_posix() if features: files = {file_path: features} else: files = {file_path: 'all'} else: # expected file - check parent dir check_dir_exists(p.parent, should_exist=True) if features: files = {p.as_posix(): features} else: files = {p.as_posix(): 'all'} if not overwrite: for file in files.keys(): check_file_exists(file, should_exist=False) return files
def test_checkFileExists(self): check_file_exists(self._test_file_path, True) check_file_exists(self._test_file_non_existent, False) with self.assertRaises(OSError): check_file_exists(self._test_dir, True) with self.assertRaises(OSError): check_file_exists(self._test_dir, False) with self.assertRaises(FileExistsError): check_file_exists(self._test_file_path, False) with self.assertRaises(FileNotFoundError): check_file_exists(self._test_file_non_existent, True)
def _check_input(self): if not self.grid.is_set: raise ValueError('The grid has not been set!') check_file_exists(self.input_path, should_exist=True) check_dir_exists(self.output_folder, should_exist=True)