lib/rubygems-requirements-system/platform/base.rb in rubygems-requirements-system-0.0.1 vs lib/rubygems-requirements-system/platform/base.rb in rubygems-requirements-system-0.0.2
- old
+ new
@@ -12,10 +12,12 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
require "fileutils"
+require "open-uri"
+require "tempfile"
require_relative "../executable-finder"
require_relative "../os-release"
module RubyGemsRequirementsSystem
@@ -77,23 +79,38 @@
def have_priviledge?
return true unless need_super_user_priviledge?
super_user?
end
+ def temporary_file_scope
+ @temporary_files = []
+ begin
+ yield
+ ensure
+ @temporary_files.each(&:close!)
+ end
+ end
+
+ def create_temporary_file(basename)
+ file = Tempfile.new(basename)
+ @temporary_files << file
+ file
+ end
+
def install_package(package)
- command_line = prepare_command_line(package)
- if command_line
- unless run_command_line(package, "prepare", command_line)
- return false
+ temporary_file_scope do
+ prepare_command_lines(package).each do |command_line|
+ unless run_command_line(package, "prepare", command_line)
+ return false
+ end
end
+ run_command_line(package, "install", install_command_line(package))
end
- run_command_line(package, "install", install_command_line(package))
end
def run_command_line(package, action, command_line)
failed_to_get_super_user_priviledge = false
- command_line = install_command_line(package)
if have_priviledge?
succeeded = system(*command_line)
else
if sudo
prompt = "[sudo] password for %u to #{action} <#{package}>: "
@@ -116,16 +133,16 @@
Shellwords.escape(part)
end
alert_warning("'#{package}' system package is required.")
alert_warning("Run the following command " +
"to #{action} required system package: " +
- escaped_command.join(" "))
+ escaped_command_line.join(" "))
end
succeeded
end
- def prepare_command_line(package)
- nil
+ def prepare_command_lines(package)
+ []
end
def install_command_line(package)
raise NotImpelementedError
end