예제 #1
0
    def files(self, 
              query = None, 
              offset = None, 
              count = None, 
              folder = None, 
              modified_after = None, 
              modified_before = None,
              namespaces = None,
              custom_metadata = None,
              sort_by = None,
              sort_direction = None):
        """
        Search for files.
        Parameters:

        * query The search string you want to find. * is supported as a postfix wildcard, AND and OR as bool operations and double quotes for phrase search.
        * offset The 0-based index of the initial record being requested (Integer >= 0).
        * count The number of entries per page (min 1, max 100)
        * folder Limit the result set to only items contained in the specified folder.
        * modified_before Limit to results before the specified datetime (datetime.date object or ISO 8601 format datetime string {YYYY-MM-DDTHH:MM:SS}).
        * modified_after Limit to results after the specified datetime timestamp (datetime.date or ISO 8601 format datetime string {YYYY-MM-DDTHH:MM:SS}).
        * namespaces List of strings containing the name of the namespaces requested. Namespace will only return if there is a value in any of the fields.
        * custom_metadata Either this or query is required. List of JSON containing values to search - See https://developers.egnyte.com/docs/read/Search_API#Search%20v2
        * sort_by Returns sorted search results. Valid values are one of {"last_modified", "size", "score", "name"}.
        * sort_direction Sort results in ascending or descending order.

        Returns list of SearchMatch objects, with additional attributes offset, total_count and has_more.
        """
        
        if not query and not custom_metadata:
            raise exc.InvalidParameters(
                "query and custom_metadata both can't be None at the same time. "
                "Either pass the query or custom_metadata or both to search."
            )
         
        if sort_by and sort_by not in self._sort_by:
            raise exc.InvalidParameters(
                "Invalid sort_by, it must be one of %s" % self._sort_by
            )
        
        if sort_direction and sort_direction not in self._sort_dir:
            raise exc.InvalidParameters(
                "Invalid sort_direction, it must be one of %s" % self._sort_dir
            )
        
        url = self._client.get_url(self._url_template)
        params = base.filter_none_values(dict(
            query=query,
            offset=offset,
            count=count,
            folder=folder,
            modified_after=base.date_in_ms(modified_after),
            modified_before=base.date_in_ms(modified_before),
            custom_metadata=custom_metadata,
            namespaces=namespaces,
            sort_by=sort_by,
            sort_direction=sort_direction)
        )
        json = exc.default.check_json_response(self._client.POST(url, json=params))
        return base.ResultList((SearchMatch(self._client, **d) for d in json.get('results', ())), json['total_count'], json['offset'], json['hasMore'])
예제 #2
0
def date_in_ms(date):
    if isinstance(date, (datetime.datetime, datetime.date)):
        return int(date.strftime("%s")) * 1000
    elif isinstance(date, (text_type, string_types)):
        try:
            date = datetime.datetime.strptime(date, "%Y-%m-%dT%H:%M:%S")
            return int(date.strftime("%s")) * 1000
        except ValueError:
            raise exc.InvalidParameters(
                "Datetime string must be in ISO 8601 format. E.g YYYY-MM-DDTHH:MM:SS, "
                "the given date {%s} couldn't be parsed" % date)
    else:
        return date
예제 #3
0
 def download(self, download_range=None):
     """
     Download file contents.
     Returns a FileDownload.
     Optional range is 2 integer sequence (start offset, end offset) used to download only part of the file.
     """
     url = self._client.get_url(self._url_template_content, path=self.path)
     if download_range is None:
         r = exc.default.check_response(self._client.GET(url, stream=True))
     else:
         if len(download_range) != 2:
             raise exc.InvalidParameters('Download range needs to be None or a 2 element integer sequence')
         r = exc.partial.check_response(self._client.GET(url, stream=True, headers={'Range': 'bytes=%d-%d' % download_range}))
     return base.FileDownload(r, self)