ppmtogdl 0.1.2

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.
@@ -0,0 +1,140 @@
1
+ ###############################################################################
2
+ # File:: gdldocbuilder.rb
3
+ # Purpose:: GdlDocBuilder class is a builder object for building GDL
4
+ # source documents.
5
+ #
6
+ # Author:: Jeff McAffee 04/30/2015
7
+ #
8
+ ##############################################################################
9
+
10
+ require 'xmlutils/ruleparser'
11
+ require 'xmlutils/lineparser'
12
+
13
+ module PpmToGdl
14
+ class GdlDocBuilder
15
+
16
+ attr_accessor :options
17
+ attr_accessor :context
18
+
19
+ #-------------------------------------------------------------------------------------------------------------#
20
+ # initialize - CTor
21
+ #
22
+ # options - Document builder options
23
+ #
24
+ #------------------------------------------------------------------------------------------------------------#
25
+ def initialize(options)
26
+ $LOG.debug "GdlDocBuilder::initialize( #{options} )"
27
+ @options = options
28
+ @context = PpmContext.new
29
+ @context.setOptions(@options)
30
+ end # initialize
31
+
32
+ #-------------------------------------------------------------------------------------------------------------#
33
+ # createDocument - create a GDL document from an XML document
34
+ #
35
+ # srcPath - XML source file
36
+ # rootDor - root directory
37
+ #
38
+ #------------------------------------------------------------------------------------------------------------#
39
+ def createDocument(srcPath)
40
+ $LOG.debug "GdlDocBuilder::createDocument( #{srcPath} )"
41
+
42
+ # Setup context object builder
43
+ ctxBuilder = ContextParser.new(@context)
44
+ ctxBuilder.setFlag(@options)
45
+
46
+ statusMsg "Creating context based on src file [ #{srcPath} ]."
47
+
48
+ ctxBuilder.parse(srcPath)
49
+
50
+ printMetrics(@context)
51
+ =begin
52
+ statusMsg "Parsing external variable definitions."
53
+
54
+ parseExternalVarDefs(@context)
55
+
56
+
57
+
58
+ statusMsg "Parsing rule data (#{ctxBuilder.context.rules.size.to_s} rules)."
59
+
60
+ ruleBuilder = RuleParser.new(@context)
61
+ ruleBuilder.setFlag(@options)
62
+
63
+ @context.rules.each do |key, rule|
64
+ rule.src = ruleBuilder.parse(rule.xml)
65
+ print "."
66
+ end # rules.each
67
+ puts
68
+ =end
69
+
70
+ # ctxBuilder.dumpResults
71
+
72
+ # Create output file and output src.
73
+ statusMsg "Generating document."
74
+
75
+ gdlDoc = GdlDoc.new(srcPath, @context)
76
+ gdlDoc.setOptions(@options)
77
+
78
+ genFile = gdlDoc.generate
79
+
80
+ statusMsg "Document created: #{genFile}"
81
+
82
+ #genFile = gdlDoc.generateRenameList
83
+
84
+ #statusMsg "Rename list document created: #{genFile}"
85
+
86
+ end # createDocument
87
+
88
+ #-------------------------------------------------------------------------------------------------------------#
89
+ # statusMsg - output a status message
90
+ #
91
+ # msg - Message to output
92
+ #
93
+ #------------------------------------------------------------------------------------------------------------#
94
+ def statusMsg(msg)
95
+
96
+ puts
97
+ puts "-} #{msg}"
98
+ puts
99
+
100
+ end # statusMsg
101
+
102
+ #-------------------------------------------------------------------------------------------------------------#
103
+ # printMetrics - Print context metrics
104
+ #
105
+ # ctx - Context to generate metrics from
106
+ #
107
+ #------------------------------------------------------------------------------------------------------------#
108
+ def printMetrics(ctx)
109
+ $LOG.debug "GdlDocBuilder::printMetrics()"
110
+ puts " PPM count: #{ctx.ppms.size.to_s}"
111
+
112
+ end # printMetrics
113
+
114
+ #-------------------------------------------------------------------------------------------------------------#
115
+ # parseExternalVarDefs - parse predefined GDL variable definition files.
116
+ #
117
+ # ctx - context containing variables to update
118
+ #
119
+ #------------------------------------------------------------------------------------------------------------#
120
+ def parseExternalVarDefs(ctx)
121
+ =begin
122
+ vp = LineParser.new # Parse externally defined GDL variable definition files.
123
+ vp.parse("R:/common/inc/DPMs.gdl") # TODO: Allow external var def files to be defined in a config file.
124
+ vp.parse("R:/common/inc/DSMs.gdl")
125
+ vp.parse("R:/common/inc/PPMs.gdl")
126
+
127
+ vp.dumpResults if $DEBUG
128
+
129
+ puts "Searching for external PPM definitions." if $DEBUG
130
+ ctx.ppms.each do |key, val|
131
+ if (vp.ppms.has_key?(key))
132
+ ctx.ppms[key] = vp.ppms[key]
133
+ puts "Found match: #{key}" if $DEBUG
134
+ end # if vp.ppms
135
+ end # do
136
+ =end
137
+ end # parseExternalVarDefs
138
+ end # class GdlDocBuilder
139
+ end # module PpmToGdl
140
+
@@ -0,0 +1,81 @@
1
+ ###############################################################################
2
+ # File:: ppmcontext.rb
3
+ # Purpose:: PpmContext class holds ppm variable definitions
4
+ #
5
+ # Author:: Jeff McAffee 04/30/2015
6
+ #
7
+ ##############################################################################
8
+
9
+ module PpmToGdl
10
+ class PpmContext
11
+
12
+ attr_accessor :ppms
13
+ attr_accessor :options
14
+
15
+ def initialize()
16
+ $LOG.debug "PpmContext::initialize()"
17
+ @ppms = Hash.new
18
+ end # initialize
19
+
20
+ def setOptions(options)
21
+ $LOG.debug "PpmContext::setOptions( #{options} )"
22
+ @options = options
23
+ end
24
+
25
+ # Generate a valid guideline (GDL) ID
26
+ # inname:: name to convert
27
+ def createValidName(inname)
28
+ $LOG.debug "PpmContext::createValidName( #{inname} )"
29
+ outname = inname.gsub(/[\s\/\\?*#+]/,'') # Remove illegal chars (replace with underscore).
30
+ outname.gsub!(/_+/,"_") # Replace consecutive uscores with single uscore.
31
+ outname.gsub!(/\./,"-") # Replace period with dash.
32
+ outname.gsub!(/[\(\)\$]/,"") # Remove L & R Parens, dollar signs.
33
+ outname.gsub!(/\%/,"Perc") # Replace '%' with Perc.
34
+
35
+ outname
36
+ end
37
+
38
+ def isPpmVar(var)
39
+ isPpm = false
40
+
41
+ case var.varType
42
+ when 'app'
43
+ isPpm = true
44
+
45
+ when 'crd'
46
+ isPpm = true
47
+
48
+ when 'prd'
49
+ isPpm = true
50
+
51
+ end # case
52
+
53
+ isPpm
54
+ end # isPpmVar
55
+
56
+ # Dump all PPM variables
57
+ def dumpPpms()
58
+ $LOG.debug "PpmContext::dumpPpms()"
59
+ 79.times {print "="}
60
+ puts
61
+ puts "PPM DUMP".center(80)
62
+ 79.times {print "="}
63
+ puts
64
+
65
+ if(@ppms.length > 0)
66
+ ppms = @ppms.sort
67
+ ppms.each do |key, ppm|
68
+ puts "#{ppm.name}\t(#{ppm.alias})"
69
+ end
70
+
71
+ else
72
+ puts "No PPM variables to dump."
73
+ end
74
+
75
+ puts ""
76
+ end # dumpppms
77
+ end # class PpmContext
78
+ end # module PpmToGdl
79
+
80
+
81
+
@@ -0,0 +1,78 @@
1
+ ##############################################################################
2
+ # File:: ppmcontextobjs.rb
3
+ # Purpose:: PrimaryParameter context objects
4
+ #
5
+ # Author:: Jeff McAffee 04/30/2015
6
+ #
7
+ ##############################################################################
8
+
9
+ module PpmToGdl
10
+ ##########################################################################
11
+ # MPpm class describes a PPM object
12
+ class MPpm
13
+
14
+ attr_accessor :id
15
+ attr_accessor :name
16
+ attr_accessor :alias
17
+ attr_accessor :varType # Type attribute - What portion of decision log value comes from: valid values "PRD, CRP, APM
18
+ attr_accessor :dataType # DataType attribute -numeric, text, money, etc.
19
+ attr_accessor :customer
20
+ attr_accessor :verbose
21
+
22
+ def initialize(name, attributes, verbose=false)
23
+ $LOG.debug "Ppm::initialize( #{name}, #{attributes} )"
24
+
25
+ @verbose = verbose
26
+ @name = name
27
+ @alias = attributes["Name"]
28
+ @varType = attributes["Type"]
29
+ #@dataType = "UNKNOWN"
30
+ @dataType = attributes["Datatype"] #if (attributes.has_key?("Datatype"))
31
+
32
+ @customer = attributes["Customer"]
33
+
34
+ if(@verbose)
35
+ attributes.each do |k, v|
36
+ puts "Attrib[ #{k} ]: #{v}"
37
+ end
38
+ end
39
+
40
+ case @varType
41
+ when 'APM'
42
+ @varType = "app"
43
+
44
+ when 'CRP'
45
+ @varType = "crd"
46
+
47
+ when 'PRD'
48
+ @varType = "prd"
49
+ end # varType
50
+
51
+ case @dataType
52
+ when 'Boolean'
53
+ @dataType = "boolean"
54
+
55
+ when 'Date'
56
+ @dataType = "date"
57
+
58
+ when 'Money'
59
+ @dataType = "money"
60
+
61
+ when 'Numeric'
62
+ @dataType = "numeric"
63
+
64
+ when 'Percentage'
65
+ @dataType = "percentage"
66
+
67
+ when 'Text'
68
+ @dataType = "text"
69
+
70
+ when 'DateTime'
71
+ @dataType = "datetime"
72
+
73
+ end # dataType
74
+ end # initialize
75
+ end # class Ppm
76
+ end # module PpmToGdl
77
+
78
+
@@ -0,0 +1,47 @@
1
+ ##############################################################################
2
+ # File:: ppmtogdlcfg.rb
3
+ # Purpose:: PpmToGdl configuration file reader/writer class.
4
+ #
5
+ # Author:: Jeff McAffee 03/07/2010
6
+ # Copyright:: Copyright (c) 2010, kTech Systems LLC. All rights reserved.
7
+ # Website:: http://ktechsystems.com
8
+ ##############################################################################
9
+
10
+ require 'ktcommon/ktcfg'
11
+
12
+ module PpmToGdl
13
+ class PpmToGdlCfg < KtCfg::CfgFile
14
+
15
+ attr_accessor :cfg
16
+
17
+ def initialize(rootDir=nil)
18
+ $LOG.debug "PpmToGdlCfg::initialize"
19
+ super
20
+ @cfg = {}
21
+
22
+ setDefaults()
23
+ end
24
+
25
+ def setDefaults
26
+ $LOG.debug "PpmToGdlCfg::setDefaults"
27
+ app_path = ENV["LOCALAPPDATA"]
28
+ app_path ||= ENV["HOME"]
29
+ @cfg[:appPath] = File.rubypath(File.join(app_path, "ppmtogdl"))
30
+ end
31
+
32
+ # Load the YAML configuration file.
33
+ # returns:: a hash containing configuration info.
34
+ def load
35
+ $LOG.debug "PpmToGdlCfg::load"
36
+ @cfg = read("ppmtogdlcfg.yml")
37
+ rescue
38
+ # Nothing to read. Leave the defaults.
39
+ end
40
+
41
+ # Save the @cfg hash to a YAML file.
42
+ def save
43
+ $LOG.debug "PpmToGdlCfg::save"
44
+ write("ppmtogdlcfg.yml", @cfg)
45
+ end
46
+ end # class PpmToGdlCfg
47
+ end # module PpmToGdl
@@ -0,0 +1,80 @@
1
+ ##############################################################################
2
+ # File:: ppmtogdlcontroller.rb
3
+ # Purpose:: Main Controller object for PpmToGdl utility
4
+ #
5
+ # Author:: Jeff McAffee 03/07/2010
6
+ # Copyright:: Copyright (c) 2010, kTech Systems LLC. All rights reserved.
7
+ # Website:: http://ktechsystems.com
8
+ ##############################################################################
9
+
10
+ require 'ktcommon/ktpath'
11
+ require 'ktcommon/ktcmdline'
12
+
13
+ module PpmToGdl
14
+ class PpmToGdlController
15
+
16
+ attr_reader :verbose
17
+ attr_reader :customer
18
+ attr_reader :srcPath
19
+ attr_reader :destPath
20
+
21
+ def initialize()
22
+ $LOG.debug "PpmToGdlController::initialize"
23
+ @cfg = PpmToGdlCfg.new.load
24
+ @verbose = false
25
+ @customer = ""
26
+ @srcPath = ""
27
+ @destPath = ""
28
+ end
29
+
30
+ def customer=( customer )
31
+ @customer = customer
32
+ end
33
+
34
+
35
+ def verbose=( verbose )
36
+ return unless (verbose == true || verbose == false)
37
+ @verbose = verbose
38
+ end
39
+
40
+
41
+ def doSomething()
42
+ $LOG.debug "PpmToGdlController::doSomething"
43
+ options = {}
44
+ options["customer"] = @customer # FIXME: I think these should be symbols now, not strings.
45
+ options["verbose"] = @verbose
46
+
47
+ destFile = ""
48
+ destFile = File.basename(@destPath) unless File.directory?(@destPath)
49
+ if(!destFile.empty?)
50
+ options[:destfile] = destFile
51
+ end
52
+ destDir = @destPath
53
+ destDir = File.dirname(@destPath) unless File.directory?(@destPath)
54
+ if(destDir.length() < 1)
55
+ destDir = Dir.getwd()
56
+ end
57
+ options[:destdir] = destDir
58
+
59
+ docBuilder = GdlDocBuilder.new(options)
60
+ docBuilder.createDocument(@srcPath)
61
+ end
62
+
63
+
64
+ def setFilenames(arg)
65
+ $LOG.debug "PpmToGdlController::setFilenames( #{arg} )"
66
+ @srcPath = arg[0]
67
+ @destPath = arg[1]
68
+
69
+ @srcPath = File.rubypath(@srcPath)
70
+ @destPath = File.rubypath(@destPath)
71
+ end
72
+
73
+
74
+ def noCmdLineArg()
75
+ $LOG.debug "PpmToGdlController::noCmdLineArg"
76
+ #exit "Should never reach here."
77
+ end
78
+ end # class PpmToGdlController
79
+ end # module PpmToGdl
80
+
@@ -0,0 +1,29 @@
1
+ ##############################################################################
2
+ # File:: ppmtogdltask.rb
3
+ # Purpose:: Rake Task for running the application
4
+ #
5
+ # Author:: Jeff McAffee 03/07/2010
6
+ # Copyright:: Copyright (c) 2010, kTech Systems LLC. All rights reserved.
7
+ # Website:: http://ktechsystems.com
8
+ ##############################################################################
9
+
10
+ require 'ppmtogdl'
11
+
12
+ include PpmToGdl
13
+
14
+ class PpmToGdlTask
15
+
16
+ def execute(customer, srcPath, destPath, verbose=false)
17
+ filenames = [srcPath, destPath]
18
+ raise "Missing source file path." unless (! srcPath.nil? && !srcPath.empty?)
19
+ raise "Missing destination file path." unless (! destPath.nil? && !destPath.empty?)
20
+
21
+ app = PpmToGdlController.new
22
+ app.customer = customer
23
+ app.setFilenames(filenames)
24
+ app.verbose = verbose
25
+ app.doSomething()
26
+ end
27
+ end # class PpmToGdlTask
28
+
29
+