puppet-courseware-manager 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,118 @@
1
+ require 'word_wrap'
2
+ require 'word_wrap/core_ext'
3
+
4
+ class Courseware
5
+ def self.question(message, default=nil)
6
+ if default
7
+ print "#{message} [#{default}] "
8
+ else
9
+ print "#{message} "
10
+ end
11
+
12
+ answer = STDIN.gets.strip
13
+
14
+ return answer.empty? ? default : answer
15
+ end
16
+
17
+ def self.confirm(message)
18
+ print "#{message} [Y/n]: "
19
+ [ 'y', 'yes', '' ].include? STDIN.gets.strip.downcase
20
+ end
21
+
22
+ def self.bailout?(message)
23
+ print "#{message} Continue? [Y/n]: "
24
+ unless [ 'y', 'yes', '' ].include? STDIN.gets.strip.downcase
25
+ if block_given?
26
+ yield
27
+ end
28
+ raise "User cancelled"
29
+ end
30
+ end
31
+
32
+ def self.dialog(header, body=nil, width=80)
33
+ width -= 6
34
+
35
+ puts '################################################################################'
36
+ puts "## #{header[0..width].center(width)} ##"
37
+ if body
38
+ puts '##----------------------------------------------------------------------------##'
39
+ body.wrap(width).split("\n").each do |line|
40
+ printf "## %-#{width}s ##\n", line
41
+ end
42
+ end
43
+ puts '################################################################################'
44
+ end
45
+
46
+ def self.choose(message, options, default = nil)
47
+ body = ""
48
+ options.each_with_index { |item, index| body << "\n[#{index}] #{item}" }
49
+ dialog(message, body)
50
+
51
+ ans = nil
52
+ loop do
53
+ if default
54
+ print "Choose an option by typing its number [#{default}]: "
55
+ ans = STDIN.gets.strip
56
+ ans = (ans == "") ? default : Integer(ans) rescue nil
57
+ else
58
+ print "Choose an option by typing its number: "
59
+ ans = Integer(STDIN.gets.strip) rescue nil
60
+ end
61
+
62
+ break if (0...options.size).include? ans
63
+ end
64
+
65
+ ans
66
+ end
67
+
68
+ def self.choose_variant
69
+ variants = Dir.glob('*.json')
70
+ maxlen = variants.max { |x,y| x.size <=> y.size }.size - 4 # accomodate for the extension we're stripping
71
+
72
+ return 'showoff.json' if variants == ['showoff.json']
73
+
74
+ # Ensures that the default `showoff.json` is listed first
75
+ variants.unshift "showoff.json"
76
+ variants.uniq!
77
+
78
+ options = variants.map do |variant|
79
+ data = JSON.parse(File.read(variant))
80
+ name = (variant == 'showoff.json') ? 'default' : File.basename(variant, '.json')
81
+ desc = data['description']
82
+
83
+ "%#{maxlen}s: %s" % [name, desc]
84
+ end
85
+
86
+ idx = Courseware.choose("This course has several variants available:", options, 0)
87
+ variants[idx]
88
+ end
89
+
90
+ def self.get_component(initial)
91
+ puts 'The component ID for this course can be found at:'
92
+ puts ' * https://tickets.puppetlabs.com/browse/COURSES/?selectedTab=com.atlassian.jira.jira-projects-plugin:components-panel'
93
+ puts
94
+ # grab the number ending the response--either the ID from the URL or the whole string
95
+ question('Please enter the component ID or copy & paste in its URL:', initial)[/(\d*)$/]
96
+ end
97
+
98
+ def self.grep(match, filename)
99
+ File.read(filename) =~ Regexp.new(match)
100
+ end
101
+
102
+ def self.increment(version, type=:point)
103
+ major, minor, point = version.split('.')
104
+ case type
105
+ when :major
106
+ major.sub!(/^v/, '') # chop off the v if needed
107
+ "v#{major.to_i + 1}.0.0"
108
+
109
+ when :minor
110
+ "#{major}.#{minor.to_i + 1}.0"
111
+
112
+ when :point
113
+ "#{major}.#{minor}.#{point.to_i + 1}"
114
+
115
+ end
116
+ end
117
+
118
+ end
@@ -0,0 +1,4 @@
1
+ class Courseware
2
+ VERSION = '0.5.0'
3
+ end
4
+
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: puppet-courseware-manager
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ platform: ruby
6
+ authors:
7
+ - Ben Ford
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-01-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mdl
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: showoff
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.10'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: word_wrap
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ description: |2
56
+ Manage the development lifecycle of Puppet courseware. This tool is not
57
+ required for presenting the material or for contributing minor updates.
58
+
59
+ This tool is not intended for general usage. If you are not a Puppet instructor
60
+ or an authorized training partner, this gem will have little interest for you.
61
+ email: education@puppetlabs.com
62
+ executables:
63
+ - courseware
64
+ extensions: []
65
+ extra_rdoc_files: []
66
+ files:
67
+ - CHANGELOG.txt
68
+ - README.txt
69
+ - LICENSE
70
+ - bin/courseware
71
+ - lib/courseware/cache.rb
72
+ - lib/courseware/composer.rb
73
+ - lib/courseware/dummy.rb
74
+ - lib/courseware/generator.rb
75
+ - lib/courseware/help.rb
76
+ - lib/courseware/manager/validators.rb
77
+ - lib/courseware/manager.rb
78
+ - lib/courseware/printer.rb
79
+ - lib/courseware/repository.rb
80
+ - lib/courseware/utils.rb
81
+ - lib/courseware/version.rb
82
+ - lib/courseware.rb
83
+ homepage: http://github.com/puppetlabs/courseware-manager
84
+ licenses:
85
+ - Apache-2.0
86
+ metadata: {}
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 2.0.14.1
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: Manage the development lifecycle of Puppet courseware. Not for general consumption.
107
+ test_files: []