puppetize 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
File without changes
@@ -1,4 +1,7 @@
1
1
  require 'fileutils'
2
+ require 'erb'
2
3
  require 'pp'
4
+ require 'open4'
3
5
  require 'puppetize/puppetize'
4
6
  require 'puppetize/command_line'
7
+ require 'puppetize/stdlib'
@@ -10,22 +10,78 @@ module Puppetize
10
10
 
11
11
  # Create config dir if it doesn't exists:
12
12
  @config_dir = File.join(File.expand_path('~'),'.puppetize')
13
+ @module_dir = File.join(File.expand_path('~'),'puppetize-module')
14
+ @rpm_db = File.join(@config_dir,'rpmlist.db')
13
15
  FileUtils.mkdir @config_dir if Dir.glob(@config_dir).empty?
14
16
 
15
17
  end
16
18
 
17
19
  def init
18
20
 
19
- rpm_list = %x[rpm -qa]
20
- File.write(File.join(@config_dir,'rpmlist.db'), rpm_list)
21
-
21
+ rpm_list = cmd "rpm -qa"
22
+ File.open(@rpm_db, 'w') {|f| f.write(rpm_list) }
23
+
22
24
  end
23
25
 
24
-
25
26
  def build
26
27
 
27
- puts "build"
28
+ # Verify necessary commands are installed:
29
+ #
30
+
31
+ commands = ['puppet','git']
32
+
33
+ commands.each do |command|
34
+
35
+ begin
36
+
37
+ test = ENV['PATH'].split(':').map do |folder|
38
+ File.exists?(File.join(folder,command))
39
+ end
40
+
41
+ if ! test.include? true
42
+ puts "ERROR - #{command} is not installed or not available on default path"
43
+ exit -1
44
+ end
45
+
46
+ rescue => e
47
+
48
+ STDERR.puts "ERROR - #{e}"
49
+ exit -1
50
+
51
+ end
52
+
53
+ end
54
+
55
+ # Generate a standard empty module
56
+
57
+ cmd "puppet module generate puppetize-module"
58
+
59
+
60
+ #################################
61
+ # Generate the Package resources:
62
+
63
+ rpm_list = cmd("rpm -qa").split("\n")
64
+ init_rpm_list = File.read(@rpm_db).split("\n")
65
+ puppet_rpm_list = rpm_list - init_rpm_list
66
+
67
+ packagelist = []
68
+
69
+ puppet_rpm_list.each do |rpm|
70
+ name = cmd("rpm --query --qf %{NAME} #{rpm}")
71
+ version = cmd("rpm --query --qf %{VERSION} #{rpm}")
72
+ release = cmd("rpm --query --qf %{RELEASE} #{rpm}")
73
+ packagelist << [name,version,release]
74
+ end
75
+
76
+ # Generate install.pp based on ERB template
77
+ template = File.join(File.dirname(__FILE__), '..', '..', 'tpl', 'install.pp.erb')
78
+ renderer = ERB.new(File.read(template))
79
+ output = renderer.result(binding)
80
+ File.open(File.join(@module_dir,'manifests','install.pp'),'w') {|f| f.write(output)}
28
81
 
82
+ ######################################
83
+ # Generate the configuration resources
84
+
29
85
  end
30
86
 
31
87
  def reset
@@ -0,0 +1,36 @@
1
+
2
+ def cmd command, opts = { :out => false , :err => true }
3
+
4
+ retval = nil
5
+ error = nil
6
+
7
+ begin
8
+
9
+ status = Open4.popen4(command) do |pid,stdin,stdout,stderr|
10
+
11
+ error = stderr.read
12
+ retval = stdout.read
13
+ STDOUT.puts stdout if opts[:out]
14
+
15
+ end
16
+
17
+ rescue => e
18
+
19
+ STDERR.puts "Error: #{e} #{error}"
20
+ exit -1
21
+
22
+ ensure
23
+
24
+ if status.exitstatus > 0
25
+
26
+ STDERR.puts "#{error}" if opts[:err]
27
+ exit -1
28
+
29
+ end
30
+
31
+ end
32
+
33
+ retval
34
+
35
+ end
36
+
@@ -0,0 +1,3 @@
1
+ module Puppetize
2
+ VERSION = "0.0.4"
3
+ end
metadata CHANGED
@@ -1,52 +1,89 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: puppetize
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.3
5
- prerelease:
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 4
10
+ version: 0.0.4
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Juan Breinlinger
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2013-10-15 00:00:00.000000000 Z
13
- dependencies: []
17
+
18
+ date: 2013-11-04 00:00:00 +00:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: trollop
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 2
32
+ - 0
33
+ version: "2.0"
34
+ type: :runtime
35
+ version_requirements: *id001
14
36
  description: Puppetize is a tool that can generate complete modules from systems
15
37
  email: juan.brein@breins.net
16
- executables:
38
+ executables:
17
39
  - puppetize
18
40
  extensions: []
41
+
19
42
  extra_rdoc_files: []
20
- files:
43
+
44
+ files:
21
45
  - lib/puppetize.rb
22
46
  - lib/puppetize/puppetize.rb
47
+ - lib/puppetize/version.rb
48
+ - lib/puppetize/stdlib.rb
23
49
  - lib/puppetize/command_line.rb
24
- - LICENSE
25
- - README.md
26
50
  - bin/puppetize
51
+ - README.md
52
+ - LICENSE
53
+ - CONTRIBUTORS
54
+ has_rdoc: true
27
55
  homepage: https://github.com/BreinsNet/puppetize
28
- licenses:
56
+ licenses:
29
57
  - GPL v3
30
58
  post_install_message:
31
59
  rdoc_options: []
32
- require_paths:
33
- - - lib
34
- required_ruby_version: !ruby/object:Gem::Requirement
60
+
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
35
64
  none: false
36
- requirements:
37
- - - ! '>='
38
- - !ruby/object:Gem::Version
39
- version: '0'
40
- required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ hash: 3
69
+ segments:
70
+ - 0
71
+ version: "0"
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
73
  none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ hash: 3
78
+ segments:
79
+ - 0
80
+ version: "0"
46
81
  requirements: []
47
- rubyforge_project:
48
- rubygems_version: 1.8.23
82
+
83
+ rubyforge_project: puppetize
84
+ rubygems_version: 1.3.7
49
85
  signing_key:
50
86
  specification_version: 3
51
87
  summary: A puppet module generation tool
52
88
  test_files: []
89
+