From 206027073c14ec1b6342fc17be0d5c0852dee537 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Fri, 13 Jul 2012 10:34:01 -0400 Subject: [PATCH] added some stat counting --- python_apps/media-monitor2/media/monitor/bootstrap.py | 8 ++++---- python_apps/media-monitor2/media/monitor/pure.py | 3 +-- python_apps/media-monitor2/media/monitor/syncdb.py | 4 ++-- python_apps/media-monitor2/media/monitor/watchersyncer.py | 4 ++++ python_apps/media-monitor2/mm2.py | 5 +++-- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/python_apps/media-monitor2/media/monitor/bootstrap.py b/python_apps/media-monitor2/media/monitor/bootstrap.py index ac18ab92f..7e27ca1c7 100644 --- a/python_apps/media-monitor2/media/monitor/bootstrap.py +++ b/python_apps/media-monitor2/media/monitor/bootstrap.py @@ -1,8 +1,8 @@ import os from pydispatch import dispatcher from media.monitor.events import OrganizeFile, NewFile, DeleteFile -import media.monitor.pure as mmp from media.monitor.log import Loggable +import media.monitor.pure as mmp class Bootstrapper(Loggable): """ @@ -34,8 +34,7 @@ class Bootstrapper(Loggable): file system """ songs = set() - modded = 0 - deleted = 0 + modded = deleted = 0 for pc in self.watch_channels: for f in mmp.walk_supported(pc.path, clean_empties=False): songs.add(f) @@ -44,7 +43,7 @@ class Bootstrapper(Loggable): dispatcher.send(signal=pc.signal, sender=self, event=DeleteFile(f)) dispatcher.send(signal=pc.signal, sender=self, event=NewFile(f)) # Want all files in the database that are not in the filesystem - for to_delete in (self.db - songs): + for to_delete in self.db.exclude(songs): for pc in self.watch_channels: if os.path.commonprefix([pc.path, to_delete]) == pc.path: dispatcher.send(signal=pc.signal, sender=self, event=DeleteFile(f)) @@ -57,3 +56,4 @@ class Bootstrapper(Loggable): self.logger.info("Flushed watch directories. (modified, deleted) = (%d, %d)" % (modded, deleted) ) + diff --git a/python_apps/media-monitor2/media/monitor/pure.py b/python_apps/media-monitor2/media/monitor/pure.py index 3282d2b21..aa0c962b9 100644 --- a/python_apps/media-monitor2/media/monitor/pure.py +++ b/python_apps/media-monitor2/media/monitor/pure.py @@ -8,7 +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? + NOTE: this decorator only works on methods and not functions. Maybe fix this? """ def __init__(self, *deco_args): self.exts = set([]) @@ -40,7 +40,6 @@ def clean_empty_dirs(path): if os.path.exists(d): if not os.listdir(d): os.removedirs(d) - def extension(path): """ return extension of path, empty string otherwise. Prefer diff --git a/python_apps/media-monitor2/media/monitor/syncdb.py b/python_apps/media-monitor2/media/monitor/syncdb.py index b5409915d..09f00aede 100644 --- a/python_apps/media-monitor2/media/monitor/syncdb.py +++ b/python_apps/media-monitor2/media/monitor/syncdb.py @@ -1,4 +1,4 @@ - +# -*- coding: utf-8 -*- class SyncDB(object): """ Represents the database returned by airtime_mvc. We do not use a list or some other @@ -6,7 +6,7 @@ class SyncDB(object): performance reasons later on. """ def __init__(self, source): - pass + self.source = source def has_file(self, path): return True def file_mdata(self, path): diff --git a/python_apps/media-monitor2/media/monitor/watchersyncer.py b/python_apps/media-monitor2/media/monitor/watchersyncer.py index ef3c8924e..202a04a63 100644 --- a/python_apps/media-monitor2/media/monitor/watchersyncer.py +++ b/python_apps/media-monitor2/media/monitor/watchersyncer.py @@ -7,6 +7,7 @@ from media.monitor.handler import ReportHandler from media.monitor.events import NewFile, DeleteFile from media.monitor.log import Loggable from media.monitor.exceptions import BadSongFile +from media.monitor.airtime import Request class RequestSync(threading.Thread,Loggable): def __init__(self, watcher, requests): @@ -15,7 +16,10 @@ class RequestSync(threading.Thread,Loggable): self.requests = requests def run(self): + # TODO : implement proper request sending self.logger.info("launching request with %d items." % len(self.requests)) + try: Request.serialize(self.requests).send() + except: self.logger.info("Failed to send request...") self.watcher.flag_done() class TimeoutWatcher(threading.Thread,Loggable): diff --git a/python_apps/media-monitor2/mm2.py b/python_apps/media-monitor2/mm2.py index 1b832cf84..4fc4b3fbb 100644 --- a/python_apps/media-monitor2/mm2.py +++ b/python_apps/media-monitor2/mm2.py @@ -7,7 +7,7 @@ from media.monitor.events import PathChannel from media.monitor.watchersyncer import WatchSyncer from media.monitor.handler import ProblemFileHandler from media.monitor.bootstrap import Bootstrapper -from media.monitor.syncdb import SyncDB +from media.monitor.airtime import DBDumper, Connection channels = { # note that org channel still has a 'watch' path because that is the path @@ -22,7 +22,8 @@ org = Organizer(channel=channels['org'],target_path=channels['watch'].path) watch = WatchSyncer(channel=channels['watch']) problem_files = ProblemFileHandler(channel=channels['badfile']) # do the bootstrapping before any listening is going one -db = SyncDB(None) +conn = Connection('localhost', 'more', 'shit', 'here') +db = DBDumper(conn).dump_block() bs = Bootstrapper(db, [channels['org']], [channels['watch']]) bs.flush_organize() bs.flush_watch()