continuent-tools-core 0.1.6 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/continuent-tools-core.rb +0 -11
- data/lib/iniparse.rb +66 -0
- data/lib/iniparse/LICENSE +19 -0
- data/lib/iniparse/document.rb +84 -0
- data/lib/iniparse/generator.rb +203 -0
- data/lib/iniparse/line_collection.rb +170 -0
- data/lib/iniparse/lines.rb +327 -0
- data/lib/iniparse/parser.rb +110 -0
- data/lib/tungsten/api.rb +3 -3
- data/lib/tungsten/common.rb +2 -2
- data/lib/tungsten/exec.rb +1 -10
- data/lib/tungsten/iniparse.rb +53 -0
- data/lib/tungsten/install.rb +111 -3
- data/lib/tungsten/properties.rb +11 -19
- data/lib/tungsten/script.rb +124 -2
- data/lib/tungsten/util.rb +94 -1
- metadata +11 -3
data/lib/tungsten/util.rb
CHANGED
@@ -32,7 +32,7 @@ class TungstenUtil
|
|
32
32
|
arguments = arguments.map{|arg|
|
33
33
|
newarg = ''
|
34
34
|
arg.split("").each{|b|
|
35
|
-
unless b.getbyte(0)<
|
35
|
+
unless b.getbyte(0)<32 || b.getbyte(0)>127 then
|
36
36
|
newarg.concat(b)
|
37
37
|
end
|
38
38
|
}
|
@@ -533,4 +533,97 @@ class TungstenUtil
|
|
533
533
|
singular
|
534
534
|
end
|
535
535
|
end
|
536
|
+
|
537
|
+
# Read an INI file and return a hash of the arguments for each section
|
538
|
+
def parse_ini_file(file, convert_to_hash = true)
|
539
|
+
unless defined?(IniParse)
|
540
|
+
require 'tungsten/iniparse'
|
541
|
+
end
|
542
|
+
|
543
|
+
unless File.exists?(file)
|
544
|
+
return
|
545
|
+
end
|
546
|
+
|
547
|
+
# Read each section and turn the lines into an array of arguments as
|
548
|
+
# they would appear in the INI file
|
549
|
+
options = {}
|
550
|
+
ini = IniParse.open(file)
|
551
|
+
ini.each{
|
552
|
+
|section|
|
553
|
+
key = section.key
|
554
|
+
|
555
|
+
# Initialize the array only if it doesn't exist
|
556
|
+
# Doing otherwise would overwrite old sections
|
557
|
+
unless options.has_key?(key)
|
558
|
+
options[key] = []
|
559
|
+
end
|
560
|
+
|
561
|
+
section.each{
|
562
|
+
|line|
|
563
|
+
unless line.is_a?(Array)
|
564
|
+
values = [line]
|
565
|
+
else
|
566
|
+
values = line
|
567
|
+
end
|
568
|
+
|
569
|
+
values.each{
|
570
|
+
|value|
|
571
|
+
if value.value == nil
|
572
|
+
options[key] << "#{value.key}"
|
573
|
+
else
|
574
|
+
options[key] << "#{value.key}=#{value.value.to_s()}"
|
575
|
+
end
|
576
|
+
}
|
577
|
+
}
|
578
|
+
}
|
579
|
+
|
580
|
+
# Most users will want a Hash, but this will allow the main
|
581
|
+
# TungstenScript class to see the parameters in order
|
582
|
+
if convert_to_hash == true
|
583
|
+
return convert_ini_array_to_hash(options)
|
584
|
+
else
|
585
|
+
return options
|
586
|
+
end
|
587
|
+
end
|
588
|
+
|
589
|
+
# Convert the information returned by parse_ini_file into a
|
590
|
+
# nested hash of values
|
591
|
+
def convert_ini_array_to_hash(options)
|
592
|
+
hash = {}
|
593
|
+
|
594
|
+
options.each{
|
595
|
+
|section,lines|
|
596
|
+
unless hash.has_key?(section)
|
597
|
+
hash[section] = {}
|
598
|
+
end
|
599
|
+
|
600
|
+
lines.each{
|
601
|
+
|line|
|
602
|
+
parts = line.split("=")
|
603
|
+
|
604
|
+
# The first part is the argument name
|
605
|
+
argument = parts.shift()
|
606
|
+
# Any remaining values will be returned as a single string
|
607
|
+
# A nil value means there was no value after the '='
|
608
|
+
if parts.size() == 0
|
609
|
+
v = nil
|
610
|
+
else
|
611
|
+
v = parts.join("=")
|
612
|
+
end
|
613
|
+
|
614
|
+
# Return repeat arguments as an array of values
|
615
|
+
if hash[section].has_key?(argument)
|
616
|
+
unless hash[section][argument].is_a?(Array)
|
617
|
+
hash[section][argument] = [hash[section][argument]]
|
618
|
+
end
|
619
|
+
|
620
|
+
hash[section][argument] << v
|
621
|
+
else
|
622
|
+
hash[section][argument] = v
|
623
|
+
end
|
624
|
+
}
|
625
|
+
}
|
626
|
+
|
627
|
+
return hash
|
628
|
+
end
|
536
629
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: continuent-tools-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Continuent
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json_pure
|
@@ -117,9 +117,17 @@ extra_rdoc_files: []
|
|
117
117
|
files:
|
118
118
|
- bin/tungsten_create_load
|
119
119
|
- lib/continuent-tools-core.rb
|
120
|
+
- lib/iniparse/document.rb
|
121
|
+
- lib/iniparse/generator.rb
|
122
|
+
- lib/iniparse/LICENSE
|
123
|
+
- lib/iniparse/line_collection.rb
|
124
|
+
- lib/iniparse/lines.rb
|
125
|
+
- lib/iniparse/parser.rb
|
126
|
+
- lib/iniparse.rb
|
120
127
|
- lib/tungsten/api.rb
|
121
128
|
- lib/tungsten/common.rb
|
122
129
|
- lib/tungsten/exec.rb
|
130
|
+
- lib/tungsten/iniparse.rb
|
123
131
|
- lib/tungsten/install.rb
|
124
132
|
- lib/tungsten/properties.rb
|
125
133
|
- lib/tungsten/README
|
@@ -149,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
157
|
version: '0'
|
150
158
|
requirements: []
|
151
159
|
rubyforge_project:
|
152
|
-
rubygems_version: 2.0.
|
160
|
+
rubygems_version: 2.0.14
|
153
161
|
signing_key:
|
154
162
|
specification_version: 4
|
155
163
|
summary: Continuent Tungsten tools core functions
|