summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2010-09-28 10:47:17 -0700
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2010-09-28 10:47:17 -0700
commit58789b9d5107a1e3ab73e3f3e0bfe810a2ae8b36 (patch)
tree7ead9af94b76464ed76ec5538f524068edfe1b32
parent6ee13289bdf6bdb32f2765e469ea5dabaa6643d7 (diff)
downloadlognotify-58789b9d5107a1e3ab73e3f3e0bfe810a2ae8b36.tar.gz
lognotify-58789b9d5107a1e3ab73e3f3e0bfe810a2ae8b36.tar.xz
Create cache directory/file if nonexistent.
-rwxr-xr-xlognotify.rb20
1 files 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