from rarslave import *
class rarslavetest (unittest.TestCase):
+
+ def assertListEquals (self, l1, l2):
+ if l1 is l2:
+ return True
+
+ self.assertEquals (len(l1), len(l2))
+
+ for e in l1:
+ if e not in l2:
+ self.fail ("Element missing from list")
+
+ return True
+
def setUp (self):
pass
self.assertFalse (has_extension (FILE, '.part01'))
self.assertFalse (has_extension (FILE, 'part01'))
+ def testIsNewRar (self):
+ DIR = '/home/irasnyd/downloads/test_material/01/'
+
+ self.assertTrue (is_newrar (os.listdir (DIR)))
+
+ def testDeletableFiles1 (self):
+ FILES = ['test.part%d.rar' % n for n in xrange(10)]
+
+ self.assertListEquals (find_deleteable_files (FILES), FILES)
+
+ def testDeletableFiles2 (self):
+ FILESN = ['%d.mp3' % n for n in xrange(20)]
+ FILESY = ['%d.zip' % n for n in xrange(5)]
+
+ self.assertListEquals (find_deleteable_files (FILESN + FILESY), FILESY)
+
if __name__ == '__main__':
unittest.main ()
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 extract (heads, todir):
+ # Try to extract each head
+ # NOTE: REQUIRES full paths to heads
+
+ PWD = os.getcwd()
+
+ # FIXME: Should come from the config
+ RCMD = 'unrar x -o+ -- '
+ ZCMD = 'unzip -- '
+
+ for h in heads:
+ # find type
+ # extract it
+
+ # NOTE: probably not able to clean up effectively...
+ pass
+
+
def main ():
print find_all_par2_files ('/home/irasnyd/downloads/test_material/01/')