astroboa-cli 0.3.1 → 0.4.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.
data/README.md CHANGED
@@ -96,15 +96,16 @@ On **Mac OS X** to install `rbenv` and `ruby-build` using the [Homebrew](http:/
96
96
  $ brew update
97
97
  $ brew install rbenv
98
98
  $ brew install ruby-build
99
-
100
- Then add the following line in your .bash_profile:
101
99
  $ echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile
102
100
 
101
+ The last command adds to your .bash_profile the code that initializes rbenv
102
+
103
+
103
104
 
104
105
  ---
105
106
  On **Ubuntu Linux** to install `rbenv` and `ruby-build` using `apt` package manager and `git` do (it has been tested in Ubuntu 12.04):
106
107
 
107
- $ sudo apt-get install zlib1g-dev openssl libopenssl-ruby1.9.1 libssl-dev libruby1.9.1 libreadline-dev git-core
108
+ $ sudo apt-get install build-essential zlib1g-dev openssl libopenssl-ruby1.9.1 libssl-dev libruby1.9.1 libreadline-dev git-core
108
109
  $ cd
109
110
  $ git clone git://github.com/sstephenson/rbenv.git .rbenv
110
111
 
@@ -139,9 +140,9 @@ Restart your shell to apply the changes in your bashrc or bash_profile
139
140
 
140
141
  $ exec $SHELL
141
142
 
142
- To install ruby version 1.9.3-p194 do:
143
+ To install ruby version 1.9.3-p286 do:
143
144
 
144
- $ rbenv install 1.9.3-p194
145
+ $ rbenv install 1.9.3-p286
145
146
  $ rbenv rehash
146
147
 
147
148
 
@@ -149,22 +150,22 @@ To install ruby version 1.9.3-p194 do:
149
150
 
150
151
  To set the global version of Ruby to be used in all your shells do:
151
152
 
152
- $ rbenv global 1.9.3-p194
153
+ $ rbenv global 1.9.3-p286
153
154
 
154
- To set ruby 1.9.3-p194 as a local per-project ruby version by writing the version name to an .rbenv-version file in the current project directory do:
155
+ To set ruby 1.9.3-p286 as a local per-project ruby version by writing the version name to an .rbenv-version file in the current project directory do:
155
156
 
156
- $ rbenv local 1.9.3-p194
157
+ $ rbenv local 1.9.3-p286
157
158
 
158
- To set ruby 1.9.3-p194 as the version to be used only in the current shell (sets the RBENV_VERSION environment variable in your shell) do:
159
+ To set ruby 1.9.3-p286 as the version to be used only in the current shell (sets the RBENV_VERSION environment variable in your shell) do:
159
160
 
160
- $ rbenv shell 1.9.3-p194
161
+ $ rbenv shell 1.9.3-p286
161
162
 
162
163
  Test your ruby installation:
163
164
 
164
- $ rbenv global 1.9.3-p194
165
+ $ rbenv global 1.9.3-p286
165
166
  $ ruby -v
166
167
 
167
- On MAC you will get output similar to this: ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin12.0.0]
168
+ On MAC you will get output similar to this: ruby 1.9.3p286 (2012-04-20 revision 35410) [x86_64-darwin12.0.0]
168
169
 
169
170
  For more information about `rbenv`, `ruby-build` and `rbenv-sudo` check https://github.com/sstephenson/rbenv, https://github.com/sstephenson/ruby-build and https://github.com/dcarley/rbenv-sudo
170
171
 
@@ -178,12 +179,12 @@ If you prefer to use 'rvm' as your ruby management utility use the following com
178
179
  For multi-user installation and detailed rvm installation instructions check: https://rvm.io/rvm/install/
179
180
  To use `sudo` to run astroboa-cli (and any other ruby-based program) you should use `rvmsudo`
180
181
 
181
- After 'rvm' has been installed run the following commands to install ruby 1.9.3-p194:
182
+ After 'rvm' has been installed run the following commands to install ruby 1.9.3-p286:
182
183
 
