summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChris Schlaeger <chris@linux.com>2014-07-22 21:06:57 +0200
committerChris Schlaeger <chris@linux.com>2014-07-22 21:06:57 +0200
commit18a4d27a9e9821c217fc22601b4363c36c31d079 (patch)
tree08d8a2bb15b986f00772dd3e9dbb2f76370b4bde /lib
parent595573ac0cd3b633e0cd22a002831ba388883289 (diff)
downloadpostrunner-18a4d27a9e9821c217fc22601b4363c36c31d079.zip
'delete' command implemented.
This command allows to remove activities from the DB. These will not be imported again.
Diffstat (limited to 'lib')
-rw-r--r--lib/postrunner/ActivitiesDB.rb27
-rw-r--r--lib/postrunner/Main.rb7
2 files changed, 26 insertions, 8 deletions
diff --git a/lib/postrunner/ActivitiesDB.rb b/lib/postrunner/ActivitiesDB.rb
index c8785fb..17e1760 100644
--- a/lib/postrunner/ActivitiesDB.rb
+++ b/lib/postrunner/ActivitiesDB.rb
@@ -42,6 +42,11 @@ module PostRunner
return false
end
+ if File.exists(File.join(@fit_dir, base_fit_file))
+ Log.debug "Activity #{fit_file} has been deleted before"
+ return false
+ end
+
begin
fit_activity = Fit4Ruby.read(fit_file)
rescue Fit4Ruby::Error
@@ -65,6 +70,12 @@ module PostRunner
true
end
+ def delete(fit_file)
+ base_fit_file = File.basename(fit_file)
+ index = @activities.index { |a| a.fit_file == base_fit_file }
+ @activities.delete_at(index)
+ sync
+ end
def rename(fit_file, name)
base_fit_file = File.basename(fit_file)
@@ -129,16 +140,16 @@ module PostRunner
end
def create_directories
- Log.info "Creating data directory #{@db_dir}"
- begin
- Dir.mkdir(@db_dir)
- rescue
- Log.fatal "Cannot create data directory #{@db_dir}: #{$!}"
- end
+ create_directory(@db_dir, 'data')
+ create_directory(@fit_dir, 'fit')
+ end
+
+ def create_directory(dir, name)
+ Log.info "Creating #{name} directory #{dir}"
begin
- Dir.mkdir(@fit_dir)
+ Dir.mkdir(dir)
rescue
- Log.fatal "Cannot create fit directory #{@fit_dir}: #{$!}"
+ Log.fatal "Cannot create #{name} directory #{dir}: #{$!}"
end
end
diff --git a/lib/postrunner/Main.rb b/lib/postrunner/Main.rb
index 7fb09f5..5187011 100644
--- a/lib/postrunner/Main.rb
+++ b/lib/postrunner/Main.rb
@@ -98,6 +98,9 @@ dump <fit file> | <ref>
import <fit file> | <directory>
Import the provided FIT file(s) into the postrunner database.
+delete <ref>
+ Delete the activity from the archive.
+
list
List all FIT files stored in the data base.
@@ -118,6 +121,8 @@ EOT
case (cmd = args.shift)
when 'check'
process_files_or_activities(args, :check)
+ when 'delete'
+ process_activities(args, :delete)
when 'dump'
@filter = Fit4Ruby::FitFilter.new unless @filter
process_files_or_activities(args, :dump)
@@ -188,6 +193,8 @@ EOT
def process_file(file, command)
case command
+ when :delete
+ @activities.delete(file)
when :import
@activities.add(file)
when :rename