prestashop-automation-tool 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.
- data/bin/pat.rb +38 -0
- data/lib/prestashop-automation-tool.rb +103 -0
- metadata +48 -0
data/bin/pat.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
require '../lib/prestashop-automation-tool.rb'
|
3
|
+
|
4
|
+
require 'optparse'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
def withConfig &block
|
8
|
+
if File.exists? 'pat.conf.json'
|
9
|
+
yield JSON.parse(File.read('pat.conf.json'), :symbolize_names => true)
|
10
|
+
else
|
11
|
+
abort "Could not find the config file #{pat.conf.json}, did you run 'pat.rb init'?"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
options = {}
|
16
|
+
OptionParser.new do |opts|
|
17
|
+
opts.on('-ad', '--accept-defaults', 'Accept default values automatically') do
|
18
|
+
options[:accept_defaults] = true
|
19
|
+
end
|
20
|
+
end.parse!
|
21
|
+
if ARGV.count != 1
|
22
|
+
puts "Missing action argument!"
|
23
|
+
exit 1
|
24
|
+
elsif ARGV[0] == 'init'
|
25
|
+
conf = PrestaShopAutomationTool::ConfigurationParser.new '.'
|
26
|
+
conf.parse
|
27
|
+
conf.ask_user_for_missing_info options
|
28
|
+
conf.autocomplete_config
|
29
|
+
File.write 'pat.conf.json', JSON.pretty_generate({
|
30
|
+
shop: conf.config
|
31
|
+
})
|
32
|
+
elsif ARGV[0] == 'install'
|
33
|
+
withConfig do |conf|
|
34
|
+
ps = PrestaShopAutomation::PrestaShop.new(conf[:shop])
|
35
|
+
ps.drop_database
|
36
|
+
ps.install options
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'apache-vhosts-parser'
|
3
|
+
require 'prestashop-automation'
|
4
|
+
|
5
|
+
module PrestaShopAutomationTool
|
6
|
+
class ConfigurationParser
|
7
|
+
|
8
|
+
attr_reader :config
|
9
|
+
|
10
|
+
def initialize root
|
11
|
+
@root = File.realpath(root)
|
12
|
+
|
13
|
+
vhosts = ApacheVhostsParser.parseDirectory
|
14
|
+
|
15
|
+
if url = vhosts.urlFor(@root)
|
16
|
+
fou = "http://#{url}/"
|
17
|
+
else
|
18
|
+
fou = "http://localhost/#{File.basename(@root)}"
|
19
|
+
end
|
20
|
+
|
21
|
+
@config_fields = {
|
22
|
+
database_user: '',
|
23
|
+
database_password: '',
|
24
|
+
database_name: '',
|
25
|
+
database_prefix: 'ps_',
|
26
|
+
database_host: 'localhost',
|
27
|
+
version: '',
|
28
|
+
front_office_url: fou,
|
29
|
+
back_office_url: nil,
|
30
|
+
installer_url: nil,
|
31
|
+
admin_email: 'pub@prestashop.com',
|
32
|
+
admin_password: '123456789',
|
33
|
+
default_customer_email: 'pub@prestashop.com',
|
34
|
+
default_customer_password: '123456789'
|
35
|
+
}
|
36
|
+
|
37
|
+
@config = {}
|
38
|
+
end
|
39
|
+
def parse
|
40
|
+
if File.exists? path=File.join(@root, 'config', 'settings.inc.php')
|
41
|
+
config = Hash[File.read(path).scan(/\bdefine\s*\(\s*'(.*?)'\s*,\s*'(.*?)'\s*\)\s*;/)]
|
42
|
+
|
43
|
+
mapping = {
|
44
|
+
database_user: '_DB_USER_',
|
45
|
+
database_password: '_DB_PASSWD_',
|
46
|
+
database_name: '_DB_NAME_',
|
47
|
+
database_prefix: '_DB_PREFIX_',
|
48
|
+
database_host: '_DB_SERVER_',
|
49
|
+
version: '_PS_VERSION_'
|
50
|
+
}
|
51
|
+
|
52
|
+
@config_fields.each_pair do |key, default_value|
|
53
|
+
if (value = config[mapping[key]].to_s.strip) != ''
|
54
|
+
@config[key] = value
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
Dir.entries('.').each do |entry|
|
60
|
+
unless entry =~ /^\./
|
61
|
+
if File.directory? entry
|
62
|
+
if File.exists? File.join(entry, 'ajax-tab.php')
|
63
|
+
@admin_folder = entry
|
64
|
+
elsif File.exists? File.join(entry, 'index_cli.php')
|
65
|
+
@installer_folder = entry
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
def ask_user_for_missing_info options={}
|
72
|
+
@config_fields.each_pair do |key, default_value|
|
73
|
+
unless @config[key]
|
74
|
+
if default_value
|
75
|
+
default = default_value != '' ? " (default: \"#{default_value.to_s})\"" : ''
|
76
|
+
unless options[:accept_defaults]
|
77
|
+
print "#{key.to_s.split('_').map(&:capitalize).join ' '}#{default}? "
|
78
|
+
value = $stdin.gets.strip
|
79
|
+
value = default_value if value == ""
|
80
|
+
@config[key] = value
|
81
|
+
else
|
82
|
+
@config[key] = default_value
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def autocomplete_config
|
90
|
+
if m = @config[:database_host].match(/^(.*?)\:(.*?)$/)
|
91
|
+
@config[:database_host] = m[1]
|
92
|
+
@config[:database_port] = m[2]
|
93
|
+
end
|
94
|
+
|
95
|
+
if @admin_folder
|
96
|
+
@config[:back_office_url] = URI.join(@config[:front_office_url], @admin_folder).to_s
|
97
|
+
end
|
98
|
+
if @installer_folder
|
99
|
+
@config[:installer_url] = URI.join(@config[:front_office_url], @installer_folder).to_s
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: prestashop-automation-tool
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- François-Marie de Jouvencel
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-05-19 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Automate prestashop.
|
15
|
+
email: fm.de.jouvencel@gmail.com
|
16
|
+
executables:
|
17
|
+
- pat.rb
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/prestashop-automation-tool.rb
|
22
|
+
- bin/pat.rb
|
23
|
+
homepage: https://github.com/djfm/prestashop-automation-tool
|
24
|
+
licenses:
|
25
|
+
- OSL
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ! '>='
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubyforge_project:
|
44
|
+
rubygems_version: 1.8.23
|
45
|
+
signing_key:
|
46
|
+
specification_version: 3
|
47
|
+
summary: This tool helps you add selenium tests to an existing prestashop installation.
|
48
|
+
test_files: []
|