183
- $ rvm install 1.9.3-p194
184
- $ rvm use 1.9.3-p194
184
+ $ rvm install 1.9.3-p286
185
+ $ rvm use 1.9.3-p286
185
186
 
186
- run: `$ rvm use 1.9.3-p194 --default` to make 1.9.3-p194 your default ruby
187
+ run: `$ rvm use 1.9.3-p286 --default` to make 1.9.3-p286 your default ruby
187
188
 
188
189
  # LICENSE
189
190
  -------
@@ -26,19 +26,31 @@ require 'fileutils'
26
26
  #
27
27
  class AstroboaCLI::Command::Model < AstroboaCLI::Command::Base
28
28
 
29
- # model:associate REPOSITORY MODEL_DIR
29
+ # model:associate REPOSITORY [MODELS_DIR]
30
30
  #
31
31
  # This command allows you to associate a repository with a domain model.
32
32
  # After the association is done your repository can store entities that follow the domain model.
33
33
  #
34
- # It is recommended to use this command only on new repositories because it does not cope with model updates
35
- # (it will cause instant performace decrease because it resets the whole repository schema and most important
36
- # it may render your data inaccessible if the updated model contain changes to property names or property value cardinality)
37
- # If you change a domain model that has been already associated with a repository use 'astroboa-cli model:propagate_updates'
34
+ # It is recommended to use this command either to bootstrap new repositories with a domain model
35
+ # or use it with CAUTION to update the domain model of an existing repository.
36
+ # It is SAFE to use it for domain model updates ONLY WHEN YOU ADD new object types or add new properties to existing types.
37
+ # This command does not cope with model updates that change existing object type names or change existing property names,
38
+ # property types and property value cardinality. I you do such updates and use this command, it may render your data inaccessible.
39
+ # In any case it will not delete any existing data so you can instantly recover your data visibility if you put back your old model.
38
40
  #
39
- # If you specify the 'MODEL_DIR' (i.e. where your models are stored) then your DSL model definition is expected to be
40
- # in 'MODEL_DIR/dsl' and your XML Schemas to be in 'MODEL_DIR/xsd'
41
- # If you do not specify the 'MODEL_DIR' then domain model is expected to be found inside current directory in 'model/dsl' and 'model/xsd'
41
+ # The command can be used both when the server is stoppped as well as when the server is up.
42
+ # So you can do LIVE UPDATES to your schema but be warned that a schema change
43
+ # will cause a few seconds performace decrease on a live system.
44
+ #
45
+ # If in some case you need to change existing object type names or change existing property names, property types
46
+ # and property value cardinality in your domain model then use 'astroboa-cli model:propagate_updates'
47
+ # in order to propagate the changes to a repository. This might require to alter data
48
+ # in the repository as opposed to 'model:associate' that never touches the stored data and
49
+ # so it should be used ONLY if you ADD new features to your model.
50
+ #
51
+ # If you specify the 'MODELS_DIR' (i.e. where your models are stored) then your DSL model definition is expected to be
52
+ # in 'MODELS_DIR/dsl' and your XML Schemas to be in 'MODELS_DIR/xsd'
53
+ # If you do not specify the 'MODELS_DIR' then the domain model is expected to be found inside the current directory in 'models/dsl' and 'models/xsd'
42
54
  #
43
55
  def associate
44
56
 
@@ -52,26 +64,26 @@ class AstroboaCLI::Command::Model < AstroboaCLI::Command::Base
52
64
 
53
65
  error "Repository '#{repository}' does not exist or it is not properly configured (use astroboa-cli repository:list to see available repositories)" unless repository?(server_configuration, repository)
54
66
 
55
- if model_dir = args.shift
56
- model_dir = model_dir.strip
67
+ if models_dir = args.shift
68
+ models_dir = models_dir.strip
57
69
  else
