2 # vim: set ts=4 sts=4 sw=4 textwidth=112 :
6 def get_basename (name):
7 """Strips most kinds of endings from a filename"""
9 regex = '^(.+)\.(par2|vol\d+\+\d+|\d\d\d|part\d+|rar|zip|avi|mp4|mkv|ogm)$'
10 r = re.compile (regex, re.IGNORECASE)
17 g = r.match (name).groups()
23 def find_likely_files (name, dir):
24 """Finds files which are likely to be part of the set corresponding
25 to $name in the directory $dir"""
27 if not os.path.isdir (os.path.abspath (dir)):
28 raise ValueError # bad directory given
30 dir = os.path.abspath (dir)
31 ename = re.escape (name)
32 regex = re.compile ('^%s.*$' % (ename, ))
34 return [f for f in os.listdir (dir) if regex.match (f)]
36 def find_all_par2_files (dir):
37 """Finds all par2 files in a directory"""
39 if not os.path.isdir (os.path.abspath (dir)):
40 raise ValueError # bad directory given
42 dir = os.path.abspath (dir)
43 regex = re.compile ('^.*\.par2$', re.IGNORECASE)
46 return [f for f in os.listdir (dir) if regex.match (f)]
51 print find_all_par2_files ('/home/irasnyd/downloads/test_material/01/')
53 if __name__ == '__main__':