foreman_templates 1.4.0 → 1.5.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0c88da13b131f090eecf394afa3476bc1ea4a741
4
- data.tar.gz: a94453ad5d7b5bfd93af2f682b23b017f31ac736
3
+ metadata.gz: 13dc963ac08604e046539bf41fe0b6d8221d94c5
4
+ data.tar.gz: 6e037a128dd982bd13f9d0f793040973995f094e
5
5
  SHA512:
6
- metadata.gz: d225ed09a20895ed2f4266788fabe274a33e9b4796dd9e59ae44ba28ae92d8ecda51fae819eee908d408caad65322ee7462a09f5cc5347519d6408a178d682d2
7
- data.tar.gz: 8dbcc358c09dae4602088c2238f9ce8ffc07d150b4cac374d47b5c45690784cf74a1d8354eaae8c13e2f6eb3fc44b3d884477df4e7465a21db1d8fdb6731031e
6
+ metadata.gz: f25a1b7948860f422816ff98683f80b7ac8bbd38b73e6d246dd66f1ea145b88c45a4278535a2ca9ba90c62c66b71eb6311c6fc479f31300ebe280d75eb9d94a8
7
+ data.tar.gz: b952bb1305484cfdab98352740bd6b7ddf42d94b0e4b291ff8292a46209b0227bd31a8b926eaa2eb551c9e6f0a480d5318f25e0a0414f41847d5dbea74a7cfe7
data/README.md CHANGED
@@ -39,12 +39,17 @@ template will be automatically associated with the OS
39
39
 
40
40
  # Rake options
41
41
 
