Ejemplo n.º 1
0
def rm(files, followlink=False, tn=""):
    if not os.path.exists(files):
        # If there isn't anything to remove, why bother with this function?
        return
    rfile = files
    dfile = delink(files)
    rmstring = "Removing "
    if os.path.isdir(files):
        rmstring += "directory "
    if dfile is not None:
        files = dfile
        if os.path.isfile(files):
            logger.logVV(tn, logger.I, utilities.utf8all(_("Removing symlink"), " ", rfile))
        elif os.path.isdir(files):
            logger.logVV(tn, logger.I, utilities.utf8all(_("Removing directory symlink"), " ", rfile))
        os.remove(rfile)
        if followlink:
            files = rfile
        else:
            return
    if os.path.isfile(files):
        logger.logVV(tn, logger.I, utilities.utf8all(_(rmstring), files))
        os.remove(rfile)
    elif os.path.isdir(files):
        logger.logVV(tn, logger.I, utilities.utf8all(_(rmstring), files))
        shutil.rmtree(rfile)
Ejemplo n.º 2
0
def rm(files, followlink=False, tn=""):
    rfile = files
    dfile = delink(files)
    rmstring = "Removing "
    if os.path.isdir(files):
        rmstring += "directory "
    if dfile != None:
        files = dfile
        if os.path.isfile(files):
            logger.logVV(tn, logger.I,
                         utilities.utf8all(_("Removing symlink"), " ", rfile))
        elif os.path.isdir(files):
            logger.logVV(
                tn, logger.I,
                utilities.utf8all(_("Removing directory symlink"), " ", rfile))
        os.remove(rfile)
        if followlink:
            files = rfile
        else:
            return
    if os.path.isfile(files):
        logger.logVV(tn, logger.I, utilities.utf8all(_(rmstring), files))
        os.remove(rfile)
    elif os.path.isdir(files):
        logger.logVV(tn, logger.I, utilities.utf8all(_(rmstring), files))
        shutil.rmtree(rfile)
Ejemplo n.º 3
0
def rm(files, followlink=False, tn=""):
    if not os.path.exists(files):
        # If there isn't anything to remove, why bother with this function?
        return
    rfile = files
    dfile = delink(files)
    rmstring = "Removing "
    if os.path.isdir(files):
        rmstring += "directory "
    if dfile is not None:
        files = dfile
        if os.path.isfile(files):
            logger.logVV(tn, logger.I,
                         utilities.utf8all(_("Removing symlink"), " ", rfile))
        elif os.path.isdir(files):
            logger.logVV(
                tn, logger.I,
                utilities.utf8all(_("Removing directory symlink"), " ", rfile))
        os.remove(rfile)
        if followlink:
            files = rfile
        else:
            return
    if os.path.isfile(files):
        logger.logVV(tn, logger.I, utilities.utf8all(_(rmstring), files))
        os.remove(rfile)
    elif os.path.isdir(files):
        logger.logVV(tn, logger.I, utilities.utf8all(_(rmstring), files))
        shutil.rmtree(rfile)
Ejemplo n.º 4
0
def adrm(dirs, options, excludes1 = [], tn = ""):
    # Get a list of all files inside the directory
    files = listdir(dirs, {"recurse": True, "dirs": True, "symlinks": False}, tn)
    excludes = []
    # Exclude the files listed to exclude
    if options["excludes"] and len(excludes1) > 0:
        excludes = exclude(files, excludes1)
    # Remove the wanted files
    for file_ in files:
        file__ = utilities.utf8(file_)
        file_ = utilities.utf8(os.path.basename(file__))
        # 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 == None:
            if os.path.isfile(fullpath):
                rm(fullpath)
            elif os.path.isdir(fullpath) and options["remdirs"]:
                rm(fullpath)
        else:
            if options["remsymlink"]:
                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"] is True:
        logger.logVV(tn, logger.I, utilities.utf8all(_("Removing source directory"), " ", dirs))
        rm(dirs)
