- return find_par2_files (files)
-
-def has_extension (f, ext):
- """Checks if f has the extension ext"""
-
- if ext[0] != '.':
- ext = '.' + ext
-
- ext = re.escape (ext)
- regex = re.compile ('^.*%s$' % (ext, ), re.IGNORECASE)
- return regex.match (f)
-
-def find_extraction_heads (dir, files):
- """Takes a list of possible files and finds likely heads of
- extraction."""
-
- # NOTE: perhaps this should happen AFTER repair is
- # NOTE: successful. That way all files would already exist
-
- # According to various sources online:
- # 1) pre rar-3.0: .rar .r00 .r01 ...
- # 2) post rar-3.0: .part01.rar .part02.rar
- # 3) zip all ver: .zip
-
- extractor = None
- p2files = find_par2_files (files)
-
- # Old RAR type, find all files ending in .rar
- if is_oldrar (files):
- extractor = RarslaveExtractor (TYPE_OLDRAR)
- regex = re.compile ('^.*\.rar$', re.IGNORECASE)
- for f in files:
- if regex.match (f):
- extractor.addHead (dir, f)
-
- if is_newrar (files):
- extractor = RarslaveExtractor (TYPE_NEWRAR)
- regex = re.compile ('^.*\.part01.rar$', re.IGNORECASE)
- for f in files:
- if regex.match (f):
- extractor.addHead (dir, f)
-
- if is_zip (files):
- extractor = RarslaveExtractor (TYPE_ZIP)
- regex = re.compile ('^.*\.zip$', re.IGNORECASE)
- for f in files:
- if regex.match (f):
- extractor.addHead (dir, f)
-
- if is_noextract (files):
- # Use the Par2 Parser (from cfv) here to find out what files are protected.
- # Since these are not being extracted, they will be mv'd to another directory
- # later.
- extractor = RarslaveExtractor (TYPE_NOEXTRACT)
-
- for f in p2files:
- done = False
- try:
- prot_files = par2parser.get_protected_files (dir, f)
- done = True
- except: #FIXME: add the actual exceptions
- print 'ERROR PARSING P2FILE ...', f
- continue
-
- if done:
- break
-
- if done:
- for f in prot_files:
- extractor.addHead (dir, f)
- else:
- print 'BADNESS'
-
- # Make sure we found the type
- assert extractor != None
-
- return extractor
-
-def is_oldrar (files):
- for f in files:
- if has_extension (f, '.r00'):
- return True
-
-def is_newrar (files):
- for f in files:
- if has_extension (f, '.part01.rar'):
- return True
-
-def is_zip (files):
- for f in files:
- if has_extension (f, '.zip'):
- return True
-
-def is_noextract (files):
- # Type that needs no extraction.
- # TODO: Add others ???
- for f in files:
- if has_extension (f, '.001'):
- return True
-
-def find_deleteable_files (files):
- # Deleteable types regex should come from the config
- dfiles = []
- dregex = re.compile ('^.*\.(par2|\d|\d\d\d|rar|r\d\d|zip)$', re.IGNORECASE)
-
- return [f for f in files if dregex.match (f)]
-
-def printlist (li):
- for f in li:
- print f
-
-class PAR2Set (object):
-
- dir = None
- file = None
- likely_files = []
-
- def __init__ (self, dir, file):
- assert os.path.isdir (dir)
- assert os.path.isfile (os.path.join (dir, file))