forked from nicoboss/nsz
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented undupe, undupe-dryrun, undupe-prioritylist, undupe-whitel…
…ist and undupe-old-versions to remove duplicate games
- Loading branch information
Showing
5 changed files
with
82 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
from pathlib import Path | ||
from nsz.FileExistingChecks import CreateTargetDict | ||
from nsz.nut import Print | ||
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) | ||
return True | ||
return False | ||
|
||
def undupe(args): | ||
filesAtTarget = {} | ||
alreadyExists = {} | ||
for f_str in args.file: | ||
(filesAtTarget, alreadyExists) = CreateTargetDict(Path(f_str).absolute(), True, None, filesAtTarget, alreadyExists) | ||
Print.info("") | ||
|
||
for (titleID_key, titleID_value) in alreadyExists.items(): | ||
maxVersion = max(titleID_value.keys()) | ||
for (version_key, version_value) in titleID_value.items(): | ||
|
||
if args.undupe_old_versions and version_key < maxVersion: | ||
for file in list(version_value): | ||
if not isOnWhitelist(args, file): | ||
if args.undupe_dryrun: | ||
Print.info("[DRYRUN] [DELETE] [OLD_VERSION]: " + file) | ||
else: | ||
del file | ||
Print.info("[DELETED] [OLD_VERSION]: " + file) | ||
continue | ||
|
||
|
||
if not args.undupe_blacklist == "": | ||
for file in list(version_value): | ||
if not isOnWhitelist(args, file) and re.match(args.undupe_blacklist, file): | ||
version_value.remove(file) | ||
if args.undupe_dryrun: | ||
Print.info("[DRYRUN] [DELETE] [BLACKLIST]: " + file) | ||
else: | ||
del file | ||
Print.info("[DRYRUN] [DELETED] [BLACKLIST]: " + file) | ||
|
||
if not args.undupe_prioritylist == "": | ||
for file in list(version_value.reverse()): | ||
if len(version_value) > 1 and not isOnWhitelisth(args, file) and re.match(args.undupe_prioritylist, file): | ||
version_value.remove(file) | ||
if args.undupe_dryrun: | ||
Print.info("[DRYRUN] [DELETE] [PRIORITYLIST]: " + file) | ||
else: | ||
del file | ||
Print.info("[DRYRUN] [DELETED] [PRIORITYLIST]: " + file) | ||
|
||
for file in list(version_value[1:]): | ||
if not isOnWhitelist(args, file): | ||
if args.undupe_dryrun: | ||
Print.info("[DRYRUN] [DELETE] [DUPE]: " + file) | ||
else: | ||
del file | ||
Print.info("[DELETED] [DUPE]: " + file) |