cc-4105: hooked last run feature into mm2
This commit is contained in:
parent
50116fa6bb
commit
84313a6135
|
@ -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_run,org_channels,watch_channels):
|
||||
def __init__(self,db,last_ran,org_channels,watch_channels):
|
||||
self.db = db
|
||||
self.org_channels = org_channels
|
||||
self.watch_channels = watch_channels
|
||||
self.last_run = last_run
|
||||
self.last_ran = last_ran
|
||||
|
||||
def flush_organize(self):
|
||||
"""
|
||||
|
@ -44,11 +44,11 @@ class Bootstrapper(Loggable):
|
|||
songs[ pc.path ].add(f)
|
||||
# We decide whether to update a file's metadata by checking
|
||||
# its system modification date. If it's above the value
|
||||
# self.last_run which is passed to us that means media monitor
|
||||
# self.last_ran which is passed to us that means media monitor
|
||||
# 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_run:
|
||||
if os.path.getmtime(f) > self.last_ran:
|
||||
modded += 1
|
||||
dispatcher.send(signal=pc.signal, sender=self, event=DeleteFile(f))
|
||||
dispatcher.send(signal=pc.signal, sender=self, event=NewFile(f))
|
||||
|
|
|
@ -3,13 +3,11 @@ import os
|
|||
from configobj import ConfigObj
|
||||
import copy
|
||||
|
||||
from media.monitor.log import Loggable
|
||||
from media.monitor.exceptions import NoConfigFile, ConfigAccessViolation
|
||||
|
||||
class MMConfig(Loggable):
|
||||
class MMConfig(object):
|
||||
def __init__(self, path):
|
||||
if not os.path.exists(path):
|
||||
self.logger.error("Configuration file does not exist. Path: '%s'" % path)
|
||||
raise NoConfigFile(path)
|
||||
self.cfg = ConfigObj(path)
|
||||
|
||||
|
|
|
@ -277,6 +277,16 @@ def fondle(path,times=None):
|
|||
with file(path, 'a'):
|
||||
os.utime(path, times)
|
||||
|
||||
def last_modified(path):
|
||||
"""
|
||||
return the time of the last time mm2 was ran. path refers to the index file whose
|
||||
date modified attribute contains this information. In the case when the file does not
|
||||
exist we set this time 0 so that any files on the filesystem were modified after it
|
||||
"""
|
||||
if os.path.exists(path):
|
||||
os.path.gmtime(path)
|
||||
else: 0
|
||||
|
||||
if __name__ == '__main__':
|
||||
import doctest
|
||||
doctest.testmod()
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import pyinotify
|
||||
import time
|
||||
import sys
|
||||
import os
|
||||
from media.monitor.listeners import OrganizeListener, StoreWatchListener
|
||||
|
@ -11,6 +10,7 @@ from media.monitor.handler import ProblemFileHandler
|
|||
from media.monitor.bootstrap import Bootstrapper
|
||||
from media.monitor.log import get_logger
|
||||
from media.monitor.config import MMConfig
|
||||
from media.monitor.toucher import ToucherThread
|
||||
from media.monitor.syncdb import SyncDB
|
||||
from media.monitor.exceptions import FailedToObtainLocale, FailedToSetLocale, NoConfigFile
|
||||
from media.monitor.airtime import AirtimeNotifier, AirtimeMessageReceiver
|
||||
|
@ -59,6 +59,7 @@ apiclient = apc.AirtimeApiClient(log)
|
|||
# We initialize sdb before anything because we must know what our watched
|
||||
# directories are.
|
||||
sdb = SyncDB(apiclient)
|
||||
|
||||
for watch_dir in sdb.list_directories():
|
||||
if not os.path.exists(watch_dir):
|
||||
# Create the watch_directory here
|
||||
|
@ -79,7 +80,7 @@ problem_files = ProblemFileHandler(channel=channels['badfile'])
|
|||
# values in channels lists later on
|
||||
# TODO : get the actual last running time instead of using the current time
|
||||
# like now
|
||||
bs = Bootstrapper(db=sdb, last_run=int(time.time()), org_channels=[channels['org']], watch_channels=channels['watch'])
|
||||
bs = Bootstrapper(db=sdb, last_ran=mmp.last_modified(config['index_path']), org_channels=[channels['org']], watch_channels=channels['watch'])
|
||||
|
||||
bs.flush_organize()
|
||||
bs.flush_watch()
|
||||
|
@ -105,5 +106,9 @@ for pc in channels['watch']:
|
|||
airtime_receiver = AirtimeMessageReceiver(config)
|
||||
airtime_notifier = AirtimeNotifier(config, airtime_receiver)
|
||||
|
||||
# Launch the toucher that updates the last time when the script was ran every
|
||||
# n seconds.
|
||||
tt = ToucherThread(path=config['index_path'], interval=config['touch_interval'])
|
||||
|
||||
notifier.loop()
|
||||
|
||||
|
|
Loading…
Reference in New Issue