summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Schlaeger <chris@linux.com>2015-03-29 09:26:23 +0200
committerChris Schlaeger <chris@linux.com>2015-03-29 09:26:23 +0200
commit90be2e3000c932b878772702027f94b09640492c (patch)
treea9bb1a7c0ad9c240696b59cc6c0486bd69609623
parente46aa0d865ae28afae415a5608bcd81b0188455b (diff)
downloadpostrunner-90be2e3000c932b878772702027f94b09640492c.zip
Update auxilliary HTML files on version updates.
-rw-r--r--lib/postrunner/ActivitiesDB.rb22
-rw-r--r--lib/postrunner/Main.rb16
2 files changed, 31 insertions, 7 deletions
diff --git a/lib/postrunner/ActivitiesDB.rb b/lib/postrunner/ActivitiesDB.rb
index f97820b..559a8e5 100644
--- a/lib/postrunner/ActivitiesDB.rb
+++ b/lib/postrunner/ActivitiesDB.rb
@@ -29,6 +29,7 @@ module PostRunner
@cfg = cfg
@fit_dir = File.join(@db_dir, 'fit')
@archive_file = File.join(@db_dir, 'archive.yml')
+ @auxilliary_dirs = %w( icons jquery flot openlayers )
create_directories
begin
@@ -61,12 +62,15 @@ module PostRunner
sync if sync_needed
end
+ # Ensure that all necessary directories are present to store the output
+ # files. This method is idempotent and can be called even when directories
+ # exist already.
def create_directories
create_directory(@db_dir, 'data')
create_directory(@fit_dir, 'fit')
create_directory(@cfg[:html_dir], 'html')
- %w( icons jquery flot openlayers ).each do |dir|
+ @auxilliary_dirs.each do |dir|
create_auxdir(dir)
end
end
@@ -290,6 +294,22 @@ module PostRunner
Log.info "HTML index files have been updated."
end
+ # Take all necessary steps to convert user data to match an updated
+ # PostRunner version.
+ def handle_version_update
+ # An updated version may bring new auxilliary directories. We remove the
+ # old directories and create new copies.
+ Log.warn('Removing old HTML auxilliary directories')
+ @auxilliary_dirs.each do |dir|
+ auxdir = File.join(@cfg[:html_dir], dir)
+ FileUtils.rm_rf(auxdir)
+ end
+ create_directories
+
+ Log.warn('Updating HTML files...')
+ generate_all_html_reports
+ end
+
private
def sync
diff --git a/lib/postrunner/Main.rb b/lib/postrunner/Main.rb
index 9029045..57ca0e3 100644
--- a/lib/postrunner/Main.rb
+++ b/lib/postrunner/Main.rb
@@ -182,12 +182,7 @@ EOT
def execute_command(args)
@activities = ActivitiesDB.new(@db_dir, @cfg)
- if @cfg.get_option(:version) != VERSION
- Log.warn "Version upgrade detected. Database conversion started..."
- @activities.generate_all_html_reports
- @cfg.set_option(:version, VERSION)
- Log.info "Version upgrade completed."
- end
+ handle_version_update
case (cmd = args.shift)
when 'check'
@@ -357,6 +352,15 @@ EOT
end
end
+ def handle_version_update
+ if @cfg.get_option(:version) != VERSION
+ Log.warn "Version upgrade detected."
+ @activities.handle_version_update
+ @cfg.set_option(:version, VERSION)
+ Log.info "Version upgrade completed."
+ end
+ end
+
end
end