예제 #1
0
 def updateProgress():
     totprogress = 0
     for i in page["progress"]:
         totprogress += utilities.floatDivision(
             float(page["progress"][i]), 100)
     QtCore.QMetaObject.invokeMethod(ui.progress, "setValue",
                                     QtCore.Qt.QueuedConnection,
                                     QtCore.Q_ARG("int", utilities.calcPercent(totprogress, numthreads2)))
예제 #2
0
 def updateProgress():
     totprogress = 0
     for i in page["progress"]:
         totprogress += utilities.floatDivision(
             float(page["progress"][i]), 100)
     QtCore.QMetaObject.invokeMethod(
         ui.progress, "setValue", QtCore.Qt.QueuedConnection,
         QtCore.Q_ARG("int",
                      utilities.calcPercent(totprogress, numthreads2)))
예제 #3
0
def adrm(dirs, **options):
    utilities.setDefault(options,
                         excludes=[],
                         remdirs=True,
                         remsymlink=True,
                         remfullpath=False,
                         remoriginal=True,
                         tn="",
                         progressfunc=None)
    # Get a list of all files inside the directory
    files = list(
        listdir(dirs,
                recurse=True,
                dirs=True,
                symlinks=False,
                tn=options["tn"]))
    excludes = []
    # Exclude the files listed to exclude
    if len(options["excludes"]) > 0:
        excludes = exclude(files, options["excludes"])
    c = 0
    l = len(files)
    # Remove the wanted files
    for file_ in files:
        file__ = utilities.utf8(file_)
        file_ = utilities.utf8(os.path.basename(file__))
        if options["progressfunc"]:
            options["progressfunc"](utilities.calcPercent(c, l))
        c += 1
        # Make sure we don't remove files that are listed to exclude from removal
        if file__ in excludes:
            #logger.logVV(tn, logger.I, utilities.utf8all(file_, " ",
            #                                             _("is to be excluded. Skipping a CPU cycle")))
            continue
        fullpath = file__
        dfile = delink(fullpath)
        if dfile is None:
            if os.path.isfile(fullpath):
                rm(fullpath)
            elif os.path.isdir(fullpath) and options["remdirs"]:
                rm(fullpath)
        else:
            if options["remsymlink"]:
                if (os.path.isdir(fullpath)
                        and options["remdirs"]) or os.path.isfile(fullpath):
                    #logger.logVV(tn, logger.I, utilities.utf8all(_("Removing symlink"), " ", fullpath))
                    rm(fullpath)
            if options["remfullpath"]:
                #logger.logVV(tn, logger.I, utilities.utf8all(_("Removing"), " ", dfile, " (",
                #                                   _("directed by symlink"), fullpath, ")"))
                rm(dfile)
    if options["remdirs"] and options["remoriginal"]:
        #logger.logVV(tn, logger.I, utilities.utf8all(_("Removing source directory"), " ", dirs))
        rm(dirs)
예제 #4
0
def adrm(dirs, **options):
    utilities.setDefault(
        options,
        excludes=[],
        remdirs=True,
        remsymlink=True,
        remfullpath=False,
        remoriginal=True,
        tn="",
        progressfunc=None,
    )
    # Get a list of all files inside the directory
    files = list(listdir(dirs, recurse=True, dirs=True, symlinks=False, tn=options["tn"]))
    excludes = []
    # Exclude the files listed to exclude
    if len(options["excludes"]) > 0:
        excludes = exclude(files, options["excludes"])
    c = 0
    l = len(files)
    # Remove the wanted files
    for file_ in files:
        file__ = utilities.utf8(file_)
        file_ = utilities.utf8(os.path.basename(file__))
        if options["progressfunc"]:
            options["progressfunc"](utilities.calcPercent(c, l))
        c += 1
        # Make sure we don't remove files that are listed to exclude from removal
        if file__ in excludes:
            # logger.logVV(tn, logger.I, utilities.utf8all(file_, " ",
            #                                             _("is to be excluded. Skipping a CPU cycle")))
            continue
        fullpath = file__
        dfile = delink(fullpath)
        if dfile is None:
            if os.path.isfile(fullpath):
                rm(fullpath)
            elif os.path.isdir(fullpath) and options["remdirs"]:
                rm(fullpath)
        else:
            if options["remsymlink"]:
                if (os.path.isdir(fullpath) and options["remdirs"]) or os.path.isfile(fullpath):
                    # logger.logVV(tn, logger.I, utilities.utf8all(_("Removing symlink"), " ", fullpath))
                    rm(fullpath)
            if options["remfullpath"]:
                # logger.logVV(tn, logger.I, utilities.utf8all(_("Removing"), " ", dfile, " (",
                #                                   _("directed by symlink"), fullpath, ")"))
                rm(dfile)
    if options["remdirs"] and options["remoriginal"]:
        # logger.logVV(tn, logger.I, utilities.utf8all(_("Removing source directory"), " ", dirs))
        rm(dirs)