42
- * verbose => Print extra information during the run [false]
43
- * repo => Sync templates from a different Git repo [https://github.com/theforeman/community-templates]
44
- * branch => Branch in Git repo [default branch]
45
- * prefix => The string all imported templates should begin with [Community]
46
- * dirname => The directory within the git tree containing the templates [/]
47
- * filter => Import names matching this regex (case-insensitive; snippets are not filtered)
42
+ * verbose => Print extra information during the run [false]
43
+ * repo => Sync templates from a different Git repo [https://github.com/theforeman/community-templates]
44
+ * branch => Branch in Git repo [_see note below_]
45
+ * prefix => The string all imported templates should begin with [Community]
46
+ * dirname => The directory within the git tree containing the templates [/]
47
+ * filter => Import names matching this regex (case-insensitive; snippets are not filtered)
48
+ * associate => Associate to OS, "always", when "new" or "never" [new]
49
+
50
+ The `branch` default will use *develop* if you're on Foreman-nightly; or the
51
+ matching *1.X-stable* branch for your version of Foreman (if it exists); or
52
+ finally it will remain on the default branch as a fallback.
48
53
 
49
54
  ## Examples
50
55
 
@@ -1,4 +1,5 @@
1
1
  require 'diffy'
2
+ require 'git'
2
3
 
3
4
  module ForemanTemplates
4
5
  #Inherit from the Rails module of the parent app (Foreman), not the plugin.
@@ -1,3 +1,3 @@
1
1
  module ForemanTemplates
2
- VERSION = "1.4.0"
2
+ VERSION = "1.5.0"
3
3
  end
data/lib/templates.rake CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'fileutils'
2
2
  require 'yaml'
3
3
  require 'diffy'
4
+ require 'git'
4
5
 
5
6
  class NoKindError < Exception ; end
6
7
 
@@ -37,24 +38,27 @@ def update_template
37
38
  :snippet => false,
38
39
  :template_kind_id => kind.id
39
40
  }
41
+ string = db_template.new_record? ? "Created" : "Updated"
40
42
 
41
43
  oses = map_oses
42
- if db_template.new_record?
44
+ if (@associate == 'new' and db_template.new_record?) or (@associate == 'always')
43
45
  data[:operatingsystem_ids] = oses.map(&:id)
44
- string = "Created"
45
- else
46
- string = "Updated"
47
46
  end
48
47
 
49
- if @text == db_template.template
50
- diff = nil
51
- status = true
52
- result = " No change to Template #{ ( 'id' + db_template.id ) rescue ''}:#{@name}"
53
- else
48
+ if @text != db_template.template
54
49
  diff = Diffy::Diff.new(db_template.template, @text, :include_diff_info => true).to_s(:color)
55
50
  status = db_template.update_attributes(data)
56
51
  result = " #{string} Template #{ 'id' + db_template.id rescue ''}:#{@name}"
57
52
  result += "\n Operatingsystem Associations:\n - #{oses.map(&:fullname).join("\n - ")}" if !oses.empty?
53
+ elsif data[:operatingsystem_ids]
54
+ diff = nil
55
+ status = db_template.update_attributes(data)
56
+ result = " #{string} Template Associations #{ 'id' + db_template.id rescue ''}:#{@name}"
57
+ result += "\n Operatingsystem Associations:\n - #{oses.map(&:fullname).join("\n - ")}" if !oses.empty?
58
+ else
59
+ diff = nil
60
+ status = true
61
+ result = " No change to Template #{ ( 'id' + db_template.id ) rescue ''}:#{@name}"
58
62
  end
59
63
  { :diff => diff, :status => status, :result => result }
60
64
  end
@@ -62,23 +66,26 @@ end
62
66
  def update_ptable
63
67
  db_ptable = Ptable.find_or_initialize_by_name(@name)
64
68
  data = { :layout => @text }
69
+ string = db_ptable.new_record? ? "Created" : "Updated"
65
70
 
66
71
  oses = map_oses
67
- if db_ptable.new_record?
72
+ if (@associate == 'new' and db_ptable.new_record?) or (@associate == 'always')
68
73
  data[:os_family] = oses.map(&:family).uniq.first
69
- string = "Created"
70
- else
71
- string = "Updated"
72
74
  end
73
75
 
74
- if @text == db_ptable.layout
75
- diff = nil
76
- status = true
77
- result = " No change to Ptable #{ ( 'id' + db_ptable.id ) rescue ''}:#{@name}"
78
- else
76
+ if @text != db_ptable.layout
79
77
  diff = Diffy::Diff.new(db_ptable.layout, @text, :include_diff_info => true).to_s(:color)
80
78
  status = db_ptable.update_attributes(data)
81
79
  result = " #{string} Ptable #{ ( 'id' + db_ptable.id ) rescue ''}:#{@name}"
80
+ elsif data[:os_family]
81
+ diff = nil
82
+ status = db_ptable.update_attributes(data)
83
+ result = " #{string} Ptable Associations #{ ( 'id' + db_ptable.id ) rescue ''}:#{@name}"
84
+ result += "\n Operatingsystem Family:\n - #{oses.map(&:family).uniq.first}" if !oses.empty?
85
+ else
86
+ diff = nil
87
+ status = true
88
+ result = " No change to Ptable #{ ( 'id' + db_ptable.id ) rescue ''}:#{@name}"
82
89
  end
83
90
  { :diff => diff, :status => status, :result => result }
84
91
  end
@@ -91,45 +98,56 @@ def update_snippet
91
98
  }
92
99
  string = db_snippet.new_record? ? "Created" : "Updated"
93
100
 
94
- if @text == db_snippet.template
95
- diff = nil
96
- status = true
97
- result = " No change to Snippet #{ 'id' + db_snippet.id rescue ''}:#{@name}"
98
- else
101
+ if @text != db_snippet.template
99
102
  diff = Diffy::Diff.new(db_snippet.template, @text, :include_diff_info => true).to_s(:color)
100
103
  status = db_snippet.update_attributes(data)
101
104
  result = " #{string} Snippet #{ ('id' + db_snippet.id) rescue ''}:#{@name}"
105
+ else
106
+ diff = nil
107
+ status = true
108
+ result = " No change to Snippet #{ 'id' + db_snippet.id rescue ''}:#{@name}"
102
109
  end
103
110
  { :diff => diff, :status => status, :result => result }
104
111
  end
105
112
 
