示例#1
0
def CreateTargetDict(targetFolder, parseCnmt, extension):
    filesAtTarget = {}
    alreadyExists = {}
    for file in os.scandir(targetFolder):
        try:
            filePath = os.path.join(targetFolder, file)
            if file.name.endswith(extension):
                Print.infoNoNewline('Extract TitleID/Version: {0} '.format(
                    file.name))
                filesAtTarget[file.name.lower()] = filePath
                (titleID, version) = ExtractTitleIDAndVersion(file, True)
                titleIDEntry = alreadyExists.get(titleID)
                if titleIDEntry == None:
                    titleIDEntry = {version: {filePath}}
                elif not version in titleIDEntry:
                    titleIDEntry.add({version: {filePath}})
                else:
                    titleIDEntry[version].add(filePath)
                alreadyExists[titleID] = titleIDEntry
                Print.info('=> {0} {1}'.format(titleID, version))
        except BaseException as e:
            Print.info("")
            traceback.print_exc()
            Print.error('Error: ' + str(e))
    return (filesAtTarget, alreadyExists)
示例#2
0
def CreateTargetDict(targetFolder, extension):
    filesAtTarget = set()
    alreadyExists = {}
    for file in os.scandir(targetFolder):
        filePath = os.path.join(targetFolder, file)
        if file.name.endswith(extension):
            Print.infoNoNewline('Extract TitleID/Version: {0} '.format(
                file.name))
            filesAtTarget.add(file.name.lower())
            (titleID, version) = ExtractTitleIDAndVersion(file)
            titleIDEntry = alreadyExists.get(titleID)
            if titleIDEntry == None:
                titleIDEntry = {version: {filePath}}
            elif not version in titleIDEntry:
                titleIDEntry.add({version: {filePath}})
            else:
                titleIDEntry[version].add(filePath)
            alreadyExists[titleID] = titleIDEntry
            Print.info('=> {0} {1}'.format(titleID, version))
    return (filesAtTarget, alreadyExists)
示例#3
0
def CreateTargetDict(targetFolder, parseCnmt, extension):
    filesAtTarget = {}
    alreadyExists = {}
    for file in scandir(str(targetFolder)):
        try:
            filePath = Path(targetFolder).joinpath(file.name)
            filePath_str = str(filePath)
            if filePath.suffix == extension:
                Print.infoNoNewline('Extract TitleID/Version: {0} '.format(
                    file.name))
                filesAtTarget[file.name.lower()] = filePath_str
                extractedIdVersion = ExtractTitleIDAndVersion(file, parseCnmt)
                if extractedIdVersion == None:
                    if parseCnmt:
                        Print.error(
                            'Failed to extract TitleID/Version from booth filename "{0}" and Cnmt - Outdated keys.txt?'
                            .format(Path(filePath).name))
                    else:
                        Print.error(
                            'Failed to extract TitleID/Version from filename "{0}". Use -p to extract from Cnmt.'
                            .format(Path(filePath).name))
                    continue
                titleID, version = extractedIdVersion
                titleIDEntry = alreadyExists.get(titleID)
                if titleIDEntry == None:
                    titleIDEntry = {version: [filePath_str]}
                elif not version in titleIDEntry:
                    titleIDEntry[version] = [filePath_str]
                else:
                    titleIDEntry[version].append(filePath_str)
                alreadyExists[titleID] = titleIDEntry
                Print.info('=> {0} {1}'.format(titleID, version))
        except BaseException as e:
            Print.info("")
            print_exc()
            Print.error('Error: ' + str(e))
    return (filesAtTarget, alreadyExists)