dmamp 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ U
@@ -0,0 +1 @@
1
+ v0.1.0. Has templating, only does manifests
@@ -0,0 +1,19 @@
1
+ CHANGELOG
2
+ Manifest
3
+ README.md
4
+ Rakefile
5
+ bin/dmamp
6
+ lib/dmamp.rb
7
+ lib/dmamp/defaultargs.rb
8
+ lib/dmamp/mod.rb
9
+ lib/dmamp/optionparser.rb
10
+ lib/dmamp/pattern.rb
11
+ lib/dmamp/patterns/parameterised-PCS/templates/config.pp
12
+ lib/dmamp/patterns/parameterised-PCS/templates/init.pp
13
+ lib/dmamp/patterns/parameterised-PCS/templates/package.pp
14
+ lib/dmamp/patterns/parameterised-PCS/templates/params.pp
15
+ lib/dmamp/patterns/parameterised-PCS/templates/service.pp
16
+ lib/dmamp/version.rb
17
+ spec/mod_spec.rb
18
+ spec/opt_spec.rb
19
+ spec/testcommon.rb
@@ -0,0 +1 @@
1
+ Module generator for puppet utilising the parameterised package-config-service pattern for puppet modules utilising the puppet stdlib puppet puppet.
@@ -0,0 +1,22 @@
1
+ require "rubygems"
2
+ require "lib/dmamp/version.rb"
3
+ require "rake"
4
+ require "echoe"
5
+
6
+ Echoe.new('dmamp', '0.0.1') do |p|
7
+ p.description = "Templating for puppet module patterns"
8
+ p.url = "http://github.com/oholiab/DMAMP"
9
+ p.author = "Matt Carroll"
10
+ p.email = "oholiab@gmail.com"
11
+ p.version = DMAMP::VERSION
12
+ p.development_dependencies = []
13
+ end
14
+
15
+ task :bump do
16
+ system 'vi lib/dmamp/version.rb'
17
+ end
18
+
19
+ task :bumplog do
20
+ version = "\nv#{DMAMP::VERSION}. CHANGEME"
21
+ system "echo \"#{version}\" >> CHANGELOG && vi CHANGELOG"
22
+ end
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+
5
+ $: << File.join(File.dirname(__FILE__), "..", "lib")
6
+ require 'dmamp'
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "dmamp"
5
+ s.version = "0.1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Matt Carroll"]
9
+ s.date = "2012-05-17"
10
+ s.description = "Templating for puppet module patterns"
11
+ s.email = "oholiab@gmail.com"
12
+ s.executables = ["dmamp"]
13
+ s.extra_rdoc_files = ["CHANGELOG", "README.md", "bin/dmamp", "lib/dmamp.rb", "lib/dmamp/defaultargs.rb", "lib/dmamp/mod.rb", "lib/dmamp/optionparser.rb", "lib/dmamp/pattern.rb", "lib/dmamp/patterns/parameterised-PCS/templates/config.pp", "lib/dmamp/patterns/parameterised-PCS/templates/init.pp", "lib/dmamp/patterns/parameterised-PCS/templates/package.pp", "lib/dmamp/patterns/parameterised-PCS/templates/params.pp", "lib/dmamp/patterns/parameterised-PCS/templates/service.pp", "lib/dmamp/version.rb"]
14
+ s.files = ["CHANGELOG", "Manifest", "README.md", "Rakefile", "bin/dmamp", "lib/dmamp.rb", "lib/dmamp/defaultargs.rb", "lib/dmamp/mod.rb", "lib/dmamp/optionparser.rb", "lib/dmamp/pattern.rb", "lib/dmamp/patterns/parameterised-PCS/templates/config.pp", "lib/dmamp/patterns/parameterised-PCS/templates/init.pp", "lib/dmamp/patterns/parameterised-PCS/templates/package.pp", "lib/dmamp/patterns/parameterised-PCS/templates/params.pp", "lib/dmamp/patterns/parameterised-PCS/templates/service.pp", "lib/dmamp/version.rb", "spec/mod_spec.rb", "spec/opt_spec.rb", "spec/testcommon.rb", "dmamp.gemspec"]
15
+ s.homepage = "http://github.com/oholiab/DMAMP"
16
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Dmamp", "--main", "README.md"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = "dmamp"
19
+ s.rubygems_version = "1.8.24"
20
+ s.summary = "Templating for puppet module patterns"
21
+ s.signing_key = '/Volumes/NO NAME/gem-private_key.pem'
22
+ s.cert_chain = ['/Volumes/NO NAME/gem-public_cert.pem']
23
+
24
+ if s.respond_to? :specification_version then
25
+ s.specification_version = 3
26
+
27
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
28
+ else
29
+ end
30
+ else
31
+ end
32
+ end
@@ -0,0 +1,8 @@
1
+ require 'singleton'
2
+ require 'optparse'
3
+ require 'dmamp/version'
4
+ require 'dmamp/optionparser'
5
+ require 'dmamp/mod'
6
+ require 'dmamp/pattern'
7
+
8
+ DMAMP::Mod.new(DMAMP::options)
@@ -0,0 +1,8 @@
1
+ module DMAMP
2
+ # Default arguments
3
+ # * +:pattern+ = parameterised-PCS
4
+ # * +:parameters+ = none
5
+ DEFAULTARGS = {:pattern => "parameterised-PCS",
6
+ :parameters => nil
7
+ }
8
+ end
@@ -0,0 +1,68 @@
1
+ # Dun Me A Module Please puppet module templater
2
+ module DMAMP
3
+ # Umbrella class that gets the pattern and builds upon
4
+ # instantiation.
5
+ class Mod
6
+ # The pattern that the created module is using
7
+ attr_reader :pattern
8
+ # The name of the new module
9
+ attr_reader :modname
10
+ # The option hash
11
+ attr_accessor :options
12
+
13
+ # Instatiates, gathers pattern metadata and then calls
14
+ # self.build to create the new module.
15
+ # +options+ - optparser option hash.
16
+ #
17
+ # ==== Options
18
+ # Must contain at least entries for keys
19
+ # * :pattern
20
+ # * :modulename
21
+ def initialize(options)
22
+ @options = options
23
+ @pattern = DMAMP.pattern(options[:pattern])
24
+ @modname = @options[:modulename]
25
+ self.build
26
+ end
27
+ # Tests whether module directory exists, then writes
28
+ # in files from template replacing placeholder variables
29
+ # and inserting extra parameters based on the template
30
+ # formatting. Quite literally builds the new module.
31
+ #
32
+ # Will abort (gracefully) if the target directory already
33
+ # exists.
34
+ def build
35
+ dir = Dir::pwd + "/" + @modname
36
+ if FileTest::directory?(dir)
37
+ abort @options[:modulename] + " directory already exists."
38
+ end
39
+
40
+ Dir::mkdir(dir)
41
+ @pattern.manitemplates.each do |m|
42
+ target = File.open(dir + "/" + m, 'a')
43
+ File.open(@pattern.templatedir + "/" + m, 'r').each_line do |s|
44
+ # Write in new parameters on appropriate lines if there are any
45
+ if s.match(/#\$PARAM/)
46
+ if @options[:parameters]
47
+ @options[:parameters].each do |p|
48
+ temp = s.gsub(/PARAM/, p)
49
+ temp.gsub!(/MODNAME/, @modname)
50
+ temp.sub!(/#/, "")
51
+ target.write temp
52
+ end
53
+ else
54
+ ## Does not write template line if no params
55
+ next
56
+ end
57
+ else
58
+ # Otherwise just make sure the module name is correct
59
+ target.write s.gsub(/MODNAME/, @modname)
60
+ end
61
+ end
62
+ target.close
63
+ end
64
+ rescue Errno::EEXIST
65
+ abort @options[:modulename] + " directory already exists."
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,42 @@
1
+ require 'dmamp/defaultargs'
2
+
3
+ module DMAMP
4
+ # Option parsing class, all options available via
5
+ # the options accessor.
6
+ class Opts
7
+ # Parsed option hash
8
+ attr_accessor :options
9
+
10
+ # Parses options from ARGV
11
+ def initialize
12
+ @options = DEFAULTARGS
13
+ op = OptionParser.new do |opts|
14
+ opts.banner = "Usage: dmamp [options] MODULENAME"
15
+
16
+ opts.on("-p", "--parameters [PARAMS]", String, "Comma seperated list of additional parameter names (default is none)") do |p|
17
+ @options[:parameters] = p.gsub(/ /, "").split(",") if p
18
+ end
19
+ opts.on("-P", "--pattern [PATTERN]", String, "Module pattern to used (defaults to parameterised-PCS)") do |p|
20
+ @options[:pattern] = p if p
21
+ end
22
+ opts.on("-v", "--version") do |v|
23
+ if v
24
+ puts VERSION
25
+ exit 0
26
+ end
27
+ end
28
+
29
+ end
30
+ op.parse!
31
+ raise OptionParser::MissingArgument unless ARGV[0]
32
+ @options[:modulename] = ARGV[0]
33
+ rescue OptionParser::MissingArgument
34
+ puts op
35
+ abort "Arguments required"
36
+ end
37
+ end
38
+ # Create and return option hash from DMAMP::Opts
39
+ def self.options
40
+ Opts.new.options
41
+ end
42
+ end
@@ -0,0 +1,47 @@
1
+ require 'singleton'
2
+
3
+ module DMAMP
4
+ # Helper for loading the appropriate metadata for the
5
+ # given pattern by reading from the appropriate directories
6
+ # including readers for the pattern name, the templates
7
+ # and the templates directory.
8
+ class Pattern
9
+ # Default pattern directory
10
+ PATTERNDIR = File.expand_path(File.dirname(__FILE__)) + "/patterns"
11
+ include Singleton
12
+
13
+ # Return the instance of Pattern if it exists, else instantiate
14
+ # it
15
+ def Pattern.instance(name)
16
+ @instance ||= new(name)
17
+ end
18
+
19
+ # Module name
20
+ attr_reader :name
21
+ # Manifest template filenames
22
+ attr_reader :manitemplates
23
+ # Template directory (currently defined inline from default constant,
24
+ # no way of changing this from the command line yet... TODO)
25
+ attr_reader :templatedir
26
+
27
+ # Instantiate pattern class and acquire metadata for pattern from
28
+ # the appropriate pattern's template directory. Will abort if the
29
+ # name given does not match a pattern directory giving a list of
30
+ # known patterns.
31
+ def initialize(name)
32
+ @name = @pattern = name
33
+ @templatedir = "#{PATTERNDIR}/#{@pattern}/templates"
34
+ @knownpatterns = Dir.entries(PATTERNDIR).reject {|x| ["..","."].include?(x)}
35
+ @manitemplates = Dir.entries(templatedir).reject {|x| ["..","."].include?(x)}
36
+ rescue Errno::ENOENT => e
37
+ abort "Pattern #{@pattern} is not defined within the patterns directory #{PATTERNDIR}
38
+ Known patterns are:
39
+ #{@knownpatterns.join("\n")}"
40
+ end
41
+ end
42
+
43
+ # Pretty much just a module level alias for Pattern.instance
44
+ def self.pattern(name)
45
+ Pattern.instance(name)
46
+ end
47
+ end
@@ -0,0 +1,8 @@
1
+ class MODNAME::config {
2
+ file { $MODNAME::config_file:
3
+ content => template("${module_name}/MODNAME_config.erb"),
4
+ owner => $MODNAME::user,
5
+ group => $MODNAME::group,
6
+ mode => '0444',
7
+ }
8
+ }
@@ -0,0 +1,18 @@
1
+ class MODNAME (
2
+ $package = $MODNAME::params::package,
3
+ $service = $MODNAME::params::service,
4
+ $config_dir = $MODNAME::params::config_dir,
5
+ $config_file = $MODNAME::params::config_file,
6
+ $user = $MODNAME::params::user,
7
+ $group = $MODNAME::params::group,
8
+ #ADDITIONALPARAMS
9
+ #$PARAM = $MODNAME::params::PARAM,
10
+ ) inherits MODNAME::params {
11
+ anchor {'MODNAME::start':}->
12
+ class { 'MODNAME::package':}~>
13
+ class { 'MODNAME::config':}~>
14
+ class { 'MODNAME::service':}~>
15
+ anchor {'MODNAME::end':}
16
+ }
17
+
18
+
@@ -0,0 +1,5 @@
1
+ class MODNAME::package {
2
+ package { $MODNAME::package:
3
+ ensure => installed,
4
+ }
5
+ }
@@ -0,0 +1,24 @@
1
+ class MODNAME::params {
2
+ case $::operatingsystem {
3
+ 'Debian':{
4
+ case $::lsbdistcodename {
5
+ 'squeeze':{
6
+ $package = 'MODNAME'
7
+ $service = 'MODNAME'
8
+ $config_dir = '/etc/MODNAME'
9
+ $config_file = "$config_dir/MODNAME_config"
10
+ $user = 'root'
11
+ $group = 'root'
12
+ #ADDITIONALPARAMS
13
+ #$PARAM = 'value'
14
+ }
15
+ default:{
16
+ fail("Release $::lsbdistcodename not supported")
17
+ }
18
+ }
19
+ }
20
+ default:{
21
+ fail("Unknown OS: $::operatingsystem")
22
+ }
23
+ }
24
+ }
@@ -0,0 +1,8 @@
1
+ class MODNAME::service {
2
+ service { $MODNAME::service:
3
+ ensure => running,
4
+ enable => true,
5
+ hasstatus => true,
6
+ hasrestart => true,
7
+ }
8
+ }
@@ -0,0 +1,4 @@
1
+ module DMAMP
2
+ # :nodoc:
3
+ VERSION = "0.1.0"
4
+ end
@@ -0,0 +1,44 @@
1
+ require 'testcommon'
2
+ require 'dmamp/mod'
3
+ require 'dmamp/pattern'
4
+
5
+ describe DMAMP::Mod do
6
+ describe "#build" do
7
+
8
+ before :each do
9
+ # Clean test directory
10
+ clean
11
+ @mod = DMAMP::Mod.new(DMAMP::Opts.new.options)
12
+ end
13
+ after :each do
14
+ clean
15
+ end
16
+
17
+ it "should create directory containing .pp files" do
18
+ File.directory?("temp").should be_true
19
+ @createdfiles = Dir.entries("temp").reject {|x| ["..","."].include?(x)}
20
+ @createdfiles.should == @mod.pattern.manitemplates
21
+ end
22
+
23
+ it "should fail when run twice" do
24
+ lambda { @mod.build }.should raise_error SystemExit
25
+ end
26
+
27
+ context "when parameters are given" do
28
+ before :all do
29
+ @testparams = ["bloo","blah"]
30
+ @mod = DMAMP::Mod.new(DMAMP::Opts.new.options)
31
+ @mod.options.merge({:parameters => @testparams})
32
+ end
33
+
34
+ it "should include new parameters in at least one of the files" do
35
+ success = false
36
+ @createdfiles = Dir.entries("temp").reject {|x| ["..","."].include?(x)}
37
+ @createdfiles.each do |f|
38
+ success = true if File.read("temp/" + f){|line| break if l.match(Regexp.new(@testparams.join("|")))}
39
+ end
40
+ success.should be true
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,27 @@
1
+ require 'testcommon'
2
+ require 'dmamp/defaultargs'
3
+
4
+ # This test is only to test that the fake Opts class approximates to the real one
5
+ # and won't screw up the rest of the testing!
6
+
7
+ describe DMAMP::Opts do
8
+ describe "#options" do
9
+ before :all do
10
+ @opt = DMAMP::Opts.new
11
+ @options = @opt.options
12
+ end
13
+
14
+ it "should be a hash" do
15
+ @options.should be_an_instance_of Hash
16
+ end
17
+
18
+ it "should have string values for :pattern" do
19
+ @options[:pattern].should be_an_instance_of String
20
+ end
21
+
22
+ it "should have string values for :modulename" do
23
+ @options[:modulename].should be_an_instance_of String
24
+ end
25
+ end
26
+ end
27
+
@@ -0,0 +1,22 @@
1
+ require 'rubygems'
2
+
3
+ $: << File.join(File.dirname(__FILE__), "..", "lib")
4
+ require 'dmamp/defaultargs'
5
+
6
+ # Dummy Opts class as optionparser does not play well with testing
7
+
8
+ module DMAMP
9
+ class Opts
10
+ attr_accessor :options
11
+ def initialize
12
+ @options = DEFAULTARGS.merge({:modulename => "temp"})
13
+ end
14
+ end
15
+ end
16
+
17
+ # Helper functions
18
+ def clean
19
+ if File.directory?("temp")
20
+ system("rm -rf temp")
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dmamp
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Matt Carroll
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain:
17
+ - |
18
+ -----BEGIN CERTIFICATE-----
19
+ MIIDMDCCAhigAwIBAgIBADANBgkqhkiG9w0BAQUFADA+MRAwDgYDVQQDDAdvaG9s
20
+ aWFiMRUwEwYKCZImiZPyLGQBGRYFZ21haWwxEzARBgoJkiaJk/IsZAEZFgNjb20w
21
+ HhcNMTIwNTE3MTYwNjU3WhcNMTMwNTE3MTYwNjU3WjA+MRAwDgYDVQQDDAdvaG9s
22
+ aWFiMRUwEwYKCZImiZPyLGQBGRYFZ21haWwxEzARBgoJkiaJk/IsZAEZFgNjb20w
23
+ ggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCde9pG4X+dG0QzcasXi3N1
24
+ GFhoyyp00UOo3VBBhW3IlldExGEEL03m4jxYFvecrcNClJcDtkNQw8dxAbvzFEAY
25
+ 7nSvWkZ8VqEPkS+NiTS8NV1Zc0rIzxs1AU/CwcTGI+xKryS5s9RbR1KYQ5Wt3c9G
26
+ 7mOXjatTi0umOojW0T69GmzqK82WlmVT616VZjDZn78Iv5Nksby6ZgP+WK4kJCUq
27
+ lzHQRhTjpWiX7betPn3NeOLfc6Kul9rJoAWiS7vK5+tbXbDeblCWqGI3g3/Q2352
28
+ KodhXj+zZQkFRdEDHHW4V36Ca0IvbxCTVwtPuii2JOTlmOBxB7QC7L10AZU42mJv
29
+ AgMBAAGjOTA3MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQWBBRYSCTm
30
+ ujiCMPvoifDo3ztvIEvNVjANBgkqhkiG9w0BAQUFAAOCAQEAdXKWSyl+LNTWBhf1
31
+ fTUvBrtuIIrqC1C1ozjsRLViVVjZIVIHWu3gn9PNEEVhXRJZrgFKCSbkgnV+UzCr
32
+ X8NRsuDRUOVISA4BHWmlyajCXcXkoBuPWve+2iav9fKfoxhGGCp9yRdU8JjvChHj
33
+ IjnULCcQ7foPOoonUz4WWzuejPYNhzg4+Sf5Ox61est7qXLGdW6gdhIVU8iGJpiz
34
+ QM8plCRvSL1beR/5wyyvidME3VjlipobOHD+sNMpNGHbQtn+H6pLUA2XvGVAS/q1
35
+ /YN5mJRORs29EZZu/GINpZVwSYOW8wQIl1RYPT9cpeJafvjzOq0xdLSftqbnTRIW
36
+ MngTTA==
37
+ -----END CERTIFICATE-----
38
+
39
+ date: 2012-05-17 00:00:00 Z
40
+ dependencies: []
41
+
42
+ description: Templating for puppet module patterns
43
+ email: oholiab@gmail.com
44
+ executables:
45
+ - dmamp
46
+ extensions: []
47
+
48
+ extra_rdoc_files:
49
+ - CHANGELOG
50
+ - README.md
51
+ - bin/dmamp
52
+ - lib/dmamp.rb
53
+ - lib/dmamp/defaultargs.rb
54
+ - lib/dmamp/mod.rb
55
+ - lib/dmamp/optionparser.rb
56
+ - lib/dmamp/pattern.rb
57
+ - lib/dmamp/patterns/parameterised-PCS/templates/config.pp
58
+ - lib/dmamp/patterns/parameterised-PCS/templates/init.pp
59
+ - lib/dmamp/patterns/parameterised-PCS/templates/package.pp
60
+ - lib/dmamp/patterns/parameterised-PCS/templates/params.pp
61
+ - lib/dmamp/patterns/parameterised-PCS/templates/service.pp
62
+ - lib/dmamp/version.rb
63
+ files:
64
+ - CHANGELOG
65
+ - Manifest
66
+ - README.md
67
+ - Rakefile
68
+ - bin/dmamp
69
+ - lib/dmamp.rb
70
+ - lib/dmamp/defaultargs.rb
71
+ - lib/dmamp/mod.rb
72
+ - lib/dmamp/optionparser.rb
73
+ - lib/dmamp/pattern.rb
74
+ - lib/dmamp/patterns/parameterised-PCS/templates/config.pp
75
+ - lib/dmamp/patterns/parameterised-PCS/templates/init.pp
76
+ - lib/dmamp/patterns/parameterised-PCS/templates/package.pp
77
+ - lib/dmamp/patterns/parameterised-PCS/templates/params.pp
78
+ - lib/dmamp/patterns/parameterised-PCS/templates/service.pp
79
+ - lib/dmamp/version.rb
80
+ - spec/mod_spec.rb
81
+ - spec/opt_spec.rb
82
+ - spec/testcommon.rb
83
+ - dmamp.gemspec
84
+ homepage: http://github.com/oholiab/DMAMP
85
+ licenses: []
86
+
87
+ post_install_message:
88
+ rdoc_options:
89
+ - --line-numbers
90
+ - --inline-source
91
+ - --title
92
+ - Dmamp
93
+ - --main
94
+ - README.md
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ hash: 3
103
+ segments:
104
+ - 0
105
+ version: "0"
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ hash: 11
112
+ segments:
113
+ - 1
114
+ - 2
115
+ version: "1.2"
116
+ requirements: []
117
+
118
+ rubyforge_project: dmamp
119
+ rubygems_version: 1.8.24
120
+ signing_key:
121
+ specification_version: 3
122
+ summary: Templating for puppet module patterns
123
+ test_files: []
124
+
Binary file