MCPcopy Index your code
hub / github.com/bugy/script-server / list_files

Method list_files

src/model/parameter_config.py:422–451  ·  view source on GitHub ↗
(self, path)

Source from the content-addressed store, hash-verified

420 return None
421
422 def list_files(self, path):
423 if not self._is_recursive_server_file():
424 raise WrongParameterUsageException(self.name, 'Can list files only for recursive file parameters')
425
426 validation_error = self._validate_recursive_path(path, intermediate=True)
427 if validation_error:
428 raise InvalidValueException(self.name, validation_error)
429
430 full_path = self._build_list_file_path(path)
431
432 result = []
433
434 if is_empty(self.file_type) or self.file_type == FILE_TYPE_FILE:
435 files = model_helper.list_files(full_path,
436 file_type=FILE_TYPE_FILE,
437 file_extensions=self.file_extensions,
438 excluded_files_matcher=self.excluded_files_matcher)
439 for file in files:
440 result.append({'name': file, 'type': FILE_TYPE_FILE, 'readable': True})
441
442 dirs = model_helper.list_files(full_path,
443 file_type=FILE_TYPE_DIR,
444 excluded_files_matcher=self.excluded_files_matcher)
445 for dir in dirs:
446 dir_path = os.path.join(full_path, dir)
447
448 readable = os.access(dir_path, os.R_OK)
449 result.append({'name': dir, 'type': FILE_TYPE_DIR, 'readable': readable})
450
451 return result
452
453 def _is_plain_server_file(self):
454 return self.type == PARAM_TYPE_SERVER_FILE and not self.file_recursive

Calls 7

_build_list_file_pathMethod · 0.95
is_emptyFunction · 0.90
appendMethod · 0.80