signature stringlengths 8 3.44k | body stringlengths 0 1.41M | docstring stringlengths 1 122k | id stringlengths 5 17 |
|---|---|---|---|
def __init__(self, filter_func, visitor): | self.filter_func = filter_func<EOL>self.visitor = visitor<EOL> | Setup to let visitor walk a project filtering out items based on a function.
:param filter_func: function(item): returns True to let visitor see the item
:param visitor: object: object with visit_project,visit_folder,visit_file methods | f3910:c4:m0 |
def walk_project(self, project): | ProjectWalker.walk_project(project, self)<EOL> | Go through all nodes(RemoteProject,RemoteFolder,RemoteFile) in project and send them to visitor if filter allows.
:param project: RemoteProject: project we will walk | f3910:c4:m1 |
def walk_project(self, project): | <EOL>ProjectWalker.walk_project(project, self)<EOL> | Walks a project and saves the project name and filenames to [str] filenames property.
:param project: LocalProject project we will read details from. | f3910:c5:m1 |
def get(self): | return self.queue.get()<EOL> | Get the next tuple added to the queue.
:return: (str, value): where str is either ERROR or PROCESSED and value is the message or processed int amount. | f3910:c6:m5 |
def __init__(self, config, project_name_or_id, folders, follow_symlinks=False, file_upload_post_processor=None): | self.config = config<EOL>self.remote_store = RemoteStore(config)<EOL>self.project_name_or_id = project_name_or_id<EOL>self.remote_project = self.remote_store.fetch_remote_project(project_name_or_id)<EOL>self.local_project = ProjectUpload._load_local_project(folders, follow_symlinks, config.file_exclude_regex)<EOL>self.local_project.update_remote_ids(self.remote_project)<EOL>self.different_items = self._count_differences()<EOL>self.file_upload_post_processor = file_upload_post_processor<EOL> | Setup for uploading folders dictionary of paths to project_name using config.
:param config: Config configuration for performing the upload(url, keys, etc)
:param project_name_or_id: ProjectNameOrId: name or id of the project we will upload files to
:param folders: [str] list of paths of files/folders to upload to the project
:param follow_symlinks: bool if true we will traverse symbolic linked directories
:param file_upload_post_processor: object: has run(data_service, file_response) method to run after uploading | f3911:c0:m0 |
def _count_differences(self): | different_items = LocalOnlyCounter(self.config.upload_bytes_per_chunk)<EOL>different_items.walk_project(self.local_project)<EOL>return different_items<EOL> | Count how many things we will be sending.
:param local_project: LocalProject project we will send data from
:return: LocalOnlyCounter contains counts for various items | f3911:c0:m2 |
def needs_to_upload(self): | return self.different_items.total_items() != <NUM_LIT:0><EOL> | Is there anything in the local project different from the remote project.
:return: bool is there any point in calling upload() | f3911:c0:m3 |
def run(self): | progress_printer = ProgressPrinter(self.different_items.total_items(), msg_verb='<STR_LIT>')<EOL>upload_settings = UploadSettings(self.config, self.remote_store.data_service, progress_printer,<EOL>self.project_name_or_id, self.file_upload_post_processor)<EOL>project_uploader = ProjectUploader(upload_settings)<EOL>project_uploader.run(self.local_project)<EOL>progress_printer.finished()<EOL> | Upload different items within local_project to remote store showing a progress bar. | f3911:c0:m4 |
def dry_run_report(self): | project_uploader = ProjectUploadDryRun()<EOL>project_uploader.run(self.local_project)<EOL>items = project_uploader.upload_items<EOL>if not items:<EOL><INDENT>return "<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>result = "<STR_LIT>"<EOL>for item in items:<EOL><INDENT>result += "<STR_LIT>".format(item)<EOL><DEDENT>result += "<STR_LIT:\n>"<EOL>return result<EOL><DEDENT> | Returns text displaying the items that need to be uploaded or a message saying there are no files/folders
to upload.
:return: str: report text | f3911:c0:m5 |
def get_differences_summary(self): | return '<STR_LIT>'.format(self.different_items.result_str())<EOL> | Print a summary of what is to be done.
:param different_items: LocalOnlyCounter item that contains the summary | f3911:c0:m6 |
def get_upload_report(self): | project = self.remote_store.fetch_remote_project(self.project_name_or_id,<EOL>must_exist=True,<EOL>include_children=False)<EOL>report = UploadReport(project.name)<EOL>report.walk_project(self.local_project)<EOL>return report.get_content()<EOL> | Generate and print a report onto stdout. | f3911:c0:m7 |
def get_url_msg(self): | msg = '<STR_LIT>'<EOL>project_id = self.local_project.remote_id<EOL>url = '<STR_LIT>'.format(msg, self.config.get_portal_url_base(), project_id)<EOL>return url<EOL> | Print url to view the project via dds portal. | f3911:c0:m8 |
def walk_project(self, project): | <EOL>ProjectWalker.walk_project(project, self)<EOL> | Increment counters for each project, folder, and files calling visit methods below.
:param project: LocalProject project we will count items of. | f3911:c1:m1 |
def visit_project(self, item): | if not item.remote_id:<EOL><INDENT>self.projects += <NUM_LIT:1><EOL><DEDENT> | Increments counter if the project is not already remote.
:param item: LocalProject | f3911:c1:m2 |
def visit_folder(self, item, parent): | if not item.remote_id:<EOL><INDENT>self.folders += <NUM_LIT:1><EOL><DEDENT> | Increments counter if item is not already remote
:param item: LocalFolder
:param parent: LocalFolder/LocalProject | f3911:c1:m3 |
def visit_file(self, item, parent): | if item.need_to_send:<EOL><INDENT>self.files += <NUM_LIT:1><EOL>self.chunks += item.count_chunks(self.bytes_per_chunk)<EOL><DEDENT> | Increments counter if item needs to be sent.
:param item: LocalFile
:param parent: LocalFolder/LocalProject | f3911:c1:m4 |
def total_items(self): | return self.projects + self.folders + self.chunks<EOL> | Total number of files/folders/chunks that need to be sent.
:return: int number of items to be sent. | f3911:c1:m5 |
def result_str(self): | return '<STR_LIT>'.format(LocalOnlyCounter.plural_fmt('<STR_LIT>', self.projects),<EOL>LocalOnlyCounter.plural_fmt('<STR_LIT>', self.folders),<EOL>LocalOnlyCounter.plural_fmt('<STR_LIT:file>', self.files))<EOL> | Return a string representing the totals contained herein.
:return: str counts/types string | f3911:c1:m6 |
@staticmethod<EOL><INDENT>def plural_fmt(name, cnt):<DEDENT> | if cnt == <NUM_LIT:1>:<EOL><INDENT>return '<STR_LIT>'.format(cnt, name)<EOL><DEDENT>else:<EOL><INDENT>return '<STR_LIT>'.format(cnt, name)<EOL><DEDENT> | pluralize name if necessary and combine with cnt
:param name: str name of the item type
:param cnt: int number items of this type
:return: str name and cnt joined | f3911:c1:m7 |
def __init__(self, project_name): | self.report_items = []<EOL>self.project_name = project_name<EOL>self._add_report_item('<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>')<EOL> | Create report witht the specified project name since the local store doesn't contain that info.
:param project_name: str project name for the report | f3911:c2:m0 |
def walk_project(self, project): | <EOL>ProjectWalker.walk_project(project, self)<EOL> | Create report items for each project, folder, and files if necessary calling visit_* methods below.
:param project: LocalProject project we will count items of. | f3911:c2:m2 |
def visit_project(self, item): | if item.sent_to_remote:<EOL><INDENT>self._add_report_item('<STR_LIT>', item.remote_id)<EOL><DEDENT> | Add project to the report if it was sent.
:param item: LocalContent project level item | f3911:c2:m3 |
def visit_folder(self, item, parent): | if item.sent_to_remote:<EOL><INDENT>self._add_report_item(item.path, item.remote_id)<EOL><DEDENT> | Add folder to the report if it was sent.
:param item: LocalFolder folder to possibly add
:param parent: LocalFolder/LocalContent not used here | f3911:c2:m4 |
def visit_file(self, item, parent): | if item.sent_to_remote:<EOL><INDENT>self._add_report_item(item.path, item.remote_id, item.size, item.get_hash_value())<EOL><DEDENT> | Add file to the report if it was sent.
:param item: LocalFile file to possibly add.
:param parent: LocalFolder/LocalContent not used here | f3911:c2:m5 |
def __init__(self, name, remote_id, size='<STR_LIT>', file_hash='<STR_LIT>'): | self.name = name<EOL>self.remote_id = remote_id<EOL>self.size = str(size)<EOL>self.file_hash = file_hash<EOL> | Setup properties for use in str method
:param name: str name of the
:param remote_id: str remote uuid of the item
:param size: int/str size of the item can be '' if blank
:return: | f3911:c3:m0 |
def str_with_sizes(self, max_name, max_remote_id, max_size): | name_str = self.name.ljust(max_name)<EOL>remote_id_str = self.remote_id.ljust(max_remote_id)<EOL>size_str = self.size.ljust(max_size)<EOL>return u'<STR_LIT>'.format(name_str, remote_id_str, size_str, self.file_hash)<EOL> | Create string for report based on internal properties using sizes to line up columns.
:param max_name: int width of the name column
:param max_remote_id: int width of the remote_id column
:return: str info from this report item | f3911:c3:m1 |
def get_user_agent_str(): | return '<STR_LIT>'.format(APP_NAME, get_internal_version_str())<EOL> | Returns the user agent: DukeDSClient/<version>
:return: str: user agent value | f3912:m0 |
def retry_when_service_down(func): | def retry_function(*args, **kwds):<EOL><INDENT>showed_status_msg = False<EOL>status_watcher = args[<NUM_LIT:0>]<EOL>while True:<EOL><INDENT>try:<EOL><INDENT>result = func(*args, **kwds)<EOL>if showed_status_msg:<EOL><INDENT>status_watcher.set_status_message('<STR_LIT>')<EOL><DEDENT>return result<EOL><DEDENT>except DataServiceError as dse:<EOL><INDENT>if dse.status_code == <NUM_LIT>:<EOL><INDENT>if not showed_status_msg:<EOL><INDENT>message = SERVICE_DOWN_MESSAGE.format(datetime.datetime.utcnow())<EOL>status_watcher.set_status_message(message)<EOL>showed_status_msg = True<EOL><DEDENT>time.sleep(SERVICE_DOWN_RETRY_SECONDS)<EOL><DEDENT>else:<EOL><INDENT>raise<EOL><DEDENT><DEDENT><DEDENT><DEDENT>return retry_function<EOL> | Decorator that will retry a function while it fails with status code 503
Assumes the first argument to the fuction will be an object with a set_status_message method.
:param func: function: will be called until it doesn't fail with DataServiceError status 503
:return: value returned by func | f3912:m1 |
def retry_until_resource_is_consistent(func, monitor): | waiting = False<EOL>while True:<EOL><INDENT>try:<EOL><INDENT>resp = func()<EOL>if waiting and monitor:<EOL><INDENT>monitor.done_waiting()<EOL><DEDENT>return resp<EOL><DEDENT>except DSResourceNotConsistentError:<EOL><INDENT>if not waiting and monitor:<EOL><INDENT>monitor.start_waiting()<EOL>waiting = True<EOL><DEDENT>time.sleep(RESOURCE_NOT_CONSISTENT_RETRY_SECONDS)<EOL><DEDENT><DEDENT> | Runs func, if func raises DSResourceNotConsistentError will retry func indefinitely.
Notifies monitor if we have to wait(only happens if DukeDS API raises DSResourceNotConsistentError.
:param func: func(): function to run
:param monitor: object: has start_waiting() and done_waiting() methods when waiting for non-consistent resource
:return: whatever func returns | f3912:m2 |
def __init__(self, config, set_status_msg=print): | self.config = config<EOL>self._auth = self.config.auth<EOL>self._expires = None<EOL>self.user_agent_str = get_user_agent_str()<EOL>self.set_status_msg = set_status_msg<EOL> | Setup with initial authorization settings from config.
:param config: ddsc.config.Config settings such as auth, user_key, agent_key
:param set_status_msg: func(str): show status message to user | f3912:c1:m0 |
def get_auth(self): | if self.legacy_auth():<EOL><INDENT>return self._auth<EOL><DEDENT>if not self.auth_expired():<EOL><INDENT>return self._auth<EOL><DEDENT>self.claim_new_token()<EOL>return self._auth<EOL> | Gets an active token refreshing it if necessary.
:return: str valid active authentication token. | f3912:c1:m1 |
@retry_when_service_down<EOL><INDENT>def claim_new_token(self):<DEDENT> | <EOL>headers = {<EOL>'<STR_LIT:Content-Type>': ContentType.json,<EOL>'<STR_LIT>': self.user_agent_str,<EOL>}<EOL>data = {<EOL>"<STR_LIT>": self.config.agent_key,<EOL>"<STR_LIT>": self.config.user_key,<EOL>}<EOL>url_suffix = "<STR_LIT>"<EOL>url = self.config.url + url_suffix<EOL>response = requests.post(url, headers=headers, data=json.dumps(data))<EOL>if response.status_code == <NUM_LIT>:<EOL><INDENT>if not self.config.agent_key:<EOL><INDENT>raise MissingInitialSetupError()<EOL><DEDENT>else:<EOL><INDENT>raise SoftwareAgentNotFoundError()<EOL><DEDENT><DEDENT>elif response.status_code == <NUM_LIT>:<EOL><INDENT>raise DataServiceError(response, url_suffix, data)<EOL><DEDENT>elif response.status_code != <NUM_LIT>:<EOL><INDENT>raise AuthTokenCreationError(response)<EOL><DEDENT>resp_json = response.json()<EOL>self._auth = resp_json['<STR_LIT>']<EOL>self._expires = resp_json['<STR_LIT>']<EOL> | Update internal state to have a new token using a no authorization data service. | f3912:c1:m2 |
def get_auth_data(self): | return self._auth, self._expires<EOL> | Returns a tuple that can be build to recreate this object's state. | f3912:c1:m3 |
def set_auth_data(self, auth_expires_tuple): | self._auth = auth_expires_tuple[<NUM_LIT:0>]<EOL>self._expires = auth_expires_tuple[<NUM_LIT:1>]<EOL> | Recreates setup based on tuple returned by get_auth_data.
:param auth_expires_tuple (auth,expires) values returned by call to get_auth_data() | f3912:c1:m4 |
def legacy_auth(self): | return self._auth and not self._expires<EOL> | Has user specified a single auth token to use with an unknown expiration.
This is the old method. User should update their config file.
:return: boolean true if we should never try to fetch a token | f3912:c1:m5 |
def auth_expired(self): | if self._auth and self._expires:<EOL><INDENT>now_with_skew = time.time() + AUTH_TOKEN_CLOCK_SKEW_MAX<EOL>return now_with_skew > self._expires<EOL><DEDENT>return True<EOL> | Compare the expiration value of our current token including a CLOCK_SKEW.
:return: true if the token has expired | f3912:c1:m6 |
def __init__(self, response, url_suffix, request_data): | resp_json = None<EOL>try:<EOL><INDENT>resp_json = response.json()<EOL><DEDENT>except:<EOL><INDENT>resp_json = {}<EOL><DEDENT>if response.status_code == <NUM_LIT>:<EOL><INDENT>if resp_json and not resp_json.get('<STR_LIT>'):<EOL><INDENT>resp_json = {'<STR_LIT>': '<STR_LIT>', '<STR_LIT>': '<STR_LIT>'}<EOL><DEDENT><DEDENT>Exception.__init__(self, '<STR_LIT>'.format(<EOL>response.status_code, url_suffix, resp_json.get('<STR_LIT>', resp_json.get('<STR_LIT:error>', '<STR_LIT>')),<EOL>resp_json.get('<STR_LIT>', '<STR_LIT>')<EOL>))<EOL>self.response = resp_json<EOL>self.url_suffix = url_suffix<EOL>self.request_data = request_data<EOL>self.status_code = response.status_code<EOL> | Create exception for failed response.
:param response: requests.Response response that was in error
:param url_suffix: str url we were trying to connect to
:param request_data: object data we were sending to url | f3912:c2:m0 |
def __init__(self, auth, url, http=None): | self.auth = auth<EOL>self.set_status_msg = auth.set_status_msg<EOL>self.base_url = url<EOL>self.http = http<EOL>if not self.http:<EOL><INDENT>self.recreate_requests_session()<EOL><DEDENT>self.user_agent_str = get_user_agent_str()<EOL> | Setup for REST api.
:param auth: str auth token to be send via Authorization header
:param url: str root url of the data service
:param http: object requests style http object to do get/post/put (defaults to new requests Session) | f3912:c4:m0 |
def recreate_requests_session(self): | self.http = requests.Session()<EOL> | Recreate our requests session ( for example in response to connection failures) | f3912:c4:m1 |
def _url_parts(self, url_suffix, data, content_type): | url = self.base_url + url_suffix<EOL>send_data = data<EOL>if content_type == ContentType.json:<EOL><INDENT>send_data = json.dumps(data)<EOL><DEDENT>headers = {<EOL>'<STR_LIT:Content-Type>': content_type,<EOL>'<STR_LIT>': self.user_agent_str,<EOL>}<EOL>if self.auth:<EOL><INDENT>headers['<STR_LIT>'] = self.auth.get_auth()<EOL><DEDENT>return url, send_data, headers<EOL> | Format the url data based on config_type.
:param url_suffix: str URL path we are sending a GET/POST/PUT to
:param data: object data we are sending
:param content_type: str from ContentType that determines how we format the data
:return: complete url, formatted data, and headers for sending | f3912:c4:m2 |
@retry_when_service_down<EOL><INDENT>def _post(self, url_suffix, data, content_type=ContentType.json):<DEDENT> | (url, data_str, headers) = self._url_parts(url_suffix, data, content_type=content_type)<EOL>resp = self.http.post(url, data_str, headers=headers)<EOL>return self._check_err(resp, url_suffix, data, allow_pagination=False)<EOL> | Send POST request to API at url_suffix with post_data.
Raises error if x-total-pages is contained in the response.
:param url_suffix: str URL path we are sending a POST to
:param data: object data we are sending
:param content_type: str from ContentType that determines how we format the data
:return: requests.Response containing the result | f3912:c4:m3 |
@retry_when_service_down<EOL><INDENT>def _put(self, url_suffix, data, content_type=ContentType.json):<DEDENT> | (url, data_str, headers) = self._url_parts(url_suffix, data, content_type=content_type)<EOL>resp = self.http.put(url, data_str, headers=headers)<EOL>return self._check_err(resp, url_suffix, data, allow_pagination=False)<EOL> | Send PUT request to API at url_suffix with post_data.
Raises error if x-total-pages is contained in the response.
:param url_suffix: str URL path we are sending a PUT to
:param data: object data we are sending
:param content_type: str from ContentType that determines how we format the data
:return: requests.Response containing the result | f3912:c4:m4 |
@retry_when_service_down<EOL><INDENT>def _get_single_item(self, url_suffix, data, content_type=ContentType.json):<DEDENT> | (url, data_str, headers) = self._url_parts(url_suffix, data, content_type=content_type)<EOL>resp = self.http.get(url, headers=headers, params=data_str)<EOL>return self._check_err(resp, url_suffix, data, allow_pagination=False)<EOL> | Send GET request to API at url_suffix with post_data.
Raises error if x-total-pages is contained in the response.
:param url_suffix: str URL path we are sending a GET to
:param url_data: object data we are sending
:param content_type: str from ContentType that determines how we format the data
:return: requests.Response containing the result | f3912:c4:m5 |
@retry_when_service_down<EOL><INDENT>def _get_single_page(self, url_suffix, data, page_num):<DEDENT> | data_with_per_page = dict(data)<EOL>data_with_per_page['<STR_LIT>'] = page_num<EOL>data_with_per_page['<STR_LIT>'] = self._get_page_size()<EOL>(url, data_str, headers) = self._url_parts(url_suffix, data_with_per_page,<EOL>content_type=ContentType.form)<EOL>resp = self.http.get(url, headers=headers, params=data_str)<EOL>return self._check_err(resp, url_suffix, data, allow_pagination=True)<EOL> | Send GET request to API at url_suffix with post_data adding page and per_page parameters to
retrieve a single page. Page size is determined by config.page_size.
:param url_suffix: str URL path we are sending a GET to
:param data: object data we are sending
:param page_num: int: page number to fetch
:return: requests.Response containing the result | f3912:c4:m6 |
def _get_collection(self, url_suffix, data): | response = self._get_single_page(url_suffix, data, page_num=<NUM_LIT:1>)<EOL>total_pages_str = response.headers.get('<STR_LIT>')<EOL>if total_pages_str:<EOL><INDENT>total_pages = int(total_pages_str)<EOL>if total_pages > <NUM_LIT:1>:<EOL><INDENT>multi_response = MultiJSONResponse(base_response=response, merge_array_field_name="<STR_LIT>")<EOL>for page in range(<NUM_LIT:2>, total_pages + <NUM_LIT:1>):<EOL><INDENT>additional_response = self._get_single_page(url_suffix, data, page_num=page)<EOL>multi_response.add_response(additional_response)<EOL><DEDENT>return multi_response<EOL><DEDENT><DEDENT>return response<EOL> | Performs GET for all pages based on x-total-pages in first response headers.
Merges the json() 'results' arrays.
If x-total-pages is missing or 1 just returns the response without fetching multiple pages.
:param url_suffix: str URL path we are sending a GET to
:param data: object data we are sending
:return: requests.Response containing the result | f3912:c4:m7 |
@retry_when_service_down<EOL><INDENT>def _delete(self, url_suffix, data, content_type=ContentType.json):<DEDENT> | (url, data_str, headers) = self._url_parts(url_suffix, data, content_type=content_type)<EOL>resp = self.http.delete(url, headers=headers, params=data_str)<EOL>return self._check_err(resp, url_suffix, data, allow_pagination=False)<EOL> | Send DELETE request to API at url_suffix with post_data.
Raises error if x-total-pages is contained in the response.
:param url_suffix: str URL path we are sending a DELETE to
:param data: object data we are sending
:param content_type: str from ContentType that determines how we format the data
:return: requests.Response containing the result | f3912:c4:m8 |
@staticmethod<EOL><INDENT>def _check_err(resp, url_suffix, data, allow_pagination):<DEDENT> | total_pages = resp.headers.get('<STR_LIT>')<EOL>if not allow_pagination and total_pages:<EOL><INDENT>raise UnexpectedPagingReceivedError()<EOL><DEDENT>if <NUM_LIT:200> <= resp.status_code < <NUM_LIT>:<EOL><INDENT>return resp<EOL><DEDENT>if resp.status_code == <NUM_LIT>:<EOL><INDENT>if resp.json().get("<STR_LIT:code>") == "<STR_LIT>":<EOL><INDENT>raise DSResourceNotConsistentError(resp, url_suffix, data)<EOL><DEDENT><DEDENT>raise DataServiceError(resp, url_suffix, data)<EOL> | Raise DataServiceError if the response wasn't successful.
:param resp: requests.Response back from the request
:param url_suffix: str url to include in an error message
:param data: data payload we sent
:param allow_pagination: when False and response headers contains 'x-total-pages' raises an error.
:return: requests.Response containing the successful result | f3912:c4:m9 |
def create_project(self, project_name, desc): | data = {<EOL>"<STR_LIT:name>": project_name,<EOL>"<STR_LIT:description>": desc<EOL>}<EOL>return self._post("<STR_LIT>", data)<EOL> | Send POST to /projects creating a new project with the specified name and desc.
Raises DataServiceError on error.
:param project_name: str name of the project
:param desc: str description of the project
:return: requests.Response containing the successful result | f3912:c4:m10 |
def get_projects(self): | return self._get_collection("<STR_LIT>", {})<EOL> | Send GET to /projects returning a list of all projects for the current user.
Raises DataServiceError on error.
:return: requests.Response containing the successful result | f3912:c4:m11 |
def get_project_by_id(self, id): | return self._get_single_item('<STR_LIT>'.format(id), {})<EOL> | Send GET request to /projects/{id} to get project details
:param id: str uuid of the project
:return: requests.Response containing the successful result | f3912:c4:m12 |
def get_file_url(self, file_id): | return self._get_single_item("<STR_LIT>".format(file_id), {})<EOL> | Send GET to /files/{}/url returning a url to download the file.
Raises DataServiceError on error.
:param file_id: str uuid of the file we want to download
:return: requests.Response containing the successful result | f3912:c4:m13 |
def create_folder(self, folder_name, parent_kind_str, parent_uuid): | data = {<EOL>'<STR_LIT:name>': folder_name,<EOL>'<STR_LIT>': {<EOL>'<STR_LIT>': parent_kind_str,<EOL>'<STR_LIT:id>': parent_uuid<EOL>}<EOL>}<EOL>return self._post("<STR_LIT>", data)<EOL> | Send POST to /folders to create a new folder with specified name and parent.
:param folder_name: str name of the new folder
:param parent_kind_str: str type of parent folder has(dds-folder,dds-project)
:param parent_uuid: str uuid of the parent object
:return: requests.Response containing the successful result | f3912:c4:m14 |
def get_folder(self, folder_id): | return self._get_single_item('<STR_LIT>' + folder_id, {})<EOL> | Send GET request to /folders/{folder_id} to retrieve folder info.
:param folder_id: str uuid of the folder we want info about
:return: requests.Response containing the successful result | f3912:c4:m15 |
def delete_folder(self, folder_id): | return self._delete("<STR_LIT>" + folder_id, {})<EOL> | Send DELETE request to the url for this folder.
:param project_id: str uuid of the folder
:return: requests.Response containing the successful result | f3912:c4:m16 |
def get_project_children(self, project_id, name_contains, exclude_response_fields=None): | return self._get_children('<STR_LIT>', project_id, name_contains, exclude_response_fields)<EOL> | Send GET to /projects/{project_id}/children filtering by a name.
:param project_id: str uuid of the project
:param name_contains: str name to filter folders by (if not None this method works recursively)
:param exclude_response_fields: [str]: list of fields to exclude in the response items
:return: requests.Response containing the successful result | f3912:c4:m17 |
def get_project_files(self, project_id): | url_prefix = "<STR_LIT>".format(project_id)<EOL>return self._get_collection(url_prefix, {})<EOL> | Send GET to /projects/{project_id}/files returning list of all files in a project.
:param project_id: str uuid of the project
:return: requests.Response containing the successful result | f3912:c4:m18 |
def get_folder_children(self, folder_id, name_contains): | return self._get_children('<STR_LIT>', folder_id, name_contains)<EOL> | Send GET to /folders/{folder_id} filtering by a name.
:param folder_id: str uuid of the folder
:param name_contains: str name to filter children by (if not None this method works recursively)
:return: requests.Response containing the successful result | f3912:c4:m19 |
def _get_children(self, parent_name, parent_id, name_contains, exclude_response_fields=None): | data = {}<EOL>if name_contains is not None:<EOL><INDENT>data['<STR_LIT>'] = name_contains<EOL><DEDENT>if exclude_response_fields:<EOL><INDENT>data['<STR_LIT>'] = '<STR_LIT:U+0020>'.join(exclude_response_fields)<EOL><DEDENT>url_prefix = "<STR_LIT>".format(parent_name, parent_id)<EOL>return self._get_collection(url_prefix, data)<EOL> | Send GET message to /<parent_name>/<parent_id>/children to fetch info about children(files and folders)
:param parent_name: str 'projects' or 'folders'
:param parent_id: str uuid of project or folder
:param name_contains: name filtering (if not None this method works recursively)
:param exclude_response_fields: [str]: list of fields to exclude in the response items
:return: requests.Response containing the successful result | f3912:c4:m20 |
def create_upload(self, project_id, filename, content_type, size,<EOL>hash_value, hash_alg, storage_provider_id=None, chunked=True): | data = {<EOL>"<STR_LIT:name>": filename,<EOL>"<STR_LIT>": content_type,<EOL>"<STR_LIT:size>": size,<EOL>"<STR_LIT>": {<EOL>"<STR_LIT:value>": hash_value,<EOL>"<STR_LIT>": hash_alg<EOL>},<EOL>"<STR_LIT>": chunked,<EOL>}<EOL>if storage_provider_id:<EOL><INDENT>data['<STR_LIT>'] = {'<STR_LIT:id>': storage_provider_id}<EOL><DEDENT>return self._post("<STR_LIT>" + project_id + "<STR_LIT>", data)<EOL> | Post to /projects/{project_id}/uploads to create a uuid for uploading chunks.
NOTE: The optional hash_value and hash_alg parameters are being removed from the DukeDS API.
:param project_id: str uuid of the project we are uploading data for.
:param filename: str name of the file we want to upload
:param content_type: str mime type of the file
:param size: int size of the file in bytes
:param hash_value: str hash value of the entire file
:param hash_alg: str algorithm used to create hash_value
:param storage_provider_id: str optional storage provider id
:param chunked: is the uploaded file made up of multiple chunks. When False a single upload url is returned.
For more see https://github.com/Duke-Translational-Bioinformatics/duke-data-service/blob/develop/api_design/DDS-1182-nonchucked_upload_api_design.md
:return: requests.Response containing the successful result | f3912:c4:m21 |
def create_upload_url(self, upload_id, number, size, hash_value, hash_alg): | if number < <NUM_LIT:1>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>data = {<EOL>"<STR_LIT>": number,<EOL>"<STR_LIT:size>": size,<EOL>"<STR_LIT>": {<EOL>"<STR_LIT:value>": hash_value,<EOL>"<STR_LIT>": hash_alg<EOL>}<EOL>}<EOL>return self._put("<STR_LIT>" + upload_id + "<STR_LIT>", data)<EOL> | Given an upload created by create_upload retrieve a url where we can upload a chunk.
:param upload_id: uuid of the upload
:param number: int incrementing number of the upload (1-based index)
:param size: int size of the chunk in bytes
:param hash_value: str hash value of chunk
:param hash_alg: str algorithm used to create hash
:return: requests.Response containing the successful result | f3912:c4:m22 |
def complete_upload(self, upload_id, hash_value, hash_alg): | data = {<EOL>"<STR_LIT>": hash_value,<EOL>"<STR_LIT>": hash_alg<EOL>}<EOL>return self._put("<STR_LIT>" + upload_id + "<STR_LIT>", data, content_type=ContentType.form)<EOL> | Mark the upload we created in create_upload complete.
:param upload_id: str uuid of the upload to complete.
:param hash_value: str hash value of chunk
:param hash_alg: str algorithm used to create hash
:return: requests.Response containing the successful result | f3912:c4:m23 |
def create_file(self, parent_kind, parent_id, upload_id): | data = {<EOL>"<STR_LIT>": {<EOL>"<STR_LIT>": parent_kind,<EOL>"<STR_LIT:id>": parent_id<EOL>},<EOL>"<STR_LIT>": {<EOL>"<STR_LIT:id>": upload_id<EOL>}<EOL>}<EOL>return self._post("<STR_LIT>", data)<EOL> | Create a new file after completing an upload.
:param parent_kind: str kind of parent(dds-folder,dds-project)
:param parent_id: str uuid of parent
:param upload_id: str uuid of complete upload
:return: requests.Response containing the successful result | f3912:c4:m24 |
def delete_file(self, file_id): | return self._delete("<STR_LIT>" + file_id, {})<EOL> | Send DELETE request to the url for this file.
:param project_id: str uuid of the file
:return: requests.Response containing the successful result | f3912:c4:m25 |
def update_file(self, file_id, upload_id): | put_data = {<EOL>"<STR_LIT>": upload_id,<EOL>}<EOL>return self._put("<STR_LIT>" + file_id, put_data, content_type=ContentType.form)<EOL> | Send PUT request to /files/{file_id} to update the file contents to upload_id and sets a label.
:param file_id: str uuid of file
:param upload_id: str uuid of the upload where all the file chunks where uploaded
:param label: str short display label for the file
:return: requests.Response containing the successful result | f3912:c4:m26 |
def send_external(self, http_verb, host, url, http_headers, chunk): | if http_verb == '<STR_LIT>':<EOL><INDENT>return self.http.put(host + url, data=chunk, headers=http_headers)<EOL><DEDENT>elif http_verb == '<STR_LIT:POST>':<EOL><INDENT>return self.http.post(host + url, data=chunk, headers=http_headers)<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>" + http_verb)<EOL><DEDENT> | Used with create_upload_url to send a chunk the the possibly external object store.
:param http_verb: str PUT or POST
:param host: str host we are sending the chunk to
:param url: str url to use when sending
:param http_headers: object headers to send with the request
:param chunk: content to send
:return: requests.Response containing the successful result | f3912:c4:m27 |
def receive_external(self, http_verb, host, url, http_headers): | if http_verb == '<STR_LIT:GET>':<EOL><INDENT>return self.http.get(host + url, headers=http_headers, stream=True)<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>" + http_verb)<EOL><DEDENT> | Retrieve a streaming request for a file.
:param http_verb: str GET is only supported right now
:param host: str host we are requesting the file from
:param url: str url to ask the host for
:param http_headers: object headers to send with the request
:return: requests.Response containing the successful result | f3912:c4:m28 |
def get_users_by_full_name(self, full_name): | data = {<EOL>"<STR_LIT>": full_name,<EOL>}<EOL>return self._get_collection('<STR_LIT>', data)<EOL> | Send GET request to /users filtering by those full name contains full_name.
:param full_name: str name of the user we are searching for
:return: requests.Response containing the successful result | f3912:c4:m29 |
def get_users(self, full_name=None, email=None, username=None): | data = {}<EOL>if full_name:<EOL><INDENT>data['<STR_LIT>'] = full_name<EOL><DEDENT>if email:<EOL><INDENT>data['<STR_LIT:email>'] = email<EOL><DEDENT>if username:<EOL><INDENT>data['<STR_LIT:username>'] = username<EOL><DEDENT>return self._get_collection('<STR_LIT>', data)<EOL> | Send GET request to /users for users with optional full_name, email, and/or username filtering.
:param full_name: str name of the user we are searching for
:param email: str: optional email to filter by
:param username: str: optional username to filter by
:return: requests.Response containing the successful result | f3912:c4:m30 |
def get_user_by_id(self, id): | return self._get_single_item('<STR_LIT>'.format(id), {})<EOL> | Send GET request to /users/{id} to get user details
:param id: str uuid of the user
:return: requests.Response containing the successful result | f3912:c4:m31 |
def set_user_project_permission(self, project_id, user_id, auth_role): | put_data = {<EOL>"<STR_LIT>": auth_role<EOL>}<EOL>return self._put("<STR_LIT>" + project_id + "<STR_LIT>" + user_id, put_data,<EOL>content_type=ContentType.form)<EOL> | Send PUT request to /projects/{project_id}/permissions/{user_id/ with auth_role value.
:param project_id: str uuid of the project
:param user_id: str uuid of the user
:param auth_role: str project role eg 'project_admin'
:return: requests.Response containing the successful result | f3912:c4:m32 |
def get_user_project_permission(self, project_id, user_id): | return self._get_single_item("<STR_LIT>" + project_id + "<STR_LIT>" + user_id, {})<EOL> | Send GET request to /projects/{project_id}/permissions/{user_id/.
:param project_id: str uuid of the project
:param user_id: str uuid of the user
:return: requests.Response containing the successful result | f3912:c4:m33 |
def get_project_permissions(self, project_id): | return self._get_collection("<STR_LIT>" + project_id + "<STR_LIT>", {})<EOL> | Send GET request to /projects/{project_id}/permissions/.
:param project_id: str uuid of the project
:return: requests.Response containing the successful result | f3912:c4:m34 |
def revoke_user_project_permission(self, project_id, user_id): | return self._delete("<STR_LIT>" + project_id + "<STR_LIT>" + user_id, {})<EOL> | Send DELETE request to /projects/{project_id}/permissions/{user_id so they will no longer have permissions.
:param project_id: str uuid of the project
:param user_id: str uuid of the user
:return: requests.Response containing the successful result | f3912:c4:m35 |
def get_file(self, file_id): | return self._get_single_item('<STR_LIT>' + file_id, {})<EOL> | Send GET request to /files/{file_id} to retrieve file info.
:param file_id: str uuid of the file we want info about
:return: requests.Response containing the successful result | f3912:c4:m36 |
def get_api_token(self, agent_key, user_key): | data = {<EOL>"<STR_LIT>": agent_key,<EOL>"<STR_LIT>": user_key,<EOL>}<EOL>return self._post("<STR_LIT>", data)<EOL> | Send POST request to get an auth token.
This method doesn't require auth obviously.
:param agent_key: str agent key (who is acting on behalf of the user)
:param user_key: str secret user key
:return: requests.Response containing the successful result | f3912:c4:m37 |
def get_current_user(self): | return self._get_single_item("<STR_LIT>", {})<EOL> | Send GET request to get info about current user.
:return: requests.Response containing the successful result | f3912:c4:m38 |
def delete_project(self, project_id): | return self._delete("<STR_LIT>" + project_id, {})<EOL> | Send DELETE request to the url for this project.
:param project_id: str uuid of the project
:return: requests.Response containing the successful result | f3912:c4:m39 |
def get_auth_roles(self, context): | return self._get_collection("<STR_LIT>", {"<STR_LIT>": context})<EOL> | Send GET request to get list of auth_roles for a context.
:param context: str which roles do we want 'project' or 'system'
:return: requests.Response containing the successful result | f3912:c4:m40 |
def get_project_transfers(self, project_id): | return self._get_collection("<STR_LIT>" + project_id + "<STR_LIT>", {})<EOL> | Send GET request to get list of transfers for a project
:param project_id: str uuid of the project
:return: requests.Response containing the successful result | f3912:c4:m41 |
def create_project_transfer(self, project_id, to_user_ids): | data = {<EOL>"<STR_LIT>": to_user_ids,<EOL>}<EOL>return self._post("<STR_LIT>" + project_id + "<STR_LIT>", data,<EOL>content_type=ContentType.form)<EOL> | Send POST request to initiate transfer of a project to the specified user ids
:param project_id: str uuid of the project
:param to_users: list of user uuids to receive the project
:return: requests.Response containing the successful result | f3912:c4:m42 |
def get_project_transfer(self, transfer_id): | return self._get_single_item("<STR_LIT>" + transfer_id, {})<EOL> | Send GET request to single project_transfer by id
:param transfer_id: str uuid of the project_transfer
:return: requests.Response containing the successful result | f3912:c4:m43 |
def get_all_project_transfers(self): | return self._get_collection("<STR_LIT>", {})<EOL> | Send GET request to get all available project transfers
:return: requests.Response containing the successful result | f3912:c4:m44 |
def _process_project_transfer(self, action, transfer_id, status_comment): | data = {}<EOL>if status_comment:<EOL><INDENT>data["<STR_LIT>"] = status_comment<EOL><DEDENT>path = "<STR_LIT>".format(transfer_id, action)<EOL>return self._put(path, data, content_type=ContentType.form)<EOL> | Send PUT request to one of the project transfer action endpoints
:param action: str name of the action (reject/accept/cancel)
:param transfer_id: str uuid of the project_transfer
:param status_comment: str comment about the action, optional
:return: requests.Response containing the successful result | f3912:c4:m45 |
def reject_project_transfer(self, transfer_id, status_comment=None): | return self._process_project_transfer('<STR_LIT>', transfer_id, status_comment)<EOL> | Send PUT request to reject a project_transfer by id
:param transfer_id: str uuid of the project_transfer
:param status_comment: str comment or reason for rejecting or None
:return: requests.Response containing the successful result | f3912:c4:m46 |
def cancel_project_transfer(self, transfer_id, status_comment=None): | return self._process_project_transfer('<STR_LIT>', transfer_id, status_comment)<EOL> | Send PUT request to cancel a project_transfer by id
:param transfer_id: str uuid of the project_transfer
:param status_comment: str comment or reason for cancelling or None
:return: requests.Response containing the successful result | f3912:c4:m47 |
def accept_project_transfer(self, transfer_id, status_comment=None): | return self._process_project_transfer('<STR_LIT>', transfer_id, status_comment)<EOL> | Send PUT request to accept a project_transfer by id
:param transfer_id: str uuid of the project_transfer
:param status_comment: str comment or reason for accepting
:return: requests.Response containing the successful result | f3912:c4:m48 |
def get_activities(self): | return self._get_collection("<STR_LIT>", {})<EOL> | Send GET to /activities returning a list of all provenance activities
for the current user. Raises DataServiceError on error.
:return: requests.Response containing the successful result | f3912:c4:m49 |
def create_activity(self, activity_name, desc=None, started_on=None, ended_on=None): | data = {<EOL>"<STR_LIT:name>": activity_name,<EOL>"<STR_LIT:description>": desc,<EOL>"<STR_LIT>": started_on,<EOL>"<STR_LIT>": ended_on<EOL>}<EOL>return self._post("<STR_LIT>", data)<EOL> | Send POST to /activities creating a new activity with the specified name and desc.
Raises DataServiceError on error.
:param activity_name: str name of the activity
:param desc: str description of the activity (optional)
:param started_on: str datetime when the activity started (optional)
:param ended_on: str datetime when the activity ended (optional)
:return: requests.Response containing the successful result | f3912:c4:m50 |
def delete_activity(self, activity_id): | return self._delete("<STR_LIT>" + activity_id, {})<EOL> | Send DELETE request to the url for this activity.
:param activity_id: str uuid of the activity
:return: requests.Response containing the successful result | f3912:c4:m51 |
def get_activity_by_id(self, activity_id): | return self._get_single_item('<STR_LIT>'.format(activity_id), {})<EOL> | Send GET request to /activities/{id} to get activity details
:param activity_id: str uuid of the activity
:return: requests.Response containing the successful result | f3912:c4:m52 |
def update_activity(self, activity_id, activity_name=None, desc=None,<EOL>started_on=None, ended_on=None): | put_data = {<EOL>"<STR_LIT:name>": activity_name,<EOL>"<STR_LIT:description>": desc,<EOL>"<STR_LIT>": started_on,<EOL>"<STR_LIT>": ended_on<EOL>}<EOL>return self._put("<STR_LIT>" + activity_id, put_data)<EOL> | Send PUT request to /activities/{activity_id} to update the activity metadata.
Raises ValueError if at least one field is not updated.
:param activity_id: str uuid of activity
:param activity_name: str new name of the activity (optional)
:param desc: str description of the activity (optional)
:param started_on: str date the updated activity began on (optional)
:param ended_on: str date the updated activity ended on (optional)
:return: requests.Response containing the successful result | f3912:c4:m53 |
def get_relations(self, object_kind, object_id): | return self._get_collection('<STR_LIT>'.format(object_kind, object_id), {})<EOL> | List provenance relations associated with an object_id.
:param object_kind: str: type of object we want relationships for (dds-activity for example)
:param object_id: str: uuid of the object
:return: requests.Response containing the successful result | f3912:c4:m54 |
def get_relation(self, relation_id): | return self._get_single_item('<STR_LIT>'.format(relation_id), {})<EOL> | Get relation details.
:param relation_id: str: uuid of the relation
:return: requests.Response containing the successful result | f3912:c4:m55 |
def create_used_relation(self, activity_id, entity_kind, entity_id): | return self._create_activity_relation(activity_id, entity_kind, entity_id, ActivityRelationTypes.USED)<EOL> | Create a was used by relationship between an activity and a entity(file).
:param activity_id: str: uuid of the activity
:param entity_kind: str: kind of entity('dds-file')
:param entity_id: str: uuid of the entity
:return: requests.Response containing the successful result | f3912:c4:m56 |
def create_was_generated_by_relation(self, activity_id, entity_kind, entity_id): | return self._create_activity_relation(activity_id, entity_kind, entity_id, ActivityRelationTypes.WAS_GENERATED_BY)<EOL> | Create a was generated by relationship between an activity and a entity(file).
:param activity_id: str: uuid of the activity
:param entity_kind: str: kind of entity('dds-file')
:param entity_id: str: uuid of the entity
:return: requests.Response containing the successful result | f3912:c4:m57 |
def create_was_invalidated_by_relation(self, activity_id, entity_kind, entity_id): | return self._create_activity_relation(activity_id, entity_kind, entity_id, ActivityRelationTypes.WAS_INVALIDATED_BY)<EOL> | Create a was invalidated by relationship between an activity and a entity(file).
:param activity_id: str: uuid of the activity
:param entity_kind: str: kind of entity('dds-file')
:param entity_id: str: uuid of the entity
:return: requests.Response containing the successful result | f3912:c4:m58 |
def create_was_derived_from_relation(self, used_entity_id, used_entity_kind,<EOL>generated_entity_id, generated_entity_kind): | data = {<EOL>"<STR_LIT>": {<EOL>"<STR_LIT:id>": used_entity_id,<EOL>"<STR_LIT>": used_entity_kind<EOL>},<EOL>"<STR_LIT>": {<EOL>"<STR_LIT:id>": generated_entity_id,<EOL>"<STR_LIT>": generated_entity_kind<EOL>}<EOL>}<EOL>return self._post("<STR_LIT>", data)<EOL> | Create a was derived from relation.
:param used_entity_id: str: uuid of the used entity (file_version_id)
:param used_entity_kind: str: kind of entity ('dds-file')
:param generated_entity_id: uuid of the generated entity (file_version_id)
:param generated_entity_kind: str: kind of entity ('dds-file')
:return: requests.Response containing the successful result | f3912:c4:m60 |
def delete_relation(self, relation_id): | return self._delete('<STR_LIT>'.format(relation_id), {})<EOL> | Delete a relationship.
:param relation_id: str: uuid of the relation
:return: requests.Response containing the successful result | f3912:c4:m61 |
def get_auth_providers(self): | return self._get_collection("<STR_LIT>", {})<EOL> | List Authentication Providers Lists Authentication Providers
Returns an array of auth provider details
:return: requests.Response containing the successful result | f3912:c4:m62 |
def get_auth_provider(self, auth_provider_id): | return self._get_single_item('<STR_LIT>'.format(auth_provider_id), {})<EOL> | Get auth provider details.
:param auth_provider_id: str: uuid of the auth provider
:return: requests.Response containing the successful result | f3912:c4:m63 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.