signature stringlengths 8 3.44k | body stringlengths 0 1.41M | docstring stringlengths 1 122k | id stringlengths 5 17 |
|---|---|---|---|
def add_patterns(self, dir_name, pattern_lines): | for pattern_line in pattern_lines:<EOL><INDENT>self.pattern_list.add_filename_pattern(dir_name, pattern_line)<EOL><DEDENT> | Add patterns the should apply below dir_name
:param dir_name: str: directory that contained the patterns
:param pattern_lines: [str]: array of patterns | f3932:c2:m2 |
def include(self, path, is_file): | return self.pattern_list.include(path) and self.file_filter.include(os.path.basename(path), is_file)<EOL> | Returns False if any pattern matches the path
:param path: str: filename path to test
:return: boolean: True if we should include this path | f3932:c2:m4 |
def upload_project_run(upload_context): | data_service = upload_context.make_data_service()<EOL>project_name = upload_context.project_name_or_id.get_name_or_raise()<EOL>result = data_service.create_project(project_name, project_name)<EOL>return result.json()['<STR_LIT:id>']<EOL> | Function run by CreateProjectCommand to create the project.
Runs in a background process.
:param upload_context: UploadContext: contains data service setup and project name to create. | f3933:m0 |
def upload_folder_run(upload_context): | data_service = upload_context.make_data_service()<EOL>folder_name, parent_kind, parent_remote_id = upload_context.params<EOL>result = data_service.create_folder(folder_name, parent_kind, parent_remote_id)<EOL>return result.json()['<STR_LIT:id>']<EOL> | Function run by CreateFolderCommand to create the folder.
Runs in a background process.
:param upload_context: UploadContext: contains data service setup and folder details. | f3933:m1 |
def create_small_file(upload_context): | data_service = upload_context.make_data_service()<EOL>parent_data, path_data, remote_file_id = upload_context.params<EOL>chunk = path_data.read_whole_file()<EOL>hash_data = path_data.get_hash()<EOL>upload_operations = FileUploadOperations(data_service, upload_context)<EOL>upload_id, url_info = upload_operations.create_upload_and_chunk_url(<EOL>upload_context.project_id, path_data, hash_data, storage_provider_id=upload_context.config.storage_provider_id)<EOL>upload_operations.send_file_external(url_info, chunk)<EOL>return upload_operations.finish_upload(upload_id, hash_data, parent_data, remote_file_id)<EOL> | Function run by CreateSmallFileCommand to create the file.
Runs in a background process.
:param upload_context: UploadContext: contains data service setup and file details.
:return dict: DukeDS file data | f3933:m2 |
def __init__(self, config, data_service, watcher, project_name_or_id, file_upload_post_processor): | self.config = config<EOL>self.data_service = data_service<EOL>self.watcher = watcher<EOL>self.project_name_or_id = project_name_or_id<EOL>self.project_id = None<EOL>self.file_upload_post_processor = file_upload_post_processor<EOL> | :param config: ddsc.config.Config user configuration settings from YAML file/environment
:param data_service: DataServiceApi: where we will upload to
:param watcher: ProgressPrinter we notify of our progress
:param project_name_or_id: ProjectNameOrId: name or id of the project so we can create it if necessary
:param file_upload_post_processor: object: has run(data_service, file_response) method to run after download | f3933:c0:m0 |
def get_data_service_auth_data(self): | return self.data_service.auth.get_auth_data()<EOL> | Serialize data_service setup into something that can be passed to another process.
:return: tuple of data service settings | f3933:c0:m1 |
@staticmethod<EOL><INDENT>def rebuild_data_service(config, data_service_auth_data):<DEDENT> | auth = DataServiceAuth(config)<EOL>auth.set_auth_data(data_service_auth_data)<EOL>return DataServiceApi(auth, config.url)<EOL> | Deserialize value into DataServiceApi object.
:param config:
:param data_service_auth_data:
:return: | f3933:c0:m2 |
def __init__(self, settings, params, message_queue, task_id): | self.data_service_auth_data = settings.get_data_service_auth_data()<EOL>self.config = settings.config<EOL>self.project_name_or_id = settings.project_name_or_id<EOL>self.project_id = settings.project_id<EOL>self.params = params<EOL>self.message_queue = message_queue<EOL>self.task_id = task_id<EOL> | Setup context so it can be passed.
:param settings: UploadSettings: project level info
:param params: tuple: values specific to the function being run
:param message_queue: Queue: queue background process can send messages to us on
:param task_id: int: id of this command's task so message will be routed correctly | f3933:c1:m0 |
def make_data_service(self): | return UploadSettings.rebuild_data_service(self.config, self.data_service_auth_data)<EOL> | Recreate data service from within background worker.
:return: DataServiceApi | f3933:c1:m1 |
def send_message(self, data): | self.message_queue.put((self.task_id, data))<EOL> | Sends a message to the command's on_message(data) method.
:param data: object: data sent to on_message | f3933:c1:m2 |
def start_waiting(self): | self.send_message(True)<EOL> | Called when we start waiting for project to be ready for file uploads. | f3933:c1:m3 |
def done_waiting(self): | self.send_message(False)<EOL> | Called when project is ready for file uploads (after waiting). | f3933:c1:m4 |
def __init__(self, settings): | self.runner = TaskRunner(TaskExecutor(settings.config.upload_workers))<EOL>self.settings = settings<EOL>self.small_item_task_builder = SmallItemUploadTaskBuilder(self.settings, self.runner)<EOL>self.small_items = []<EOL>self.large_items = []<EOL> | Setup to talk to the data service based on settings.
:param settings: UploadSettings: settings to use for uploading. | f3933:c2:m0 |
def run(self, local_project): | <EOL>ProjectWalker.walk_project(local_project, self)<EOL>self.runner.run()<EOL>self.upload_large_items()<EOL> | Upload a project by uploading project, folders, and small files then uploading the large files.
:param local_project: LocalProject: project to upload | f3933:c2:m1 |
def visit_project(self, item): | self.small_item_task_builder.visit_project(item)<EOL> | Add create project to small task list. | f3933:c2:m2 |
def visit_folder(self, item, parent): | self.small_item_task_builder.visit_folder(item, parent)<EOL> | Add create folder to small task list. | f3933:c2:m3 |
def visit_file(self, item, parent): | if self.is_large_file(item):<EOL><INDENT>self.large_items.append((item, parent))<EOL><DEDENT>else:<EOL><INDENT>self.small_item_task_builder.visit_file(item, parent)<EOL><DEDENT> | If file is large add it to the large items to be processed after small task list.
else file is small add it to the small task list. | f3933:c2:m4 |
def upload_large_items(self): | for local_file, parent in self.large_items:<EOL><INDENT>if local_file.need_to_send:<EOL><INDENT>self.process_large_file(local_file, parent)<EOL><DEDENT><DEDENT> | Upload files that were too large. | f3933:c2:m6 |
def process_large_file(self, local_file, parent): | file_content_sender = FileUploader(self.settings.config, self.settings.data_service, local_file,<EOL>self.settings.watcher, self.settings.file_upload_post_processor)<EOL>remote_id = file_content_sender.upload(self.settings.project_id, parent.kind, parent.remote_id)<EOL>local_file.set_remote_id_after_send(remote_id)<EOL> | Upload a single file using multiple processes to upload multiple chunks at the same time.
Updates local_file with it's remote_id when done.
:param local_file: LocalFile: file we are uploading
:param parent: LocalFolder/LocalProject: parent of the file | f3933:c2:m7 |
def walk_project(self, project): | ProjectWalker.walk_project(project, self)<EOL> | Calls visit_* methods of self.
:param project: project we will visit children of. | f3933:c3:m1 |
def visit_project(self, item): | if not item.remote_id:<EOL><INDENT>command = CreateProjectCommand(self.settings, item)<EOL>self.task_runner_add(None, item, command)<EOL><DEDENT>else:<EOL><INDENT>self.settings.project_id = item.remote_id<EOL><DEDENT> | Adds create project command to task runner if project doesn't already exist. | f3933:c3:m2 |
def visit_folder(self, item, parent): | if not item.remote_id:<EOL><INDENT>command = CreateFolderCommand(self.settings, item, parent)<EOL>self.task_runner_add(parent, item, command)<EOL><DEDENT> | Adds create folder command to task runner if folder doesn't already exist. | f3933:c3:m3 |
def visit_file(self, item, parent): | if item.need_to_send:<EOL><INDENT>if item.size > self.settings.config.upload_bytes_per_chunk:<EOL><INDENT>msg = "<STR_LIT>"<EOL>raise ValueError(msg.format(item.size, item.name))<EOL><DEDENT>else:<EOL><INDENT>command = CreateSmallFileCommand(self.settings, item, parent,<EOL>self.settings.file_upload_post_processor)<EOL>self.task_runner_add(parent, item, command)<EOL><DEDENT><DEDENT> | If file is small add create small file command otherwise raise error.
Large files shouldn't be passed to SmallItemUploadTaskBuilder. | f3933:c3:m4 |
def task_runner_add(self, parent, item, command): | parent_task_id = self.item_to_id.get(parent)<EOL>task_id = self.task_runner.add(parent_task_id, command)<EOL>self.item_to_id[item] = task_id<EOL> | Add command to task runner with parent's task id createing a task id for item/command.
Save this item's id to a lookup.
:param parent: object: parent of item
:param item: object: item we are running command on
:param command: parallel TaskCommand we want to have run | f3933:c3:m5 |
def __init__(self, settings, local_project): | self.settings = settings<EOL>self.local_project = local_project<EOL>if not settings.project_name_or_id.is_name:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>self.func = upload_project_run<EOL> | Setup passing in all necessary data to create project and update external state.
:param settings: UploadSettings: settings to be used/updated when we upload the project.
:param local_project: LocalProject: information about the project(holds remote_id when done) | f3933:c4:m0 |
def before_run(self, parent_task_result): | self.settings.watcher.transferring_item(self.local_project)<EOL> | Notify progress bar that we are creating the project. | f3933:c4:m1 |
def create_context(self, message_queue, task_id): | return UploadContext(self.settings, (), message_queue, task_id)<EOL> | Create data needed by upload_project_run(DukeDS connection info).
:param message_queue: Queue: queue background process can send messages to us on
:param task_id: int: id of this command's task so message will be routed correctly | f3933:c4:m2 |
def after_run(self, result_id): | self.local_project.set_remote_id_after_send(result_id)<EOL>self.settings.project_id = result_id<EOL> | Save uuid associated with project we just created.
:param result_id: str: uuid of the project | f3933:c4:m3 |
def __init__(self, settings, remote_folder, parent): | self.settings = settings<EOL>self.remote_folder = remote_folder<EOL>self.parent = parent<EOL>self.func = upload_folder_run<EOL> | Setup passing in all necessary data to create folder and update external state.
:param settings: UploadSettings: contains data_service connection info
:param remote_folder: object: contains data about the folder we should create
:param parent: object: contains info about the parent of the folder we will create. | f3933:c5:m0 |
def before_run(self, parent_task_result): | self.settings.watcher.transferring_item(self.remote_folder)<EOL> | Notify progress bar that we are creating this folder. | f3933:c5:m1 |
def create_context(self, message_queue, task_id): | params = (self.remote_folder.name, self.parent.kind, self.parent.remote_id)<EOL>return UploadContext(self.settings, params, message_queue, task_id)<EOL> | Create values to be used by upload_folder_run function.
:param message_queue: Queue: queue background process can send messages to us on
:param task_id: int: id of this command's task so message will be routed correctly | f3933:c5:m2 |
def after_run(self, result_id): | self.remote_folder.set_remote_id_after_send(result_id)<EOL> | Save the uuid of our new folder back to our LocalFolder object.
:param result_id: str: uuid of the folder we just created. | f3933:c5:m3 |
def __init__(self, settings, local_file, parent, file_upload_post_processor=None): | self.settings = settings<EOL>self.local_file = local_file<EOL>self.parent = parent<EOL>self.func = create_small_file<EOL>self.file_upload_post_processor = file_upload_post_processor<EOL> | Setup passing in all necessary data to create file and update external state.
:param settings: UploadSettings: contains data_service connection info
:param local_file: object: information about the file we will upload
:param parent: object: parent of the file (folder or project)
:param file_upload_post_processor: object: has run(data_service, file_response) method to run after download | f3933:c6:m0 |
def create_context(self, message_queue, task_id): | parent_data = ParentData(self.parent.kind, self.parent.remote_id)<EOL>path_data = self.local_file.get_path_data()<EOL>params = parent_data, path_data, self.local_file.remote_id<EOL>return UploadContext(self.settings, params, message_queue, task_id)<EOL> | Create values to be used by create_small_file function.
:param message_queue: Queue: queue background process can send messages to us on
:param task_id: int: id of this command's task so message will be routed correctly | f3933:c6:m2 |
def after_run(self, remote_file_data): | if self.file_upload_post_processor:<EOL><INDENT>self.file_upload_post_processor.run(self.settings.data_service, remote_file_data)<EOL><DEDENT>remote_file_id = remote_file_data['<STR_LIT:id>']<EOL>self.settings.watcher.transferring_item(self.local_file)<EOL>self.local_file.set_remote_id_after_send(remote_file_id)<EOL> | Save uuid of file to our LocalFile
:param remote_file_data: dict: DukeDS file data | f3933:c6:m3 |
def on_message(self, started_waiting): | watcher = self.settings.watcher<EOL>if started_waiting:<EOL><INDENT>watcher.start_waiting()<EOL><DEDENT>else:<EOL><INDENT>watcher.done_waiting()<EOL><DEDENT> | Receives started_waiting boolean from create_small_file method and notifies project_status_monitor in settings.
:param started_waiting: boolean: True when we start waiting, False when done | f3933:c6:m4 |
def run(self, local_project): | self._visit_recur(local_project)<EOL> | Appends file/folder paths to upload_items based on the contents of this project that need to be uploaded.
:param local_project: LocalProject: project we will build the list for | f3933:c7:m2 |
def _visit_recur(self, item): | if item.kind == KindType.file_str:<EOL><INDENT>if item.need_to_send:<EOL><INDENT>self.add_upload_item(item.path)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if item.kind == KindType.project_str:<EOL><INDENT>pass<EOL><DEDENT>else:<EOL><INDENT>if not item.remote_id:<EOL><INDENT>self.add_upload_item(item.path)<EOL><DEDENT><DEDENT>for child in item.children:<EOL><INDENT>self._visit_recur(child)<EOL><DEDENT><DEDENT> | Recursively visits children of item.
:param item: object: project, folder or file we will add to upload_items if necessary. | f3933:c7:m3 |
def get_pypi_version(): | try:<EOL><INDENT>response = requests.get(PYPI_URL, timeout=HALF_SECOND_TIMEOUT)<EOL>response.raise_for_status()<EOL>data = response.json()<EOL>version_str = data["<STR_LIT:info>"]["<STR_LIT:version>"]<EOL>return _parse_version_str(version_str)<EOL><DEDENT>except requests.exceptions.ConnectionError:<EOL><INDENT>raise VersionException(UNABLE_TO_ACCESS_PYPI + "<STR_LIT>")<EOL><DEDENT>except requests.exceptions.Timeout:<EOL><INDENT>raise VersionException(UNABLE_TO_ACCESS_PYPI + "<STR_LIT>")<EOL><DEDENT> | Returns the version info from pypi for this app. | f3934:m0 |
def get_internal_version(): | version_str = get_internal_version_str()<EOL>return _parse_version_str(version_str)<EOL> | Returns internal version info. | f3934:m1 |
def get_internal_version_str(): | return pkg_resources.get_distribution(APP_NAME).version<EOL> | Returns internal version string. | f3934:m2 |
def check_version(): | pypi_version = get_pypi_version()<EOL>internal_version = get_internal_version()<EOL>if pypi_version > internal_version:<EOL><INDENT>raise VersionException(UPDATE_VERSION_MESSAGE)<EOL><DEDENT> | Check version and raises VersionException if the installed DukeDSClient is out of date
or unable to access pypi. | f3934:m4 |
def __init__(self, config=create_config()): | self.dds_connection = DDSConnection(config)<EOL> | :param config: ddsc.config.Config: settings used to connect to DDSConnection | f3938:c0:m0 |
def get_projects(self): | return self.dds_connection.get_projects()<EOL> | Get list of all projects user has access to.
:return: [Project]: list of projects | f3938:c0:m1 |
def get_project_by_id(self, project_id): | return self.dds_connection.get_project_by_id(project_id)<EOL> | Retrieve a single project.
:param project_id:
:return: Project | f3938:c0:m2 |
def create_project(self, name, description): | return self.dds_connection.create_project(name, description)<EOL> | Create a new project with the specified name and description
:param name: str: name of the project
:param description: str: description of the project
:return: Project | f3938:c0:m3 |
def get_folder_by_id(self, folder_id): | return self.dds_connection.get_folder_by_id(folder_id)<EOL> | Return details about a folder with the specified uuid
:param folder_id: str: uuid of the folder to fetch
:return: Folder | f3938:c0:m4 |
def get_file_by_id(self, file_id): | return self.dds_connection.get_file_by_id(file_id)<EOL> | Return details about a file with the specified uuid
:param file_id: str: uuid of the file to fetch
:return: File | f3938:c0:m5 |
def __init__(self, config): | self.config = config<EOL>self.data_service = DataServiceApi(DataServiceAuth(config), config.url)<EOL> | :param config: ddsc.config.Config: settings used to connect to DDSConnection | f3938:c1:m0 |
def get_projects(self): | return self._create_array_response(<EOL>self.data_service.get_projects(),<EOL>Project)<EOL> | Get details for all projects you have access to in DDSConnection
:return: [Project]: list of projects | f3938:c1:m3 |
def get_project_by_id(self, project_id): | return self._create_item_response(<EOL>self.data_service.get_project_by_id(project_id),<EOL>Project)<EOL> | Get details about project with the specified uuid
:param project_id: str: uuid of the project to fetch
:return: Project | f3938:c1:m4 |
def create_project(self, name, description): | return self._create_item_response(<EOL>self.data_service.create_project(name, description),<EOL>Project)<EOL> | Create a new project with the specified name and description
:param name: str: name of the project to create
:param description: str: description of the project to create
:return: Project | f3938:c1:m5 |
def delete_project(self, project_id): | self.data_service.delete_project(project_id)<EOL> | Delete the project with the specified uuid
:param project_id: str: uuid of the project to delete | f3938:c1:m6 |
def create_folder(self, folder_name, parent_kind_str, parent_uuid): | return self._create_item_response(<EOL>self.data_service.create_folder(folder_name, parent_kind_str, parent_uuid),<EOL>Folder<EOL>)<EOL> | Create a folder under a particular parent
:param folder_name: str: name of the folder to create
:param parent_kind_str: str: kind of the parent of this folder
:param parent_uuid: str: uuid of the parent of this folder (project or another folder)
:return: Folder: folder metadata | f3938:c1:m7 |
def delete_folder(self, folder_id): | self.data_service.delete_folder(folder_id)<EOL> | Delete the folder with the specified uuid
:param folder_id: str: uuid of the folder to delete | f3938:c1:m8 |
def get_project_children(self, project_id, name_contains=None): | return self._create_array_response(<EOL>self.data_service.get_project_children(<EOL>project_id, name_contains<EOL>),<EOL>DDSConnection._folder_or_file_constructor<EOL>)<EOL> | Get direct files and folders of a project.
:param project_id: str: uuid of the project to list contents
:param name_contains: str: filter children based on a pattern
:return: [File|Folder]: list of Files/Folders contained by the project | f3938:c1:m9 |
def get_folder_children(self, folder_id, name_contains=None): | return self._create_array_response(<EOL>self.data_service.get_folder_children(<EOL>folder_id, name_contains<EOL>),<EOL>DDSConnection._folder_or_file_constructor<EOL>)<EOL> | Get direct files and folders of a folder.
:param folder_id: str: uuid of the folder
:param name_contains: str: filter children based on a pattern
:return: File|Folder | f3938:c1:m10 |
def get_file_download(self, file_id): | return self._create_item_response(<EOL>self.data_service.get_file_url(file_id),<EOL>FileDownload<EOL>)<EOL> | Get a file download object that contains temporary url settings needed to download the contents of a file.
:param file_id: str: uuid of the file
:return: FileDownload | f3938:c1:m11 |
def upload_file(self, local_path, project_id, parent_data, existing_file_id=None, remote_filename=None): | path_data = PathData(local_path)<EOL>hash_data = path_data.get_hash()<EOL>file_upload_operations = FileUploadOperations(self.data_service, None)<EOL>upload_id = file_upload_operations.create_upload(project_id, path_data, hash_data,<EOL>remote_filename=remote_filename,<EOL>storage_provider=self.config.storage_provider_id)<EOL>context = UploadContext(self.config, self.data_service, upload_id, path_data)<EOL>ParallelChunkProcessor(context).run()<EOL>remote_file_data = file_upload_operations.finish_upload(upload_id, hash_data, parent_data, existing_file_id)<EOL>return File(self, remote_file_data)<EOL> | Upload a file under a specific location in DDSConnection possibly replacing an existing file.
:param local_path: str: path to a local file to upload
:param project_id: str: uuid of the project to add this file to
:param parent_data: ParentData: info about the parent of this file
:param existing_file_id: str: uuid of file to create a new version of (or None to create a new file)
:param remote_filename: str: name to use for our remote file (defaults to local_path basename otherwise)
:return: File | f3938:c1:m12 |
@staticmethod<EOL><INDENT>def _folder_or_file_constructor(dds_connection, data_dict):<DEDENT> | kind = data_dict['<STR_LIT>']<EOL>if kind == KindType.folder_str:<EOL><INDENT>return Folder(dds_connection, data_dict)<EOL><DEDENT>elif data_dict['<STR_LIT>'] == KindType.file_str:<EOL><INDENT>return File(dds_connection, data_dict)<EOL><DEDENT> | Create a File or Folder based on the kind value in data_dict
:param dds_connection: DDSConnection
:param data_dict: dict: payload received from DDSConnection API
:return: File|Folder | f3938:c1:m13 |
def get_folder_by_id(self, folder_id): | return self._create_item_response(<EOL>self.data_service.get_folder(folder_id),<EOL>Folder<EOL>)<EOL> | Get folder details for a folder id.
:param folder_id: str: uuid of the folder
:return: Folder | f3938:c1:m14 |
def get_file_by_id(self, file_id): | return self._create_item_response(<EOL>self.data_service.get_file(file_id),<EOL>File<EOL>)<EOL> | Get folder details for a file id.
:param file_id: str: uuid of the file
:return: File | f3938:c1:m15 |
def __init__(self, dds_connection, data_dict): | self.dds_connection = dds_connection<EOL>self._data_dict = dict(data_dict)<EOL> | :param dds_connection: DDSConnection
:param data_dict: dict: dictionary response from DDSConnection API | f3938:c2:m0 |
def __getattr__(self, key): | try:<EOL><INDENT>return self._data_dict[key]<EOL><DEDENT>except KeyError:<EOL><INDENT>msg = "<STR_LIT>".format(self.__class__.__name__, key)<EOL>raise AttributeError(msg)<EOL><DEDENT> | Return property from the dictionary passed to the constructor. | f3938:c2:m1 |
def __init__(self, dds_connection, data): | super(Project, self).__init__(dds_connection, data)<EOL> | :param dds_connection: DDSConnection
:param data: dict: dictionary response from DDSConnection API in project format | f3938:c3:m0 |
def get_children(self): | return self.dds_connection.get_project_children(self.id)<EOL> | Fetch the direct children of this project.
:return: [File|Folder] | f3938:c3:m1 |
def get_child_for_path(self, path): | child_finder = ChildFinder(path, self)<EOL>return child_finder.get_child()<EOL> | Based on a remote path get a single remote child.
:param path: str: path within a project specifying a file or folder to download
:return: File|Folder | f3938:c3:m2 |
def create_folder(self, folder_name): | return self.dds_connection.create_folder(folder_name, KindType.project_str, self.id)<EOL> | Create a new folder as a top level child of this project.
:param folder_name: str: name of the folder to create
:return: Folder | f3938:c3:m3 |
def upload_file(self, local_path, remote_filename=None): | parent_data = ParentData(self.kind, self.id)<EOL>return self.dds_connection.upload_file(local_path, project_id=self.id, parent_data=parent_data,<EOL>remote_filename=remote_filename)<EOL> | Upload a new file based on a file on the file system as a top level child of this project.
:param local_path: str: path to a file to upload
:param remote_filename: str: name to use for our remote file (defaults to local_path basename otherwise)
:return: File | f3938:c3:m4 |
def delete(self): | self.dds_connection.delete_project(self.id)<EOL> | Delete this project and it's children. | f3938:c3:m5 |
def __init__(self, dds_connection, data): | super(Folder, self).__init__(dds_connection, data)<EOL>self.project_id = self.project['<STR_LIT:id>']<EOL> | :param dds_connection: DDSConnection
:param data: dict: dictionary response from DDSConnection API in folder format | f3938:c4:m0 |
def get_children(self): | return self.dds_connection.get_folder_children(self.id)<EOL> | Fetch the direct children of this folder.
:return: [File|Folder] | f3938:c4:m1 |
def create_folder(self, folder_name): | return self.dds_connection.create_folder(folder_name, KindType.folder_str, self.id)<EOL> | Create a new folder as a top level child of this folder.
:param folder_name: str: name of the folder to create
:return: Folder | f3938:c4:m2 |
def upload_file(self, local_path, remote_filename=None): | parent_data = ParentData(self.kind, self.id)<EOL>return self.dds_connection.upload_file(local_path, project_id=self.project_id, parent_data=parent_data,<EOL>remote_filename=remote_filename)<EOL> | Upload a new file based on a file on the file system as a top level child of this folder.
:param local_path: str: path to a file to upload
:param remote_filename: str: name to use for our remote file (defaults to local_path basename otherwise)
:return: File | f3938:c4:m3 |
def delete(self): | self.dds_connection.delete_folder(self.id)<EOL> | Delete this folder and it's children. | f3938:c4:m4 |
def __init__(self, dds_connection, data): | super(File, self).__init__(dds_connection, data)<EOL>self.project_id = self.project['<STR_LIT:id>']<EOL> | :param dds_connection: DDSConnection
:param data: dict: dictionary response from DDSConnection API in folder format | f3938:c5:m0 |
def download_to_path(self, file_path): | file_download = self.dds_connection.get_file_download(self.id)<EOL>path = file_path<EOL>if not path:<EOL><INDENT>path = self.name<EOL><DEDENT>file_download.save_to_path(path)<EOL> | Download the contents of this file to a local file path
:param file_path: str: local filesystem path to write this file contents into, if none it will default to self.name | f3938:c5:m1 |
def delete(self): | self.dds_connection.delete_file(self.id)<EOL> | Delete this file and it's children. | f3938:c5:m2 |
def upload_new_version(self, file_path): | parent_data = ParentData(self.parent['<STR_LIT>'], self.parent['<STR_LIT:id>'])<EOL>return self.dds_connection.upload_file(file_path, project_id=self.project_id, parent_data=parent_data,<EOL>existing_file_id=self.id)<EOL> | Upload a new version of this file.
:param file_path: str: local filesystem path to write this file contents into
:return: File | f3938:c5:m3 |
def __init__(self, dds_connection, data): | super(FileDownload, self).__init__(dds_connection, data)<EOL> | :param dds_connection: DDSConnection
:param data: dict: dictionary response from DDSConnection API in file download url format | f3938:c6:m0 |
def save_to_path(self, file_path, chunk_size=DOWNLOAD_FILE_CHUNK_SIZE): | response = self._get_download_response()<EOL>with open(file_path, '<STR_LIT:wb>') as f:<EOL><INDENT>for chunk in response.iter_content(chunk_size=chunk_size):<EOL><INDENT>if chunk: <EOL><INDENT>f.write(chunk)<EOL><DEDENT><DEDENT><DEDENT> | Save the contents of the remote file to a local path.
:param file_path: str: file path
:param chunk_size: chunk size used to write local file | f3938:c6:m2 |
def __init__(self, remote_path, node): | self.remote_path = remote_path<EOL>self.node = node<EOL> | :param remote_path: path under a project in DDSConnection
:param node: Project|Folder to find children under | f3938:c8:m0 |
def get_child(self): | path_parts = self.remote_path.split(os.sep)<EOL>return self._get_child_recurse(path_parts, self.node)<EOL> | Find file or folder at the remote_path
:return: File|Folder | f3938:c8:m1 |
def __init__(self, path_data): | self.size = path_data.size()<EOL>self.path = path_data.path<EOL>self.kind = KindType.file_str<EOL> | :param path_data: PathData | f3938:c11:m0 |
@staticmethod<EOL><INDENT>def list_projects():<DEDENT> | return Session().list_projects()<EOL> | Return a list of project names
:return: [str]: list of project names | f3939:c0:m0 |
@staticmethod<EOL><INDENT>def create_project(name, description):<DEDENT> | return Session().create_project(name, description)<EOL> | Create a project with the specified name and description
:param name: str: unique name for this project
:param description: str: long description of this project
:return: str: name of the project | f3939:c0:m1 |
@staticmethod<EOL><INDENT>def delete_project(project_name):<DEDENT> | Session().delete_project(project_name)<EOL> | Delete a project with the specified name. Raises ItemNotFound if no such project exists
:param project_name: str: name of the project to delete
:return: | f3939:c0:m2 |
@staticmethod<EOL><INDENT>def list_files(project_name):<DEDENT> | return Session().list_files(project_name)<EOL> | Return a list of file paths that make up project_name
:param project_name: str: specifies the name of the project to list contents of
:return: [str]: returns a list of remote paths for all files part of the specified project qq | f3939:c0:m3 |
@staticmethod<EOL><INDENT>def download_file(project_name, remote_path, local_path=None):<DEDENT> | Session().download_file(project_name, remote_path, local_path)<EOL> | Download a file from a project
When local_path is None the file will be downloaded to the base filename
:param project_name: str: name of the project to download a file from
:param remote_path: str: remote path specifying which file to download
:param local_path: str: optional argument to customize where the file will be downloaded to | f3939:c0:m4 |
@staticmethod<EOL><INDENT>def upload_file(project_name, local_path, remote_path=None):<DEDENT> | return Session().upload_file(project_name, local_path, remote_path)<EOL> | Upload a file into project creating a new version if it already exists.
Will also create project and parent folders if they do not exist.
:param project_name: str: name of the project to upload a file to
:param local_path: str: path to download the file into
:param remote_path: str: remote path specifying file to upload to (defaults to local_path basename) | f3939:c0:m5 |
@staticmethod<EOL><INDENT>def delete_file(project_name, remote_path):<DEDENT> | Session().delete_file(project_name, remote_path)<EOL> | Delete a file or folder from a project
:param project_name: str: name of the project containing a file we will delete
:param remote_path: str: remote path specifying file to delete | f3939:c0:m6 |
def __init__(self, config=create_config()): | self.client = Client(config)<EOL>self.projects = None<EOL> | :param config: ddsc.config.Config: configuration specifying DukeDS endpoint and credential to use | f3939:c1:m0 |
def list_projects(self): | self._cache_project_list_once()<EOL>return [project.name for project in self.projects]<EOL> | Return a list of project names
:return: [str]: list of project names | f3939:c1:m1 |
def create_project(self, name, description): | self._cache_project_list_once()<EOL>if name in [project.name for project in self.projects]:<EOL><INDENT>raise DuplicateNameError("<STR_LIT>".format(name))<EOL><DEDENT>self.client.create_project(name, description)<EOL>self.clear_project_cache()<EOL>return name<EOL> | Create a project with the specified name and description
:param name: str: unique name for this project
:param description: str: long description of this project
:return: str: name of the project | f3939:c1:m2 |
def delete_project(self, project_name): | project = self._get_project_for_name(project_name)<EOL>project.delete()<EOL>self.clear_project_cache()<EOL> | Delete a project with the specified name. Raises ItemNotFound if no such project exists
:param project_name: str: name of the project to delete
:return: | f3939:c1:m3 |
def list_files(self, project_name): | project = self._get_project_for_name(project_name)<EOL>file_path_dict = self._get_file_path_dict_for_project(project)<EOL>return list(file_path_dict)<EOL> | Return a list of file paths that make up project_name
:param project_name: str: specifies the name of the project to list contents of
:return: [str]: returns a list of remote paths for all files part of the specified project qq | f3939:c1:m4 |
def download_file(self, project_name, remote_path, local_path=None): | project = self._get_project_for_name(project_name)<EOL>file = project.get_child_for_path(remote_path)<EOL>file.download_to_path(local_path)<EOL> | Download a file from a project
When local_path is None the file will be downloaded to the base filename
:param project_name: str: name of the project to download a file from
:param remote_path: str: remote path specifying which file to download
:param local_path: str: optional argument to customize where the file will be downloaded to | f3939:c1:m5 |
def upload_file(self, project_name, local_path, remote_path=None): | project = self._get_or_create_project(project_name)<EOL>file_upload = FileUpload(project, remote_path, local_path)<EOL>file_upload.run()<EOL> | Upload a file into project creating a new version if it already exists.
Will also create project and parent folders if they do not exist.
:param project_name: str: name of the project to upload a file to
:param local_path: str: path to download the file into
:param remote_path: str: remote path specifying file to upload to (defaults to local_path basename) | f3939:c1:m6 |
def clear_project_cache(self): | self.projects = None<EOL> | Empty project cache so successive methods will re-fetch the list when it is needed | f3939:c1:m9 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.