From 58789b9d5107a1e3ab73e3f3e0bfe810a2ae8b36 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Tue, 28 Sep 2010 10:47:17 -0700 Subject: Create cache directory/file if nonexistent. --- lognotify.rb | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lognotify.rb b/lognotify.rb index 3e26b5b..8996869 100755 --- a/lognotify.rb +++ b/lognotify.rb @@ -7,6 +7,8 @@ # Distributed under the terms of the GNU General Public License v3. # See http://www.gnu.org/licenses/gpl.txt for the full license text. +require 'ftools' + CACHE_DIR="~/.cache/lognotify" CONFIG_DIR="~/.config/lognotify" @@ -51,8 +53,8 @@ end # Append new lines to cached log. def append_lines identifier, lines - filepath = File.expand_path(CACHE_DIR + '/' + identifier + '.log') - file = File.open(filepath, 'a') + path = File.expand_path(CACHE_DIR + '/' + identifier + '.log') + file = File.open(path, 'a') file.print lines file.close @@ -61,10 +63,24 @@ end # Output all messages immediately, as opposed to buffering. STDOUT.sync = true +# Create cache directory, if nonexistent. +path = File.expand_path(CACHE_DIR) +unless File.directory?(path) + File.makedirs(path) + puts 'Done' +end + # Treat each argument as a log identifier. ARGV.each do |identifier| conf = parse(identifier) + # Create cache file, if nonexistent. + path = File.expand_path(CACHE_DIR + '/' + identifier + '.log') + unless File.exist?(path) + File.open(path, 'w').close + puts 'Done' + end + print '* Counting lines in cached log... ' lines = count_lines(identifier) puts lines -- cgit v1.2.3-70-g09d2