lorj 0.2.0 → 1.0.0
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +46 -0
- data/Gemfile +15 -15
- data/README.md +22 -17
- data/Rakefile +12 -2
- data/bin/cloud_test.rb +13 -65
- data/example/students_1/process/students.rb +39 -0
- data/example/students_1/students.rb +22 -5
- data/example/students_2/process/students.rb +48 -0
- data/example/students_2/students.rb +39 -16
- data/example/students_3/controller/yaml_students.rb +50 -43
- data/example/students_3/controller/yaml_students_controller.rb +100 -87
- data/example/students_3/process/students.rb +161 -97
- data/example/students_3/students.rb +85 -56
- data/example/yaml_students/students.rb +40 -40
- data/example/yaml_students/yaml_students.rb +103 -90
- data/lib/core/core.rb +356 -696
- data/lib/core/core_controller.rb +227 -0
- data/lib/core/core_internal.rb +339 -0
- data/lib/core/core_model.rb +328 -0
- data/lib/core/core_object_data.rb +330 -0
- data/lib/core/core_object_params.rb +230 -0
- data/lib/core/core_process.rb +391 -0
- data/lib/core/core_process_setup.rb +353 -0
- data/lib/core/core_setup_ask.rb +241 -0
- data/lib/core/core_setup_encrypt.rb +146 -0
- data/lib/core/core_setup_init.rb +229 -0
- data/lib/core/core_setup_list.rb +160 -0
- data/lib/core/definition.rb +647 -469
- data/lib/core/definition_internal.rb +264 -308
- data/lib/core/lorj_basecontroller.rb +95 -0
- data/lib/core/lorj_basedefinition.rb +307 -0
- data/lib/core/lorj_baseprocess.rb +265 -0
- data/lib/core/lorj_data.rb +583 -0
- data/lib/core/lorj_keypath.rb +119 -0
- data/lib/core_process/cloud/process/common.rb +63 -0
- data/lib/core_process/cloud/process/connection.rb +93 -0
- data/lib/core_process/cloud/process/external_network.rb +94 -0
- data/lib/core_process/cloud/process/flavor.rb +99 -0
- data/lib/core_process/cloud/process/images.rb +87 -0
- data/lib/core_process/cloud/process/internet_network.rb +34 -0
- data/lib/core_process/cloud/process/internet_server.rb +30 -0
- data/lib/core_process/cloud/process/keypairs.rb +276 -0
- data/lib/core_process/cloud/process/network.rb +108 -0
- data/lib/core_process/cloud/process/public_ip.rb +100 -0
- data/lib/core_process/cloud/process/router.rb +260 -0
- data/lib/core_process/cloud/process/rules.rb +120 -0
- data/lib/core_process/cloud/process/security_groups.rb +121 -0
- data/lib/core_process/cloud/process/server.rb +127 -0
- data/lib/core_process/cloud/process/server_log.rb +35 -0
- data/lib/core_process/cloud/process/subnetwork.rb +108 -0
- data/lib/core_process/cloud_process.rb +30 -0
- data/lib/logging.rb +298 -0
- data/lib/lorj/version.rb +18 -1
- data/lib/lorj.rb +58 -18
- data/lib/lorj_account.rb +556 -0
- data/lib/lorj_config.rb +468 -0
- data/lib/lorj_defaults.rb +278 -0
- data/lib/prc.rb +136 -104
- data/lib/prc_base_config.rb +285 -0
- data/lib/prc_core_config.rb +878 -0
- data/lib/prc_section_config.rb +57 -0
- data/lib/providers/hpcloud/compute.rb +81 -93
- data/lib/providers/hpcloud/hpcloud.rb +462 -0
- data/lib/providers/hpcloud/network.rb +96 -98
- data/lib/providers/hpcloud/security_groups.rb +41 -40
- data/lib/providers/mock/mock.rb +144 -0
- data/lib/providers/openstack/openstack.rb +45 -0
- data/lib/providers/templates/compute.rb +21 -23
- data/lib/providers/templates/mycloud.rb +72 -0
- data/lib/providers/templates/network.rb +11 -12
- data/lib/rh.rb +339 -0
- data/lorj-spec/defaults.yaml +4 -0
- data/lorj.gemspec +6 -0
- data/spec/00_lorj_log_spec.rb +53 -0
- data/spec/01_hash_rh_spec.rb +243 -0
- data/spec/02_prc_base_config_spec.rb +216 -0
- data/spec/04_prc_core_config_spec.rb +83 -0
- data/spec/11_lorj_config_spec.rb +263 -0
- data/spec/12_lorj_account_spec.rb +181 -0
- metadata +76 -28
- data/Gemfile.lock +0 -37
- data/example/students_1/process/Students.rb +0 -20
- data/example/students_2/process/Students.rb +0 -27
- data/example/students_4/controller/yaml_students.rb +0 -82
- data/example/students_4/controller/yaml_students_controller.rb +0 -141
- data/example/students_4/process/students.rb +0 -112
- data/example/students_4/students.rb +0 -103
- data/lib/core/lorj-basecontroller.rb +0 -90
- data/lib/core/lorj-basedefinition.rb +0 -1139
- data/lib/core/lorj-baseprocess.rb +0 -236
- data/lib/core/lorj-data.rb +0 -567
- data/lib/core/lorj-keypath.rb +0 -115
- data/lib/core_process/CloudProcess.rb +0 -337
- data/lib/core_process/global_process.rb +0 -502
- data/lib/core_process/network_process.rb +0 -605
- data/lib/prc-account.rb +0 -339
- data/lib/prc-config.rb +0 -1030
- data/lib/prc-logging.rb +0 -261
- data/lib/providers/hpcloud/Hpcloud.rb +0 -426
- data/lib/providers/mock/Mock.rb +0 -141
- data/lib/providers/openstack/Openstack.rb +0 -47
- data/lib/providers/templates/core.rb +0 -61
- data/spec/forj-account_spec.rb +0 -75
- data/spec/forj-config_spec.rb +0 -196
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# encoding: UTF-8
|
|
3
|
+
|
|
4
|
+
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
|
|
18
|
+
require 'rubygems'
|
|
19
|
+
require 'yaml'
|
|
20
|
+
|
|
21
|
+
# Lorj module implements Lorj::Config
|
|
22
|
+
# Lorj exposes defaults, as attribute to access the Lorj::Defaults instance.
|
|
23
|
+
module Lorj
|
|
24
|
+
# This class is the Application configuration class used by Lorj::Config
|
|
25
|
+
#
|
|
26
|
+
# It load a defaults.yaml file (path defined by PrcLib::app_defaults)
|
|
27
|
+
#
|
|
28
|
+
# defaults.yaml is divided in 3 sections:
|
|
29
|
+
#
|
|
30
|
+
# * :default: Contains a list of key = value
|
|
31
|
+
# * :setup: Contains :ask_step array
|
|
32
|
+
# - :ask_step: Array of group of keys/values to setup. Each group will be
|
|
33
|
+
# internally identified by a index starting at 0. parameters
|
|
34
|
+
# are as follow:
|
|
35
|
+
# - :desc: string to print out before group setup
|
|
36
|
+
# - :explanation: longer string to display after :desc:
|
|
37
|
+
# - :add: array of keys to add manually in the group.
|
|
38
|
+
#
|
|
39
|
+
# By default, thanks to data model dependency, the group is
|
|
40
|
+
# automatically populated.
|
|
41
|
+
#
|
|
42
|
+
# * :section: Contains a list of sections contains several key and attributes
|
|
43
|
+
# and eventually :default:
|
|
44
|
+
# This list of sections and keys will be used to build the account files
|
|
45
|
+
# with the lorj Lorj::Core::Setup function.
|
|
46
|
+
#
|
|
47
|
+
# - :default: This section define updatable data available from config.yaml.
|
|
48
|
+
# But will never be added in an account file.
|
|
49
|
+
# It contains a list of key and options.
|
|
50
|
+
#
|
|
51
|
+
# - :<aKey>: Possible options
|
|
52
|
+
# - :desc: default description for that <aKey>
|
|
53
|
+
#
|
|
54
|
+
# - :<aSectionName>: Name of the section which should contains a list
|
|
55
|
+
# - :<aKeyName>: Name of the key to setup.
|
|
56
|
+
# - :desc: Description of that key, printed out at setup
|
|
57
|
+
# time.
|
|
58
|
+
# - :readonly: true if this key is not modifiable by a simple
|
|
59
|
+
# Lorj::Account::set function. false otherwise.
|
|
60
|
+
# - :account_exclusive: true if the key cannot be set as default from
|
|
61
|
+
# config.yaml or defaults.yaml.
|
|
62
|
+
# - :account: true to ask setup to ask this key to the user.
|
|
63
|
+
# - :validate: Ruby Regex to validate the end user input.
|
|
64
|
+
# Ex: !ruby/regexp /^\w?\w*$/
|
|
65
|
+
# - :default_value: default value proposed to the user.
|
|
66
|
+
# - :ask_step: Define the group number to attach the key to be
|
|
67
|
+
# asked. ex: 2
|
|
68
|
+
# - :list_values: Provide capabililities to get a list and choose
|
|
69
|
+
# from.
|
|
70
|
+
# - :query_type: Can be:
|
|
71
|
+
#
|
|
72
|
+
# ':query_call' to execute a query on flavor, query_params is empty
|
|
73
|
+
# for all.
|
|
74
|
+
#
|
|
75
|
+
# ':process_call' to execute a process function to get the values.
|
|
76
|
+
#
|
|
77
|
+
# ':controller_call' to execute a controller query.
|
|
78
|
+
#
|
|
79
|
+
# - :object:
|
|
80
|
+
#
|
|
81
|
+
# Used with :query_type=:query_call. object type symbol to query.
|
|
82
|
+
#
|
|
83
|
+
# - :query
|
|
84
|
+
#
|
|
85
|
+
# Used with :query_type=:process_call. process function name to call
|
|
86
|
+
#
|
|
87
|
+
# - :query_call:
|
|
88
|
+
#
|
|
89
|
+
# Used with :query_type=:controller_call. Handler function to use.
|
|
90
|
+
# (query_e, create_e, ...)
|
|
91
|
+
#
|
|
92
|
+
# Used with :query_type=:process_call. Function name to call
|
|
93
|
+
#
|
|
94
|
+
# - :query_params:
|
|
95
|
+
#
|
|
96
|
+
# Used with :query_type=:query_call. Query hash defining filtering
|
|
97
|
+
# capabilities.
|
|
98
|
+
#
|
|
99
|
+
# Used with :query_type=:process_call. hParams data passed to the
|
|
100
|
+
# process function.
|
|
101
|
+
#
|
|
102
|
+
# - :value: fields to extract for the list of objects
|
|
103
|
+
# displayed.
|
|
104
|
+
# - :validate: if :list_strict, the value is limited to the
|
|
105
|
+
# possible values from the list
|
|
106
|
+
class Defaults < PRC::SectionConfig
|
|
107
|
+
# Remove inherited method []=
|
|
108
|
+
def []=(*_keys, _value)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# Load yaml documents (defaults)
|
|
112
|
+
# If config doesn't exist, it will be created, empty with 'defaults:' only
|
|
113
|
+
|
|
114
|
+
# Loop on Config metadata
|
|
115
|
+
#
|
|
116
|
+
#
|
|
117
|
+
# * *Args* :
|
|
118
|
+
# - ++ ->
|
|
119
|
+
# * *Returns* :
|
|
120
|
+
# -
|
|
121
|
+
# * *Raises* :
|
|
122
|
+
# - ++ ->
|
|
123
|
+
def meta_each
|
|
124
|
+
return nil if @data.rh_get(:sections).nil?
|
|
125
|
+
|
|
126
|
+
@data.rh_get(:sections).each do | section, hValue |
|
|
127
|
+
hValue.each do | key, value |
|
|
128
|
+
yield section, key, value
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
#
|
|
134
|
+
#
|
|
135
|
+
# * *Args* :
|
|
136
|
+
# - ++ ->
|
|
137
|
+
# * *Returns* :
|
|
138
|
+
# -
|
|
139
|
+
# * *Raises* :
|
|
140
|
+
# - ++ ->
|
|
141
|
+
def meta_exist?(key)
|
|
142
|
+
return nil unless key
|
|
143
|
+
|
|
144
|
+
key = key.to_sym if key.class == String
|
|
145
|
+
|
|
146
|
+
section = @account_section_mapping.rh_get(key)
|
|
147
|
+
@data.rh_exist?(:sections, section, key)
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
# Get model data options. Section name is determined by the associated
|
|
151
|
+
# data name
|
|
152
|
+
#
|
|
153
|
+
# * *Args* :
|
|
154
|
+
# - +data+ : data name
|
|
155
|
+
# - options+ : options tree.
|
|
156
|
+
# * *Returns* :
|
|
157
|
+
# - data options values
|
|
158
|
+
# OR
|
|
159
|
+
# - nil if:
|
|
160
|
+
# - missing data name as parameter.
|
|
161
|
+
# - data was not found. defined in /:sections/<section>/<data
|
|
162
|
+
# * *Raises* :
|
|
163
|
+
# - ++ ->
|
|
164
|
+
def get_meta_auto(*keys)
|
|
165
|
+
return nil unless keys.length > 0
|
|
166
|
+
section = @account_section_mapping.rh_get(keys[0])
|
|
167
|
+
return nil if section.nil?
|
|
168
|
+
@data.rh_get(:sections, section, keys)
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
# Get model section/data options.
|
|
172
|
+
#
|
|
173
|
+
# * *Args* :
|
|
174
|
+
# - +section+ : section name
|
|
175
|
+
# - +data+ : data name
|
|
176
|
+
# - +options+ : options tree.
|
|
177
|
+
#
|
|
178
|
+
# * *Returns* :
|
|
179
|
+
# - data options values
|
|
180
|
+
# OR
|
|
181
|
+
# - nil if:
|
|
182
|
+
# - missing section and data name as parameter.
|
|
183
|
+
# - data was not found. defined in /:sections/<section>/<data
|
|
184
|
+
# * *Raises* :
|
|
185
|
+
# - ++ ->
|
|
186
|
+
def get_meta(*keys)
|
|
187
|
+
return nil unless keys.length > 1
|
|
188
|
+
@data.rh_get(:sections, keys)
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
#
|
|
192
|
+
#
|
|
193
|
+
# * *Args* :
|
|
194
|
+
# - ++ ->
|
|
195
|
+
# * *Returns* :
|
|
196
|
+
# -
|
|
197
|
+
# * *Raises* :
|
|
198
|
+
# - ++ ->
|
|
199
|
+
def build_section_mapping
|
|
200
|
+
if @data.rh_get(:sections).nil?
|
|
201
|
+
PrcLib.warning('defaults.yaml do not defines :sections')
|
|
202
|
+
return nil
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
# TODO: Support multiple identical key name on distinct sections
|
|
206
|
+
# The primary data key should change from key to section & key.
|
|
207
|
+
@data.rh_get(:sections).each do | section, hValue |
|
|
208
|
+
next if section == :default
|
|
209
|
+
hValue.each_key do | map_key |
|
|
210
|
+
if @account_section_mapping.rh_exist?(map_key)
|
|
211
|
+
PrcLib.fatal(1, 'defaults.yaml: Duplicate entry between sections. '\
|
|
212
|
+
"'%s' defined in section '%s' already exists in"\
|
|
213
|
+
" section '%s'", map_key, section,
|
|
214
|
+
@account_section_mapping.rh_get(map_key))
|
|
215
|
+
end
|
|
216
|
+
@account_section_mapping.rh_set(section, map_key)
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
#
|
|
222
|
+
#
|
|
223
|
+
# * *Args* :
|
|
224
|
+
# - ++ ->
|
|
225
|
+
# * *Returns* :
|
|
226
|
+
# -
|
|
227
|
+
# * *Raises* :
|
|
228
|
+
# - ++ ->
|
|
229
|
+
def get_meta_section(key)
|
|
230
|
+
key = key.to_sym if key.class == String
|
|
231
|
+
@account_section_mapping.rh_get(key)
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
#
|
|
235
|
+
#
|
|
236
|
+
# * *Args* :
|
|
237
|
+
# - ++ ->
|
|
238
|
+
# * *Returns* :
|
|
239
|
+
# -
|
|
240
|
+
# * *Raises* :
|
|
241
|
+
# - ++ ->
|
|
242
|
+
def load
|
|
243
|
+
@account_section_mapping = {}
|
|
244
|
+
|
|
245
|
+
if !PrcLib.app_defaults
|
|
246
|
+
PrcLib.warning('PrcLib.app_defaults is not set. Application defaults'\
|
|
247
|
+
" won't be loaded.")
|
|
248
|
+
else
|
|
249
|
+
@filename = File.join(PrcLib.app_defaults, 'defaults.yaml')
|
|
250
|
+
|
|
251
|
+
PrcLib.info("Reading default configuration '%s'...", @filename)
|
|
252
|
+
|
|
253
|
+
if File.exist?(@filename)
|
|
254
|
+
_load(@filename)
|
|
255
|
+
|
|
256
|
+
build_section_mapping
|
|
257
|
+
else
|
|
258
|
+
PrcLib.warning("PrcLib.app_defaults is set to '%s'. Trying to load"\
|
|
259
|
+
" '%s' but not found. Application defaults won't "\
|
|
260
|
+
'be loaded.', PrcLib.app_defaults, @filename)
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
end
|
|
264
|
+
end
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
module_function
|
|
268
|
+
|
|
269
|
+
# Lorj::defaults exposes the application defaults and Config Lorj metadata.
|
|
270
|
+
def defaults
|
|
271
|
+
return @defaults unless @defaults.nil?
|
|
272
|
+
@defaults = Defaults.new
|
|
273
|
+
|
|
274
|
+
@defaults.load
|
|
275
|
+
|
|
276
|
+
@defaults
|
|
277
|
+
end
|
|
278
|
+
end
|
data/lib/prc.rb
CHANGED
|
@@ -15,114 +15,146 @@
|
|
|
15
15
|
require 'fileutils'
|
|
16
16
|
require 'logger'
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
# General lorj library. Used as library data configuration
|
|
19
|
+
# List of possible library settings:
|
|
20
|
+
# PrcLib.log : PrcLib::Logging object. Used internally by PrcLib
|
|
21
|
+
# logging system.
|
|
22
|
+
# This object is automatically created as soon as
|
|
23
|
+
# a message is printed out
|
|
24
|
+
# PrcLib.core_level : lorj debug level. from 0 to 5.
|
|
25
|
+
# PrcLib.pdata_path : Define the private data local directory. Usually used
|
|
26
|
+
# for any private keys, passwords, etc...
|
|
27
|
+
# By default: ~/.config/<app_name>
|
|
28
|
+
# PrcLib.data_path : Define the data local directory.
|
|
29
|
+
# By default: ~/.<app_name>
|
|
30
|
+
# PrcLib.app_name : Define the application name. By default 'lorj'
|
|
31
|
+
# PrcLib.app_defaults : Used by Lorj::Config to load application default data.
|
|
32
|
+
# By default nil.
|
|
33
|
+
# PrcLib.log_file : Define the log file name used.
|
|
34
|
+
# By default, defined as ~/.<app_name>/<app_name>.log
|
|
35
|
+
# PrcLib.level : logger level used.
|
|
36
|
+
# Can be set at runtime, with PrcLib.set_level
|
|
37
|
+
# PrcLib.model : Model loaded.
|
|
19
38
|
module PrcLib
|
|
39
|
+
# Check if dir exists and is fully accessible (rwx)
|
|
40
|
+
def self.dir_exists?(path)
|
|
41
|
+
return false unless File.exist?(path)
|
|
42
|
+
|
|
43
|
+
unless File.directory?(path)
|
|
44
|
+
msg = format("'%s' is not a directory. Please fix it.", path)
|
|
45
|
+
|
|
46
|
+
fatal_error(1, msg)
|
|
47
|
+
end
|
|
48
|
+
unless File.readable?(path) &&
|
|
49
|
+
File.writable?(path) &&
|
|
50
|
+
File.executable?(path)
|
|
51
|
+
msg = format("'%s is not a valid directory. "\
|
|
52
|
+
'Check permissions and fix it.', path)
|
|
53
|
+
|
|
54
|
+
fatal_error(1, msg)
|
|
55
|
+
end
|
|
56
|
+
true
|
|
57
|
+
end
|
|
20
58
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
PrcLib.set_level(v)
|
|
101
|
-
end
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
def level
|
|
105
|
-
@level
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
def lib_path=(v)
|
|
109
|
-
@lib_path = v if @lib_path.nil?
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
def lib_path()
|
|
113
|
-
@lib_path
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
def controller_path()
|
|
117
|
-
File.expand_path(File.join(@lib_path, "providers"))
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
def process_path()
|
|
121
|
-
File.join(@lib_path, "core_process")
|
|
122
|
-
end
|
|
123
|
-
end
|
|
59
|
+
def self.fatal_error(rc, msg)
|
|
60
|
+
fail msg if log.nil?
|
|
61
|
+
log.fatal(rc, msg)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# ensure dir exists and is fully accessible (rwx)
|
|
65
|
+
def self.ensure_dir_exists(path)
|
|
66
|
+
FileUtils.mkpath(path) unless dir_exists?(path)
|
|
67
|
+
rescue => e
|
|
68
|
+
fatal_error(1, e.message)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# Define module data for lorj library configuration
|
|
72
|
+
class << self
|
|
73
|
+
attr_accessor :log, :core_level
|
|
74
|
+
attr_reader :pdata_path, :data_path, :app_defaults, :log_file, :level,
|
|
75
|
+
:model
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
module_function
|
|
79
|
+
|
|
80
|
+
def pdata_path
|
|
81
|
+
return @pdata_path unless @pdata_path.nil?
|
|
82
|
+
@pdata_path = File.expand_path(File.join('~', '.config', app_name))
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def app_name
|
|
86
|
+
@app_name = 'Lorj' unless @app_name
|
|
87
|
+
@app_name
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def pdata_path=(v)
|
|
91
|
+
@pdata_path = File.expand_path(v) unless @pdata_path
|
|
92
|
+
PrcLib.ensure_dir_exists(@pdata_path)
|
|
93
|
+
begin
|
|
94
|
+
FileUtils.chmod(0700, @pdata_path) # no-op on windows
|
|
95
|
+
rescue => e
|
|
96
|
+
fatal_error(1, e.message)
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def data_path
|
|
101
|
+
return @data_path unless @data_path.nil?
|
|
102
|
+
|
|
103
|
+
default_path = File.join('~', '.' + app_name)
|
|
104
|
+
@data_path = File.expand_path(default_path)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def data_path=(v)
|
|
108
|
+
@data_path = File.expand_path(v) unless @data_path
|
|
109
|
+
PrcLib.ensure_dir_exists(@data_path)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
# TODO: Low. Be able to support multiple model.
|
|
113
|
+
def app_name=(v)
|
|
114
|
+
@app_name = v unless @app_name
|
|
115
|
+
@model = Lorj::Model.new
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# TODO: Support for several defaults, depending on controllers loaded.
|
|
119
|
+
def app_defaults=(v)
|
|
120
|
+
return if @app_defaults
|
|
121
|
+
|
|
122
|
+
v = File.join(File.dirname(__FILE__), v) unless v[0] == '/'
|
|
123
|
+
|
|
124
|
+
@app_defaults = File.expand_path(v)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def log_file=(v)
|
|
128
|
+
file = File.basename(v)
|
|
129
|
+
dir = File.dirname(File.expand_path(v))
|
|
130
|
+
unless File.exist?(dir)
|
|
131
|
+
fail format("'%s' doesn't exist. Unable to create file '%s'", dir, file)
|
|
132
|
+
end
|
|
133
|
+
@log_file = File.join(dir, file)
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def level=(v)
|
|
137
|
+
@level = v
|
|
124
138
|
|
|
139
|
+
PrcLib.level = v unless PrcLib.log.nil?
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def lib_path=(v)
|
|
143
|
+
@lib_path = v if @lib_path.nil?
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
attr_reader :lib_path
|
|
147
|
+
|
|
148
|
+
def controller_path
|
|
149
|
+
File.expand_path(File.join(@lib_path, 'providers'))
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def process_path
|
|
153
|
+
File.join(@lib_path, 'core_process')
|
|
154
|
+
end
|
|
155
|
+
end
|
|
125
156
|
|
|
157
|
+
# Redefine Object to add a boolean? function.
|
|
126
158
|
class Object
|
|
127
159
|
# Simplify boolean test on objects
|
|
128
160
|
def boolean?
|