58
- model_dir = File.join(Dir.getwd, 'model')
70
+ models_dir = File.join(Dir.getwd, 'models')
59
71
  end
60
72
 
61
- error <<-MSG unless Dir.exists? model_dir
62
- Directory #{model_dir} does not exist.
63
- If you specify the 'MODEL_DIR' then your DSL model definition is expected to be
64
- in 'MODEL_DIR/dsl' and your XML Schemas to be in 'MODEL_DIR/xsd'
65
- If you do not specify the 'MODEL_DIR' then domain model is expected to be found inside current directory in 'model/dsl' and 'model/xsd'
73
+ error <<-MSG unless Dir.exists? models_dir
74
+ Directory #{models_dir} does not exist.
75
+ If you specify the 'MODELS_DIR' then your DSL model definition is expected to be
76
+ in 'MODELS_DIR/dsl' and your XML Schemas to be in 'MODELS_DIR/xsd'
77
+ If you do not specify the 'MODELS_DIR' then domain model is expected to be found inside current directory in 'models/dsl' and 'models/xsd'
66
78
  MSG
67
79
 
68
80
  astroboa_dir = server_configuration['install_dir']
69
81
 
70
82
  display "Looking for XML Schemas..."
71
- xsd_dir = File.join model_dir, 'xsd'
72
- model_contains_xsd = Dir.exists?(xsd_dir) && Dir.entries(xsd_dir) != [".", ".."]
83
+ xsd_dir = File.join models_dir, 'xsd'
84
+ models_contain_xsds = Dir.exists?(xsd_dir) && Dir.entries(xsd_dir) != [".", ".."]
73
85
 
74
- if model_contains_xsd
86
+ if models_contain_xsds
75
87
  display "Found XML Schemas in '#{xsd_dir}'"
76
88
  display "Validating XML Schemas..."
77
89
 
@@ -131,8 +143,244 @@ class AstroboaCLI::Command::Model < AstroboaCLI::Command::Base
131
143
 
132
144
  end
133
145
 
