webappsword_sdk 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. data/.gitignore +1 -0
  2. data/Gemfile +4 -0
  3. data/Gemfile.lock +24 -0
  4. data/README.md +67 -0
  5. data/Rakefile +20 -0
  6. data/VERSION +1 -0
  7. data/bin/webappsword_sdk +85 -0
  8. data/easy_installer-0.0.1.gem +0 -0
  9. data/example/Rakefile +72 -0
  10. data/example/additional/after_install.rb +1 -0
  11. data/example/additional/return_callback.rb +2 -0
  12. data/example/arch.zip +0 -0
  13. data/example/config.yml +6 -0
  14. data/example/files/joomla/index.php +54 -0
  15. data/example/installers/global.rb +2 -0
  16. data/example/installers/local.rb +2 -0
  17. data/example/validators/ftp.rb +6 -0
  18. data/example/validators/local.rb +0 -0
  19. data/lib/easy_installer.rb +4 -0
  20. data/lib/easy_installer/autoload.rb +28 -0
  21. data/lib/easy_installer/coffeescript_sandbox.rb +95 -0
  22. data/lib/easy_installer/config.rb +138 -0
  23. data/lib/easy_installer/config_validator.rb +73 -0
  24. data/lib/easy_installer/fake/ftp/install_helper.rb +34 -0
  25. data/lib/easy_installer/fake/ftp/validate_helper.rb +12 -0
  26. data/lib/easy_installer/fake/local/install_helper.rb +30 -0
  27. data/lib/easy_installer/fake/local/standart_input.yml +2 -0
  28. data/lib/easy_installer/fake/local/validate_helper.rb +6 -0
  29. data/lib/easy_installer/fake/php/validate_helper.rb +12 -0
  30. data/lib/easy_installer/fake/validator.rb +0 -0
  31. data/lib/easy_installer/fake/zip.rb +9 -0
  32. data/lib/easy_installer/generators/base.rb +25 -0
  33. data/lib/easy_installer/generators/config.rb +58 -0
  34. data/lib/easy_installer/install.rb +56 -0
  35. data/lib/easy_installer/install_helpers/result.rb +14 -0
  36. data/lib/easy_installer/install_helpers/template.rb +19 -0
  37. data/lib/easy_installer/install_helpers/zip.rb +9 -0
  38. data/lib/easy_installer/methods/ftp/install_helper.rb +105 -0
  39. data/lib/easy_installer/methods/ftp/standart_input.yml +5 -0
  40. data/lib/easy_installer/methods/ftp/standart_input.yml~ +5 -0
  41. data/lib/easy_installer/methods/ftp/validate_helper.rb +24 -0
  42. data/lib/easy_installer/methods/local/install_helper.rb +37 -0
  43. data/lib/easy_installer/methods/local/standart_input.yml +2 -0
  44. data/lib/easy_installer/methods/local/validate_helper.rb +4 -0
  45. data/lib/easy_installer/methods/sample/install_helper.rb +67 -0
  46. data/lib/easy_installer/methods/sample/standart_input.yml +5 -0
  47. data/lib/easy_installer/methods/sample/standart_input.yml~ +5 -0
  48. data/lib/easy_installer/methods/sample/validate_helper.rb +17 -0
  49. data/lib/easy_installer/modules/php/standart_input.yml +6 -0
  50. data/lib/easy_installer/modules/php/validate_helper.rb +47 -0
  51. data/lib/easy_installer/sandbox.rb +100 -0
  52. data/lib/easy_installer/sandbox_modules/message.rb +62 -0
  53. data/lib/easy_installer/steps.rb +36 -0
  54. data/lib/easy_installer/temp.rb +23 -0
  55. data/lib/easy_installer/translate.rb +70 -0
  56. data/lib/easy_installer/validator.rb +99 -0
  57. data/lib/easy_installer/validator_support_methods.rb +37 -0
  58. data/tests/files/additional/after_install.rb +1 -0
  59. data/tests/files/config.yml +10 -0
  60. data/tests/files/installers/global.rb +1 -0
  61. data/tests/files/installers/local.rb +1 -0
  62. data/tests/files/sample.zip +0 -0
  63. data/tests/files/template.erb +1 -0
  64. data/tests/files/translations/pl.yml +11 -0
  65. data/tests/files/validators/ftp.rb +3 -0
  66. data/tests/files/validators/local.rb +0 -0
  67. data/tests/files/validators/sample.rb +2 -0
  68. data/tests/test_config.rb +30 -0
  69. data/tests/test_config_validator.rb +22 -0
  70. data/tests/test_ftp.rb +51 -0
  71. data/tests/test_install.rb +19 -0
  72. data/tests/test_sandbox.rb +48 -0
  73. data/tests/test_sandbox_messages.rb +18 -0
  74. data/tests/test_steps.rb +19 -0
  75. data/tests/test_temp.rb +14 -0
  76. data/tests/test_template.rb +17 -0
  77. data/tests/test_validator.rb +31 -0
  78. data/tests/test_zip.rb +26 -0
  79. data/tests/wrong_config/config.yml +6 -0
  80. data/tests/wrong_config/install/global.rb +2 -0
  81. data/tests/wrong_config/install/local.rb +1 -0
  82. data/tests/wrong_config/translations/pl.yml +11 -0
  83. data/tests/wrong_config/validators/ftp.rb +4 -0
  84. data/tests/wrong_config/validators/local.rb +0 -0
  85. data/tests/wrong_config/validators/sample.rb +3 -0
  86. data/tests/~test_translator.rb +17 -0
  87. data/webappsword_sdk.gemspec +24 -0
  88. metadata +149 -0
