Ejemplo n.º 1
0
def TaskFile(entry, tree_item):
    taskname = 'default'        # !!!
    tasktype = 'file'

    if isinstance(entry, QtCore.QFileInfo):
        filename = entry.absoluteFilePath()
#       basename = entry.fileName()
    else:
        filename = entry
        entry = QtCore.QFileInfo(filename)
#       basename = entry.fileName()

    logging.debug("TaskFile: %s" % filename)

    # Создаём Регистратор
    Reg = Register(taskname)

    # Делаем запись о задании
    Task = save.task(Reg, taskname=taskname, tasktype=tasktype, source=filename)

    # Получаем и записываем информацию о директории
    directory = entry.absoluteDir()
    Dir = save.dir(Task, dirname=directory.absolutePath(), volume=-1)

    # Добавляем к tree_item
    dir_item = DirItem(tree_item, directory.dirName())

    # Обрабатываем
    res, summary = proceed.ProceedFile(entry, Dir, dir_item)

    logging.debug("Task '%s' завершён: %s, %r" % (taskname, res, summary))

    dir_item.setExpanded(True)
Ejemplo n.º 2
0
def ProceedDir(entry, Reg, tree_item):
    if isinstance(entry, QtCore.QFileInfo):
        filename = entry.absoluteFilePath()
        basename = entry.fileName()
    else:
        filename = entry
        entry = QtCore.QFileInfo(filename)
        basename = entry.fileName()

#   logging.debug(u"ProceedDir: %s" % filename)

    # Делаем запись в БД
    Dir = save.dir(Reg, dirname=filename)

    # Добавляем к tree_item
    dir_item = DirItem(tree_item, basename)

    # Информация о процессе выполнения / директории
    summary = dict(dirs=0, files=0, volume=0)

    directory = QtCore.QDir(filename)
    directory.setFilter(QtCore.QDir.Dirs | QtCore.QDir.Files | QtCore.QDir.NoSymLinks | QtCore.QDir.NoDotAndDotDot | QtCore.QDir.Hidden)
    directory.setSorting(QtCore.QDir.DirsFirst)

    # Пролистываем содержимое директории
    for entry in directory.entryInfoList():
        # Директория
        if entry.isDir():
            subdir_res, subdir_summary = ProceedDir(entry.absoluteFilePath(), Reg, dir_item)
            summary['dirs'] += 1
            summary['dirs'] += subdir_summary['dirs']
            summary['files'] += subdir_summary['files']
            summary['volume'] += subdir_summary['volume']

        # Файл
        else:
            file_res, file_summary = ProceedFile(entry, Dir, dir_item)
            summary['files'] += 1
            summary['volume'] += file_summary['size']

    # Обновляем информацию о директории
    Dir.update(summary)

    res = 0
    dir_item.update(res, summary)

    return res, summary