Added more verbose error logging to flv conversion script, and ensured that the ...
[recordtv.git] / src / rtv_delete.py
blobd41fe768a0208e897cac4f755b31ca3c7c9fe82e
1 #!/usr/bin/python
3 import os
4 import shutil
5 import rtv_utils
7 def _delete_file( base_dir, filename ):
8 fullpath = os.path.join( base_dir, filename )
9 print "Deleting '%s'." % fullpath
10 os.remove( fullpath )
12 def collect_walk_no_slashes( top_dir ):
13 len_top_dir = len( top_dir ) + 1
14 ret = {}
15 for ( dirpath, dirnames, filenames ) in os.walk( top_dir ):
16 for filename in filenames:
17 filepath = os.path.join( dirpath[len_top_dir:], filename )
18 filepath_noslashes = filepath.replace( "/", "_" )
19 ret[filepath_noslashes] = filepath
20 return ret
22 def delete( config ):
24 deleted_dir = os.path.join( config.converted_progs_dir, "deleted" )
26 rtv_utils.ensure_dir_exists( deleted_dir )
28 noslash_to_real = collect_walk_no_slashes( config.converted_progs_dir )
29 noslash_filenames = noslash_to_real.keys()
31 old_dir = os.path.join( config.recorded_progs_dir, "old" )
33 for fn in os.listdir( deleted_dir ):
34 if fn in noslash_filenames:
35 _delete_file( config.converted_progs_dir, noslash_to_real[fn] )
37 rtvinfo_fn = fn[ : fn.rfind( "." ) ] + ".rtvinfo"
38 if rtvinfo_fn in noslash_filenames:
40 # Move the old .rtvinfo file into the old directory
41 # so we can avoid re-recording things that we've
42 # already seen and deleted.
43 rtv_utils.ensure_dir_exists( old_dir )
45 rtvinfo_fullpath = os.path.join( config.converted_progs_dir,
46 noslash_to_real[rtvinfo_fn] )
48 print "mv %s -> %s" % ( rtvinfo_fullpath, old_dir )
49 shutil.move( rtvinfo_fullpath, old_dir )
51 fn_fullpath = os.path.join( deleted_dir, fn )
52 print "rm %s" % fn_fullpath
53 os.remove( fn_fullpath )