Skip to content

Commit

Permalink
Fixed undupe not deleting any files, added undupe support for NSX (NS…
Browse files Browse the repository at this point in the history
…P files without Titlekeys) and fixed not whitelisting the first occurrence but undupe-whitelist any other occurrence not deleting the first occurrence
  • Loading branch information
nicoboss committed Oct 4, 2020
1 parent 0c1b2dd commit ef0fc74
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion nsz/FileExistingChecks.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def CreateTargetDict(targetFolder, parseCnmt, extension, filesAtTarget = {}, alr
for filePath in expandFiles(targetFolder):
try:
filePath_str = str(filePath)
if (isGame(filePath) or filePath.suffix == ".nspz") and (extension == None or filePath.suffix == extension):
if (isGame(filePath) or filePath.suffix == ".nspz" or filePath.suffix == ".nsx") and (extension == None or filePath.suffix == extension):
print(filePath)
Print.infoNoNewline('Extract TitleID/Version: {0} '.format(filePath.name))
filesAtTarget[filePath.name.lower()] = filePath_str
Expand Down
31 changes: 22 additions & 9 deletions nsz/undupe.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from pathlib import Path
from nsz.FileExistingChecks import CreateTargetDict
from nsz.nut import Print
from nsz.nut import Print
import os
import re

def isOnWhitelist(args, file):
if not args.undupe_whitelist == "" and re.match(args.undupe_whitelist, file):
if args.undupe_dryrun:
Print.info("[DRYRUN] [WHITELISTED]: " + file)
else:
Print.info("[WHITELISTED]: " + file)
#if args.undupe_dryrun:
# Print.info("[DRYRUN] [WHITELISTED]: " + file)
#else:
# Print.info("[WHITELISTED]: " + file)
return True
return False

Expand All @@ -29,7 +30,7 @@ def undupe(args):
if args.undupe_dryrun:
Print.info("[DRYRUN] [DELETE] [OLD_VERSION]: " + file)
else:
del file
os.remove(file)
Print.info("[DELETED] [OLD_VERSION]: " + file)
continue

Expand All @@ -41,7 +42,7 @@ def undupe(args):
if args.undupe_dryrun:
Print.info("[DRYRUN] [DELETE] [BLACKLIST]: " + file)
else:
del file
os.remove(file)
Print.info("[DRYRUN] [DELETED] [BLACKLIST]: " + file)

if not args.undupe_prioritylist == "":
Expand All @@ -51,13 +52,25 @@ def undupe(args):
if args.undupe_dryrun:
Print.info("[DRYRUN] [DELETE] [PRIORITYLIST]: " + file)
else:
del file
os.remove(file)
Print.info("[DRYRUN] [DELETED] [PRIORITYLIST]: " + file)

firstDeleted = False
for file in list(version_value[1:]):
if not isOnWhitelist(args, file):
if args.undupe_dryrun:
Print.info("[DRYRUN] [DELETE] [DUPE]: " + file)
Print.info("Keeping " + version_value[0])
else:
del file
os.remove(file)
Print.info("[DELETED] [DUPE]: " + file)
Print.info("Keeping " + version_value[0])
elif not firstDeleted and not isOnWhitelist(args, version_value[0]):
firstDeleted = True
if args.undupe_dryrun:
Print.info("[DRYRUN] [DELETE] [DUPE]: " + version_value[0])
Print.info("Keeping " + file)
else:
os.remove(version_value[0])
Print.info("[DELETED] [DUPE]: " + version_value[0])
Print.info("Keeping " + file)

0 comments on commit ef0fc74

Please sign in to comment.