diff options
author | Benjamin Kiessling <mittagessen@l.unchti.me> | 2012-03-02 23:34:04 +0100 |
---|---|---|
committer | Benjamin Kiessling <mittagessen@l.unchti.me> | 2012-03-02 23:34:04 +0100 |
commit | 68d2362666f7349636bc597e203e278e7b5d4a1a (patch) | |
tree | cc319f6753fd6f6eb9e306839ba8049bf8f33ff6 /model_fs.js | |
parent | d45d56dfebe29b55ee1ee00b2f31e371134bc8a5 (diff) |
Add new logging module
Diffstat (limited to 'model_fs.js')
-rw-r--r-- | model_fs.js | 115 |
1 files changed, 64 insertions, 51 deletions
diff --git a/model_fs.js b/model_fs.js index 1a2dfbd..91234ba 100644 --- a/model_fs.js +++ b/model_fs.js @@ -11,20 +11,23 @@ var files = []; exports.start = function(config) { configuration = config; - if(typeof configuration.ignoreDotFiles !== 'undefined' && configuration.ignoreDotFiles == 'false') { + if(configuration.ignoreDotFiles == 'false') { watcher = require('watch-tree').watchTree(configuration.rootDir, {}); } else { watcher = require('watch-tree').watchTree(configuration.rootDir, {ignore: '.*'}); } - watcher.on('fileDeleted', exports.rebuildFiles); - watcher.on('fileCreated', exports.rebuildFiles); - watcher.on('fileModified', exports.rebuildFiles); - exports.rebuildFiles(); + if(typeof configuration.fetchInterval == 'number' && configuration.fetchInterval > 0) { + setInterval(fetchAllEvents, configuration.fetchInterval); + } + watcher.on('fileDeleted', rebuildFiles); + watcher.on('fileCreated', rebuildFiles); + watcher.on('fileModified', rebuildFiles); + rebuildFiles(); + setTimeout(fetchAllEvents, 2000); }; -exports.rebuildFiles = function() { - - console.log('rebuilding...'); +var rebuildFiles = function() { + configuration.logger.inf('Rebuilding slideset database...'); walker = walk.walk(configuration.rootDir, { followLinks: false }); var newSlides = {}; @@ -86,59 +89,69 @@ exports.rebuildFiles = function() { }); } collectDescs(slideset); - fetchEvents(slideset); + } + }); +}; + +var fetchAllEvents = function() { + configuration.logger.inf('Fetching all events...'); + exports.getAllSlides(function(Slides) { + for(var slideset in Slides) { + if(!Slides.hasOwnProperty(slideset)) { continue; } + fetchEvents(Slides[slideset]); } }); }; /* collect events and adds them to the slideset */ var fetchEvents = function(slideset) { + configuration.logger.inf('Fetching ' + slideset); fs.readFile(path.join(__dirname, configuration.rootDir, slideset, configuration.eventFile), function(err, data) { - if(err) { return; } - try { - var events = JSON.parse(data.toString()); - } catch(e) { - return; - } - if(events['type'] == 'text') { - setEvents(slideset, events['events'], function(err) { - if(err) { throw err; } - }); - } else if(events['type'] == 'ical') { - ical.fromURL(events['url'], {}, function(err, bloat) { - if(err) { throw err; } - var bDate = new Date(); - var fDate = new Date(); - bDate.setMinutes(bDate.getMinutes() - events['before']); - fDate.setMinutes(bDate.getMinutes() + events['after']); - var data = ical.events_between(bDate, fDate); - var compEv = []; - for (var k in data) { - if (!data.hasOwnProperty(k)) { continue; } - var ev = data[k]; - if(ev.start && ev.summary) { - var dateStr = ev.start.toLocaleDateString(); - ev.start = ev.start.toLocaleTimeString(); - ev.end = ev.end.toLocaleTimeString(); - delete ev.rrule; - delete ev.uid; - delete ev.type; - for(var i in ev) { - if(!ev.hasOwnProperty(i)) { continue; } - if(typeof ev[i] != 'string') { continue; } - ev[i] = ev[i].replace(/\\,/g, ','); - } - if(typeof compEv[dateStr] == "undefined") { - compEv[dateStr] = []; + if(err) { return; } + try { + var events = JSON.parse(data.toString()); + } catch(e) { + return; + } + if(events['type'] == 'text') { + setEvents(slideset, events['events'], function(err) { + if(err) { throw err; } + }); + } else if(events['type'] == 'ical') { + ical.fromURL(events['url'], {}, function(err, bloat) { + if(err) { throw err; } + var bDate = new Date(); + var fDate = new Date(); + bDate.setMinutes(bDate.getMinutes() - events['before']); + fDate.setMinutes(bDate.getMinutes() + events['after']); + var data = ical.events_between(bDate, fDate); + var compEv = []; + for (var k in data) { + if (!data.hasOwnProperty(k)) { continue; } + var ev = data[k]; + if(ev.start && ev.summary) { + var dateStr = ev.start.toLocaleDateString(); + ev.start = ev.start.toLocaleTimeString(); + ev.end = ev.end.toLocaleTimeString(); + delete ev.rrule; + delete ev.uid; + delete ev.type; + for(var i in ev) { + if(!ev.hasOwnProperty(i)) { continue; } + if(typeof ev[i] != 'string') { continue; } + ev[i] = ev[i].replace(/\\,/g, ','); + } + if(typeof compEv[dateStr] == "undefined") { + compEv[dateStr] = []; + } + compEv[dateStr].push(ev); } - compEv[dateStr].push(ev); } - } - setEvents(slideset, compEv, function(err) { - if(err) { throw err; } + setEvents(slideset, compEv, function(err) { + if(err) { throw err; } + }); }); - }); - } + } }); }; |