added some stat counting
This commit is contained in:
parent
832401704a
commit
309b071142
5 changed files with 14 additions and 10 deletions
|
@ -1,8 +1,8 @@
|
||||||
import os
|
import os
|
||||||
from pydispatch import dispatcher
|
from pydispatch import dispatcher
|
||||||
from media.monitor.events import OrganizeFile, NewFile, DeleteFile
|
from media.monitor.events import OrganizeFile, NewFile, DeleteFile
|
||||||
import media.monitor.pure as mmp
|
|
||||||
from media.monitor.log import Loggable
|
from media.monitor.log import Loggable
|
||||||
|
import media.monitor.pure as mmp
|
||||||
|
|
||||||
class Bootstrapper(Loggable):
|
class Bootstrapper(Loggable):
|
||||||
"""
|
"""
|
||||||
|
@ -34,8 +34,7 @@ class Bootstrapper(Loggable):
|
||||||
file system
|
file system
|
||||||
"""
|
"""
|
||||||
songs = set()
|
songs = set()
|
||||||
modded = 0
|
modded = deleted = 0
|
||||||
deleted = 0
|
|
||||||
for pc in self.watch_channels:
|
for pc in self.watch_channels:
|
||||||
for f in mmp.walk_supported(pc.path, clean_empties=False):
|
for f in mmp.walk_supported(pc.path, clean_empties=False):
|
||||||
songs.add(f)
|
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=DeleteFile(f))
|
||||||
dispatcher.send(signal=pc.signal, sender=self, event=NewFile(f))
|
dispatcher.send(signal=pc.signal, sender=self, event=NewFile(f))
|
||||||
# Want all files in the database that are not in the filesystem
|
# 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:
|
for pc in self.watch_channels:
|
||||||
if os.path.commonprefix([pc.path, to_delete]) == pc.path:
|
if os.path.commonprefix([pc.path, to_delete]) == pc.path:
|
||||||
dispatcher.send(signal=pc.signal, sender=self, event=DeleteFile(f))
|
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)"
|
self.logger.info("Flushed watch directories. (modified, deleted) = (%d, %d)"
|
||||||
% (modded, deleted) )
|
% (modded, deleted) )
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ unicode_unknown = u'unknown'
|
||||||
class IncludeOnly(object):
|
class IncludeOnly(object):
|
||||||
"""
|
"""
|
||||||
A little decorator to help listeners only be called on extensions they support
|
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):
|
def __init__(self, *deco_args):
|
||||||
self.exts = set([])
|
self.exts = set([])
|
||||||
|
@ -40,7 +40,6 @@ def clean_empty_dirs(path):
|
||||||
if os.path.exists(d):
|
if os.path.exists(d):
|
||||||
if not os.listdir(d): os.removedirs(d)
|
if not os.listdir(d): os.removedirs(d)
|
||||||
|
|
||||||
|
|
||||||
def extension(path):
|
def extension(path):
|
||||||
"""
|
"""
|
||||||
return extension of path, empty string otherwise. Prefer
|
return extension of path, empty string otherwise. Prefer
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
class SyncDB(object):
|
class SyncDB(object):
|
||||||
"""
|
"""
|
||||||
Represents the database returned by airtime_mvc. We do not use a list or some other
|
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.
|
performance reasons later on.
|
||||||
"""
|
"""
|
||||||
def __init__(self, source):
|
def __init__(self, source):
|
||||||
pass
|
self.source = source
|
||||||
def has_file(self, path):
|
def has_file(self, path):
|
||||||
return True
|
return True
|
||||||
def file_mdata(self, path):
|
def file_mdata(self, path):
|
||||||
|
|
|
@ -7,6 +7,7 @@ from media.monitor.handler import ReportHandler
|
||||||
from media.monitor.events import NewFile, DeleteFile
|
from media.monitor.events import NewFile, DeleteFile
|
||||||
from media.monitor.log import Loggable
|
from media.monitor.log import Loggable
|
||||||
from media.monitor.exceptions import BadSongFile
|
from media.monitor.exceptions import BadSongFile
|
||||||
|
from media.monitor.airtime import Request
|
||||||
|
|
||||||
class RequestSync(threading.Thread,Loggable):
|
class RequestSync(threading.Thread,Loggable):
|
||||||
def __init__(self, watcher, requests):
|
def __init__(self, watcher, requests):
|
||||||
|
@ -15,7 +16,10 @@ class RequestSync(threading.Thread,Loggable):
|
||||||
self.requests = requests
|
self.requests = requests
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
# TODO : implement proper request sending
|
||||||
self.logger.info("launching request with %d items." % len(self.requests))
|
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()
|
self.watcher.flag_done()
|
||||||
|
|
||||||
class TimeoutWatcher(threading.Thread,Loggable):
|
class TimeoutWatcher(threading.Thread,Loggable):
|
||||||
|
|
|
@ -7,7 +7,7 @@ from media.monitor.events import PathChannel
|
||||||
from media.monitor.watchersyncer import WatchSyncer
|
from media.monitor.watchersyncer import WatchSyncer
|
||||||
from media.monitor.handler import ProblemFileHandler
|
from media.monitor.handler import ProblemFileHandler
|
||||||
from media.monitor.bootstrap import Bootstrapper
|
from media.monitor.bootstrap import Bootstrapper
|
||||||
from media.monitor.syncdb import SyncDB
|
from media.monitor.airtime import DBDumper, Connection
|
||||||
|
|
||||||
channels = {
|
channels = {
|
||||||
# note that org channel still has a 'watch' path because that is the path
|
# 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'])
|
watch = WatchSyncer(channel=channels['watch'])
|
||||||
problem_files = ProblemFileHandler(channel=channels['badfile'])
|
problem_files = ProblemFileHandler(channel=channels['badfile'])
|
||||||
# do the bootstrapping before any listening is going one
|
# 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 = Bootstrapper(db, [channels['org']], [channels['watch']])
|
||||||
bs.flush_organize()
|
bs.flush_organize()
|
||||||
bs.flush_watch()
|
bs.flush_watch()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue