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,30 @@
1
+ #!/bin/sh
2
+ #Sample pre-delete.sh script for easyfpm : https://github.com/wanix/easyfpm.git
3
+ #Usage for deb : https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html
4
+ #Usage for rpm : http://www.rpm.org/max-rpm-snapshot/s1-rpm-inside-scripts.html
5
+
6
+ myOperation=${1}
7
+
8
+ case ${myOperation} in
9
+ 0) #Uninstall RedHat
10
+ exit 0;;
11
+ 1) #Upgrade RedHat
12
+ exit 0;;
13
+ remove) #Debian:
14
+ #prerm remove
15
+ #or conflictor's-prerm remove in-favour <package> <new-version>
16
+ exit 0;;
17
+ upgrade) #Debian:
18
+ #old-prerm upgrade <new-version>
19
+ exit 0;;
20
+ deconfigure) #Debian:
21
+ #deconfigured's-prerm deconfigure in-favour <package-being-installed> <version> [removing <conflicting-package> <version>]
22
+ exit 0;;
23
+ failed-upgrade) #Debian:
24
+ #new-prerm failed-upgrade <old-version>
25
+ exit 0;;
26
+ \?) #Unknown
27
+ exit 1;;
28
+ *) exit 1;;
29
+ esac
30
+ exit 0
@@ -0,0 +1,27 @@
1
+ #!/bin/sh
2
+ #Sample pre-install.sh script for easyfpm : https://github.com/wanix/easyfpm.git
3
+ #Usage for deb : https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html
4
+ #Usage for rpm : http://www.rpm.org/max-rpm-snapshot/s1-rpm-inside-scripts.html
5
+
6
+ myOperation=${1}
7
+
8
+ case ${myOperation} in
9
+ 1) #Install RedHat
10
+ exit 0;;
11
+ 2) #Upgrade RedHat
12
+ exit 0;;
13
+ install) #Debian:
14
+ #new-preinst install
15
+ #or new-preinst install <old-version>
16
+ exit 0;;
17
+ upgrade) #Debian:
18
+ #new-preinst upgrade <old-version>
19
+ exit 0;;
20
+ abort-upgrade) #Debian:
21
+ #old-preinst abort-upgrade <new-version>
22
+ exit 0;;
23
+ \?) #Unknown
24
+ exit 1;;
25
+ *) exit 1;;
26
+ esac
27
+ exit 0
@@ -0,0 +1,20 @@
1
+ #
2
+ # This is a mapping sample
3
+ #
4
+ # source file (root dir is pkg-src-dir) => destination (root dir is pkg-prefix)
5
+ #
6
+
7
+ #This example suppose we want to package an apache specific configuration
8
+ # Tree on dev
9
+ # myapp
10
+ # conf.d/myapp.conf
11
+ # site/<php code>
12
+ # doc
13
+ #
14
+ # the pkg-source-dir is /home/packager/retrieve/myapp
15
+ # the pkg-prefix is /
16
+
17
+ conf.d/myapp.conf => etc/apache2/site-available/myapp.conf
18
+ site => app/httpd/www/myapp
19
+ doc => usr/share/doc/myapp
20
+
@@ -0,0 +1,274 @@
1
+ ###############################################################################
2
+ ## Class : EASYFPM::CommandLine
3
+ ## Author : Erwan SEITE
4
+ ## Aim : Manage EASYFPM Command Line
5
+ ## Licence : GPL v2
6
+ ## Source : https://github.com/wanix/easyfpm.git
7
+ ###############################################################################
8
+ require "easyfpm"
9
+ require "optparse"
10
+ begin
11
+ require "unixconfigstyle"
12
+ rescue LoadError
13
+ require "rubygems"
14
+ require "unixconfigstyle"
15
+ end
16
+
17
+
18
+ class EASYFPM::CommandLine
19
+
20
+ def initialize()
21
+ @easyfpmconf = UnixConfigStyle.new()
22
+ @verbose = false
23
+ @dryrun = false
24
+ @debug=false
25
+ @labels = []
26
+ parse()
27
+ end
28
+
29
+
30
+ #(private) Parse the command line arguments and create a UnixConfigStyle object
31
+ def parse(*args)
32
+ easyfpmconffiles = []
33
+ options = {}
34
+ labelListAsked = false
35
+ optparse = OptionParser.new do |opts|
36
+ opts.banner = "Usage easyfpm [options]"
37
+
38
+ opts.on("--config-file [string]", String, "Configuration file's path", " (can be declared multiple times, declarative order is priority order)") do |opt|
39
+ easyfpmconffiles.push(opt)
40
+ end
41
+
42
+ opts.on("--label [list by comma]", String, "Labels to work with", " (can be declared multiple times)") do |opt|
43
+ @labels.concat(opt.split(','))
44
+ end
45
+
46
+ opts.on("--pkg-name [string]", String, "Package name") do |opt|
47
+ @easyfpmconf.addValues(opt,"pkg-name")
48
+ end
49
+
50
+ opts.on("--pkg-type [string]", String, "Package type") do |opt|
51
+ @easyfpmconf.addValues(opt,"pkg-type")
52
+ end
53
+
54
+ opts.on("--pkg-version [string]", String, "Package version, example 1.0") do |opt|
55
+ @easyfpmconf.addValues(opt,"pkg-version")
56
+ end
57
+
58
+ opts.on("--pkg-src-dir [string]", String, "Package source dir") do |opt|
59
+ @easyfpmconf.addValues(opt,"pkg-src-dir")
60
+ end
61
+
62
+ opts.on("--pkg-mapping [string]", String, "Package install map file") do |opt|
63
+ @easyfpmconf.addValues(opt,"pkg-mapping")
64
+ end
65
+
66
+ opts.on("--pkg-prefix [string]", String, "Package installation prefix") do |opt|
67
+ @easyfpmconf.addValues(opt,"pkg-prefix")
68
+ end
69
+
70
+ opts.on("--pkg-output-dir [string]", String, "Destination dir for packages") do |opt|
71
+ @easyfpmconf.addValues(opt,"pkg-output-dir")
72
+ end
73
+
74
+ opts.on("--pkg-description [string]", String, "Package description") do |opt|
75
+ @easyfpmconf.addValues(opt,"pkg-description")
76
+ end
77
+
78
+ opts.on("--pkg-arch [string]", String, "Package architecture") do |opt|
79
+ @easyfpmconf.addValues(opt,"pkg-arch")
80
+ end
81
+
82
+ opts.on("--pkg-content [string]", String, "source elements to package") do |opt|
83
+ @easyfpmconf.addValues(opt,"pkg-content")
84
+ end
85
+
86
+ opts.on("--pkg-user [string]", String, "Owner of package's elements") do |opt|
87
+ @easyfpmconf.addValues(opt,"pkg-user")
88
+ end
89
+
90
+ opts.on("--pkg-group [string]", String, "Group of package's elements") do |opt|
91
+ @easyfpmconf.addValues(opt,"pkg-group")
92
+ end
93
+
94
+ opts.on("--template-activated [yes|no]", String, "Activate fpm templating mode") do |opt|
95
+ @easyfpmconf.addValues(opt,"template-activated")
96
+ end
97
+
98
+ opts.on("--template-value [string key:value]", String, "Couple key:value for fpm templating") do |opt|
99
+ @easyfpmconf.addValues(opt,"template-value")
100
+ end
101
+
102
+ opts.on("--pkg-preinst [string]", String, "Path to pre-install package script") do |opt|
103
+ @easyfpmconf.addValues(opt,"pkg-preinst")
104
+ end
105
+
106
+ opts.on("--pkg-postinst [string]", String, "Path to post-install package script") do |opt|
107
+ @easyfpmconf.addValues(opt,"pkg-postinst")
108
+ end
109
+
110
+ opts.on("--pkg-prerm [string]", String, "Path to pre-delete package script") do |opt|
111
+ @easyfpmconf.addValues(opt,"pkg-prerm")
112
+ end
113
+
114
+ opts.on("--pkg-postrm [string]", String, "Path to post-delete package script") do |opt|
115
+ @easyfpmconf.addValues(opt,"pkg-postrm")
116
+ end
117
+
118
+ opts.on("--pkg-iteration [string]", String, "Package iteration") do |opt|
119
+ @easyfpmconf.addValues(opt,"pkg-iteration")
120
+ end
121
+
122
+ opts.on("--pkg-epoch [integer]", Integer, "Package epoch value") do |opt|
123
+ @easyfpmconf.addValues(opt,"pkg-epoch")
124
+ end
125
+
126
+ opts.on("--easyfpm-pkg-changelog [string]", String, "Path to an easyfpm format changelog file") do |opt|
127
+ @easyfpmconf.addValues(opt,"easyfpm-pkg-changelog")
128
+ end
129
+
130
+ opts.on("--pkg-vendor [string]", String, "Package vendor name") do |opt|
131
+ @easyfpmconf.addValues(opt,"pkg-vendor")
132
+ end
133
+
134
+ opts.on("--pkg-url [string]", String, "Package vendor url") do |opt|
135
+ @easyfpmconf.addValues(opt,"pkg-url")
136
+ end
137
+
138
+ opts.on("--pkg-license [string]", String, "Package license") do |opt|
139
+ @easyfpmconf.addValues(opt,"pkg-license")
140
+ end
141
+
142
+ opts.on("--pkg-config-files [string]", String, "Files or directories considered as conf in the targeted OS", " (can be declared multiple time)") do |opt|
143
+ @easyfpmconf.addValues(opt,"pkg-config-files")
144
+ end
145
+
146
+ opts.on("--pkg-depends [string]", String, "Package dependancie"," (can be declared multiple times)") do |opt|
147
+ @easyfpmconf.addValues(opt,"pkg-depends")
148
+ end
149
+
150
+ opts.on("--pkg-suffix [string]", String, "Package suffix") do |opt|
151
+ @easyfpmconf.addValues(opt,"pkg-suffix")
152
+ end
153
+
154
+ opts.on("--pkg-changelog [string]", String, "Package changelog (in the wanted format for the package)") do |opt|
155
+ @easyfpmconf.addValues(opt,"pkg-changelog")
156
+ end
157
+
158
+ opts.on("--pkg-force [yes|no]", String, "Force package generation even if the same name exists") do |opt|
159
+ @easyfpmconf.addValues(opt,"pkg-force")
160
+ end
161
+
162
+ opts.on("--pkg-category [string]", String, "Category for this package") do |opt|
163
+ @easyfpmconf.addValues(opt,"pkg-category")
164
+ end
165
+
166
+ opts.on("--pkg-provides [string]", String, "A tag of what provides this package"," (can be declared multiple times)") do |opt|
167
+ @easyfpmconf.addValues(opt,"pkg-provides")
168
+ end
169
+
170
+ opts.on("--pkg-conflicts [string]", String, "Other packages that conflict with that one"," (can be declared multiple times)") do |opt|
171
+ @easyfpmconf.addValues(opt,"pkg-conflicts")
172
+ end
173
+
174
+ opts.on("--pkg-recommends [string]", String, "Other package to recommend"," (can be declared multiple times)") do |opt|
175
+ @easyfpmconf.addValues(opt,"pkg-recommends")
176
+ end
177
+
178
+ opts.on("--pkg-suggests [string]", String, "Other package to suggests"," (can be declared multiple times)") do |opt|
179
+ @easyfpmconf.addValues(opt,"pkg-suggests")
180
+ end
181
+
182
+ opts.on("--pkg-directories [string]", String, "Mark recursively a directory on the targeted system as being owned by the package"," (can be declared multiple times)") do |opt|
183
+ @easyfpmconf.addValues(opt,"pkg-directories")
184
+ end
185
+
186
+ opts.on("--pkg-maintainer [string]", String, "The maintainer of this package") do |opt|
187
+ @easyfpmconf.addValues(opt,"pkg-maintainer")
188
+ end
189
+
190
+ opts.on("--pkg-compression [string]", String, "The compression to use with this package (may not be possible)") do |opt|
191
+ @easyfpmconf.addValues(opt,"pkg-compression")
192
+ end
193
+
194
+ opts.on("--pkg-priority [string]", String, "The package 'priority' (depends of the targetted package type") do |opt|
195
+ @easyfpmconf.addValues(opt,"pkg-priority")
196
+ end
197
+
198
+ opts.on("--pkg-replaces [string]", String, "Other packages this package replace"," (can be declared multiple times)") do |opt|
199
+ @easyfpmconf.addValues(opt,"pkg-replaces")
200
+ end
201
+
202
+ opts.on("-v", "--verbose", "Verbose mode") do |opt|
203
+ @verbose = true;
204
+ end
205
+
206
+ opts.on("--debug", "Debug mode") do |opt|
207
+ @debug = true;
208
+ end
209
+
210
+ opts.on("-n", "--dry-run", "Do not exec fpm, juste print what would be done") do |opt|
211
+ @dryrun = true;
212
+ end
213
+
214
+ opts.on("--version", "Display version and quit") do |opt|
215
+ puts "easyfpm version #{EASYFPM::VERSION}"
216
+ exit
217
+ end
218
+
219
+ opts.on("--label-list", String, "Display the availables labels and quit") do |opt|
220
+ labelListAsked=true
221
+ end
222
+
223
+ opts.on("--help", "Display help and quit") do |opt|
224
+ puts opts
225
+ exit
226
+ end
227
+ end #OptionParser.new do
228
+
229
+ optparse.parse!
230
+ easyfpmconffiles.each do |conffile|
231
+ @easyfpmconf.push_unix_config_file(conffile)
232
+ end
233
+ if labelListAsked
234
+ labels = @easyfpmconf.getSections()
235
+ if labels.empty?
236
+ puts "No labels available"
237
+ else
238
+ puts "Availables labels :"
239
+ labels.each do |label|
240
+ puts " - "+label
241
+ end
242
+ end
243
+ exit
244
+ end
245
+ end #parse
246
+ private :parse
247
+
248
+ # For debugging purpose, print the UnixConfigStyle object for this instance
249
+ def print()
250
+ @easyfpmconf.print()
251
+ end #print
252
+
253
+ # Run the command line given
254
+ #def run(*args)
255
+ def run()
256
+ returnCode=true
257
+ if @labels.empty?
258
+ easyfpmpkg = EASYFPM::Packaging.new(@easyfpmconf)
259
+ easyfpmpkg.verbose = @verbose
260
+ easyfpmpkg.dryrun = @dryrun
261
+ easyfpmpkg.debug = @debug
262
+ returnCode=false unless easyfpmpkg.makeAll()
263
+ else
264
+ @labels.each do |label|
265
+ easyfpmpkg = EASYFPM::Packaging.new(@easyfpmconf,label)
266
+ easyfpmpkg.verbose = @verbose
267
+ easyfpmpkg.dryrun = @dryrun
268
+ easyfpmpkg.debug = @debug
269
+ returnCode=false unless easyfpmpkg.make(label)
270
+ end
271
+ end
272
+ return returnCode
273
+ end #run
274
+ end
@@ -0,0 +1,274 @@
1
+ ###############################################################################
2
+ ## Class : EASYFPM::Configuration
3
+ ## Author : Erwan SEITE
4
+ ## Aim : Manage EASYFPM Conf
5
+ ## Licence : GPL v2
6
+ ## Source : https://github.com/wanix/easyfpm.git
7
+ ###############################################################################
8
+ require "easyfpm/exceptions"
9
+ begin
10
+ require "unixconfigstyle"
11
+ rescue LoadError
12
+ require "rubygems"
13
+ require "unixconfigstyle"
14
+ end
15
+
16
+ class EASYFPM::Configuration
17
+
18
+ @@templateVarExpReg = /(\{\{([\d\w\-]+?)\}\})/
19
+ @@defaultLabelName = "@@easyfpm-default@@"
20
+
21
+ attr_reader :conf
22
+
23
+ #Initialize the class
24
+ def initialize (unixconfigstyle, specificLabel=nil)
25
+ raise ArgumentError, 'the argument "unixconfigstyle" must be an UnixConfigStyle object' unless unixconfigstyle.is_a? UnixConfigStyle
26
+ raise ArgumentError, 'the argument "specificLabel" must be an String' unless (specificLabel.is_a? String or specificLabel == nil)
27
+
28
+ @conf={}
29
+ createconf(unixconfigstyle,specificLabel)
30
+ raise EASYFPM::InvalidConfiguration, "No configuration found (error with the label #{specificLabel}?" if @conf.empty?
31
+ replaceTemplateVars()
32
+ raise EASYFPM::InvalidConfiguration, "Error(s) during validation" unless validate()
33
+ end
34
+
35
+ #Create the easyfpm struct configuration from an UnixConfigStyle object
36
+ def createconf(unixconfigstyle, specificLabel=nil)
37
+ #No work if the conf is empty
38
+ return nil if unixconfigstyle.isEmpty?()
39
+ #No work if the conf doesn't contain the wanted label
40
+ return nil unless ( specificLabel==nil or unixconfigstyle.sectionExists?(specificLabel) )
41
+ #We create an array with all keys presents in the conf
42
+ allkeys=unixconfigstyle.getAllKeys(specificLabel)
43
+ if (specificLabel == nil)
44
+ if unixconfigstyle.haveSections?()
45
+ #We have section, we create a separate conf for each one
46
+ unixconfigstyle.getSections().each { |section| @conf[section]={} }
47
+ else
48
+ #No sections, only the default config
49
+ @conf[@@defaultLabelName]={}
50
+ end
51
+ else
52
+ #We create config only for this specific label
53
+ @conf[specificLabel]={}
54
+ end
55
+ #We have our label(s)
56
+ #It's now time to filter the configuration and create a valid conf
57
+
58
+ #Foreach conf label
59
+ @conf.each_key do |label|
60
+ confsection=label
61
+ confsection=unixconfigstyle.getRootSectionName() if (label==@@defaultLabelName)
62
+
63
+ #Foreach key found
64
+ allkeys.each do |param|
65
+ #If the param has no value (???), next
66
+ next unless unixconfigstyle.getValues(param,confsection,true)
67
+ case param
68
+ #Params for which each member of array is a string line
69
+ when "pkg-description"
70
+ @conf[label][param]=unixconfigstyle.getValues(param,confsection,true).join("\n").strip
71
+
72
+ #Params for which each member is a string separated with a space
73
+ when "pkg-content"
74
+ @conf[label][param]=unixconfigstyle.getValues(param,confsection,true).join(" ").strip
75
+
76
+ #Params for which we need to keep an array:
77
+ when "pkg-depends","template-value","pkg-config-files","pkg-provides","pkg-conflicts","pkg-replaces","pkg-directories","pkg-recommends","pkg-suggests"
78
+ @conf[label][param]=unixconfigstyle.getValues(param,confsection,true)
79
+
80
+ else
81
+ #For the others, the last one is the right string
82
+ @conf[label][param]=unixconfigstyle.getValues(param,confsection,true).last.strip
83
+ end #case
84
+ end #allkeys.each
85
+
86
+ #Now, we have specific rules :
87
+ #If we have a mapping AND a content, we delete the content
88
+ @conf[label].delete("pkg-content") if (@conf[label].has_key? "pkg-content" and @conf[label].has_key? "pkg-mapping")
89
+ #If we have an easyfpm-pkg-changelog AND a pkg-changelog, the pkg-changelog stay
90
+ @conf[label].delete("easyfpm-pkg-changelog") if (@conf[label].has_key? "easyfpm-pkg-changelog" and @conf[label].has_key? "pkg-changelog")
91
+
92
+ end #@conf.each_key
93
+
94
+
95
+
96
+ end #createconf
97
+
98
+ # (private) replace the easyfpm vars value
99
+ # the recursive param is here to stop multi recursive call
100
+ # We limit the work to two calls
101
+ def replaceTemplateVars(recursive=false)
102
+ #We start to scan each value if a var is present
103
+ return false if @conf.empty?
104
+ newTemplateFound=false
105
+ @conf.keys.each do |label|
106
+ @conf[label].keys.each do |param|
107
+ if (@conf[label][param].is_a? Array)
108
+ #Array of String
109
+ @conf[label][param].each_index do |index|
110
+ if containTemplateVar?(@conf[label][param][index])
111
+ @conf[label][param][index]=replaceTemplateVar(@conf[label][param][index],label)
112
+ newTemplateFound=true if containTemplateVar?(@conf[label][param][index])
113
+ end
114
+ end #@conf[label][param].each_index
115
+ else
116
+ #Should be String
117
+ if containTemplateVar?(@conf[label][param])
118
+ @conf[label][param]=replaceTemplateVar(@conf[label][param],label)
119
+ newTemplateFound=true if containTemplateVar?(@conf[label][param])
120
+ end
121
+ end #if (@conf[myLabel][param].is_a? Array)
122
+ end #@conf[myLabel].keys.each
123
+ end #@conf.getKeys.each
124
+
125
+ #First pass done, second needed ?
126
+ replaceTemplateVars(true) if (recursive == false and newTemplateFound == true)
127
+ raise EASYFPM::LoopTemplateDetected, "Need more than two occurs of function replaceTemplateVars()" if (recursive == true and newTemplateFound == true)
128
+ end
129
+ private :replaceTemplateVars
130
+
131
+ # (private) return true if the string contain at list one var
132
+ def containTemplateVar?(myString)
133
+ return false if (myString == nil)
134
+ return true if myString.match(@@templateVarExpReg)
135
+ return false
136
+ end
137
+ private :containTemplateVar?
138
+
139
+ # (private) return a string with vars replaced if a corresponding value is found
140
+ def replaceTemplateVar(myString, workinglabel)
141
+ # return myString
142
+ #foreach matchdata on each string
143
+ myString.to_enum(:scan, @@templateVarExpReg).map { Regexp.last_match }.each do |matchData|
144
+ myParam=matchData[2]
145
+ #If we can't found the key, we stop
146
+ raise EASYFPM::NoTemplateFound , "the key #{myParam} is not found for label #{workinglabel}" unless @conf[workinglabel].has_key? myParam
147
+ #If the value is not a String, error
148
+ raise EASYFPM::InvalidTemplateType, "the value given by the key #{myParam} can't be a multiline one" unless @conf[workinglabel][myParam].is_a? String
149
+ #Replace the template with its value
150
+ myString.gsub!(matchData[1],@conf[workinglabel][myParam])
151
+ end #myString.to_enum(:scan...
152
+ return myString
153
+ end
154
+ private :replaceTemplateVar
155
+
156
+ # (private) Validate the given configuration and clean it if necessary
157
+ def validate
158
+ errorlist = []
159
+ #We have to analyse some parameters and some ones MUST be present
160
+ @conf.keys.each do |label|
161
+ if (label == @@defaultLabelName)
162
+ displaylabel=""
163
+ else
164
+ displaylabel="[section "+label+"] "
165
+ end
166
+
167
+ #Looking for mandatory params
168
+ errorlist.push(displaylabel+"The parameter pkg-name (--pkg-name) MUST be given") unless @conf[label].has_key? "pkg-name"
169
+ errorlist.push(displaylabel+"The parameter pkg-src-dir (--pkg-src-dir) MUST be given") unless @conf[label].has_key? "pkg-src-dir"
170
+ errorlist.push(displaylabel+"The parameter pkg-version (--pkg-version) MUST be given") unless @conf[label].has_key? "pkg-version"
171
+ errorlist.push(displaylabel+"One of the two parameters pkg-content (--pkg-content) or pkg-mapping (--pkg-mapping) MUST be given") unless (@conf[label].has_key? "pkg-content" or @conf[label].has_key? "pkg-mapping")
172
+ errorlist.push(displaylabel+"The parameter pkg-type (--pkg-type) MUST be given") unless @conf[label].has_key? "pkg-type"
173
+
174
+ @conf[label].keys.each do |param|
175
+ case param
176
+ #these parameters are directories which must exists and be readable
177
+ when "pkg-src-dir"
178
+ errorlist.push(displaylabel+"The directory #{@conf[label][param]} (given by --#{param}) MUST exists") unless File.directory?(@conf[label][param])
179
+
180
+ #pkg-content can be replaced by pkg-mapping (higher priority for this last one)
181
+ #If no mapping, all the files or directories given must existsi and be readable in pkg-src-dir
182
+ when "pkg-content"
183
+ next unless @conf[label].has_key? "pkg-src-dir"
184
+ #If we already have an error on pkg-src-dir, next
185
+ next unless File.directory?(@conf[label]["pkg-src-dir"])
186
+ @conf[label][param].split.each do |fileOrDir|
187
+ errorlist.push(displaylabel+"The file (or directory) #{@conf[label]["pkg-src-dir"]}/#{fileOrDir} (given by --pkg-content) MUST be readable") unless (File.readable?(@conf[label]["pkg-src-dir"]+"/"+fileOrDir))
188
+ end
189
+
190
+ #the followings parameters must be readable files
191
+ when "pkg-mapping","easyfpm-pkg-changelog","pkg-changelog","pkg-preinst","pkg-postinst","pkg-prerm","pkg-postrm"
192
+ errorlist.push(displaylabel+"The file #{@conf[label][param]} (given by --#{param}) MUST be readable") unless (File.readable?(@conf[label][param]))
193
+
194
+ #the following parameters must be writable directories
195
+ when "pkg-output-dir"
196
+ errorlist.push(displaylabel+"The directory #{@conf[label][param]} (given by --#{param}) MUST exists and be writable") unless (File.directory?(@conf[label][param]) and File.writable?(@conf[label][param]))
197
+
198
+ #The following parameters should be only yes or no
199
+ when "template-activated", "pkg-force"
200
+ errorlist.push(displaylabel+"The param #{param} should accept only 'yes' or 'no' (and not #{@conf[label][param]})") unless (@conf[label][param].downcase == "yes" or @conf[label][param].downcase == "no")
201
+ end #case param
202
+ end #conf[label].keys.each do
203
+ end #@conf.keys.each
204
+
205
+ unless errorlist.empty?
206
+ warn("Errors in configuration detected:")
207
+ errorlist.each do |currenterror|
208
+ warn(" "+currenterror)
209
+ end
210
+ return false
211
+ end
212
+ return true
213
+ end #validate
214
+ private :validate
215
+
216
+ # Print the configuration (debugging)
217
+ def print(specificLabel=nil)
218
+ if (specificLabel == nil)
219
+ @conf.each_key do |label|
220
+ printLabelConf(label)
221
+ end
222
+ else
223
+ printLabelConf(specificLabel)
224
+ end
225
+ end
226
+
227
+ #Print the configuration for one label (debugging)
228
+ def printLabelConf(specificLabel)
229
+ if (specificLabel == @@defaultLabelName)
230
+ puts "========================================"
231
+ puts " Default package conf"
232
+ puts "========================================"
233
+ else
234
+ puts "========================================"
235
+ puts " Configuration label #{specificLabel}"
236
+ puts "========================================"
237
+ end
238
+ @conf[specificLabel].each_key do |param|
239
+ header="<"+param+"> : "
240
+ if @conf[specificLabel][param].is_a? Array
241
+ puts header+@conf[specificLabel][param][0]
242
+ subheader=" "*header.length()
243
+ index=1
244
+ while index < @conf[specificLabel][param].length()
245
+ puts subheader+@conf[specificLabel][param][index]
246
+ index += 1
247
+ end
248
+ else
249
+ puts header+@conf[specificLabel][param].to_s
250
+ end #if @conf[specificLabel][param].is_a Array
251
+ end #@conf[specificLabel].each_key
252
+ end
253
+ private :printLabelConf
254
+
255
+ #return true if any labels are defined
256
+ def hasLabels?()
257
+ return false if @conf.has_key? @@defaultLabelName
258
+ return true
259
+ end
260
+
261
+ #return all labels into Array, nil if no labels
262
+ def getLabels()
263
+ return nil unless hasLabels?()
264
+ return @conf.keys()
265
+ end
266
+
267
+ #return an hash for the label configuration
268
+ #return nil if problem
269
+ def getLabelHashConf(label=nil)
270
+ label=@@defaultLabelName if label == nil
271
+ return nil unless @conf.has_key? label
272
+ return @conf[label]
273
+ end
274
+ end
@@ -0,0 +1,18 @@
1
+ # The EASYFPM exceptions
2
+
3
+ #Raised if an unknown changelog format is asked
4
+ class EASYFPM::InvalidChangelogFormat < StandardError; end
5
+ #Raised if a needed argument for a package is missing
6
+ class EASYFPM::MissingArgument < StandardError; end
7
+ #Raised if a packaging label is asked and not configured
8
+ class EASYFPM::NoSuchSection < StandardError; end
9
+ #Raised if a loop is detected with templates
10
+ class EASYFPM::LoopTemplateDetected < StandardError; end
11
+ #Raised if a template var is asked and not found
12
+ class EASYFPM::NoTemplateFound < StandardError; end
13
+ #Raised if a template var is not a string
14
+ class EASYFPM::InvalidTemplateType < StandardError; end
15
+ #Raised if a configuration is not validated
16
+ class EASYFPM::InvalidConfiguration < StandardError; end
17
+ #Raised if a problem is detected on the system
18
+ class EASYFPM::InvalidEnvironment < StandardError; end