Ejemplo n.º 5
0
def fscopy(src, dst, excludes1, tn=""):
    src1 = re.sub(r"/+$", "", src)
    src = src1
    # Get a list of all files
    files = listdir(src, {
        "recurse": True,
        "dirs": True,
        "symlinks": False
    }, tn)
    # Exclude the files that are not wanted
    excludes = []
    if len(excludes1) > 0:
        excludes = exclude(files, excludes1)
    makedir(dst)
    # Copy the files
    for file__ in files:
        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))
        # Save some valuable time
        if os.path.exists(newpath):
            fpmd5 = genMD5(fullpath)
            npmd5 = genMD5(newpath)
            if fpmd5 == npmd5:
                continue
        dfile = delink(fullpath)
        if dfile is not None:
            logger.logVV(
                tn, logger.I,
                utilities.utf8all(
                    file_, " ",
                    _("is a symlink. Creating an identical symlink at"), " ",
                    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))
            shutil.copy2(fullpath, newpath)
    logger.logVV(tn, logger.I, _("Setting permissions"))
    copystat(src, dst)
Ejemplo n.º 6
0
def chmod(files, mod, tn=""):
    '''val = 0x00
    c = 0
    logger.logVV(tn, logger.I, utilities.utf8all(
        _("Calculating permissions of"), " ", files))
    # In case the user of this function used UGO instead of SUGO, we'll cover up for that
    if len(mod) < 4:
        c = 1
    # OR all of the chmod options
    for i in mod:
        # OR this option to val
        val = val | _chmod(c, int(i))
        c = c + 1'''
    val = mod
    if isinstance(mod, str):
        val = int(mod, 8)
    else:
        mod_ = str(oct(mod))[1:]
        mod = mod_
    # Chmod it
    logger.logVV(
        tn, logger.I,
        utilities.utf8all(_("Setting permissions of"), " ", files, " ",
                          _("to"), " ", mod))
    os.chmod(files, val)
Ejemplo n.º 7
0
def adrm(dirs, options, excludes1=[], tn=""):
    # Get a list of all files inside the directory
    files = listdir(dirs, {
        "recurse": True,
        "dirs": True,
        "symlinks": False
    }, tn)
    excludes = []
    # Exclude the files listed to exclude
    if options["excludes"] and len(excludes1) > 0:
        excludes = exclude(files, excludes1)
    # Remove the wanted files
    for file_ in files:
        file__ = utilities.utf8(file_)
        file_ = utilities.utf8(os.path.basename(file__))
        # 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 == None:
            if os.path.isfile(fullpath):
                rm(fullpath)
            elif os.path.isdir(fullpath) and options["remdirs"]:
                rm(fullpath)
        else:
            if options["remsymlink"]:
                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"] is True:
        logger.logVV(
            tn, logger.I,
            utilities.utf8all(_("Removing source directory"), " ", dirs))
        rm(dirs)
Ejemplo n.º 8
0
def fscopy(src, dst, excludes1, tn = ""):
    src1 = re.sub(r"/+$", "", src)
    src = src1
    # Get a list of all files
    files = listdir(src, {"recurse": True, "dirs": True, "symlinks": False}, tn)
    # Exclude the files that are not wanted
    excludes = []
    if len(excludes1) > 0:
        excludes = exclude(files, excludes1)
    makedir(dst)
    # Copy the files
    for file__ in files:
        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))
        # Save some valuable time
        if os.path.exists(newpath):
            fpmd5 = genMD5(fullpath)
            npmd5 = genMD5(newpath)
            if fpmd5 == npmd5:
                continue
        dfile = delink(fullpath)
        if dfile is not None:
            logger.logVV(tn, logger.I, utilities.utf8all(file_, " ",
                                            _("is a symlink. Creating an identical symlink at"), " ",
                                            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))
            shutil.copy2(fullpath, newpath)
    logger.logVV(tn, logger.I, _("Setting permissions"))
    copystat(src, dst)
