示例#1
0
 def archive_list(self, filename):
     """Test archive listing."""
     archive = os.path.join(datadir, filename)
     for verbosity in (-1, 0, 1, 2):
         patoolib.list_archive(archive,
                               program=self.program,
                               verbosity=verbosity)
示例#2
0
def getArchiveMembers(fileName):
    import patoolib

    try:
        patoolib.test_archive(fileName, verbosity=-1)
        print "<ArchiveMembers>"
        patoolib.list_archive(fileName)
        print "</ArchiveMembers>"
    except:
        pass
示例#3
0
def getArchiveMembers(fileName):
    import patoolib
    
    try:
        patoolib.test_archive(fileName, verbosity=-1)
        print "<ArchiveMembers>"
        patoolib.list_archive(fileName)
        print "</ArchiveMembers>"
    except:
        pass
示例#4
0
def run_list(args):
    """List files in archive(s)."""
    res = 0
    for archive in args.archive:
        try:
            # increase default verbosity since the listing output should be visible
            verbosity = args.verbosity + 1
            patoolib.list_archive(archive,
                                  verbosity=verbosity,
                                  interactive=args.interactive,
                                  password=args.password)
        except PatoolError as msg:
            log_error("error listing %s: %s" % (archive, msg))
            res += 1
    return res
示例#5
0
 def archive_list (self, filename):
     """Test archive listing."""
     archive = os.path.join(datadir, filename)
     for verbosity in (-1, 0, 1, 2):
         patoolib.list_archive(archive, program=self.program, verbosity=verbosity)
def _test_patool(file_path):
    archive_format = patoolib.get_archive_format(file_path)
    rv = patoolib.test_archive(file_path)

    contents = patoolib.list_archive(file_path)
    return contents
示例#7
0
def scanroms(locations, types=None):
    if not types:
        types = ['.7z', '.zip']
    romfiles = {}
    allfiles = []
    for location in locations:
        for typ in types:
            allfiles.extend(glob.glob(f'{location}\\**\\*{typ}'))
    for allfile in tqdm(allfiles, desc='rom files', unit='file'):
        listed = None
        try:
            listed = patoolib.list_archive(allfile, verbosity=-1)
        except Exception as e:
            print(e)
            print(f'Bad rom file {allfile}')
            continue
        lines = listed.splitlines()
        started = False
        last = []
        headers = []
        offsets = [0]
        fileinfo = {}
        fileinfo['path'] = allfile
        fileinfo['files'] = {}
        for line in lines:
            line = str(line, 'utf-8')
            parts = line.split()
            dividers = True
            for part in parts:
                if not part.startswith('-'):
                    dividers = False
                    break
            if not started and len(parts) > 4:
                if dividers:
                    headers = last
                    validheaders = [
                        'Date', 'Time', 'Attr', 'Size', 'Compressed', 'Name'
                    ]
                    if not len(headers) == len(validheaders):
                        print(
                            f'Headers {headers} do not match valid headers {validheaders}'
                        )
                        exit()
                    for validheader in validheaders:
                        if not validheader in headers:
                            print(
                                f'Header {validheader} is not in headers: {headers}'
                            )
                            exit()
                    offsets.append(11)
                    offsets.append(20)
                    for part in parts[1:len(headers) - 2]:
                        lastoffset = offsets[-1]
                        lastoffset += len(part) + 1
                        offsets.append(lastoffset)
                    offsets[-1] = offsets[-1] + 1
                    started = True
                    continue
            if started:
                if dividers:
                    break
                info = {}
                for index, offset in enumerate(offsets):
                    begin = offset
                    end = len(line)
                    if index + 1 < len(offsets):
                        end = offsets[index + 1]
                    subline = line[begin:end]
                    if index < len(offsets) - 1:
                        subline = subline.strip()
                    if subline.strip() == '':
                        continue
                    info[headers[index]] = subline
                subname = info['Name']
                fileinfo['files'][subname] = info

            else:
                last = parts
        romfiles[allfile] = fileinfo
    return romfiles