lib/system_description_store.rb in machinery-tool-1.2.0 vs lib/system_description_store.rb in machinery-tool-1.4.0

- old
+ new

@@ -1,6 +1,6 @@ -# Copyright (c) 2013-2014 SUSE LLC +# Copyright (c) 2013-2015 SUSE LLC # # This program is free software; you can redistribute it and/or # modify it under the terms of version 3 of the GNU General Public License as # published by the Free Software Foundation. # @@ -65,93 +65,48 @@ end def copy(from, to) SystemDescription.validate_name(from) SystemDescription.validate_name(to) - if !list.include?(from) - raise Machinery::Errors::SystemDescriptionNotFound.new( - "System description \"#{from}\" does not exist." - ) - end - if list.include?(to) - raise Machinery::Errors::SystemDescriptionError.new( - "A System description with the name \"#{to}\" does already exist." - ) - end + validate_existence_of_description(from) + validate_nonexistence_of_description(to) FileUtils.cp_r(description_path(from), description_path(to)) end def backup(description_name) SystemDescription.validate_name(description_name) - if !list.include?(description_name) - raise Machinery::Errors::SystemDescriptionNotFound.new( - "System description \"#{description_name}\" does not exist." - ) - end + validate_existence_of_description(description_name) backup_name = get_backup_name(description_name) FileUtils.cp_r(description_path(description_name), description_path(backup_name)) backup_name end def rename(from, to) SystemDescription.validate_name(from) SystemDescription.validate_name(to) - if !list.include?(from) - raise Machinery::Errors::SystemDescriptionNotFound.new( - "System description \"#{from}\" does not exist." - ) - end - if list.include?(to) - raise Machinery::Errors::SystemDescriptionError.new( - "A System description with the name \"#{to}\" does already exist." - ) - end + validate_existence_of_description(from) + validate_nonexistence_of_description(to) FileUtils.mv(description_path(from), description_path(to)) end - def initialize_file_store(description_name, store_name) - file_store = ScopeFileStore.new(description_path(description_name), - store_name) - file_store.create - end + def swap(description_name_1, description_name_2) + validate_existence_of_description(description_name_1) + validate_existence_of_description(description_name_2) - def file_store(description_name, store_name) - file_store = ScopeFileStore.new(description_path(description_name), - store_name) - file_store.path - end + tmp_description_name = "#{description_name_1}-#{Time.now.to_i}-#{rand(1000)}" - def remove_file_store(description_name, store_name) - file_store = ScopeFileStore.new(description_path(description_name), - store_name) - file_store.remove + FileUtils.mv(description_path(description_name_1), description_path(tmp_description_name)) + FileUtils.mv(description_path(description_name_2), description_path(description_name_1)) + FileUtils.mv(description_path(tmp_description_name), description_path(description_name_2)) end - def rename_file_store(description_name, store_old, store_new) - file_store = ScopeFileStore.new(description_path(description_name), - store_old) - file_store.rename(store_new) - end - - def create_file_store_sub_dir(description_name, store_name, sub_dir) - file_store = ScopeFileStore.new(description_path(description_name), - store_name) - file_store.create_sub_directory(sub_dir) - end - - def list_file_store_content(description_name, store_name) - file_store = ScopeFileStore.new(description_path(description_name), - store_name) - file_store.list_content - end - def directory_for(name) dir = description_path(name) create_dir(dir) dir end @@ -172,7 +127,23 @@ backup_name = "#{description_name}.backup.#{number}" number += 1 end backup_name + end + + def validate_existence_of_description(description_name) + if !list.include?(description_name) + raise Machinery::Errors::SystemDescriptionNotFound.new( + "System description \"#{description_name}\" does not exist." + ) + end + end + + def validate_nonexistence_of_description(description_name) + if list.include?(description_name) + raise Machinery::Errors::SystemDescriptionError.new( + "A System description with the name \"#{description_name}\" does already exist." + ) + end end end