예제 #1
0
    def on_drive_create(self, file_id):
        path = self._compute_drive_path_by_file_id(file_id)
        remote_file = self._get_remote_file(file_id)
        drive_item = GoogleDriveFile(path, remote_file)
        self.drive_files[path] = drive_item

        self._notify("Created " + remote_file["title"])
        if remote_file["mimeType"] == folder_mime_type:
            self._create_local_dir(path)
        if remote_file.has_key("downloadUrl"):
            drive_item.download_from_url()
예제 #2
0
    def _synchronize_files_by_type(self, root_path, query):
        self._create_local_dir(root_path)
        items = self._list_file(query=query)

        for item in items:
            path = os.path.join(root_path, item["title"])
            drive_item = GoogleDriveFile(path, item)
            self.drive_files[path] = drive_item

            if item["mimeType"] == folder_mime_type:
                self._synchronize_files(item["id"], path)
            if item.has_key("downloadUrl"):
                drive_item.download_from_url()
예제 #3
0
    def _synchronize_files(self, root_id, root_path, query=None):
        self._create_local_dir(root_path)
        children = self._list_children(folderId=root_id, query=query)

        for child in children:
            item = self._get_remote_file(child["id"])
            path = os.path.join(root_path, item["title"])
            drive_item = GoogleDriveFile(path, item)
            self.drive_files[path] = drive_item

            if item["mimeType"] == folder_mime_type:
                self._synchronize_files(item["id"], path, query)
            if item.has_key("downloadUrl"):
                drive_item.download_from_url()
예제 #4
0
    def on_local_create(self, path):
        head, _ = os.path.split(path)
        if not self.drive_files.has_key(head):
            self.on_local_create(head)

        if self.drive_files.has_key(path):
            logger.info("file %s already exists", path)
            return

        # create drive item
        parent = self._find_parent(head)
        if parent is None:
            return

        to_create = GoogleDriveFile(path)
        to_create.create(parent.id)
        self.drive_files[path] = to_create