146
+ # model:create_object_type NAME
147
+ #
148
+ # Creates a new object type. The name of the new object type (the class name in programming terms) will be NAME
149
+ #
150
+ # It will create a new XML Schema and will add the required definitions (namespaces, imports, xml tags) for the new object type.
151
+ # The generated file will be named '{NAME}.xsd'
152
+ # If you do not specify a namespace for your new object type (using --namespace) then the namespace 'http://astroboa/schema/{NAME}' will be used by default
153
+ #
154
+ # If you specify the 'MODELS_DIR' (i.e. where your models are stored) then the XML Schema file will be written inside '{MODELS_DIR}/xsd/' ('{MODELS_DIR}/xsd' will be created if it does not exist)
155
+ # If you do not specify the 'MODELS_DIR' then the XML Schema file will be written in 'models/xsd/' inside the current directory ('./models/xsd' will be created if it does not exist).
156
+ #
157
+ # The created object type will not have any properties. Use the 'model:add_property' command to add properties to your new type.
158
+ #
159
+ # NOTE: If you are creating XML Schema files manually besides using this command please follow the same convension
160
+ # that this command follows, that is to keep each object type in a separate file and name your file after the name of the type.
161
+ #
162
+ # -d, --models_dir MODELS_DIR # The directory (absolute path) where your models are stored. # The generated XML Schema file will be written inside '{MODELS_DIR}/xsd/' # If directory {MODELS_DIR}/xsd does not exist, it will be created.
163
+ # -n, --namespace NAMESPACE # The namespace to be used for your new object type # (i.e. the corresponding entity tag will be namespaced with the provided namespace) # If not specified, the default namespace 'http://astroboa/schema/{NAME}' will be used (NAME is the name of your object type).
164
+ # -l, --localized_labels OBJECT_TYPE_LABELS # Provide friendly object type names for different languages # By default the 'NAME' of the object type will be used as the english label # Example: -l en:Movie,fr:Film,es:Filme
165
+ #
166
+ def create_object_type
167
+ if object_type = args.shift
168
+ object_type = object_type.strip
169
+ else
170
+ error "Please specify a name for your new object type. Usage: model:create_object_type NAME"
171
+ end
172
+
173
+ namespace = options[:namespace] ||= "http://astroboa/schema/#{object_type}"
174
+ models_dir = options[:models_dir] ||= File.join(Dir.getwd, 'models')
175
+ localized_labels = options[:localized_labels] ||= "en:#{object_type}"
176
+ localized_labels_map = {}
177
+ localized_labels.split(',').each {|loc_lab| loc_lab_array = loc_lab.split(':'); localized_labels_map[loc_lab_array[0]] = loc_lab_array[1]}
178
+
179
+ xsd_dir = File.join models_dir, 'xsd'
180
+
181
+ unless Dir.exists? xsd_dir
182
+ FileUtils.mkdir_p xsd_dir
183
+ end
184
+
185
+ schema_file = File.join xsd_dir, "#{object_type}.xsd"
186
+
187
+ error <<-MSG if File.exists? schema_file
188
+ XML Schema file '#{schema_file}' exists.
189
+ This means that you have already defined a type named '#{object_type}' (the command creates each object type
190
+ in a different schema file named after the object type name).
191
+ There is also the possibility that you have manually created the file '#{schema_file}'.
192
+ If you are creating XML Schema files manually please follow the convension
193
+ to keep each object type in a separate file and name your file after the name of the type.
194
+ MSG
195
+
196
+ # TODO: Extra check all other schemas to verify that user has not manually add this type
197
+
198
+ server_configuration = get_server_configuration
199
+ astroboa_dir = server_configuration['install_dir']
200
+
201
+ object_type_template = File.join(astroboa_dir, 'astroboa-setup-templates', 'object_type_template.xsd')
202
+ context = {namespace: namespace, object_type: object_type, localized_labels_map: localized_labels_map}
203
+ render_template_to_file(object_type_template, context, schema_file)
204
+
205
+ display "Generate schema file '#{schema_file}' for new object type '#{object_type}': OK"
206
+ display "You can now use 'model:add_property' to add properties to your new object type."
207
+ display "When you finish adding properties to your type use 'model:associate' to associate a repository with your new object type and start creating object instances of this type"
208
+ end
209
+
210
+
211
+ # model:add_property PROPERTY_NAME OBJECT_TYPE
212
+ #
213
+ # Adds a new property with name 'PROPERTY_NAME' to 'OBJECT_TYPE'. If '--update' is specified it updates an existing property
214
+ #
215
+ # If you specify the 'MODELS_DIR' (i.e. where your models are stored) then the XML Schema that contains the object type definition
216
+ # is expected to be found in '{MODELS_DIR}/xsd/{OBJECT_TYPE}.xsd'
217
+ # If you do not specify the 'MODELS_DIR' then the XML Schema that contains the object type definition is expected to be found inside the current directory in 'models/xsd/{OBJECT_TYPE}.xsd'
218
+ #
219
+ # -d, --models_dir MODELS_DIR # The directory (absolute path) where your models are stored. # Default is './models' # The XML Schema file that contains the object type definition is expected to be found in '{MODELS_DIR}/xsd/{OBJECT_TYPE}.xsd'
220
+ # -t, --type TYPE # The property type. # Accepted types are: string,integer,double,boolean,date,dateTime,binary,topic_ref,object_ref,complex,[USER_DEFINED_TYPE]. Default type is 'string'.
221
+ # -x, --max_values MAX_NUM_OF_VALUES # The maximum number of values that are permitted for this property. # Specify '1' if you want to store only one value. # Specify 'unbounded' if you want to store a list of values without an upper limit in list size. # Default is '1'.
222
+ # -n, --min_values MIN_NUM_VALUES # The minimum number of values that are permitted for this property. # Specify '0' to designate a non mandatory field. # Specify '1' to designate a mandatory field. # Default is '0'.
223
+ # -p, --parent PROPERTY_NAME # The name of an EXISTING property that will contain this property. # The parent property should always be of type 'complex'. # Properties of type 'complex' act as a grouping container for their child properties. # Imagine them as named fieldsets of a form # E.g. The 'complex' property 'address' is the parent (container) of the properties 'street', 'city', 'zipcode', 'country'. # You may arbitrarily nest 'complex' properties inside other 'complex' properties to create property trees.
224
+ # -l, --localized_labels PROPERTY_NAME_LABELS # Provide friendly names for the property in different languages # By default the 'PROPERTY_NAME' will be used as the english label # Example: -l en:First Name,fr:Prénom,es:Primer Nombre
225
+ # -u, --update # Use this option to specify whether you want to update an EXISTING property. # If the property with 'PROPERTY_NAME' exists and you do not use this option then NO UPDATE will be performed. # The default values for property attributes are not used during a property update. # ONLY the property attributes that are expicitly specified with the options will be updated. # E.g. if you give 'astroboa-cli model:add_property age person -t integer --update' # and the property 'age' exists then only its 'type' will be changed. # The 'minValues', 'maxValues', 'localized_labels' will keep their existing values.
226
+ #
227
+ def add_property
228
+ if property_name = args.shift
229
+ property_name = property_name.strip
230
+ else
231
+ error "Please specify a name for the property. Usage: model:add_property PROPERTY_NAME OBJECT_TYPE"
232
+ end
233
+
234
+ if object_type = args.shift
235
+ object_type = object_type.strip
236
+ else
237
+ error "Please specify the object type for which you want to add / update a property. Usage: model:add_property PROPERTY_NAME OBJECT_TYPE"
238
+ end
239
+
240
+ models_dir = options[:models_dir] ||= File.join(Dir.getwd, 'models')
241
+ xsd_dir = File.join models_dir, 'xsd'
242
+ schema_file = File.join xsd_dir, "#{object_type}.xsd"
243
+
244
+ error <<-MSG unless File.exists? schema_file
245
+ XML Schema file #{schema_file} does not exist.
246
+ The XML Schema that contains the object type definition
247
+ is expected to be found in 'MODELS_DIR/xsd/OBJECT_TYPE.xsd'
248
+ If you do not specify the MODELS_DIR with '--models_dir MODELS_DIR'
249
+ the default is './models'
250
+ MSG
251
+
252
+ localized_labels = options[:localized_labels] ||= "en:#{property_name}"
253
+ localized_labels_map = {}
254
+ localized_labels.split(',').each {|loc_lab| loc_lab_array = loc_lab.split(':'); localized_labels_map[loc_lab_array[0]] = loc_lab_array[1]}
255
+
256
+ type_specified = options.has_key? :type
257
+ max_values_specified = options.has_key? :max_values
258
+ min_values_specified = options.has_key? :min_values
259
+ parent_specified = options.has_key? :parent
260
+ type = options[:type] ||= 'string'
261
+ max_values = options[:max_values] ||= '1'
262
+ min_values = options[:min_values] ||= '0'
263
+ parent = options[:parent]
264
+
265
+ schema = nil
266
+ File.open(schema_file, 'r') do |f|
267
+ schema = Nokogiri::XML(f) do |config|
268
+ config.noblanks
269
+ end
270
+ end
271
+
272
+
273
+ # find if specified property is already defined
274
+ property_node_set = schema.xpath "//xs:element[@name='#{property_name}']"
275
+ if property_node_set.length == 0 # property is not defined
276
+ # if a parent has been specified check if it exists
277
+ error <<-MSG if parent && schema.xpath("//xs:element[@name='#{parent}']").length == 0
278
+ The parent property '#{parent}' you specified does not exist.
279
+ Please check the XML Schema at '#{schema_file}' and run the command again with a
280
+ existing parent property.
281
+ MSG
282
+ display "property '#{property_name}' is not yet defined. Lets create it..."
283
+ property = create_property schema, object_type: object_type, name: property_name,
284
+ type: type, min_values: min_values, max_values: max_values, i18n: localized_labels_map
285
+
286
+ write_xml schema, schema_file
287
+ display <<-MSG
288
+ Create new property '#{property_name}' for object type '#{object_type}': OK
289
+ The new property is now defined in file: #{schema_file}
290
+ The xml schema definition for the new property is:
291
+ #{property.to_xml indent: 1, indent_text: "\t", encoding: 'UTF-8'}
292
+ MSG
293
+ else
294
+ display "property '#{property_name}' is already defined. Lets update it..."
295
+ error "property update is not yet supported"
296
+ end
297
+ end
298
+
299
+
134
300
  private