113
+ def get_default_branch(repo)
114
+ branch_names = repo.branches.map(&:name).uniq
115
+
116
+ # Always use develop on Foreman-nightly, if present, or else relevant stable branch
117
+ target = SETTINGS[:version].tag == 'develop' ? 'develop' : "#{SETTINGS[:version].short}-stable"
118
+ return target if branch_names.include?(target)
119
+
120
+ # stay on default branch as fallback
121
+ return nil
122
+ end
123
+
106
124
  desc <<-END_DESC
107
125
  Synchronize templates from a git repo
108
126
  END_DESC
109
127
  namespace :templates do
110
128
  task :sync => :environment do
111
129
  # Available options:
112
- #* verbose => Print extra information during the run [false]
113
- #* repo => Sync templates from a different Git repo [https://github.com/theforeman/community-templates]
114
- #* branch => Branch in Git repo [default branch]
115
- #* prefix => The string all imported templates should begin with [Community]
116
- #* dirname => The directory within the git tree containing the templates [/]
117
- #* filter => Import names matching this regex (case-insensitive; snippets are not filtered)
118
-
119
- @verbose = ( ENV['verbose'] and ENV['verbose'] != 'false' ) ? true : false
120
- repo = ENV['repo'] ? ENV['repo'] : "https://github.com/theforeman/community-templates.git"
121
- branch = ENV['branch'] ? "-b #{ENV['branch']}" : ""
122
- prefix = ENV['prefix'] ? ENV['prefix'] : nil
123
- dirname = ENV['dirname'] ? ENV['dirname'] : '/'
124
- filter = ENV['filter'] ? ENV['filter'] : nil
130
+ #* verbose => Print extra information during the run [false]
131
+ #* repo => Sync templates from a different Git repo [https://github.com/theforeman/community-templates]
132
+ #* branch => Branch in Git repo [default branch]
133
+ #* prefix => The string all imported templates should begin with [Community]
134
+ #* dirname => The directory within the git tree containing the templates [/]
135
+ #* filter => Import names matching this regex (case-insensitive; snippets are not filtered)
136
+ #* associate => Associate to OS, always, new or never [new]
137
+
138
+ @verbose = ( ENV['verbose'] and ENV['verbose'] != 'false' ) ? true : false
139
+ @associate = ENV['associate'] ? ENV['associate'] : 'new'
140
+ prefix = ENV['prefix'] ? ENV['prefix'] : nil
141
+ dirname = ENV['dirname'] ? ENV['dirname'] : '/'
142
+ filter = ENV['filter'] ? ENV['filter'] : nil
143
+ repo = ENV['repo'] ? ENV['repo'] : "https://github.com/theforeman/community-templates.git"
125
144
 
126
145
  # Check out the community templates to a temp location
127
146
  begin
128
147
  dir = Dir.mktmpdir
129
- command = "git clone #{branch} #{repo} #{dir}"
130
-
131
- status = `#{command}`
132
- puts "#{status}" if @verbose
148
+ gitrepo = Git.clone(repo, dir)
149
+ branch = ENV['branch'] ? ENV['branch'] : get_default_branch(gitrepo)
150
+ gitrepo.checkout(branch) if branch
133
151
 
134
152
  # Build a list of ERB files to parse
135
153
  Dir["#{dir}#{dirname}/**/*.erb"].each do |template|
@@ -142,7 +160,7 @@ namespace :templates do
142
160
  filename = template.split('/').last
143
161
  title = filename.split('.').first
144
162
  @name = @metadata ['name'] || title
145
- @name = [prefix, @name].compact.join(' ')
163
+ @name = [prefix, @name].compact.join()
146
164
  next if filter and not @name.match(/#{filter}/i)
147
165
 
148
166
  unless @metadata['kind']
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_templates
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Greg Sutcliffe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-30 00:00:00.000000000 Z
11
+ date: 2015-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: diffy
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: git
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  description: Engine to sychronise provisioning templates from GitHub
28
42
  email: gsutclif@redhat.com
29
43
  executables: []
@@ -59,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
73
  version: '0'
60
74
  requirements: []
61
75
  rubyforge_project:
62
- rubygems_version: 2.2.0
76
+ rubygems_version: 2.4.5
63
77
  signing_key:
64
78
  specification_version: 4
65
79
  summary: Template-syncing engine for Foreman