cc-4105. Refactored syncdb and fixed a few typos

This commit is contained in:
root 2012-07-20 15:37:13 -04:00 committed by Rudi Grinberg
parent 9964c826ab
commit 3e251997f8
6 changed files with 53 additions and 28 deletions

View file

@ -9,11 +9,11 @@ class Bootstrapper(Loggable):
Bootstrapper reads all the info in the filesystem flushes organize
events and watch events
"""
def __init__(self,db,last_ran,org_channels,watch_channels):
def __init__(self,db,last_run,org_channels,watch_channels):
self.db = db
self.org_channels = org_channels
self.watch_channels = watch_channels
self.last_ran = last_ran
self.last_run = last_run
def flush_organize(self):
"""
@ -44,12 +44,12 @@ class Bootstrapper(Loggable):
# wasn't aware when this changes occured in the filesystem
# hence it will send the correct events to sync the database
# with the filesystem
if os.path.getmtime(f) > self.last_ran:
if os.path.getmtime(f) > self.last_run:
modded += 1
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.exclude(songs):
for to_delete in self.db.difference(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,9 +57,8 @@ class Bootstrapper(Loggable):
deleted += 1
break
else:
self.logger.info("Error, could not find watch directory of would be deleted \
file '%s'" % to_delete)
self.logger.info("Flushed watch directories. (modified, deleted) = (%d, %d)"
self.logger.info("Error, could not find watch directory of would be deleted file '%s'" % to_delete)
self.logger.info( "Flushed watch directories. (modified, deleted) = (%d, %d)"
% (modded, deleted) )

View file

@ -2,7 +2,7 @@
import os
import abc
from media.monitor.pure import LazyProperty
from media.monitor.monitor import Metadata
from media.monitor.metadata import Metadata
class PathChannel(object):
"""a dumb struct; python has no record types"""

View file

@ -13,3 +13,6 @@ class Loggable(object):
# TODO : Clean this up
if not hasattr(self,"_logger"): self._logger = logging.getLogger('mediamonitor2')
return self._logger
def get_logger():
return logging.getLogger('mediamonitor2')

View file

@ -1,13 +1,27 @@
# -*- coding: utf-8 -*-
class SyncDB(object):
"""
Represents the database returned by airtime_mvc. We do not use a list or some other
fixed data structure because we might want to change the internal representation for
performance reasons later on.
"""
def __init__(self, source):
self.source = source
def has_file(self, path):
return True
def file_mdata(self, path):
return None
from media.monitor.log import Loggable
class SyncDB(Loggable):
def __init__(self, apc):
self.apc = apc
dirs = self.apc.list_all_watched_dirs()
directories = None
try:
directories = dirs['dirs']
except KeyError as e:
self.logger.error("Could not find index 'dirs' in dictionary: %s", str(dirs))
self.logger.error(e)
raise
# self.directories is a dictionary where a key is the directory and the
# value is the directory's id in the db
self.directories = dict( (v,k) for k,v in directories.iteritems() )
def list_directories(self):
return self.directories.keys()
def directory_get_files(self, directory):
print("trying to access dir id: %s" % self.directories[directory])
self.apc.list_all_db_files(self.directories[directory])