Ejemplo n.º 9
0
def rm(files, followlink = False, tn = ""):
    rfile = files
    dfile = delink(files)
    rmstring = "Removing "
    if os.path.isdir(files):
        rmstring += "directory "
    if dfile != None:
        files = dfile
        if os.path.isfile(files):
            logger.logVV(tn, logger.I, utilities.utf8all(_("Removing symlink"), " ", rfile))
        elif os.path.isdir(files):
            logger.logVV(tn, logger.I, utilities.utf8all(_("Removing directory symlink"), " ", rfile))
        os.remove(rfile)
        if followlink:
            files = rfile
        else:
            return
    if os.path.isfile(files):
        logger.logVV(tn, logger.I, utilities.utf8all(_(rmstring), files))
        os.remove(rfile)
    elif os.path.isdir(files):
        logger.logVV(tn, logger.I, utilities.utf8all(_(rmstring), files))
        shutil.rmtree(rfile)
Ejemplo n.º 10
0
def listdir(dirs, options = {}, tn = ""):
    utilities.setDefault(options, recurse = True, dirs = True, symlinks = False)
    logger.logV(tn, logger.I, utilities.utf8all(_("Gathering a list of files in"), " ", dirs))
    listed = []
    if options["recurse"]:
        listed = os.walk(utilities.utf8(dirs), True, None, options["symlinks"])
    else:
        listed = os.listdir(utilities.utf8(dirs))
    returnme = []
    for i in listed:
        if options["dirs"]:
            if options["recurse"]:
                returnme.append(utilities.utf8(i[0]))
            elif os.path.isdir(i):
                returnme.append(utilities.utf8(i))
        if options["recurse"]:
            for x in i[2]:
                returnme.append(utilities.utf8(os.path.join(i[0], x)))
        elif os.path.isfile(i) or os.path.islink(i):
            returnme.append(utilities.utf8(i))
    return returnme
Ejemplo n.º 11
0
def chmod(files, mod, tn = ""):
    '''val = 0x00
    c = 0
    logger.logVV(tn, logger.I, utilities.utf8all(_("Calculating permissions of"), " ", files))
    # In case the user of this function used UGO instead of SUGO, we'll cover up for that
    if len(mod) < 4:
        c = 1
    # OR all of the chmod options
    for i in mod:
        # OR this option to val
        val = val | _chmod(c, int(i))
        c = c + 1'''
    val = mod
    if isinstance(mod, str):
        val = int(mod, 8)
    else:
        mod_ = str(oct(mod))[1:]
        mod = mod_
    # Chmod it
    logger.logVV(tn, logger.I, utilities.utf8all(_("Setting permissions of"), " ", files, " ", _("to"), " ", mod))
    os.chmod(files, val)
Ejemplo n.º 12
0
def listdir(dirs, options={}, tn=""):
    utilities.setDefault(options, recurse=True, dirs=True, symlinks=False)
    logger.logV(
        tn, logger.I,
        utilities.utf8all(_("Gathering a list of files in"), " ", dirs))
    listed = []
    if options["recurse"]:
        listed = os.walk(utilities.utf8(dirs), True, None, options["symlinks"])
    else:
        listed = os.listdir(utilities.utf8(dirs))
    returnme = []
    for i in listed:
        if options["dirs"]:
            if options["recurse"]:
                returnme.append(utilities.utf8(i[0]))
            elif os.path.isdir(i):
                returnme.append(utilities.utf8(i))
        if options["recurse"]:
            for x in i[2]:
                returnme.append(utilities.utf8(os.path.join(i[0], x)))
        elif os.path.isfile(i) or os.path.islink(i):
            returnme.append(utilities.utf8(i))
    return returnme
Ejemplo n.º 13
0
def symlink(files, dst, tn=""):
    if not os.path.lexists(dst) and not os.path.exists(dst):
        logger.logVV(tn, logger.I, utilities.utf8all(_("Creating symlink"), " ", dst))
        os.symlink(files, dst)
Ejemplo n.º 14
0
def symlink(files, dst, tn=""):
    if not os.path.lexists(dst) and not os.path.exists(dst):
        logger.logVV(tn, logger.I,
                     utilities.utf8all(_("Creating symlink"), " ", dst))
        os.symlink(files, dst)