Пример #1
0
 def __populate_metadata(metadata):
     for f in metadata.entries:
         try:
             full_path = re.split(add_slash(self.path), f.path_display, flags=re.IGNORECASE, maxsplit=1)[1]
             if isinstance(f, FolderMetadata):
                 if self.include_folders:
                     self._listdir.append((add_slash(full_path)))
             else:
                 self._listdir.append(full_path)
         except IndexError:
             # failed to split path
             continue
Пример #2
0
 def path(self, value):
     if value is None:
         self._current_path = None
         self._current_path_with_backslash = None
     else:
         self._current_path = value[:-1] if (value.endswith('/') and value != '/') else value
         self._current_path_with_backslash = add_slash(self._current_path)
Пример #3
0
 def path(self, value):
     if value is None:
         self._current_path = None
         self._current_bucket = None
     else:
         value = value[:-1] if value.endswith('/') else value
         self._current_bucket, self._current_path = self._parse_bucket(value)
         self._current_path_with_backslash = add_slash(self._current_path)
Пример #4
0
    def _populate_listdir(self, blob_name):
        """Appends each blob inner name to self._listdir for bucket case
        :param blob_name: storage.blob.Blob object
        :return:
        """
        split_list = blob_name.split('/', 1)
        if len(split_list) == 2:
            inner_object_name = add_slash(split_list[0])
        else:
            inner_object_name = split_list[0]

        if inner_object_name not in self._listdir:
            self._listdir.append(inner_object_name)
Пример #5
0
 def _populate_listdir(self):
     """Appends each file.folder name to self._listdir"""
     if self.recursive:
         for root, dirs, files in os.walk(self.path):
             for name in files:
                 self._listdir.append(os.path.join(root, name).split(self._current_path_with_backslash, 1)[1])
             if self.include_folders:
                 for name in dirs:
                     self._listdir.append(str(os.path.join(root, name).split(self._current_path_with_backslash, 1)[1])
                                          + '/')
     else:
         for i in os.listdir(self.path):
             if os.path.isdir(os.path.join(self.path, i)):
                 if self.include_folders:
                     self._listdir.append(add_slash(i))
             else:
                 self._listdir.append(i)
Пример #6
0
    def _populate_listdir(self, folder_id: str, parent: Optional[str] = ''):
        """Appends each file.folder name to self._listdir"""
        try:
            file_list = self.drive.ListFile({'q': "'{}' in parents and trashed=false".format(folder_id)}).GetList()
            for f in file_list:
                if f['mimeType'] == 'application/vnd.google-apps.folder':
                    p = parent + add_slash(f['title'])
                    if self.include_folders:
                        self._listdir.append(p)
                    if self.recursive:
                        self._populate_listdir(f['id'], parent=p)
                else:
                    full_path = os.path.join(parent, f['title'])
                    self._listdir.append(full_path)

        except HttpError:
            pass