lib/user.rb in sprout-0.5.23 vs lib/user.rb in sprout-0.5.25

- old
+ new

@@ -1,15 +1,15 @@ module PatternPark - class ExecutionError < StandardError; end + class ExecutionError < StandardError; end ############################# - # User class + # User class class User @@user = nil - + def User.new(os=nil, impl=nil) if(os.nil? && impl.nil? && @@user) return @@user end if(os.nil?) @@ -30,84 +30,84 @@ @@user = UnixUser.new else @@user = UnixUser.new end end - + def User.user=(user) @@user = user end - + def User.home=(path) User.new().home = path end - + def User.in_path?(executable) User.new().in_path?(executable) end def User.home User.new().home end - + def User.application_home(name) return User.new().application_home(name) end - + def User.library return User.new().library end - + def User.execute(tool, options='') return User.new().execute(tool, options) end - + def User.execute_thread(tool, options='') if(Log.debug) return ThreadMock.new else return User.new().execute_thread(tool, options) end end - + def User.clean_path(path) return User.new().clean_path(path) end - + # Called from Sprout.init_values... def User.init_values @@user = nil @@home = nil end end - + ############################# - # UnixUser class + # UnixUser class class UnixUser - + def initialize require 'open3' @home = nil end - + def home=(path) @home = path end - + def home if(@home) return @home end - + ["HOME", "USERPROFILE"].each do |homekey| return @home = ENV[homekey] if ENV[homekey] end - + if ENV["HOMEDRIVE"] && ENV["HOMEPATH"] return @home = "#{ENV["HOMEDRIVE"]}:#{ENV["HOMEPATH"]}" end - + begin return @home = File.expand_path("~") rescue StandardError => ex if File::ALT_SEPARATOR return @home = "C:\\" @@ -146,15 +146,15 @@ return :macosx else return Platform::IMPL end end - + def get_process_runner(command) return ProcessRunner.new(command) end - + def execute(tool, options='') tool = Sprout.load(tool) if(tool.executable) target = get_exe_path(tool.executable) else @@ -169,62 +169,62 @@ end if(error.size > 0) raise ExecutionError.new("[ERROR] #{error}") end end - + def execute_thread(tool, options='') return Thread.new { execute(tool, options) } end - + def clean_path(path) if(path.index(' ')) return %{'#{path}'} end return path end - + def application_home(name) return File.join(library, format_application_name(name.to_s)); end - + def format_application_name(name) if(name.index('.') != 0) name = '.' + name end return name.split(" ").join("_").downcase end end - + class OSXUser < UnixUser @@LIBRARY = 'Library' - + def library lib = File.join(home, @@LIBRARY) if(File.exists?(lib)) return lib else return super end end - + def format_application_name(name) return name.capitalize end end - + class WinUser < UnixUser @@LOCAL_SETTINGS = "Local\ Settings" @@APPLICATION_DATA = "Application\ Data" - + def initialize require 'win32/open3' @home = nil end - + def home usr = super if(usr.index "My Documents") usr = File.dirname(usr) end @@ -232,11 +232,11 @@ end def get_paths return ENV['PATH'].split(';') end - + def library # For some reason, my homepath returns inside 'My Documents'... application_data = File.join(home, @@LOCAL_SETTINGS, @@APPLICATION_DATA) if(File.exists?(application_data)) return application_data @@ -250,31 +250,51 @@ if(path.index(' ')) return %{"#{path}"} end return path end - + def format_application_name(name) return name.capitalize end end class CygwinUser < WinUser def initialize require 'open3' @home = nil + @win_home = nil + @win_home_cyg_path = nil end - + def clean_path(path) if(path.index(' ')) return %{'#{path}'} end return path end + def win_home + if(@win_home.nil?) + @win_home = ENV['HOMEDRIVE'] + ENV['HOMEPATH'] + end + return @win_home + end + + def home + if(@home.nil?) + path = win_home.split('\\').join("/") + path = path.split(":").join("") + parts = path.split("/") + path = parts.shift().downcase + "/" + parts.join("/") + @home = "/cygdrive/" + path + end + return @home + end + end - + class VistaUser < WinUser def home profile = ENV['USERPROFILE'] if(profile) return profile