예제 #5
0
 def setProgress(tn, progress):
     logger.logVV(tn, logger.D, "Setting progress to " + str(progress) + " (from thread " + threading.current_thread().name + ")")
     #return
     # Do something here
     if progress > 100:
         progress = 100
     elif progress < 0:
         progress = 0
     page["progress"][tn] = progress
     totprogress = 0
     for i in page["progress"]:
         totprogress += utilities.floatDivision(float(page["progress"][i]), 100)
     QtCore.QMetaObject.invokeMethod(ui.progress, "setValue",
                                     QtCore.Qt.QueuedConnection,
                         QtCore.Q_ARG("int", utilities.calcPercent(totprogress, numthreads2)))
예제 #6
0
 def setProgress(tn, progress):
     logger.logVV(
         tn, logger.D, "Setting progress to " + str(progress) +
         " (from thread " + threading.current_thread().name + ")")
     #return
     # Do something here
     if progress > 100:
         progress = 100
     elif progress < 0:
         progress = 0
     page["progress"][tn] = progress
     totprogress = 0
     for i in page["progress"]:
         totprogress += utilities.floatDivision(
             float(page["progress"][i]), 100)
     QtCore.QMetaObject.invokeMethod(
         ui.progress, "setValue", QtCore.Qt.QueuedConnection,
         QtCore.Q_ARG("int",
                      utilities.calcPercent(totprogress, numthreads2)))
예제 #7
0
def fscopy(src, dst, excludes1, tn="", **options):
    utilities.setDefault(options, progressfunc=None)
    src1 = re.sub(r"/+$", "", src)
    src = src1
    dst1 = re.sub(r"/+$", "", dst)
    dst = dst1
    dstp = re.sub(r"/+$", "", os.path.dirname(dst))
    # Get a list of all files
    files = list(listdir(src, tn=tn))
    # Get the length of the file list
    lfiles = len(files)
    # Exclude the files that are not wanted
    excludes = []
    if len(excludes1) > 0:
        excludes = exclude(files, excludes1)
    makedir(dst)
    c = 0
    # Copy the files
    for file___ in files:
        if options["progressfunc"]:
            options["progressfunc"](utilities.calcPercent(c, lfiles))
        c += 1
        file__ = utilities.utf8(os.path.abspath(file___))
        file_ = utilities.utf8(os.path.basename(utilities.utf8(file__)))
        # Make sure we don't copy files that are supposed to be excluded
        if file_ in excludes:
            # logger.logVV(tn, logger.W, utilities.utf8all(file_, " ", _("is to be excluded. Skipping a CPU cycle")))
            continue
        fullpath = utilities.utf8(file__)
        # print(dst + " " + file__[len(src):])
        temp = re.sub(r"^/+", "", file__[len(src) :])
        newpath = utilities.utf8(os.path.join(dst, temp))
        if not os.path.exists(fullpath):
            # Either an error on fsutil's part, or the file got deleted
            continue
        # Save some valuable time
        if os.path.exists(newpath):
            fpmd5 = genMD5(fullpath)
            npmd5 = genMD5(newpath)
            if fpmd5 == npmd5:
                continue
        dfile = delink(fullpath, False)
        if dfile is not None:
            """logger.logVV(tn, logger.D, utilities.utf8all(file_, " ",
                                            _("is a symlink. Creating an identical symlink at"), " ",
                                            newpath))
            logger.logI(
                tn, logger.D, utilities.utf8all("ORIGINAL ", dfile, "NEW ",
                                                        os.path.relpath(dfile, fullpath)))
            symlink(os.path.normpath("/" +
                                    abspath(
                                        os.path.relpath(
                                            dfile, fullpath), newpath)[len(
                                                dstp):]),
                                newpath)"""
            symlink(dfile, newpath)
        elif os.path.isdir(fullpath):
            # logger.logVV(tn, logger.I, utilities.utf8all(_("Creating directory"), " ", file_))
            makedir(newpath)
            # logger.logVV(tn, logger.I, _("Setting permissions"))
            copystat(fullpath, newpath)
        else:
            # logger.logVV(tn, logger.I, utilities.utf8all(_("Copying"), " ", fullpath, " ", _("to"), " ", newpath))
            try:
                shutil.copy2(fullpath, newpath)
            except Exception as e:
                print e
    # logger.logVV(tn, logger.I, _("Setting permissions"))
    copystat(src, dst)
