manman 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest.txt +4 -0
- data/Rakefile +2 -2
- data/bin/manman +9 -0
- data/lib/manman/opts.rb +69 -0
- data/lib/manman/runner.rb +208 -0
- data/lib/manman/version.rb +4 -0
- data/lib/manman.rb +37 -2
- metadata +10 -6
data/Manifest.txt
CHANGED
data/Rakefile
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'hoe'
|
2
|
-
require './lib/manman.rb'
|
2
|
+
require './lib/manman/version.rb'
|
3
3
|
|
4
4
|
Hoe.spec 'manman' do
|
5
5
|
|
@@ -12,7 +12,7 @@ Hoe.spec 'manman' do
|
|
12
12
|
|
13
13
|
self.author = 'Gerald Bauer'
|
14
14
|
self.email = 'webslideshow@googlegroups.com'
|
15
|
-
|
15
|
+
|
16
16
|
# switch extension to .markdown for gihub formatting
|
17
17
|
self.readme_file = 'README.markdown'
|
18
18
|
self.history_file = 'History.markdown'
|
data/bin/manman
ADDED
data/lib/manman/opts.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
module Manman
|
2
|
+
|
3
|
+
class Opts
|
4
|
+
|
5
|
+
def base=(value)
|
6
|
+
@base = value
|
7
|
+
end
|
8
|
+
|
9
|
+
def base
|
10
|
+
@base || './paket'
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
def template=(value)
|
15
|
+
@template = value
|
16
|
+
end
|
17
|
+
|
18
|
+
def template
|
19
|
+
@template || 'paket.txt.erb'
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
def output=(value)
|
24
|
+
@output = value
|
25
|
+
end
|
26
|
+
|
27
|
+
def output
|
28
|
+
@output || 'paket.txt'
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
def release=(value)
|
33
|
+
@release = value
|
34
|
+
end
|
35
|
+
|
36
|
+
def release
|
37
|
+
@release # NB: has no default; required arg
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
def env=(value)
|
42
|
+
@env = value
|
43
|
+
end
|
44
|
+
|
45
|
+
def env
|
46
|
+
@env # NB: has no default; required arg
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
def valid=(value)
|
51
|
+
@valid = value
|
52
|
+
end
|
53
|
+
|
54
|
+
def valid
|
55
|
+
@valid # NB: has no default; required arg
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
def config_path=(value)
|
60
|
+
@config_path = value
|
61
|
+
end
|
62
|
+
|
63
|
+
def config_path
|
64
|
+
@config_path || '~/.manman'
|
65
|
+
end
|
66
|
+
|
67
|
+
end # class Opts
|
68
|
+
|
69
|
+
end # module Manman
|
@@ -0,0 +1,208 @@
|
|
1
|
+
module Manman
|
2
|
+
|
3
|
+
class Runner
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@logger = Logger.new(STDOUT)
|
7
|
+
@logger.level = Logger::INFO
|
8
|
+
|
9
|
+
@opts = Opts.new
|
10
|
+
end
|
11
|
+
|
12
|
+
attr_reader :logger, :opts
|
13
|
+
|
14
|
+
def run( args )
|
15
|
+
opt=OptionParser.new do |cmd|
|
16
|
+
|
17
|
+
cmd.banner = "Usage: manman [options]"
|
18
|
+
|
19
|
+
cmd.on( '-r', '--release RELEASE', 'Release Version (e.g. 2013.08)' ) do |release|
|
20
|
+
opts.release = release
|
21
|
+
end
|
22
|
+
|
23
|
+
cmd.on( '-e', '--env ENV', 'Environment (e.g. TEST)' ) do |env|
|
24
|
+
opts.env = env
|
25
|
+
end
|
26
|
+
|
27
|
+
cmd.on( '-u', '--valid_until VALID', 'Valid until (e.g. 2014.01.31)' ) do |valid|
|
28
|
+
opts.valid = valid
|
29
|
+
end
|
30
|
+
|
31
|
+
cmd.on( '-d', '--dir PATH', "Path to Packages (default is #{opts.base})" ) do |path|
|
32
|
+
opts.base = path
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
cmd.on( '-t', '--template FILE', "Input Template (default is #{opts.template})" ) do |file|
|
37
|
+
opts.template = file
|
38
|
+
end
|
39
|
+
|
40
|
+
cmd.on( '-o', '--out FILE', "Output File (default is #{opts.output})" ) do |file|
|
41
|
+
opts.output = file
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
cmd.on( '-c', '--config PATH', "Configuration Path (default is #{opts.config_path})" ) do |path|
|
47
|
+
opts.config_path = path
|
48
|
+
end
|
49
|
+
|
50
|
+
cmd.on( '-v', '--version', "Show version" ) do
|
51
|
+
puts Manman.banner
|
52
|
+
exit
|
53
|
+
end
|
54
|
+
|
55
|
+
cmd.on( "--verbose", "Show debug trace" ) do
|
56
|
+
logger.datetime_format = "%H:%H:%S"
|
57
|
+
logger.level = Logger::DEBUG
|
58
|
+
end
|
59
|
+
|
60
|
+
cmd.on_tail( "-h", "--help", "Show this message" ) do
|
61
|
+
puts <<EOS
|
62
|
+
|
63
|
+
manman - Manifest Manager, Version #{VERSION}
|
64
|
+
|
65
|
+
#{cmd.help}
|
66
|
+
|
67
|
+
Examples:
|
68
|
+
manman -r 2013.08 -e TEST -u 2014.12.31
|
69
|
+
|
70
|
+
EOS
|
71
|
+
exit
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
opt.parse!( args )
|
76
|
+
|
77
|
+
puts Manman.banner
|
78
|
+
|
79
|
+
|
80
|
+
# check for required args
|
81
|
+
|
82
|
+
puts "*** Missing Argument: Release Argument Required" if opts.release.nil?
|
83
|
+
puts "*** Missing Argument: Environment Argument Required" if opts.env.nil?
|
84
|
+
puts "*** Missing Argument: Environment Argument Required" if opts.valid.nil?
|
85
|
+
|
86
|
+
if opts.release.nil? || opts.env.nil? || opts.valid.nil?
|
87
|
+
puts
|
88
|
+
puts "Use -h/--help for usage options."
|
89
|
+
return ## exit ??
|
90
|
+
end
|
91
|
+
|
92
|
+
puts "Using settings:"
|
93
|
+
pp opts
|
94
|
+
|
95
|
+
|
96
|
+
generate_manifest()
|
97
|
+
|
98
|
+
puts 'Done.'
|
99
|
+
|
100
|
+
end # method run
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
def generate_manifest
|
105
|
+
|
106
|
+
puts " working folder is: #{Dir.pwd}"
|
107
|
+
|
108
|
+
puts "Loading template #{opts.template}..."
|
109
|
+
|
110
|
+
old_lines = File.read( opts.template )
|
111
|
+
|
112
|
+
new_lines = []
|
113
|
+
|
114
|
+
header_lines = []
|
115
|
+
|
116
|
+
|
117
|
+
### todo/fix: move to template ???
|
118
|
+
header_lines << "####################################################\n"
|
119
|
+
header_lines << "# generated on #{Time.now} using #{Manman.banner}\n"
|
120
|
+
header_lines << "# - version: #{opts.release}, env: #{opts.env}, valid until: #{opts.valid}\n"
|
121
|
+
|
122
|
+
old_lines.each_line do |line|
|
123
|
+
|
124
|
+
if line =~ /^\s*#/
|
125
|
+
# skip komments and do NOT copy to result (keep comments secret!)
|
126
|
+
logger.debug 'skipping comment line'
|
127
|
+
next
|
128
|
+
end
|
129
|
+
|
130
|
+
if line =~ /^\s*$/
|
131
|
+
# kommentar oder leerzeile überspringen
|
132
|
+
logger.debug 'skipping blank line'
|
133
|
+
new_lines << line
|
134
|
+
next
|
135
|
+
end
|
136
|
+
|
137
|
+
# split/process key value pair
|
138
|
+
|
139
|
+
tokens = line.split( ':' )
|
140
|
+
|
141
|
+
key = tokens[0]
|
142
|
+
values = tokens[1]
|
143
|
+
|
144
|
+
|
145
|
+
## special keys (NOT files; do NOT calculate md5 digest)
|
146
|
+
|
147
|
+
## todo: make headers configurable
|
148
|
+
|
149
|
+
if [ 'VERSION', 'UMGEBUNG', 'MANDANT', 'GUELTIG_BIS', 'CHECKSUM' ].include?( key )
|
150
|
+
if key == 'VERSION'
|
151
|
+
new_lines << "#{key}: #{opts.release}\n"
|
152
|
+
elsif key == 'UMGEBUNG'
|
153
|
+
new_lines << "#{key}: #{opts.env}\n"
|
154
|
+
elsif key == 'GUELTIG_BIS'
|
155
|
+
new_lines << "#{key}: #{opts.valid}\n"
|
156
|
+
else
|
157
|
+
new_lines << line ## just pass header line throug; not modified
|
158
|
+
end
|
159
|
+
next
|
160
|
+
end
|
161
|
+
|
162
|
+
### calculate md5 digests
|
163
|
+
|
164
|
+
md5 = ""
|
165
|
+
fn = "#{opts.base}/#{key}" # filename
|
166
|
+
|
167
|
+
if File.exists?( fn ) == false
|
168
|
+
md5 = "xxxxxxx"
|
169
|
+
msg = "*** ERROR: #{key} missing; using path #{fn}"
|
170
|
+
puts msg
|
171
|
+
header_lines << "# #{msg}\n" # add error to header in manifest
|
172
|
+
else
|
173
|
+
md5 = calc_digest_md5( fn )
|
174
|
+
puts "OK #{key} -> #{md5}"
|
175
|
+
end
|
176
|
+
|
177
|
+
new_lines << "#{key}: #{md5}, #{values}"
|
178
|
+
|
179
|
+
end # oldlines.each
|
180
|
+
|
181
|
+
|
182
|
+
header_lines << "#####################################\n"
|
183
|
+
header_lines << "\n"
|
184
|
+
|
185
|
+
new_lines = header_lines + new_lines
|
186
|
+
|
187
|
+
File.open( opts.output, 'w') do |f|
|
188
|
+
new_lines.each do |line|
|
189
|
+
f.write( line )
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
end # method generate_manifest
|
194
|
+
|
195
|
+
|
196
|
+
def calc_digest_md5( fn )
|
197
|
+
# digest/hash is a string of 20 hexadecimal 8-bit numbers
|
198
|
+
# example:
|
199
|
+
# 5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8
|
200
|
+
|
201
|
+
md5 = Digest::MD5.hexdigest( File.open( fn, 'rb') { |f| f.read } )
|
202
|
+
md5
|
203
|
+
end
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
end # class Runner
|
208
|
+
end # module Manman
|
data/lib/manman.rb
CHANGED
@@ -1,4 +1,39 @@
|
|
1
1
|
|
2
|
+
require 'yaml'
|
3
|
+
require 'pp'
|
4
|
+
require 'logger'
|
5
|
+
require 'optparse'
|
6
|
+
require 'fileutils'
|
7
|
+
require 'date'
|
8
|
+
require 'digest/md5'
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
# rubygems
|
13
|
+
|
14
|
+
#### nothing here for now
|
15
|
+
|
16
|
+
# our own code
|
17
|
+
|
18
|
+
require 'manman/version'
|
19
|
+
require 'manman/opts'
|
20
|
+
require 'manman/runner'
|
21
|
+
|
2
22
|
module Manman
|
3
|
-
|
4
|
-
|
23
|
+
|
24
|
+
def self.banner
|
25
|
+
"manman #{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.root
|
29
|
+
"#{File.expand_path( File.dirname(File.dirname(__FILE__)) )}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.main
|
33
|
+
Runner.new.run(ARGV)
|
34
|
+
end
|
35
|
+
|
36
|
+
end # module Manman
|
37
|
+
|
38
|
+
|
39
|
+
Manman.main if __FILE__ == $0
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: manman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
- 0
|
9
8
|
- 1
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Gerald Bauer
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-10-
|
18
|
+
date: 2012-10-17 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rdoc
|
@@ -49,8 +49,8 @@ dependencies:
|
|
49
49
|
version_requirements: *id002
|
50
50
|
description: manman - Manifest Manager
|
51
51
|
email: webslideshow@googlegroups.com
|
52
|
-
executables:
|
53
|
-
|
52
|
+
executables:
|
53
|
+
- manman
|
54
54
|
extensions: []
|
55
55
|
|
56
56
|
extra_rdoc_files:
|
@@ -60,7 +60,11 @@ files:
|
|
60
60
|
- Manifest.txt
|
61
61
|
- README.markdown
|
62
62
|
- Rakefile
|
63
|
+
- bin/manman
|
63
64
|
- lib/manman.rb
|
65
|
+
- lib/manman/opts.rb
|
66
|
+
- lib/manman/runner.rb
|
67
|
+
- lib/manman/version.rb
|
64
68
|
homepage: http://geraldb.github.com/manman
|
65
69
|
licenses: []
|
66
70
|
|