@@ -0,0 +1,138 @@
1
+ require 'yaml'
2
+ require 'singleton'
3
+ class Hash
4
+ def flattern namespace = nil
5
+ result = {}
6
+ self.each do |k, v|
7
+ if v.class != Hash
8
+ result["#{namespace}_#{k}"] = v if namespace
9
+ result["#{k}"] = v unless namespace
10
+ else
11
+ result.merge!(v.flattern "#{namespace}_#{k}") if namespace
12
+ result.merge!(v.flattern "#{k}") unless namespace
13
+ end
14
+ end
15
+ result
16
+ end
17
+
18
+ def flatern_to_array namespace = nil
19
+ result = []
20
+ self.each do |k, v|
21
+ if v.class == String
22
+ result << "#{namespace}_#{v}" if namespace
23
+ result << "#{v}" unless namespace
24
+ elsif v.class == Array
25
+ v.each{|val| result << "#{namespace}_#{val}" if namespace
26
+ result << "#{val}" unless namespace
27
+
28
+ }
29
+ else
30
+ result += (v.flatern_to_array "#{namespace}_#{k}") if namespace
31
+ result += (v.flatern_to_array "#{k}") unless namespace
32
+ end
33
+ end
34
+ result
35
+ end
36
+ end
37
+
38
+ module EasyInstaller
39
+ class Config
40
+ attr_accessor :method
41
+ require 'easy_installer/config_validator'
42
+
43
+ def initialize(config_yaml)
44
+ if config_yaml.class == String
45
+ config_yaml = File.open(config_yaml)
46
+ end
47
+ @config = YAML::load config_yaml
48
+ @installer_files_path = File.split(config_yaml.path)[0]
49
+ end
50
+
51
+ def valid?
52
+ raise "No InstallerConfig.File " if !@config
53
+ @validator = Config::Validator.new(self)
54
+ @validator.check
55
+ end
56
+
57
+ def validator
58
+ @validator
59
+ end
60
+
61
+ def to_hash
62
+ @config
63
+ end
64
+
65
+ def [](arg)
66
+ @config[arg]
67
+ end
68
+
69
+ def required_inputs_for_method(method)
70
+ required_inputs_for_method_as_tree(method).flatern_to_array
71
+ end
72
+
73
+ def required_inputs_for_method_as_tree(method)
74
+ required_input = Hash.new
75
+ lang_file = File.open(self.path_to_gem+"/lib/easy_installer/modules/"+@config["lang"]+"/standart_input.yml")
76
+ method_file = File.open(self.path_to_gem+"/lib/easy_installer/methods/#{method}/standart_input.yml")
77
+ method_input = YAML::load method_file
78
+ lang_input = YAML::load lang_file
79
+
80
+ required_input['lang'] = lang_input[@config["lang"]] if lang_input[@config["lang"]]
81
+ required_input['method'] = method_input if method_input
82
+ required_input.merge! @config["additonal_inputs"] if @config["additonal_inputs"]
83
+ if @config["submodules"]
84
+ @config["submodules"].each do |submodule|
85
+ required_input[submodule] = lang_input[submodule] if lang_input[submodule]
86
+ end
87
+ end
88
+
89
+ required_input
90
+ end
91
+
92
+ def install_code(method)
93
+ if File.exist?(File.join(@installer_files_path, "installers/#{method}.rb"))
94
+ return File::open(File.join(@installer_files_path, "installers/#{method}.rb")).read
95
+ else
96
+ return File::open(File.join(@installer_files_path, "installers/global.rb")).read
97
+ end
98
+ end
99
+
100
+ def validating_code(method)
101
+ File.read(File.join(@installer_files_path, "validators/#{method}.rb"))
102
+ end
103
+
104
+ def after_install_code
105
+ if(File.exists?(File.join(@installer_files_path, "additional/after_install.rb")))
106
+ File.read(File.join(@installer_files_path, "additional/after_install.rb"))
107
+ else
108
+ ""
109
+ end
110
+ end
111
+
112
+ def return_callback_code
113
+ if(File.exists?(File.join(@installer_files_path, "additional/return_callback.rb")))
114
+ File.read(File.join(@installer_files_path, "additional/return_callback.rb"))
115
+ else
116
+ ""
117
+ end
118
+ end
119
+
120
+ def create_input_for_method(method)
121
+ $user_input = Hash.new
122
+ required_input_for_method(method).each do |input|
123
+ $user_input[input] = Input::create_by_name(input)
124
+ end
125
+ end
126
+
127
+ def has_key?(key)
128
+ @config.has_key?(key)
129
+ end
130
+
131
+ protected
132
+
133
+ def path_to_gem
134
+ Gem.loaded_specs['easy_installer'].full_gem_path
135
+ end
136
+
137
+ end
138
+ end
@@ -0,0 +1,73 @@
1
+ module EasyInstaller
2
+ class Config::Validator
3
+
4
+ def initialize (config)
5
+ @config = config
6
+ end
7
+
8
+ def check
9
+ begin
10
+ self.validate_config_keys
11
+ self.validate_validator_code
12
+ self.validate_install_code
13
+ true
14
+ rescue Exception => e
15
+ @error_message = e.message
16
+ @error_backtrace = e.backtrace
17
+ false
18
+ end
19
+ end
20
+
21
+ # Return error returned by validating function
22
+ def error_message
23
+ @error_message
24
+ end
25
+
26
+ def error_backtrace
27
+ @error_backtrace
28
+ end
29
+
30
+ protected
31
+
32
+ def validate_config_keys
33
+ (@config.has_key?("methods") || @config.has_key?(:methods)) &&
34
+ (@config.has_key?("lang") || @config.has_key?(:lang)) &&
35
+ (@config.has_key?("submodules") || @config.has_key?(:submodules))
36
+ end
37
+
38
+ def validate_install_code
39
+ require 'easy_installer/install'
40
+ require 'easy_installer/fake/zip'
41
+ @config["methods"].each do |method|
42
+ require "easy_installer/fake/#{method}/install_helper"
43
+ code = @config.install_code method
44
+ run = Installer::RunInstall.new
45
+ run.inputs = {}
46
+ run.extend FakeLib::ZipFile
47
+ run.extend FakeLib::InstallHelper
48
+ run.instance_eval code
49
+ end
50
+ end
51
+
52
+ def validate_validator_code
53
+ require 'easy_installer/validator'
54
+ validator = Validator.new(@config)
55
+ @config["methods"].each do |method|
56
+ validator.import_from_config_by_method(method)
57
+ end
58
+ end
59
+
60
+ def deep_validation
61
+ return false if @config["methods"].class != Array
62
+ @config["methods"].each do |method|
63
+ return false unless Dir.exist?(File.join(path_to_gem, "lib", "easy_installer", "methods", method))
64
+ end
65
+ return false unless Dir.exist?(File.join(path_to_gem, "lib", "easy_installer", "modules", @config["methods"]))
66
+ end
67
+
68
+ def path_to_gem
69
+ gem_root = Gem.loaded_specs['easy_installer'].full_gem_path
70
+ end
71
+
72
+ end
73
+ end
@@ -0,0 +1,34 @@
1
+ module EasyInstaller
2
+ module FakeLib
3
+ module InstallHelper
4
+ def setup params = {}
5
+ host = params[:host] || $user_input["ftp_host"].value
6
+ username = params[:username] || $user_input["ftp_username"].value
7
+ password = params[:password] || $user_input["ftp_password"].value
8
+ @ftp = Net::FTP.new(host)
9
+ @ftp.login(username, password)
10
+ end
11
+
12
+ def move_directory(local_directory,remote_directory)
13
+ true
14
+ end
15
+
16
+ def create_directory(dirpath, chmod=664)
17
+ true
18
+ end
19
+
20
+ def move_file(local_file,remote_file, chmod=664)
21
+ true
22
+ end
23
+
24
+ def chmod(remote_file, chmod)
25
+ true
26
+ end
27
+ #need to test
28
+ def chmod_r(remote_dir, chmod)
29
+ true
30
+ end
31
+
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,12 @@
1
+ require 'easy_installer/methods/ftp/install_helper'
2
+ module FakeLib
3
+ module MethodValidateHelper
4
+ include InstallHelper
5
+ def check_connection params = {}
6
+ host = params[:host]
7
+ username = params[:username]
8
+ password = params[:password]
9
+ true
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,30 @@
1
+ require 'fileutils'
2
+ module EasyInstaller
3
+ module FakeLib
4
+ module InstallHelper
5
+ def setup
6
+ end
7
+
8
+ def move_directory(from_directory, to_directory)
9
+ true
10
+ end
11
+
12
+ def create_directory(dirpath,chmod=664)
13
+ true
14
+ end
15
+
16
+ def move_file(local_file,remote_file, chmod=664)
17
+ true
18
+ end
19
+
20
+ def chmod(remote_file, chmod)
21
+ true
22
+ end
23
+
24
+ def chmod_r(remote_dir, chmod)
25
+ true
26
+ end
27
+
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,2 @@
1
+ - path
2
+ - http_address
@@ -0,0 +1,6 @@
1
+ module EasyInstaller
2
+ module FakeLib
3
+ module MethodValidateHelper
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,12 @@
1
+ require 'erb'
2
+ module FakeLib
3
+ module ModuleValidateHelper
4
+ def php?
5
+ true
6
+ end
7
+
8
+ def mysql?
9
+ true
10
+ end
11
+ end
12
+ end
File without changes
@@ -0,0 +1,9 @@
1
+ module EasyInstaller
2
+ module FakeLib
3
+ module ZipFile
4
+ def unzip(filename, destination)
5
+ true
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,25 @@
1
+ require 'fileutils'
2
+ module EasyInstaller
3
+ module Generator
4
+ class Base
5
+ def initialize(dir, &block)
6
+ @base_path = dir
7
+ if block
8
+ block.call(self)
9
+ end
10
+ end
11
+
12
+ def create_directories(dirs)
13
+ dirs.each do |dir|
14
+ FileUtils.mkdir_p(File.join(@base_path, dir))
15
+ end
16
+ end
17
+
18
+ def create_files(files)
19
+ files.each do |file|
20
+ File.open(File.join(@base_path, file), "w"){}
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,58 @@
1
+ require 'erb'
2
+ module EasyInstaller
3
+ module Generator
4
+ class Config
5
+ attr_accessor :methods, :submodules, :lang
6
+
7
+ # Sets avabile methods
8
+ # ==== Attributes
9
+ # * +methods+ - Array of String
10
+ # ==== Example
11
+ # set_methods(['ftp','local'])
12
+ def set_methods(methods)
13
+ @methods = methods
14
+ end
15
+
16
+ #Same like set_methods
17
+ def set_submodules(submodules)
18
+ @submodules = methods
19
+ end
20
+
21
+ # Sets used lang
22
+ # ==== Attributes
23
+ # * +lang+ - String
24
+ # ==== Example
25
+ # set_lang('php')
26
+ def set_lang(lang)
27
+ @lang = lang
28
+ end
29
+
30
+ # Saves current config to file
31
+ # ==== Attributes
32
+ # +file+ - could be File or String
33
+ # ==== Example
34
+ # save(File.new("sample.yml", "w"))
35
+ # save("sample.yml")
36
+ def save(file)
37
+ if file.class == String
38
+ file = File.exist?(file) ? File::open(file, "w") : File::new(file, "w")
39
+ end
40
+ file.write(self.generate)
41
+ file.close
42
+ end
43
+
44
+ #Returns config as string
45
+ def generate
46
+ template = ERB.new <<-EOF
47
+ methods:
48
+ <% @methods.each do |method| %> - <%=method%>
49
+ <% end %>lang: <%=@lang%>
50
+ submodules:
51
+ <% @submodules.each do |submodule| %> - <%=submodule%>
52
+ <% end %>additonal_inputs:
53
+ EOF
54
+ template.result binding
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,56 @@
1
+ require 'easy_installer/install_helpers/zip'
2
+ module EasyInstaller
3
+ class Installer
4
+ class RunInstall
5
+ attr_accessor :inputs
6
+ end
7
+
8
+ def initialize(config)
9
+ @config = config
10
+ end
11
+ # Runs code in temporary directory
12
+ # * *Args* :
13
+ # - +inputs+ -> Hash of inputs
14
+ # * *Returns* :
15
+ # - EasyInstaller::Sandbox
16
+
17
+ def install(inputs = {})
18
+ require "easy_installer/methods/#{@config.method}/install_helper"
19
+ create_and_go_to_temp
20
+ evaluate = Sandbox.new(@config.install_code(@config.method), inputs)
21
+ evaluate.helpers << InstallHelper::ZipFile
22
+ evaluate.helpers << InstallHelper
23
+ evaluate.modules << EasyInstaller::Sandbox::Message
24
+ result = evaluate.eval
25
+ unless result
26
+ raise evaluate.returned
27
+ end
28
+ @success = true
29
+ clear_temp
30
+
31
+ evaluate
32
+ end
33
+
34
+ def returned
35
+ @returned
36
+ end
37
+
38
+ def success?
39
+ @success
40
+ end
41
+
42
+ protected
43
+
44
+ def create_and_go_to_temp
45
+ @current_dir = Dir.pwd
46
+ @temp = EasyInstaller::Temp.new
47
+ @temp.copy_to_tempdir(".")
48
+ Dir.chdir(@temp.tempdir)
49
+ end
50
+
51
+ def clear_temp
52
+ Dir.chdir(@current_dir)
53
+ @temp.clear
54
+ end
55
+ end
56
+ end