Skip to content

Commit

Permalink
import fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jooleer committed May 10, 2023
1 parent a802c94 commit 072baf1
Showing 1 changed file with 44 additions and 44 deletions.
88 changes: 44 additions & 44 deletions folder_hash_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,6 @@
import argparse
from multiprocessing.pool import ThreadPool

parser = argparse.ArgumentParser(
prog='folder_hash_compare.py',
description='Compares the hashes of all files in 2 folders',
epilog='Folder Hash Compare - https://github.com/jooleer/folder-hash-compare')

parser.add_argument('-p', '--primary', help='Primary directory, f.e. -p \"C:\\folder1\\\" or -p \"/home/user/dir1\"')
parser.add_argument('-s', '--secondary', help='Secondary directory, f.e. -s \"D:\\folder2\\\" or -s \"/home/user/dir2\"')
parser.add_argument('-a', '--algorithm', help='Set algorithm: CRC32 (default), MD5, SHA256')
parser.add_argument('-d', '--disable', action='store_true', help='Disable multithreading (recommended when both directories are on the same drive)')
parser.add_argument('-m', '--missing', action='store_true', help='Search for missing files in secondary directory')
parser.add_argument('-n', '--nmissing', action='store_true', help='Search for missing files in primary directory')
parser.add_argument('-v', '--verbose', action='store_true', help='Enables verbose logging')
parser.add_argument('-l', '--logging', action='store_true', help='Disables logging to txt file in logs/ folder')
parser.add_argument('-c', '--custom', action='store_true', help='Use custom/hardcoded variables in stead of -p -s command-line arguments')


args = parser.parse_args()

# define the paths of the two directories to compare
if(args.custom):
primary_directory = r""
secondary_directory = r""
if(args.verbose):
print(f"Comparing:\n{primary_directory}\nagainst:\n{secondary_directory}\n")
else:
if(not args.primary) or (not args.secondary):
sys.exit("No primary or secondary folder given, use -h for help")
primary_directory = args.primary
secondary_directory = args.secondary
if(args.verbose):
print(f"Comparing:\n{primary_directory}\nagainst:\n{secondary_directory}\n")

# hash algorythm (CRC32, MD5, SHA256)
if(not args.algorithm):
hash_algorithm = "CRC32"
else:
hash_algorithm = args.algorithm

# text markup
class bcolors:
HEADER = '\033[95m'
Expand Down Expand Up @@ -122,13 +84,13 @@ def main():
logging.info(f"-p {args.primary} -s {args.secondary} -a {args.algorithm} -d {args.disable} -m {args.missing} -n {args.nmissing} -v {args.verbose} -l {args.logging} -c {args.custom}")


# start time
# start time
start = time.time()

f1_amount = get_files_amount(primary_directory)
f2_amount = get_files_amount(secondary_directory)

# multithreading
# multithreading
if(args.disable):
# run without multithreading
if(args.verbose):
Expand All @@ -140,15 +102,15 @@ def main():
# use multithreading
if(args.verbose):
print(bcolors.UNDERLINE + "Running jobs with multithreading" + bcolors.ENDC)

pool = ThreadPool(processes=2)
async_result1 = pool.apply_async(folder_generate_hashes, args = (primary_directory, ))
async_result2 = pool.apply_async(folder_generate_hashes, args = (secondary_directory, ))

pool.close()
pool.join()

folder1_hashes = async_result1.get()
folder1_hashes = async_result1.get()
folder2_hashes = async_result2.get()

# check for missing files in primary directory
Expand Down Expand Up @@ -178,7 +140,7 @@ def main():
if relative_path not in folder2_hashes:
if(args.verbose):
print(bcolors.WARNING + f"{relative_path} is missing from {secondary_directory}." + bcolors.ENDC)
if(not args.logging):
if(not args.logging):
logging.info(f"[WARNING - MISSING FILE]: {relative_path}")
files_missing += 1
files_dir2_missing += 1
Expand Down Expand Up @@ -214,12 +176,50 @@ def main():
print(f"Process finished in {round(ct[0])} hours, {round(ct[1])} minutes, {round(ct[2])} seconds")
else:
print("\nProcess finished in {:.2f}".format(round((total_time), 2)) + " seconds")

print(f"Processed {files_amount} file(s): "
+ bcolors.OKGREEN + f"\n{files_completed} file(s) OK" + bcolors.ENDC
+ bcolors.FAIL + f"\n{files_errors} file(s) FAILED" + bcolors.ENDC
+ bcolors.WARNING + f"\n{files_missing} file(s) MISSING" + bcolors.ENDC)


if __name__ == '__main__':
parser = argparse.ArgumentParser(
prog='folder_hash_compare.py',
description='Compares the hashes of all files in 2 folders',
epilog='Folder Hash Compare - https://github.com/jooleer/folder-hash-compare')

parser.add_argument('-p', '--primary', help='Primary directory, f.e. -p \"C:\\folder1\\\" or -p \"/home/user/dir1\"')
parser.add_argument('-s', '--secondary', help='Secondary directory, f.e. -s \"D:\\folder2\\\" or -s \"/home/user/dir2\"')
parser.add_argument('-a', '--algorithm', help='Set algorithm: CRC32 (default), MD5, SHA256')
parser.add_argument('-d', '--disable', action='store_true', help='Disable multithreading (recommended when both directories are on the same drive)')
parser.add_argument('-m', '--missing', action='store_true', help='Search for missing files in secondary directory')
parser.add_argument('-n', '--nmissing', action='store_true', help='Search for missing files in primary directory')
parser.add_argument('-v', '--verbose', action='store_true', help='Enables verbose logging')
parser.add_argument('-l', '--logging', action='store_true', help='Disables logging to txt file in logs/ folder')
parser.add_argument('-c', '--custom', action='store_true', help='Use custom/hardcoded variables in stead of -p -s command-line arguments')


args = parser.parse_args()

# define the paths of the two directories to compare
if(args.custom):
primary_directory = r""
secondary_directory = r""
if(args.verbose):
print(f"Comparing:\n{primary_directory}\nagainst:\n{secondary_directory}\n")
else:
if(not args.primary) or (not args.secondary):
sys.exit("No primary or secondary folder given, use -h for help")
primary_directory = args.primary
secondary_directory = args.secondary
if(args.verbose):
print(f"Comparing:\n{primary_directory}\nagainst:\n{secondary_directory}\n")

# hash algorythm (CRC32, MD5, SHA256)
if(not args.algorithm):
hash_algorithm = "CRC32"
else:
hash_algorithm = args.algorithm

main()

0 comments on commit 072baf1

Please sign in to comment.