예제 #8
0
def rmfiles(arr, tn="", progressfunc=None):
    la = len(arr)
    for i in range(la):
        rm(arr[i], tn)
        if progressfunc:
            progressfunc(utilities.calcPercent(i, la))
예제 #9
0
def maketree(arr, tn="", progressfunc=None):
    la = len(arr)
    for i in range(la):
        makedir(arr[i], tn)
        if progressfunc:
            progressfunc(utilities.calcPercent(i, la))
예제 #10
0
def fscopy(src, dst, excludes1, tn="", **options):
    utilities.setDefault(options, progressfunc=None)
    src1 = re.sub(r"/+$", "", src)
    src = src1
    dst1 = re.sub(r"/+$", "", dst)
    dst = dst1
    dstp = re.sub(r"/+$", "", os.path.dirname(dst))
    # Get a list of all files
    files = list(listdir(src, tn=tn))
    # Get the length of the file list
    lfiles = len(files)
    # Exclude the files that are not wanted
    excludes = []
    if len(excludes1) > 0:
        excludes = exclude(files, excludes1)
    makedir(dst)
    c = 0
    # Copy the files
    for file___ in files:
        if options["progressfunc"]:
            options["progressfunc"](utilities.calcPercent(c, lfiles))
        c += 1
        file__ = utilities.utf8(os.path.abspath(file___))
        file_ = utilities.utf8(os.path.basename(utilities.utf8(file__)))
        # Make sure we don't copy files that are supposed to be excluded
        if file_ in excludes:
            #logger.logVV(tn, logger.W, utilities.utf8all(file_, " ", _("is to be excluded. Skipping a CPU cycle")))
            continue
        fullpath = utilities.utf8(file__)
        #print(dst + " " + file__[len(src):])
        temp = re.sub(r"^/+", "", file__[len(src):])
        newpath = utilities.utf8(os.path.join(dst, temp))
        if not os.path.exists(fullpath):
            # Either an error on fsutil's part, or the file got deleted
            continue
        # Save some valuable time
        if os.path.exists(newpath):
            fpmd5 = genMD5(fullpath)
            npmd5 = genMD5(newpath)
            if fpmd5 == npmd5:
                continue
        dfile = delink(fullpath, False)
        if dfile is not None:
            '''logger.logVV(tn, logger.D, utilities.utf8all(file_, " ",
                                            _("is a symlink. Creating an identical symlink at"), " ",
                                            newpath))
            logger.logI(
                tn, logger.D, utilities.utf8all("ORIGINAL ", dfile, "NEW ",
                                                        os.path.relpath(dfile, fullpath)))
            symlink(os.path.normpath("/" +
                                    abspath(
                                        os.path.relpath(
                                            dfile, fullpath), newpath)[len(
                                                dstp):]),
                                newpath)'''
            symlink(dfile, newpath)
        elif os.path.isdir(fullpath):
            #logger.logVV(tn, logger.I, utilities.utf8all(_("Creating directory"), " ", file_))
            makedir(newpath)
            #logger.logVV(tn, logger.I, _("Setting permissions"))
            copystat(fullpath, newpath)
        else:
            #logger.logVV(tn, logger.I, utilities.utf8all(_("Copying"), " ", fullpath, " ", _("to"), " ", newpath))
            try:
                shutil.copy2(fullpath, newpath)
            except Exception as e:
                print e
    #logger.logVV(tn, logger.I, _("Setting permissions"))
    copystat(src, dst)
예제 #11
0
def rmfiles(arr, tn="", progressfunc=None):
    la = len(arr)
    for i in range(la):
        rm(arr[i], tn)
        if progressfunc:
            progressfunc(utilities.calcPercent(i, la))
예제 #12
0
def maketree(arr, tn="", progressfunc=None):
    la = len(arr)
    for i in range(la):
        makedir(arr[i], tn)
        if progressfunc:
            progressfunc(utilities.calcPercent(i, la))