easyfpm 0.1.0.pre

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,50 @@
1
+ ###############################################################################
2
+ ## Class : EASYFPM::Mapping
3
+ ## Author : Erwan SEITE
4
+ ## Aim : Manage EASYFPM Mapping Conf Files
5
+ ## Licence : GPL v2
6
+ ## Source : https://github.com/wanix/easyfpm.git
7
+ ###############################################################################
8
+ require "easyfpm/exceptions"
9
+
10
+ class EASYFPM::Mapping
11
+
12
+ #Waited format:
13
+ #
14
+ # #A comment
15
+ # src-dir => newdir
16
+ # src-file => newdir/new-file
17
+ #
18
+ # New path can't start with /
19
+
20
+ @@regexpStruct={}
21
+ #Empty line definition
22
+ @@regexpStruct[:emptyline] = /^\s*$/
23
+ #Comment line definition
24
+ @@regexpStruct[:commentline] = /^\s*[#]/
25
+ #Mapping line definition
26
+ @@regexpStruct[:mappingline] = /^\s*(.+?)\s+=>\s+(.*?)\s*$/
27
+
28
+ attr_reader :hashmap
29
+
30
+ def initialize(mappingfile)
31
+ file = File.open(mappingfile, 'r')
32
+ @hashmap={}
33
+ while !file.eof?
34
+ line = file.readline
35
+ #We ignore the empty lines
36
+ next if @@regexpStruct[:emptyline].match(line)
37
+ #We ignore the comment lines
38
+ next if @@regexpStruct[:commentline].match(line)
39
+ linematch = @@regexpStruct[:mappingline].match(line)
40
+ if linematch
41
+ #We are on a mapping line
42
+ #Verifying that new path don't start with /
43
+ raise EASYFPM::InvalidConfiguration, "New path can't start with / mapping file #{mappingfile}:\n\t#{line}" if linematch[2][0] == "/"
44
+ @hashmap[linematch[1]]=linematch[2]
45
+ else
46
+ raise EASYFPM::InvalidConfiguration, "The following line is not recognized in mapping file #{mappingfile}:\n\t#{line}"
47
+ end
48
+ end
49
+ end #initialize
50
+ end
@@ -0,0 +1,4 @@
1
+ # The EASYFPM namespace
2
+ module EASYFPM
3
+ class Package; end
4
+ end
@@ -0,0 +1,406 @@
1
+ ###############################################################################
2
+ ## Class : EASYFPM::Packaging
3
+ ## Author : Erwan SEITE
4
+ ## Aim : Create packages with fpm
5
+ ## Licence : GPL v2
6
+ ## Source : https://github.com/wanix/easyfpm.git
7
+ ###############################################################################
8
+ require "easyfpm/configuration"
9
+ require "easyfpm/exceptions"
10
+ require "easyfpm/pkgchangelog"
11
+ require "fileutils"
12
+ require "tempfile"
13
+ require "tmpdir"
14
+ require "open3"
15
+ begin
16
+ require "unixconfigstyle"
17
+ require "ptools"
18
+ rescue LoadError
19
+ require "rubygems"
20
+ require "unixconfigstyle"
21
+ require "ptools"
22
+ end
23
+
24
+
25
+ class EASYFPM::Packaging
26
+
27
+ attr_accessor :verbose
28
+ attr_accessor :dryrun
29
+ attr_accessor :debug
30
+
31
+ #Initialize the class
32
+ def initialize(unixconfigstyle, specificLabel=nil)
33
+ raise ArgumentError, 'the argument must be an UnixConfigStyle object' unless unixconfigstyle.is_a? UnixConfigStyle
34
+
35
+ #We need fpm in the path
36
+ raise EASYFPM::InvalidEnvironment, "the fpm script is not found in PATH, please install it or put it in your PATH" unless File.which("fpm")
37
+
38
+ @easyfpmconf = EASYFPM::Configuration.new(unixconfigstyle, specificLabel)
39
+ @label=specificLabel
40
+ @verbose = false
41
+ @dryrun = false
42
+ @debug = false
43
+ end #initialize
44
+
45
+ #return a fpmcmdline for the specific label
46
+ def generatefpmline(labelhashconf,makingConf=nil)
47
+ debug "generatefpmline","generatefpmline (#{labelhashconf.class.name},#{makingConf.class.name})"
48
+ return nil unless labelhashconf
49
+ fpmconf=""
50
+
51
+ fpmconf += " --verbose" if @verbose
52
+ fpmconf += " --debug" if @debug
53
+
54
+ packageType = labelhashconf["pkg-type"]
55
+
56
+ #Let analyse the options given
57
+ labelhashconf.each_key do |param|
58
+ case param
59
+ #The followings params have specific treatments
60
+ when "pkg-mapping", "pkg-content"
61
+ next
62
+ when "easyfpm-pkg-changelog"
63
+ #We should have generate a temporary file for this
64
+ raise EASYFPM::MissingArgument, "The easyfpm changelog has not been generated" unless makingConf.has_key? "pkg-changelog"
65
+ case packageType
66
+ when "deb","rpm"
67
+ fpmconf += " --#{packageType}-changelog '"+makingConf["pkg-changelog"]+"'"
68
+ else
69
+ warn "Warning: the package type #{packageType} doesn't use "+param
70
+ end #case packageType
71
+ when "pkg-name"
72
+ fpmconf += " --name "+labelhashconf[param]
73
+ when "pkg-type"
74
+ fpmconf += " -t "+labelhashconf[param]
75
+ when "pkg-version"
76
+ fpmconf += " -v "+labelhashconf[param]
77
+ when "pkg-src-dir"
78
+ #If we have a mapping file, we have to rebuild the source later in temporary dir
79
+ fpmconf += " -s dir -C "+labelhashconf[param] unless labelhashconf.has_key? "pkg-mapping"
80
+ when "pkg-prefix"
81
+ fpmconf += " --prefix "+labelhashconf[param]
82
+ #There's a bug with pkg-output-dir and deb so easyfpm make it itself
83
+ when "pkg-output-dir"
84
+ next
85
+ # fpmconf += " -p "+labelhashconf[param]
86
+ when "pkg-description"
87
+ fpmconf += " --description '"+labelhashconf[param]+"'"
88
+ when "pkg-arch"
89
+ fpmconf += " -a "+labelhashconf[param]
90
+ when "pkg-user"
91
+ case packageType
92
+ when "deb","rpm","solaris"
93
+ fpmconf += " --#{packageType}-user "+labelhashconf[param]
94
+ else
95
+ warn "Warning: the package type #{packageType} doesn't use "+param
96
+ end #case packageType
97
+ when "pkg-group"
98
+ case packageType
99
+ when "deb","rpm","solaris"
100
+ fpmconf += " --#{packageType}-group "+labelhashconf[param]
101
+ else
102
+ warn "Warning: the package type #{packageType} doesn't use "+param
103
+ end #case packageType
104
+ when "template-activated"
105
+ fpmconf += " --template-scripts" if labelhashconf[param] == "yes"
106
+ when "template-value"
107
+ #We have an Array for this param
108
+ labelhashconf[param].each do |tplvalue|
109
+ fpmconf += " --template-value "+tplvalue
110
+ end #labelhashconf[param].each
111
+ when "pkg-preinst"
112
+ fpmconf += " --before-install "+labelhashconf[param]
113
+ when "pkg-postinst"
114
+ fpmconf += " --after-install "+labelhashconf[param]
115
+ when "pkg-prerm"
116
+ fpmconf += " --before-remove "+labelhashconf[param]
117
+ when "pkg-postrm"
118
+ fpmconf += " --after-remove "+labelhashconf[param]
119
+ when "pkg-iteration"
120
+ fpmconf += " --iteration "+labelhashconf[param]
121
+ fpmconf += labelhashconf["pkg-suffix"] if labelhashconf.has_key? "pkg-suffix"
122
+ when "pkg-epoch"
123
+ fpmconf += " --epoch "+labelhashconf[param]
124
+ when "pkg-vendor"
125
+ fpmconf += " --vendor '"+labelhashconf[param]+"'"
126
+ when "pkg-url"
127
+ fpmconf += " --url '"+labelhashconf[param]+"'"
128
+ when "pkg-license"
129
+ fpmconf += " --license '"+labelhashconf[param]+"'"
130
+ when "pkg-config-files"
131
+ #We have an Array for this param
132
+ labelhashconf[param].each do |pkgconfig|
133
+ fpmconf += " --config-files '"+pkgconfig+"'"
134
+ end #labelhashconf[param].each
135
+ when "pkg-depends"
136
+ #We have an Array for this param
137
+ labelhashconf[param].each do |pkgdepend|
138
+ fpmconf += " -d '"+pkgdepend+"'"
139
+ end #labelhashconf[param].each
140
+ when "pkg-suffix"
141
+ #if iteration defines, suffix is with it, else it is like an iteration
142
+ next if labelhashconf.has_key? "pkg-iteration"
143
+ fpmconf += " --iteration 1"+labelhashconf[param]
144
+ when "pkg-changelog"
145
+ case packageType
146
+ when "deb","rpm"
147
+ fpmconf += " --#{packageType}-changelog "+labelhashconf[param]
148
+ else
149
+ warn "Warning: the package type #{packageType} doesn't use "+param
150
+ end #case packageType
151
+ when "pkg-force"
152
+ fpmconf += " -f" if labelhashconf[param] == "yes"
153
+ when "pkg-category"
154
+ fpmconf += " --category "+labelhashconf[param]
155
+ when "pkg-provides"
156
+ #We have an Array for this param
157
+ labelhashconf[param].each do |pkgprovide|
158
+ fpmconf += " --provides '"+pkgprovide+"'"
159
+ end #labelhashconf[param].each
160
+ when "pkg-conflicts"
161
+ #We have an Array for this param
162
+ labelhashconf[param].each do |pkgconflict|
163
+ fpmconf += " --conflicts '"+pkgconflict+"'"
164
+ end #labelhashconf[param].each
165
+ when "pkg-recommends"
166
+ #We have an Array for this param
167
+ case packageType
168
+ when "deb"
169
+ labelhashconf[param].each do |pkgrecommends|
170
+ fpmconf += " --#{packageType}-recommends '"+pkgrecommends+"'"
171
+ end #labelhashconf[param].each
172
+ else
173
+ warn "Warning: the package type #{packageType} doesn't use "+param
174
+ end #case packageType
175
+ when "pkg-suggests"
176
+ #We have an Array for this param
177
+ case packageType
178
+ when "deb"
179
+ labelhashconf[param].each do |pkgsuggests|
180
+ fpmconf += " --#{packageType}-suggests '"+pkgsuggests+"'"
181
+ end #labelhashconf[param].each
182
+ else
183
+ warn "Warning: the package type #{packageType} doesn't use "+param
184
+ end #case packageType
185
+ when "pkg-directories"
186
+ fpmconf += " --directories "+labelhashconf[param]
187
+ when "pkg-maintainer"
188
+ fpmconf += " --maintainer "+labelhashconf[param]
189
+ when "pkg-compression"
190
+ case packageType
191
+ when "deb","rpm"
192
+ fpmconf += " --#{packageType}-compression "+labelhashconf[param]
193
+ else
194
+ warn "Warning: the package type #{packageType} doesn't use "+param
195
+ end #case packageType
196
+ when "pkg-priority"
197
+ case packageType
198
+ when "deb"
199
+ fpmconf += " --#{packageType}-priority "+labelhashconf[param]
200
+ else
201
+ warn "Warning: the package type #{packageType} doesn't use "+param
202
+ end #case packageType
203
+ when "pkg-replaces"
204
+ #We have an Array for this param
205
+ labelhashconf[param].each do |pkgreplace|
206
+ fpmconf += " --replaces '"+pkgreplace+"'"
207
+ end #labelhashconf[param].each
208
+ else
209
+ warn "Warning: parameter #{param} not taken into account in EASYFPM::Packaging.generatefpmline (should be a bug)"
210
+ end #case param
211
+ end #labelhashconf.each_key
212
+
213
+ #if we have pkg-content, we must insert it at the end of the string
214
+ fpmconf += " "+labelhashconf["pkg-content"] if labelhashconf.has_key? "pkg-content"
215
+
216
+ #If we have pkg-mapping, the temporary dir should have been created and
217
+ # the content to manage in makingConf["pkg-content"]
218
+ if labelhashconf.has_key? "pkg-mapping"
219
+ #The new source dir has been generated
220
+ fpmconf += " -s dir -C '"+makingConf["pkg-src-dir"]+"'"
221
+ #The new content is mapped
222
+ fpmconf += " "+makingConf["pkg-content"]
223
+ end
224
+
225
+ return fpmconf
226
+ end #generatefpmline
227
+
228
+ #make alls packages in the configuration
229
+ def makeAll()
230
+ debug "makeAll"
231
+ returnCode = true
232
+ if @easyfpmconf.hasLabels?
233
+ @easyfpmconf.getLabels().each do |label|
234
+ returnCode = false unless make(label)
235
+ end #@easyfpmconf.getLabels().each
236
+ else
237
+ returnCode = false unless make()
238
+ end
239
+ return returnCode
240
+ end
241
+
242
+ #Create the packages
243
+ def make(label=nil)
244
+ returnCode=true
245
+ begin
246
+ debug "make", "make(#{label})"
247
+ #Make packages for each labels in conf
248
+
249
+ if @debug
250
+ puts "*"*80
251
+ puts " EASYFPM::Packaging : configuration"
252
+ puts "*"*80
253
+ @easyfpmconf.print(label)
254
+ puts "*"*80
255
+ end
256
+
257
+ labelconf = @easyfpmconf.getLabelHashConf(label)
258
+
259
+ makingConf={}
260
+ #Do we need to generate the changelog ?
261
+ if labelconf.has_key? "easyfpm-pkg-changelog"
262
+ #Create a temp file
263
+ makingConf["file-easyfpm-pkg-changelog"]=Tempfile.new("easyfpm-pkg-changelog")
264
+ #Give it for config
265
+ makingConf["pkg-changelog"]=makingConf["file-easyfpm-pkg-changelog"].path
266
+ debug "make","Generating easyfpm changelog #{makingConf["pkg-changelog"]}"
267
+ #Create a easyfpm-changelog object from file
268
+ easyfpmcl = EASYFPM::PkgChangelog.new(labelconf["easyfpm-pkg-changelog"])
269
+ #Writing a changelog for package type in temp file
270
+ easyfpmcl.write(labelconf["pkg-type"],makingConf["pkg-changelog"])
271
+ end
272
+
273
+ #Do we have a mapping file ?
274
+ # If so we have to recreate the source directory
275
+ if labelconf.has_key? "pkg-mapping"
276
+ hashmap = EASYFPM::Mapping.new(labelconf["pkg-mapping"]).hashmap
277
+ makingConf["pkg-content"] = hashmap.values.join(" ")
278
+ makingConf["pkg-src-dir"] = Dir.mktmpdir("easyfpm-mapping")
279
+ debug "make","mapping pkg-src-dir into #{makingConf["pkg-src-dir"]}"
280
+ #We copy from pkg-src-dir to temp dir
281
+ hashmap.keys.each do |file|
282
+ #First, we create the arborescence if it doesn't exists
283
+ newArbo = File.dirname(hashmap[file])
284
+ unless newArbo == "."
285
+ debug "make","creating "+makingConf["pkg-src-dir"]+"/"+newArbo
286
+ FileUtils.mkdir_p(makingConf["pkg-src-dir"]+"/"+newArbo) unless Dir.exist?(makingConf["pkg-src-dir"]+"/"+newArbo)
287
+ end
288
+ #Then copy the source into it
289
+ debug "make", "copying #{labelconf["pkg-src-dir"]}/#{file} to "+makingConf["pkg-src-dir"]+"/"+hashmap[file]
290
+ if (@verbose or @debug)
291
+ FileUtils.cp_r(labelconf["pkg-src-dir"]+"/"+file, makingConf["pkg-src-dir"]+"/"+hashmap[file], :preserve => true, :verbose => true)
292
+ else
293
+ FileUtils.cp_r(labelconf["pkg-src-dir"]+"/"+file, makingConf["pkg-src-dir"]+"/"+hashmap[file], :preserve => true)
294
+ end
295
+ end #hashmap.keys.each
296
+ end #if labelconf.has_key? "pkg-mapping"
297
+
298
+ #Do we have a specific output dir ?
299
+ # there's a bug with fpm and this feature, so easyfpm take it itself for the moment
300
+ if labelconf.has_key? "pkg-output-dir"
301
+ #Making a new tmpdir for working in
302
+ makingConf["pkg-output-dir"] = Dir.mktmpdir("easyfpm-output-dir")
303
+ end
304
+
305
+ #We are ready to generate the fpm command
306
+ fpmCmdOptions = generatefpmline(labelconf,makingConf)
307
+
308
+ puts "fpm "+fpmCmdOptions if (@verbose or @debug or @dryrun)
309
+
310
+ unless @dryrun
311
+ if makingConf.has_key? "pkg-output-dir"
312
+ #returnCode = system "cd "+makingConf["pkg-output-dir"]+" && fpm "+fpmCmdOptions
313
+ Open3.popen2e("cd "+makingConf["pkg-output-dir"]+" && fpm "+fpmCmdOptions) do |stdin, stdout_err, wait_thr|
314
+ #fpm uses Cabin::channel for logging
315
+ while line = stdout_err.gets
316
+ #cbchannelmatch = /^\{.*:message=>"(.*?)",.+?(:level=>:(\w+),)?.*(:path=>"(.*?)")?.*\}$/.match(line)
317
+ cbchannelmatch = /^\{.*:message=>"(.*?)",.+?(:level=>:(\w+),)?.*\}$/.match(line)
318
+ cbpathmatch = /^\{.*:message=>"(.*?)",.*( :path=>"(.*?)").*\}$/.match(line)
319
+ #Outline cause we have to filter messages before output if package-output-dir
320
+ outline=nil
321
+ if cbchannelmatch
322
+ message = cbchannelmatch[1]
323
+ loglevel = cbchannelmatch[3]
324
+ path = cbpathmatch[3] if cbpathmatch
325
+ if (loglevel == "info" and (@verbose or @debug))
326
+ outline = cbchannelmatch[0]
327
+ elsif (loglevel == "debug" and @debug)
328
+ outline = cbchannelmatch[0]
329
+ elsif loglevel
330
+ #Ni info, ni debug => warning ou error ou autre ?
331
+ warn message
332
+ else
333
+ outline = message+" "+path if path
334
+ outline = message unless path
335
+ end #if loglevel
336
+
337
+ #Here we have the pkg-output-dir treatment
338
+ if message == "Created package" and path
339
+ if File.exists?(makingConf["pkg-output-dir"]+"/"+path)
340
+ puts (message+" "+makingConf["pkg-output-dir"]+"/"+path)
341
+ outline=nil
342
+ if File.exists?(labelconf["pkg-output-dir"]+"/"+path)
343
+ if labelconf.has_key?("pkg-force") and (labelconf["pkg-force"] == "yes")
344
+ #Move file
345
+ if (@verbose or @debug)
346
+ FileUtils.mv(makingConf["pkg-output-dir"]+"/"+path, labelconf["pkg-output-dir"]+"/"+path, :force => true, :verbose => true)
347
+ else
348
+ FileUtils.mv(makingConf["pkg-output-dir"]+"/"+path, labelconf["pkg-output-dir"]+"/"+path, :force => true)
349
+ end #if (@verbose or @debug)
350
+ puts "Package moved to #{labelconf["pkg-output-dir"]}/#{path}"
351
+ # We suppress
352
+ else
353
+ warn labelconf["pkg-output-dir"]+"/"+path+" already exists, use '--pkg-force yes' to force copy"
354
+ returnCode = false
355
+ end #if labelconf.has_key? "pkg-force" and labelconf["pkg-force"] == "yes"
356
+ else
357
+ #Move file
358
+ if (@verbose or @debug)
359
+ FileUtils.mv(makingConf["pkg-output-dir"]+"/"+path, labelconf["pkg-output-dir"]+"/"+path, :verbose => true)
360
+ else
361
+ FileUtils.mv(makingConf["pkg-output-dir"]+"/"+path, labelconf["pkg-output-dir"]+"/"+path)
362
+ end
363
+ puts "Package moved to #{labelconf["pkg-output-dir"]}/#{path}"
364
+ end #if File.exists?(labelconf["pkg-output-dir"]+"/"+path)
365
+ end #if File.exists?(makingConf["pkg-output-dir"]+"/"+path)
366
+ end #message == "Created package" and path
367
+ #We display the message if not filtered
368
+ puts outline unless outline.nil?
369
+ else
370
+ puts line if line
371
+ end #if cbchannelmatch
372
+ end #while line=stdout_err.gets
373
+ returnCode = false unless wait_thr.value.success?
374
+ end #Open3.popen2e
375
+ else
376
+ returnCode = system "fpm "+fpmCmdOptions
377
+ end
378
+ else
379
+ puts " dry-run mode, fpm not executed"
380
+ end
381
+
382
+ #We clean all before exiting
383
+ ensure
384
+ # tempfile for changelog if created
385
+ if makingConf.has_key? "file-easyfpm-pkg-changelog"
386
+ makingConf["file-easyfpm-pkg-changelog"].close
387
+ debug "make"," #{makingConf["pkg-changelog"]} deleted"
388
+ end
389
+ # tempdir for mapping if created
390
+ if makingConf.has_key? "pkg-src-dir"
391
+ FileUtils.remove_entry_secure(makingConf["pkg-src-dir"])
392
+ debug "make","#{makingConf["pkg-src-dir"]} deleted"
393
+ end
394
+ if makingConf.has_key? "pkg-output-dir"
395
+ FileUtils.remove_entry_secure(makingConf["pkg-output-dir"])
396
+ debug "make","#{makingConf["pkg-output-dir"]} deleted"
397
+ end
398
+ end #begin
399
+ return returnCode
400
+ end #make
401
+
402
+ def debug (function, message="")
403
+ puts "EASYFPM::Packaging."+function+": "+message if @debug
404
+ end
405
+ private :debug
406
+ end
@@ -0,0 +1,195 @@
1
+ ###############################################################################
2
+ ## Class : EASYFPM::Changelog
3
+ ## Author : Erwan SEITE
4
+ ## Aim : Manage EASYFPM changelog Format
5
+ ## Licence : GPL v2
6
+ ## Source : https://github.com/wanix/easyfpm.git
7
+ ###############################################################################
8
+ require "easyfpm/exceptions"
9
+ require "time"
10
+
11
+ class EASYFPM::PkgChangelog
12
+
13
+ @@easyfpmCLRegExp={}
14
+ @@easyfpmCLRegExp[:comment] = /^\s*#/
15
+ @@easyfpmCLRegExp[:header] = /^\s*((\d{4}-?\d{2}-?\d{2}) (\d{2}:\d{2}:\d{2} )?)?Version (\d+\.\d+(\.\d+)?(-\d+)?) (.+? )?\(((.+?)(@| at ).+?\.[\d\w]+)\)\s*$/i
16
+ @@easyfpmCLRegExp[:description] = /^(( )+)(.+)$/
17
+ @@easyfpmCLRegExp[:ignored] = /^\s*$/
18
+
19
+ attr_accessor :defaultDate
20
+ attr_accessor :pkgname
21
+ attr_accessor :distribution
22
+ attr_accessor :urgency
23
+
24
+ def initialize(changelogFile)
25
+ raise ArgumentError, 'the argument "changelogFile" must be a String' unless changelogFile.is_a? String
26
+ raise Errno::EACCES, "Can't read #{changelogFile}" unless File.readable?(changelogFile)
27
+ @changelog=changelogFile
28
+ self.defaultDate = Time.now
29
+ self.pkgname = File.basename(File.dirname(changelogFile))
30
+ self.distribution = "stable"
31
+ self.urgency = "low"
32
+ end
33
+
34
+ def write (format, fileToWrite)
35
+ raise ArgumentError, 'the argument "format" must be a String' unless format.is_a? String
36
+ raise ArgumentError, 'the argument "fileToWrite" must be a String' unless fileToWrite.is_a? String
37
+
38
+ File.open(fileToWrite,'w') do |file|
39
+ case format.downcase
40
+ when "deb", "rpm"
41
+ return self.print(format,file)
42
+ else
43
+ raise EASYFPM::InvalidChangelogFormat, "The format #{format} is not (yet) implemented"
44
+ end
45
+ end
46
+ end #write
47
+
48
+ def print (format, io_obj=$stdout)
49
+ raise ArgumentError, 'the argument "format" must be a String' unless format.is_a? String
50
+ raise ArgumentError, 'the argument "io_obj" must be an IO class or an IO inherited class' unless io_obj.is_a? IO
51
+
52
+ case format.downcase
53
+ when "deb"
54
+ return printDEB(io_obj)
55
+ when "rpm"
56
+ return printRPM(io_obj)
57
+ else
58
+ raise EASYFPM::InvalidChangelogFormat, "The format #{format} is not implemented"
59
+ end
60
+ end #print
61
+
62
+
63
+ #(private) Write a RPM format changelog on an IO obj
64
+ #Parameters:
65
+ # io_obj : IO
66
+ def printRPM (io_obj=$stdout)
67
+ returnCode = 0
68
+ lineNumber=0
69
+ errorLines = []
70
+ myChangelog = File.new(@changelog, "r")
71
+ header = {}
72
+ while (myLine = myChangelog.gets)
73
+ lineNumber += 1
74
+ commentLine = @@easyfpmCLRegExp[:comment].match(myLine)
75
+ #If we have a comment, we ignore it
76
+ next if commentLine
77
+ ignoredLine = @@easyfpmCLRegExp[:ignored].match(myLine)
78
+ #Line we have explicitely to ignore
79
+ next if ignoredLine
80
+ headerLine = @@easyfpmCLRegExp[:header].match(myLine)
81
+ if headerLine
82
+ #header line is found, we analyse it
83
+ #if a header was here before, we display a cariage return
84
+ io_obj.puts "" if header.length > 0
85
+ header.clear
86
+ if headerLine[1]
87
+ header[:date] = Time.parse(headerLine[1])
88
+ elsif defaultDate
89
+ header[:date] = self.defaultDate
90
+ else
91
+ header[:date] = Time.now
92
+ end
93
+ header[:version] = headerLine[4] if headerLine[4]
94
+ if headerLine[7]
95
+ header[:author] = headerLine[7]
96
+ else
97
+ header[:author] = headerLine[9]
98
+ end
99
+ header[:mail] = headerLine[8] if headerLine[8]
100
+ #Header in a RedHat format
101
+ io_obj.puts "* " + header[:date].strftime("%a %b %d %Y") + " " + header[:author] + " <" + header[:mail] + "> " + header[:version]
102
+ next
103
+ end
104
+ descriptionLine = @@easyfpmCLRegExp[:description].match(myLine)
105
+ if descriptionLine
106
+ io_obj.puts descriptionLine[1] + "- " + descriptionLine[3]
107
+ next
108
+ end
109
+
110
+ #A line we can't analyse
111
+ errorLines.push(" line " + lineNumber.to_s + " : " + myLine)
112
+ returnCode=1
113
+ end
114
+
115
+ if errorLines.length > 0
116
+ warn("Error : the followning(s) line(s) are not in easyfpm changelog format :")
117
+ errorLines.each { |error| warn(error) }
118
+ end
119
+ return returnCode
120
+ end #printRPM
121
+ private :printRPM
122
+
123
+ #(private) Write a DEB format changelog on an IO obj
124
+ #Parameters:
125
+ # io_obj : IO
126
+ def printDEB (io_obj=$stdout)
127
+ returnCode = 0
128
+ lineNumber = 0
129
+ errorLines = []
130
+ myChangelog = File.new(@changelog, "r")
131
+ header = {}
132
+ while (myLine = myChangelog.gets)
133
+ lineNumber += 1
134
+ commentLine = @@easyfpmCLRegExp[:comment].match(myLine)
135
+ #If we have a comment, we ignore it
136
+ next if commentLine
137
+ ignoredLine = @@easyfpmCLRegExp[:ignored].match(myLine)
138
+ #Line we have explicitely to ignore
139
+ next if ignoredLine
140
+ headerLine = @@easyfpmCLRegExp[:header].match(myLine)
141
+ if headerLine
142
+ #header line is found, we analyse it
143
+ #if a header was here before, we display the debian style footer for the last one
144
+ if header.length != 0
145
+ io_obj.puts " -- " + header[:author] + " <" + header[:mail] + "> " + header[:date].strftime("%a %d %b %Y %H:%M:%S %z")
146
+ io_obj.puts ""
147
+ end
148
+ header.clear
149
+ if headerLine[1]
150
+ header[:date] = Time.parse(headerLine[1])
151
+ elsif defaultDate
152
+ header[:date] = self.defaultDate
153
+ else
154
+ header[:date] = Time.now
155
+ end
156
+ header[:version] = headerLine[4] if headerLine[4]
157
+ if headerLine[7]
158
+ header[:author] = headerLine[7]
159
+ else
160
+ header[:author] = headerLine[9]
161
+ end
162
+ header[:mail] = headerLine[8] if headerLine[8]
163
+ #Debian style header
164
+ io_obj.puts self.pkgname + " (" + header[:version] + ") " + self.distribution + "; urgency=" + self.urgency
165
+ next
166
+ end
167
+ descriptionLine = @@easyfpmCLRegExp[:description].match(myLine)
168
+ if descriptionLine
169
+ if descriptionLine[1].length == 2
170
+ io_obj.puts " * " + descriptionLine[3]
171
+ else
172
+ io_obj.puts myLine
173
+ end
174
+ next
175
+ end
176
+
177
+ #A line we can't analyse
178
+ errorLines.push(" line " + lineNumber.to_s + " : " + myLine)
179
+ returnCode=1
180
+ end
181
+ if header.length != 0
182
+ #We put the footer for the last header
183
+ io_obj.puts " -- " + header[:author] + " <" + header[:mail] + "> " + header[:date].strftime("%a %d %b %Y %H:%M:%S %z")
184
+ end
185
+
186
+ if errorLines.length > 0
187
+ $stderr.puts "Error : the followning(s) line(s) are not in easyfpm changelog format :"
188
+ errorLines.each { |error| $stderr.puts(error) }
189
+ end
190
+
191
+ return returnCode
192
+ end #printDEB
193
+ private :printDEB
194
+
195
+ end
@@ -0,0 +1,4 @@
1
+ #EASYFPM Module version
2
+ module EASYFPM
3
+ VERSION = "1.0-dev"
4
+ end
data/lib/easyfpm.rb ADDED
@@ -0,0 +1,15 @@
1
+ ###############################################################################
2
+ ## Class : easyfpm
3
+ ## Author : Erwan SEITE
4
+ ## Aim : Manage FPM packaging
5
+ ## Licence : GPL v2
6
+ ## Source : https://github.com/wanix/easyfpm.git
7
+ ###############################################################################
8
+
9
+ require "easyfpm/namespace"
10
+ require "easyfpm/version"
11
+ require "easyfpm/exceptions"
12
+ require "easyfpm/configuration"
13
+ require "easyfpm/mapping"
14
+ require "easyfpm/packaging"
15
+ require "easyfpm/pkgchangelog"