From f9a1af1c1c2414f30d6f32d989a0e72b5fede03c Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Thu, 12 Jul 2012 11:32:08 -0400 Subject: [PATCH] fixed clean empty dirs --- python_apps/media-monitor2/dispatch.py | 15 --------------- python_apps/media-monitor2/media/monitor/pure.py | 13 ++++++++----- 2 files changed, 8 insertions(+), 20 deletions(-) delete mode 100644 python_apps/media-monitor2/dispatch.py diff --git a/python_apps/media-monitor2/dispatch.py b/python_apps/media-monitor2/dispatch.py deleted file mode 100644 index 18400f6f1..000000000 --- a/python_apps/media-monitor2/dispatch.py +++ /dev/null @@ -1,15 +0,0 @@ -from pydispatch import dispatcher -SIGNAL = 'my-first-signal' - -def handle_event( sender ): - """Simple event handler""" - print 'Signal was sent by', sender -dispatcher.connect( handle_event, signal=SIGNAL, sender=dispatcher.Any ) - -first_sender = object() -second_sender = {} -def main( ): - dispatcher.send( signal=SIGNAL, sender=first_sender ) - dispatcher.send( signal=SIGNAL, sender=second_sender ) - -main() diff --git a/python_apps/media-monitor2/media/monitor/pure.py b/python_apps/media-monitor2/media/monitor/pure.py index a1670ccb5..3282d2b21 100644 --- a/python_apps/media-monitor2/media/monitor/pure.py +++ b/python_apps/media-monitor2/media/monitor/pure.py @@ -8,6 +8,7 @@ unicode_unknown = u'unknown' class IncludeOnly(object): """ A little decorator to help listeners only be called on extensions they support + NOTE: this decorator only works on methods and not functions. maybe fix this? """ def __init__(self, *deco_args): self.exts = set([]) @@ -24,7 +25,6 @@ class IncludeOnly(object): def is_file_supported(path): return extension(path) in supported_extensions - # In the future we would like a better way to find out # whether a show has been recorded def is_airtime_recorded(md): @@ -32,10 +32,13 @@ def is_airtime_recorded(md): def clean_empty_dirs(path): """ walks path and deletes every empty directory it finds """ - for root, dirs, _ in os.walk(path): - full_paths = ( os.path.join(root, d) for d in dirs ) - for d in full_paths: - if not os.listdir(d): os.rmdir(d) + if path.endswith('/'): clean_empty_dirs(path[0:-1]) + else: + for root, dirs, _ in os.walk(path, topdown=False): + full_paths = ( os.path.join(root, d) for d in dirs ) + for d in full_paths: + if os.path.exists(d): + if not os.listdir(d): os.removedirs(d) def extension(path):