135
301
 
302
+ def create_property schema, options
303
+ object_type = options[:object_type]
304
+ property = Nokogiri::XML::Node.new 'element', schema
305
+ property['name'] = options[:name]
306
+ property['minOccurs'] = options[:min_values]
307
+ property['maxOccurs'] = options[:max_values]
308
+ type = xsd_type options[:type]
309
+ if type
310
+ property['type'] = type
311
+ else # complex properties do not have type but they need some more child tags
312
+ property = to_complex schema, property
313
+ end
314
+
315
+ # add localized labels for property name
316
+ localize schema, property, options[:i18n]
317
+
318
+ # append the new property in XML Schema
319
+ parent_node = schema.xpath("//xs:element[@name='#{object_type}']//xs:sequence").first
320
+ error <<-MSG unless parent_node
321
+ Could not locate the child '<xs:sequence>' tag inside '<xs:element name="#{object_type}"'
322
+ in order to append the new property.
323
+ If you have manually created the XML Schema file for object type '#{object_type}'
324
+ then make sure that you have also created an empty '<xs:sequence></xs:sequence>' child tag
325
+ before using this command to add new properties.
326
+ MSG
327
+ parent_node << property
328
+ property
329
+ end
330
+
331
+
332
+ def localize schema, element, localized_labels_map
333
+ localized_labels_map.each do |locale, label|
334
+ annotation_node = Nokogiri::XML::Node.new 'annotation', schema
335
+ documentation_node = Nokogiri::XML::Node.new 'documentation', schema
336
+ documentation_node["xml:lang"] = locale
337
+
338
+ # here we need to add the astroboa namespace so lets find it in schema
339
+ astroboa_namespace = schema.root.namespace_definitions.find{|ns| ns.prefix=="astroboa"}
340
+ error <<-MSG unless astroboa_namespace
341
+ Could not find the astroboa model namespace using namespace prefix 'astroboa'.
342
+ If you have manually created the XML Schema make sure that you have specified
343
+ (inside the <xml:schema> tag) the astroboa model namespace with the proper prefix as follows:
344
+ xmlns:astroboa="http://www.betaconceptframework.org/schema/astroboa/model"
345
+ MSG
346
+ display_name_node = Nokogiri::XML::Node.new 'displayName', schema
347
+ display_name_node.namespace = astroboa_namespace
348
+ display_name_node.content = label
349
+
350
+ documentation_node << display_name_node
351
+ annotation_node << documentation_node
352
+ element << annotation_node
353
+ end
354
+ end
355
+
356
+
357
+ def to_complex schema, property
358
+ complex_type_node = Nokogiri::Node.new 'xs:complexType', schema
359
+ sequence_node = Nokogiri::Node.new 'xs:sequence', schema
360
+ complex_type_node.add_child sequence_node
361
+ property.add_child complex_type_node
362
+ end
363
+
364
+
365
+ def xsd_type type
366
+ type = case type
367
+ when 'string'; 'xs:string'
368
+ when 'integer'; 'xs:int'
369
+ when 'double'; 'xs:double'
370
+ when 'boolean'; 'xs:boolean'
371
+ when 'date'; 'xs:date'
372
+ when 'dateTime'; 'xs:dateTime'
373
+ when 'binary'
374
+
375
+ when 'topic_ref'
376
+
377
+ when 'object_ref'; 'astroboa:contentObjectReferenceType'
378
+ when 'complex'; nil
379
+ else type
380
+ end
381
+ end
382
+
383
+
136
384
  def domain_model_valid? domain_model_file, schemas_dir
