Example #1
0
def findSpecific(path = '/tmp', Extention = 'iso'):
	dup = []
	ErrorFiles = []
	record = {}
	d = diskwalk(path)
	files = d.enumerateFilesByExt( Extention )
	return { Extention: files }
Example #2
0
def construct_zip(src_dir,
                  base_dir,
                  base_name="vimwiki_diff_backup",
                  excluded_ending=None,
                  dbg=False):
    """ Construct zip file
    excluded_ending is None removes items line [".swo", ".swp", ".pyc", ".o", ".gz"],
        for all pass in []
    """
    dt_str, time_str = calc_date_time()
    base_name = "_".join([base_name, dt_str, time_str])
    zipname = None

    if excluded_ending is None:
        excluded_final = set([".swo", ".swp", ".pyc", ".o", ".gz"])
    else:
        excluded_final = set(excluded_ending)

    try:
        zipname = "".join([src_dir, os.sep, base_name, ".zip"])
        zip_count = 0
        with zp.ZipFile(zipname, mode='w') as zp_ptr:
            dw = dwa.diskwalk(os.sep.join([src_dir, base_dir]))
            for itm in dw.enumeratePaths():
                _, init_splt = os.path.splitext(itm)

                # print(filename + " " + str(init_splt) + " " + str(not_empty) + " " + cur_dir)
                if init_splt != '' and init_splt in excluded_final:
                    base_str = ": ".join(["Excluding", itm])
                    dbc.print_helper(base_str, dbg=dbg)
                else:
                    itm_loc = str(itm).find(base_dir)
                    base_str = "--".join(["adding", itm[itm_loc:]])
                    zp_ptr.write(itm[itm_loc:])
                    if not itm.endswith(base_dir):
                        zip_count = zip_count + 1

            zp_ptr.close()

            if zip_count < 2:
                dbc.print_helper("Warning construct_zip -- likely empty zip",
                                 dbg=dbg)
    except OSError as err:
        if zp_ptr is not None:
            zp_ptr.close()
        dbc.error_helper(("OSError: Zip" + err.strerror),
                         stderr=None,
                         post=zipname,
                         dbg=dbg)
    except:
        if zp_ptr is not None:
            zp_ptr.close()
        dbc.error_helper(("Error: Zip" + str(sys.exc_info()[0])),
                         stderr=None,
                         post=None,
                         dbg=dbg)

    return zipname
Example #3
0
def find_dupes(path='/tmp'):
    dup=[]
    record={}
    d=diskwalk(path)
    files=d.enumeratepaths()
    for file in files:
        compound_key=(os.path.getsize(file),create_checksum(file))
        if compound_key in record:
            dup.append(file)
        else:
            record[compound_key]=file
    return dup
Example #4
0
def findDupes(path='/tmp'):
    dup = []
    record = {}
    d = diskwalk(path)
    files = d.enumreatePaths()
    for file in files:
        compound_key = (getsize(file), create_checksum(file))
        if compund_key in record:
            dup.append(file)
        else:
            record[compound_key] = file
    return dup
Example #5
0
def findDupes(path = '/tmp'):
    dup = []
    record = {}
    d = diskwalk(path)
    files = d.enumeratePaths()
    for file in files:
        compound_key = (getsize(file),create_checksum(file))
        if compound_key in record:
            dup.append(file)
        else:
            #print "Creating compound key record:", compound_key
            record[compound_key] = file
    return dup
Example #6
0
def findDupes(path = "/home/simon/Downloads"):
    dup = []
    record = []
    d = diskwalk(path)
    files = d.enumeratepaths()
    for file in files:
        compound_key = (getsize(file), create_checksum(file))
        if compound_key in record:
            dup.append(file)
        else:
            record.append(compound_key)
            #record[compound_key] = file
    return dup
Example #7
0
def find_dupes(path = '/tmp'):
    dup = []
    record = {}
    files = diskwalk(path).enumerate_paths()
    for file in files:
        try:
            compound_key = (getsize(file), create_checksum(file))
            if compound_key in record:
                dup.append(file)
            else:
                #print 'Creating compound_key record:', compound_key
                record[compound_key] = file
        except:
            pass
    return dup
Example #8
0
def find_dupes(path='/tmp'):
    dup = []
    record = {}
    files = diskwalk(path).enumerate_paths()
    for file in files:
        try:
            compound_key = (getsize(file), create_checksum(file))
            if compound_key in record:
                dup.append(file)
            else:
                #print 'Creating compound_key record:', compound_key
                record[compound_key] = file
        except:
            pass
    return dup
Example #9
0
def findDupes(path='/tmp'):
    dup = []
    record = {}
    d = diskwalk(path)
    files = d.enumeratePaths()
    for file in files:
        compound_key = (getsize(file),create_checksum(file))
        if compound_key in record:
            dup.append(file)
        else:
            record[compound_key] = file
    return dup

    if __name__ =="__main__":
        dupes = findDupes()
        for dup in dupes:
            print "Duplicate:%s" % dup
Example #10
0
def fidnDupes(path='/'):
    dup = []
    record = {}
    d = diskwalk(path)
    files = d.enumeratePaths()
    for file in files:
        compound_key = (getsize(file), create_checksum(file))
        if compound_key in record:
            dup.append(file)
        else:
            #print "Creating compound key record:", compound_key
            record[compound_key] = file
    return dup

    if __name__ == "__main__":
        dupes = findDupes()
    for dup in dupes:
        print "Duplicate: %s" % dup
Example #11
0
def construct_gzip(src_dir,
                   base_dir,
                   base_name="MySQL_backup_",
                   excluded_ending=None,
                   dbg=False):
    """ constructs tar.gz file based in src dir
    excluded_ending is None removes items [".swo", ".swp", ".pyc", ".o", ".gz"], for all pass in []
    """
    dt_str, time_str = calc_date_time()
    base_name = "_".join([base_name, dt_str, time_str])
    tarfilename = None
    excluded = []

    if excluded_ending is None:
        excluded_final = set([".swo", ".swp", ".pyc", ".o", ".gz"])
    else:
        excluded_final = set(excluded_ending)

    try:
        tarfilename = "".join([src_dir, os.sep, base_name, ".tar.gz"])
        with tarfile.open(tarfilename, "w:gz") as tar:
            dw = dwa.diskwalk(os.sep.join([src_dir, base_dir]))
            for itm in dw.enumeratePaths():
                _, init_splt = os.path.splitext(itm)

                # print(filename + " " + str(init_splt) + " " + str(not_empty) + " " + cur_dir)
                if init_splt != '' and init_splt in excluded_final:
                    base_str = ": ".join(["Excluding", itm])
                    dbc.print_helper(base_str, dbg=dbg)
                    excluded.append(itm)
                else:
                    itm_loc = str(itm).find(base_dir)
                    base_str = "--".join(["adding", itm[itm_loc:]])
                    tar.add(itm[itm_loc:])

            tar.close()
    except:
        tar.close()

    return tarfilename, excluded
Example #12
0
#!/usr/bin/python

from diskwalk_api import diskwalk

from shutil import move

files = diskwalk("/tmp")

for file in files:
    if fnmatch(file, "*.txt"):
        #here we can do anuthing we want, delete, mobe rename.... hmm rename
        move(file, "%s.mp3" % file)