Allowed files inside the Wii directory to live in subdirs. Supports deleting them...
[recordtv.git] / src / rtv_delete.py
blobbf5e643007950c5aa4a4ac40b37f485034d77844
1 #!/usr/bin/python
3 import os
5 def _delete_file( base_dir, filename ):
6 print "Deleting '%s'." % filename
7 os.remove( os.path.join( base_dir, filename ) )
9 def collect_walk_no_slashes( top_dir ):
10 len_top_dir = len( top_dir ) + 1
11 ret = {}
12 for ( dirpath, dirnames, filenames ) in os.walk( top_dir ):
13 for filename in filenames:
14 filepath = os.path.join( dirpath[len_top_dir:], filename )
15 filepath_noslashes = filepath.replace( "/", "_" )
16 ret[filepath_noslashes] = filepath
17 return ret
19 def delete( config ):
21 deleted_dir = os.path.join( config.converted_progs_dir, "deleted" )
23 noslash_to_real = collect_walk_no_slashes( config.converted_progs_dir )
24 noslash_filenames = noslash_to_real.keys()
26 for fn in os.listdir( deleted_dir ):
27 if fn in noslash_filenames:
28 _delete_file( config.converted_progs_dir, noslash_to_real[fn] )
30 rtfinfo_fn = fn[ : fn.rfind( "." ) ] + ".rtvinfo"
31 if rtfinfo_fn in noslash_filenames:
32 os.remove( os.path.join( config.converted_progs_dir, noslash_to_real[rtfinfo_fn] ) )
33 #print "rm " + os.path.join( config.converted_progs_dir, noslash_to_real[rtfinfo_fn] )
35 os.remove( os.path.join( deleted_dir, fn ) )
36 #print "rm " + os.path.join( deleted_dir, fn )