137
385
  Dir.chdir(schemas_dir) do
138
386
 
@@ -339,11 +339,8 @@ private
339
339
 
340
340
  repository << jcrCache
341
341
 
342
- strip_text_nodes(repo_conf)
343
342
  new_astroboa_repos_config = "#{astroboa_repos_config}.new"
344
- File.open(new_astroboa_repos_config, 'w') do |f|
345
- repo_conf.write_xml_to(f, :indent => 1, :indent_text => "\t", :encoding => 'UTF-8')
346
- end
343
+ write_xml repo_conf, new_astroboa_repos_config
347
344
 
348
345
  # save old config file
349
346
  if conf_exists
@@ -372,11 +369,9 @@ private
372
369
 
373
370
  if !repo_nodes.empty?
374
371
  repo_nodes.remove
375
- strip_text_nodes(repo_conf)
372
+
376
373
  new_astroboa_repos_config = "#{astroboa_repos_config}.new"
377
- File.open(new_astroboa_repos_config, 'w') do |f|
378
- repo_conf.write_xml_to(f, :indent => 1, :indent_text => "\t", :encoding => 'UTF-8')
379
- end
374
+ write_xml repo_conf, new_astroboa_repos_config
380
375
 
381
376
  current_date = DateTime.now().strftime('%Y-%m-%dT%H.%M')
