def add_item_with_meta_file_object(self, file_object, show_more_info, show_all_files, snapshot_info, type_item, file_icon):

        meta_file_object = file_object.get_meta_file_object()
        child_item = QtGui.QTreeWidgetItem()
        file_name = file_object.get_filename_with_ext()
        if not meta_file_object.is_exists():
            file_name += ' (File Offline)'
        child_item.setText(0, file_name)
        child_item.setData(0, QtCore.Qt.UserRole, file_object)
        if show_more_info:
            child_item.setText(1, gf.sizes(file_object.get_file_size()))
            child_item.setText(2, file_object.get_abs_path())
            child_item.setText(3, snapshot_info.get('repo'))
            child_item.setText(4, file_object.get_base_type())
        if show_all_files:
            type_item.addChild(child_item)
        else:
            self.filesTreeWidget.addTopLevelItem(child_item)

        child_item.setIcon(0, file_icon)
        if len(meta_file_object.get_all_files_list()) > 1:
            # if this is meta with sequence or udims etc...
            for meta_file_name in meta_file_object.get_all_files_list(filenames=True):
                sub_child_item = QtGui.QTreeWidgetItem()
                child_item.addChild(sub_child_item)
                sub_child_item.setText(0, meta_file_name)
                sub_child_item.setData(0, QtCore.Qt.UserRole, file_object)
                sub_child_item.setIcon(0, file_icon)

        child_item.setExpanded(True)
 def add_item_with_tactic_file_object(self, file_object, show_more_info, show_all_files, snapshot_info, type_item, file_icon):
     child_item = QtGui.QTreeWidgetItem()
     file_name = file_object.get_filename_with_ext()
     if not file_object.is_exists():
         file_name += ' (File Offline)'
     child_item.setText(0, file_name)
     child_item.setData(0, QtCore.Qt.UserRole, file_object)
     if show_more_info:
         child_item.setText(1, gf.sizes(file_object.get_file_size()))
         child_item.setText(2, file_object.get_abs_path())
         child_item.setText(3, snapshot_info.get('repo'))
         child_item.setText(4, file_object.get_base_type())
     if show_all_files:
         type_item.addChild(child_item)
     else:
         self.filesTreeWidget.addTopLevelItem(child_item)
     child_item.setIcon(0, file_icon)
     child_item.setExpanded(True)
Esempio n. 3
0
    def execute(self, path, progress_signal=None):
        assert self.server_url
        #f = open(path, 'rb')
        import codecs
        f = codecs.open(path, 'rb')

        if self.offset:
            f.seek(self.offset * self.chunk_size)
        else:
            self.offset = 0

        file_size = os.stat(path).st_size
        total_count = int(file_size / self.chunk_size)
        if total_count == 0:
            total_count = 1

        info_dict = {
            'status_text': 'Uploading to Server ...',
            'total_count': total_count
        }
        import thlib.global_functions as gf

        while 1:
            buffer = f.read(self.chunk_size)
            if not buffer:
                break

            if self.offset == 0:
                action = "create"
            else:
                action = "append"

            fields = [
                ("ajax", "true"),
                ("action", action),
            ]
            if self.ticket:
                fields.append(("ticket", self.ticket))
                fields.append(("login_ticket", self.ticket))
                basename = os.path.basename(path)
                from json import dumps as jsondumps

                # Workaround for python inside Maya, maya.Output has no sys.stdout.encoding property
                try:
                    if getattr(sys.stdout, "encoding",
                               None) is not None and sys.stdout.encoding:
                        basename = basename.decode(sys.stdout.encoding)
                    else:
                        import locale
                        basename = basename.decode(
                            locale.getpreferredencoding())
                except AttributeError:
                    # Python3 has no decode method on strings objects
                    pass

                basename = jsondumps(basename)
                basename = basename.strip('"')
                # the first index begins at 0
                fields.append(("file_name0", basename))

            if self.subdir:
                fields.append(("subdir", self.subdir))

            files = [("file", path, buffer)]
            (status, reason, content) = self.upload(self.server_url, fields,
                                                    files)

            current_uploaded = self.offset * self.chunk_size
            info_dict['status_text'] = 'Uploading {1} of {0}'.format(
                gf.sizes(file_size), gf.sizes(current_uploaded))
            if self.offset == 0:
                gf.emit_progress(1, info_dict, progress_signal)
            else:
                gf.emit_progress(self.offset, info_dict, progress_signal)

            if reason != "OK":
                raise TacticUploadException("Upload of '%s' failed: %s %s" %
                                            (path, status, reason))

            self.offset += 1

        f.close()