rlogic 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/wlst/wlst.rb ADDED
@@ -0,0 +1,196 @@
1
+ # The MIT License
2
+ #
3
+ # Copyright (c) 2012 Marcelo Guimarães <ataxexe@gmail.com>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ require 'yaml'
24
+
25
+ module WLST
26
+
27
+ class ScriptResolver
28
+
29
+ attr_reader :scripts
30
+
31
+ def initialize params = {}
32
+ @scripts = {}
33
+ base_dir = File.dirname(__FILE__)
34
+ dir = "#{base_dir}/scripts"
35
+ find_scripts(dir)
36
+ find_scripts params[:scripts_dir] if params[:scripts_dir]
37
+ @includes = []
38
+ includes.each do |include|
39
+ @includes << File.join(base_dir, include)
40
+ end
41
+ end
42
+
43
+ def has_script? key
44
+ @scripts.has_key? key
45
+ end
46
+
47
+ def create params
48
+ send :"create_from_#{params[:from]}", params[:script], params[:for], *params[:using]
49
+ end
50
+
51
+ private
52
+
53
+ def find_scripts dir
54
+ scripts = Dir.entries(dir).find_all { |f| f.end_with? '.py' }
55
+ scripts.each do |script|
56
+ key = script.gsub(/.py/, '').gsub(/_/, '-')
57
+ @scripts[key] = {
58
+ :file => "#{dir}/#{script}",
59
+ :info => {}
60
+ }
61
+ info_file = "#{dir}/#{script.gsub '.py', '.info'}"
62
+ definition_file = "#{dir}/#{script.gsub '.py', '.yaml'}"
63
+ @scripts[key][:info] = File.read info_file if File.exist? info_file
64
+ @scripts[key][:definition] = YAML::load_file definition_file if File.exist? definition_file
65
+ end
66
+ end
67
+
68
+ def create_from_command_line script, server, *args
69
+ script = @scripts[script]
70
+ parser = ArgParser::new script[:definition]
71
+ params = parser.parse *args
72
+ content = ""
73
+ @includes.each do |include|
74
+ content << File.read(include)
75
+ end
76
+ content << "weblogic = #{server.to_s.gsub(/:(\w+)=>/, '\'\1\':')}\n"
77
+ content << "args = #{params.to_s.gsub(/=>:(\w+)/, ':\1').gsub("=>", ":")}\n"
78
+ content << File.read(script[:file])
79
+ content
80
+ end
81
+
82
+ end
83
+
84
+ class ArgParser
85
+
86
+ attr_reader :converter
87
+
88
+ def initialize definitions = {}
89
+ @definitions = definitions
90
+ @converter = {
91
+ :array => lambda do |arg|
92
+ return arg if arg.is_a? Array
93
+ arg.split(',')
94
+ end,
95
+ :boolean => lambda do |arg|
96
+ if arg.is_a? FalseClass or arg.is_a? TrueClass
97
+ return arg.to_s.capitalize.to_sym
98
+ end
99
+ return :False if arg.downcase == 'false'
100
+ return :True if arg.downcase == 'true'
101
+ :True
102
+ end,
103
+ :int => lambda do |arg|
104
+ arg.to_i
105
+ end,
106
+ :float => lambda do |arg|
107
+ arg.to_f
108
+ end,
109
+ :string => lambda do |arg|
110
+ arg
111
+ end
112
+ }
113
+ end
114
+
115
+ def parse *args
116
+ params = {}
117
+ args.each do |arg|
118
+ value = arg.split '='
119
+ key = value.delete_at(0).gsub('-', '_')
120
+ definition = @definitions[key]
121
+ converter = @converter[definition['type'].to_sym]
122
+ value = value.join('=')
123
+ params[key] = converter.call value if converter
124
+ params[key] ||= value
125
+ end
126
+ @definitions.each do |name, defs|
127
+ unless params.has_key? name
128
+ raise "#{name} not specified" if defs['required']
129
+ converter = @converter[defs['type'].to_sym]
130
+ params[name] = converter.call defs['default'] if converter
131
+ params[name] ||= defs['default']
132
+ end
133
+ end
134
+ params
135
+ end
136
+
137
+ end
138
+
139
+ class Command
140
+
141
+ def initialize buffer = ""
142
+ @__buffer__ = buffer
143
+ end
144
+
145
+ def method_missing(symbol, *args)
146
+ args = args.to_s[1..-2]
147
+ if symbol.to_s.end_with? '='
148
+ param = symbol.to_s[0..-2]
149
+ param[0] = param[0].upcase
150
+ self << "set#{param}(#{args})"
151
+ else
152
+ self << "#{symbol}(#{args})"
153
+ end
154
+ end
155
+
156
+ def << command
157
+ append = ""
158
+ append << command << "\n"
159
+ @__buffer__ << append
160
+ append
161
+ end
162
+
163
+ def to_f file
164
+ File.open(file, 'w') { |f| f.write to_s }
165
+ end
166
+
167
+ def to_s
168
+ @__buffer__.chomp
169
+ end
170
+
171
+ end
172
+
173
+ class Runner
174
+
175
+ def initialize wl_home
176
+ @wl_home = wl_home
177
+ end
178
+
179
+ def run file
180
+ result = `#{command file}`
181
+ truncated = ""
182
+ flag = false
183
+ result.each_line do |line|
184
+ if line.strip == "Type help() for help on available commands"
185
+ flag = true
186
+ next
187
+ end
188
+ truncated << line if flag
189
+ end
190
+ return truncated.strip unless truncated.empty?
191
+ result
192
+ end
193
+
194
+ end
195
+
196
+ end
data/rlogic.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "rlogic/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "rlogic"
7
+ s.version = Rlogic::VERSION
8
+ s.authors = ["Ataxexe"]
9
+ s.email = ["ataxexe@gmail.com"]
10
+ s.homepage = "https://github.com/ataxexe/rlogic"
11
+ s.summary = %q{A tool for dealing with WebLogic Scripting Tool}
12
+ s.description = %q{A tool for dealing with WebLogic Scripting Tool}
13
+
14
+ s.rubyforge_project = "rlogic"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ # s.add_runtime_dependency "rest-client"
24
+ end
data/rlogic.iml ADDED
@@ -0,0 +1,211 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="RUBY_MODULE" version="4">
3
+ <component name="FacetManager">
4
+ <facet type="Python" name="Python">
5
+ <configuration sdkName="Python 2.7.2 (/usr/bin/python2.7)" />
6
+ </facet>
7
+ </component>
8
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
9
+ <exclude-output />
10
+ <content url="file://$MODULE_DIR$">
11
+ <sourceFolder url="file://$MODULE_DIR$/lib" isTestSource="false" />
12
+ <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
13
+ <sourceFolder url="file://$MODULE_DIR$/bin" isTestSource="false" />
14
+ <excludeFolder url="file://$MODULE_DIR$/pkg" />
15
+ </content>
16
+ <orderEntry type="jdk" jdkName="RVM: ruby-1.9.2-p290" jdkType="RUBY_SDK" />
17
+ <orderEntry type="sourceFolder" forTests="false" />
18
+ <orderEntry type="library" name="Python 2.7.2 (/usr/bin/python2.7) interpreter library" level="application" />
19
+ <orderEntry type="library" scope="PROVIDED" name="bundler (v1.1.1, RVM: ruby-1.9.2-p290) [gem]" level="application" />
20
+ </component>
21
+ <component name="org.twodividedbyzero.idea.findbugs">
22
+ <option name="_basePreferences">
23
+ <map>
24
+ <entry key="property.analysisEffortLevel" value="default" />
25
+ <entry key="property.analyzeAfterCompile" value="false" />
26
+ <entry key="property.exportAsHtml" value="true" />
27
+ <entry key="property.exportAsXml" value="true" />
28
+ <entry key="property.exportBaseDir" value="" />
29
+ <entry key="property.exportCreateArchiveDir" value="false" />
30
+ <entry key="property.exportOpenBrowser" value="true" />
31
+ <entry key="property.minPriorityToReport" value="Medium" />
32
+ <entry key="property.runAnalysisInBackground" value="false" />
33
+ <entry key="property.showHiddenDetectors" value="false" />
34
+ <entry key="property.toolWindowToFront" value="true" />
35
+ </map>
36
+ </option>
37
+ <option name="_detectors">
38
+ <map>
39
+ <entry key="AppendingToAnObjectOutputStream" value="true" />
40
+ <entry key="BCPMethodReturnCheck" value="false" />
41
+ <entry key="BadAppletConstructor" value="false" />
42
+ <entry key="BadResultSetAccess" value="true" />
43
+ <entry key="BadSyntaxForRegularExpression" value="true" />
44
+ <entry key="BadUseOfReturnValue" value="true" />
45
+ <entry key="BadlyOverriddenAdapter" value="true" />
46
+ <entry key="BooleanReturnNull" value="true" />
47
+ <entry key="BuildInterproceduralCallGraph" value="false" />
48
+ <entry key="BuildObligationPolicyDatabase" value="true" />
49
+ <entry key="CallToUnsupportedMethod" value="false" />
50
+ <entry key="CalledMethods" value="true" />
51
+ <entry key="CheckCalls" value="false" />
52
+ <entry key="CheckExpectedWarnings" value="false" />
53
+ <entry key="CheckImmutableAnnotation" value="true" />
54
+ <entry key="CheckTypeQualifiers" value="true" />
55
+ <entry key="CloneIdiom" value="true" />
56
+ <entry key="ComparatorIdiom" value="true" />
57
+ <entry key="ConfusedInheritance" value="true" />
58
+ <entry key="ConfusionBetweenInheritedAndOuterMethod" value="true" />
59
+ <entry key="CrossSiteScripting" value="true" />
60
+ <entry key="DoInsideDoPrivileged" value="true" />
61
+ <entry key="DontCatchIllegalMonitorStateException" value="true" />
62
+ <entry key="DontIgnoreResultOfPutIfAbsent" value="true" />
63
+ <entry key="DontUseEnum" value="true" />
64
+ <entry key="DroppedException" value="true" />
65
+ <entry key="DumbMethodInvocations" value="true" />
66
+ <entry key="DumbMethods" value="true" />
67
+ <entry key="DuplicateBranches" value="true" />
68
+ <entry key="EmptyZipFileEntry" value="true" />
69
+ <entry key="EqStringTest" value="false" />
70
+ <entry key="EqualsOperandShouldHaveClassCompatibleWithThis" value="true" />
71
+ <entry key="FieldItemSummary" value="true" />
72
+ <entry key="FinalizerNullsFields" value="true" />
73
+ <entry key="FindBadCast" value="false" />
74
+ <entry key="FindBadCast2" value="true" />
75
+ <entry key="FindBadEqualsImplementation" value="false" />
76
+ <entry key="FindBadForLoop" value="true" />
77
+ <entry key="FindBugsSummaryStats" value="true" />
78
+ <entry key="FindCircularDependencies" value="false" />
79
+ <entry key="FindDeadLocalStores" value="true" />
80
+ <entry key="FindDoubleCheck" value="true" />
81
+ <entry key="FindEmptySynchronizedBlock" value="true" />
82
+ <entry key="FindFieldSelfAssignment" value="true" />
83
+ <entry key="FindFinalizeInvocations" value="true" />
84
+ <entry key="FindFloatEquality" value="true" />
85
+ <entry key="FindFloatMath" value="false" />
86
+ <entry key="FindHEmismatch" value="true" />
87
+ <entry key="FindInconsistentSync2" value="true" />
88
+ <entry key="FindJSR166LockMonitorenter" value="true" />
89
+ <entry key="FindLocalSelfAssignment2" value="true" />
90
+ <entry key="FindMaskedFields" value="true" />
91
+ <entry key="FindMismatchedWaitOrNotify" value="true" />
92
+ <entry key="FindNakedNotify" value="true" />
93
+ <entry key="FindNonSerializableStoreIntoSession" value="true" />
94
+ <entry key="FindNonSerializableValuePassedToWriteObject" value="true" />
95
+ <entry key="FindNonShortCircuit" value="true" />
96
+ <entry key="FindNullDeref" value="true" />
97
+ <entry key="FindNullDerefsInvolvingNonShortCircuitEvaluation" value="true" />
98
+ <entry key="FindOpenStream" value="true" />
99
+ <entry key="FindPuzzlers" value="true" />
100
+ <entry key="FindRefComparison" value="true" />
101
+ <entry key="FindReturnRef" value="true" />
102
+ <entry key="FindRunInvocations" value="true" />
103
+ <entry key="FindSelfComparison" value="true" />
104
+ <entry key="FindSelfComparison2" value="true" />
105
+ <entry key="FindSleepWithLockHeld" value="true" />
106
+ <entry key="FindSpinLoop" value="true" />
107
+ <entry key="FindSqlInjection" value="true" />
108
+ <entry key="FindTwoLockWait" value="true" />
109
+ <entry key="FindUncalledPrivateMethods" value="true" />
110
+ <entry key="FindUnconditionalWait" value="true" />
111
+ <entry key="FindUninitializedGet" value="true" />
112
+ <entry key="FindUnrelatedTypesInGenericContainer" value="true" />
113
+ <entry key="FindUnreleasedLock" value="true" />
114
+ <entry key="FindUnsatisfiedObligation" value="true" />
115
+ <entry key="FindUnsyncGet" value="true" />
116
+ <entry key="FindUselessControlFlow" value="true" />
117
+ <entry key="FormatStringChecker" value="true" />
118
+ <entry key="HugeSharedStringConstants" value="true" />
119
+ <entry key="IDivResultCastToDouble" value="true" />
120
+ <entry key="IncompatMask" value="true" />
121
+ <entry key="InconsistentAnnotations" value="true" />
122
+ <entry key="InefficientMemberAccess" value="false" />
123
+ <entry key="InefficientToArray" value="true" />
124
+ <entry key="InfiniteLoop" value="true" />
125
+ <entry key="InfiniteRecursiveLoop" value="true" />
126
+ <entry key="InfiniteRecursiveLoop2" value="false" />
127
+ <entry key="InheritanceUnsafeGetResource" value="true" />
128
+ <entry key="InitializationChain" value="true" />
129
+ <entry key="InstantiateStaticClass" value="true" />
130
+ <entry key="InvalidJUnitTest" value="true" />
131
+ <entry key="IteratorIdioms" value="true" />
132
+ <entry key="LazyInit" value="true" />
133
+ <entry key="LoadOfKnownNullValue" value="true" />
134
+ <entry key="LockedFields" value="false" />
135
+ <entry key="LostLoggerDueToWeakReference" value="true" />
136
+ <entry key="MethodReturnCheck" value="true" />
137
+ <entry key="Methods" value="true" />
138
+ <entry key="MultithreadedInstanceAccess" value="true" />
139
+ <entry key="MutableLock" value="true" />
140
+ <entry key="MutableStaticFields" value="true" />
141
+ <entry key="Naming" value="true" />
142
+ <entry key="Noise" value="false" />
143
+ <entry key="NoiseNullDeref" value="false" />
144
+ <entry key="NoteAnnotationRetention" value="true" />
145
+ <entry key="NoteCheckReturnValue" value="true" />
146
+ <entry key="NoteCheckReturnValueAnnotations" value="true" />
147
+ <entry key="NoteDirectlyRelevantTypeQualifiers" value="true" />
148
+ <entry key="NoteJCIPAnnotation" value="true" />
149
+ <entry key="NoteNonNullAnnotations" value="true" />
150
+ <entry key="NoteNonnullReturnValues" value="true" />
151
+ <entry key="NoteSuppressedWarnings" value="true" />
152
+ <entry key="NoteUnconditionalParamDerefs" value="true" />
153
+ <entry key="NumberConstructor" value="true" />
154
+ <entry key="OverridingEqualsNotSymmetrical" value="true" />
155
+ <entry key="PreferZeroLengthArrays" value="true" />
156
+ <entry key="PublicSemaphores" value="false" />
157
+ <entry key="QuestionableBooleanAssignment" value="true" />
158
+ <entry key="ReadOfInstanceFieldInMethodInvokedByConstructorInSuperclass" value="true" />
159
+ <entry key="ReadReturnShouldBeChecked" value="true" />
160
+ <entry key="RedundantInterfaces" value="true" />
161
+ <entry key="ReflectiveClasses" value="true" />
162
+ <entry key="RepeatedConditionals" value="true" />
163
+ <entry key="ResolveAllReferences" value="false" />
164
+ <entry key="RuntimeExceptionCapture" value="true" />
165
+ <entry key="SerializableIdiom" value="true" />
166
+ <entry key="StartInConstructor" value="true" />
167
+ <entry key="StaticCalendarDetector" value="true" />
168
+ <entry key="StringConcatenation" value="true" />
169
+ <entry key="SuperfluousInstanceOf" value="true" />
170
+ <entry key="SuspiciousThreadInterrupted" value="true" />
171
+ <entry key="SwitchFallthrough" value="true" />
172
+ <entry key="SynchronizationOnSharedBuiltinConstant" value="true" />
173
+ <entry key="SynchronizeAndNullCheckField" value="true" />
174
+ <entry key="SynchronizeOnClassLiteralNotGetClass" value="true" />
175
+ <entry key="SynchronizingOnContentsOfFieldToProtectField" value="true" />
176
+ <entry key="TestASM" value="false" />
177
+ <entry key="TestDataflowAnalysis" value="false" />
178
+ <entry key="TestingGround" value="false" />
179
+ <entry key="TrainFieldStoreTypes" value="true" />
180
+ <entry key="TrainNonNullAnnotations" value="true" />
181
+ <entry key="TrainUnconditionalDerefParams" value="true" />
182
+ <entry key="URLProblems" value="true" />
183
+ <entry key="UncallableMethodOfAnonymousClass" value="true" />
184
+ <entry key="UnnecessaryMath" value="true" />
185
+ <entry key="UnreadFields" value="true" />
186
+ <entry key="UseObjectEquals" value="false" />
187
+ <entry key="UselessSubclassMethod" value="false" />
188
+ <entry key="VarArgsProblems" value="true" />
189
+ <entry key="VolatileUsage" value="true" />
190
+ <entry key="WaitInLoop" value="true" />
191
+ <entry key="WrongMapIterator" value="true" />
192
+ <entry key="XMLFactoryBypass" value="true" />
193
+ </map>
194
+ </option>
195
+ <option name="_reportCategories">
196
+ <map>
197
+ <entry key="BAD_PRACTICE" value="true" />
198
+ <entry key="CORRECTNESS" value="true" />
199
+ <entry key="EXPERIMENTAL" value="true" />
200
+ <entry key="I18N" value="true" />
201
+ <entry key="MALICIOUS_CODE" value="true" />
202
+ <entry key="MT_CORRECTNESS" value="true" />
203
+ <entry key="NOISE" value="false" />
204
+ <entry key="PERFORMANCE" value="true" />
205
+ <entry key="SECURITY" value="true" />
206
+ <entry key="STYLE" value="true" />
207
+ </map>
208
+ </option>
209
+ </component>
210
+ </module>
211
+