382
377
  FileUtils.cp astroboa_repos_config, "#{astroboa_repos_config}.#{current_date}"
@@ -392,17 +387,7 @@ private
392
387
  error "cannot find repositories configuration file: '#{astroboa_repos_config}'"
393
388
  end
394
389
  end
395
-
396
-
397
- # remove leading and trailing white space from XML Document text nodes
398
- def strip_text_nodes(xml_doc)
399
- xml_doc.traverse do |node|
400
- if node.text?
401
- node.content = node.content.strip
402
- end
403
- end
404
- end
405
-
390
+
406
391
 
407
392
  def add_repo_conf_to_server_conf(server_configuration, repository_name)
408
393
  repo_domain_name = options[:domain_name] ||= 'localhost:8080'
@@ -327,7 +327,7 @@ private
327
327
  download_package(@torquebox_version_download_url, @install_dir) unless File.size?(File.join(@install_dir, @torquebox_version_file)) == 6
328
328
 
329
329
  # download astroboa ear
330
- download_package(@astroboa_ear_download_url, @install_dir) unless File.size?(File.join(@install_dir, @astroboa_ear_package)) == 64585240
330
+ download_package(@astroboa_ear_download_url, @install_dir) unless File.size?(File.join(@install_dir, @astroboa_ear_package)) == 63783475
331
331
 
332
332
  # download astroboa version file
333
333
  download_package(@astroboa_version_download_url, @install_dir) unless File.size?(File.join(@install_dir, @astroboa_version_file)) == 15
@@ -1,6 +1,7 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  require 'astroboa-cli/command/base'
4
+ require 'fileutils'
4
5
  require 'rbconfig'
5
6
 
6
7
  # setup astroboa as a system service (daemon) that automatically starts on boot
@@ -108,8 +109,11 @@ private
108
109
  launchd_config_template = File.join(astroboa_dir, 'astroboa-setup-templates', 'AstroboaDaemon.plist.template')
109
110
  context = {:astroboa_dir => astroboa_dir, :java_home => ENV['JAVA_HOME'], :jruby_home => File.join(server_configuration['install_dir'], 'torquebox', 'jruby'), :astroboa_user => astroboa_user}
110
111
  render_template_to_file(launchd_config_template, context, temp_launchd_config)
111
- error "Failed to copy launchd config file to #{LAUNCHD_CONFIG}" unless process_os_command "sudo cp #{temp_launchd_config} #{LAUNCHD_CONFIG}"
112
- error "Failed to remove temporary launchd config file #{temp_launchd_config}" unless process_os_command "rm #{temp_launchd_config}"
112
+ unless FileUtils.cp temp_launchd_config LAUNCHD_CONFIG
113
+ FileUtils.rm temp_launchd_config
114
+ error "Failed to copy launchd config file to #{LAUNCHD_CONFIG}"
115
+ end
116
+ error "Failed to remove temporary launchd config file #{temp_launchd_config}" unless FileUtils.rm temp_launchd_config
113
117
  display "Generating launchd config file '#{LAUNCHD_CONFIG}': OK"
114
118
  end
115
119
 
@@ -467,20 +467,20 @@ module AstroboaCLI
467
467
  database_admin, database_admin_password, database_server = get_postgresql_config(server_configuration)
468
468
  begin
469
469
  conn = PG.connect(
470
- :host => database_server,
471
- :port => '5432',
472
- :dbname => 'postgres',
473
- :user => database_admin,
474
- :password => database_admin_password)
470
+ host: database_server,
471
+ port: '5432',
472
+ dbname: 'postgres',
473
+ user: database_admin,
474
+ password: database_admin_password)
475
475
 
476
476
  # check if db exists
477
477
  res = conn.exec("SELECT COUNT(*) FROM pg_database WHERE datname=$1",[database_name])
478
- unless res.entries[0]['count'] == 0
478
+ unless res.entries[0]['count'].to_i == 0
479
479
  display "Database #{database_name} exists. You may run the command with --db_name repo_db_name to specify a different database name"
480
480
  raise
481
481
  end
482
482
 
483
- res = conn.exec("CREATE DATABASE $1 ENCODING 'UNICODE'", [database_name])
483
+ res = conn.exec("CREATE DATABASE #{database_name} ENCODING 'UNICODE'")
484
484
  if res.result_status == PG::Result::PGRES_COMMAND_OK
485
485
  display %(Create Postges database "#{database_name}" : OK)
486
486
  else
@@ -540,6 +540,27 @@ module AstroboaCLI
540
540
  end
541
541
 
542
542
 
543
+ # remove leading and trailing white space from XML Document text nodes
544
+ # xml_doc should be a Nokogiri::XML:Document or Nokogiri::XML::Node
545
+ def strip_text_nodes xml_doc
546
+ xml_doc.traverse do |node|
547
+ if node.text?
548
+ node.content = node.content.strip
549
+ end
550
+ end
551
+ end
552
+
553
+ # write XML document to a file
554
+ # document should be a Nokogiri::XML:Document or Nokogiri::XML::Node
555
+ def write_xml document, file_full_path
556
+ strip_text_nodes document
557
+
558
+ File.open(file_full_path, 'w') do |f|
559
+ document.write_xml_to(f, :indent => 1, :indent_text => "\t", :encoding => 'UTF-8')
560
+ end
561
+ end
562
+
563
+
543
564
  # Not used because only works in jruby, TO BE REMOVED
544
565
  def create_postgresql_db_with_jdbc(server_configuration, database_name, repo_dir)
545
566
  database_admin, database_admin_password, database_server = get_postgresql_config(server_configuration)
@@ -591,5 +612,6 @@ module AstroboaCLI
591
612
  raise
592
613
  end
593
614
  end
615
+
594
616
  end
595
617
  end
@@ -1,3 +1,3 @@
1
1
  module AstroboaCLI
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: astroboa-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-09-18 00:00:00.000000000 Z
13
+ date: 2012-11-05 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: progressbar