Class: BuildTool::Configuration
- Inherits:
-
Object
- Object
- BuildTool::Configuration
- Defined in:
- lib/build-tool/configuration.rb
Instance Attribute Summary collapse
-
#active_feature ⇒ Object
Returns the value of attribute active_feature.
-
#environments ⇒ Object
readonly
Returns the value of attribute environments.
-
#features ⇒ Object
readonly
Returns the value of attribute features.
-
#modules ⇒ Object
readonly
Returns the value of attribute modules.
-
#recipe ⇒ Object
Returns the value of attribute recipe.
-
#settings ⇒ Object
readonly
Returns the value of attribute settings.
Class Method Summary collapse
Instance Method Summary collapse
- #add_build_system(bs) ⇒ Object
- #add_environment(env) ⇒ Object
- #add_feature(feature) ⇒ Object
- #add_module(mod) ⇒ Object
- #add_repository(repo) ⇒ Object
- #add_server(server) ⇒ Object
- #add_setting(s) ⇒ Object
- #add_sshkey(key) ⇒ Object
- #build_system_adjust(name, parent = nil, *args) ⇒ Object
- #build_system_defaults(name, *args) ⇒ Object
-
#complete_buildsets(name) ⇒ Object
Complete buildsets.
- #complete_module(name, include_templates = false, all = false, resume_from = nil, resume_after = nil) ⇒ Object
- #complete_modules(name, include_templates = false, all = false, resume_from = nil, resume_after = nil) ⇒ Object
- #create_build_system(name, parent = nil, *args) ⇒ Object
- #environment(name) ⇒ Object
- #feature(name) ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #load ⇒ Object
- #log_directory ⇒ Object
- #log_directory=(path) ⇒ Object
-
#migrate ⇒ Object
Execute the necessary steps to adapt the configuration to the current state of the recipe.
- #module(name) ⇒ Object
- #repository(name) ⇒ Object
- #save ⇒ Object
- #server(name) ⇒ Object
- #sshkey(name) ⇒ Object
- #truncate ⇒ Object
- #vcs(name) ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/build-tool/configuration.rb', line 123 def initialize() @recipe = nil @server = {} @log_directory = nil @environments = {} @module = {} @modules = [] @build_system = {} @repository = {} @sshkey = {} @active_feature = nil @features = {} @settings = {} end |
Instance Attribute Details
#active_feature ⇒ Object
Returns the value of attribute active_feature.
54 55 56 |
# File 'lib/build-tool/configuration.rb', line 54 def active_feature @active_feature end |
#environments ⇒ Object (readonly)
Returns the value of attribute environments.
52 53 54 |
# File 'lib/build-tool/configuration.rb', line 52 def environments @environments end |
#features ⇒ Object (readonly)
Returns the value of attribute features.
53 54 55 |
# File 'lib/build-tool/configuration.rb', line 53 def features @features end |
#modules ⇒ Object (readonly)
Returns the value of attribute modules.
51 52 53 |
# File 'lib/build-tool/configuration.rb', line 51 def modules @modules end |
#recipe ⇒ Object
Returns the value of attribute recipe.
50 51 52 |
# File 'lib/build-tool/configuration.rb', line 50 def recipe @recipe end |
#settings ⇒ Object (readonly)
Returns the value of attribute settings.
55 56 57 |
# File 'lib/build-tool/configuration.rb', line 55 def settings @settings end |
Class Method Details
.edit(only = []) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/build-tool/configuration.rb', line 29 def self.edit( only = [] ) settings = BuildTool::Setting::export( BuildTool::Application.instance.configuration.settings, only ) editor = MJ::Tools::TmpFileEditor.new( YAML::dump( settings ) ) editor.edit() if not Pathname.new( editor.path() ).exist? info( "File deleted!" ) return 0 end values = YAML::load( File.open( editor.path(), 'r:UTF-8' ) ) BuildTool::Setting::import( BuildTool::Application.instance.configuration.settings, values ) return 0 end |
Instance Method Details
#add_build_system(bs) ⇒ Object
189 190 191 |
# File 'lib/build-tool/configuration.rb', line 189 def add_build_system( bs ) return @build_system[bs.name] = bs end |
#add_environment(env) ⇒ Object
74 75 76 |
# File 'lib/build-tool/configuration.rb', line 74 def add_environment( env) @environments[env.name] = env end |
#add_feature(feature) ⇒ Object
82 83 84 |
# File 'lib/build-tool/configuration.rb', line 82 def add_feature( feature ) @features[feature.path] = feature end |
#add_module(mod) ⇒ Object
90 91 92 93 |
# File 'lib/build-tool/configuration.rb', line 90 def add_module( mod ) @module[mod.name] = mod @modules << mod end |
#add_repository(repo) ⇒ Object
99 100 101 |
# File 'lib/build-tool/configuration.rb', line 99 def add_repository( repo ) @repository[repo.name] = repo end |
#add_server(server) ⇒ Object
107 108 109 |
# File 'lib/build-tool/configuration.rb', line 107 def add_server( server ) @server[ server.name ] = server end |
#add_setting(s) ⇒ Object
119 120 121 |
# File 'lib/build-tool/configuration.rb', line 119 def add_setting( s ) @settings[s.name] = s end |
#add_sshkey(key) ⇒ Object
115 116 117 |
# File 'lib/build-tool/configuration.rb', line 115 def add_sshkey( key ) @sshkey[key.name] = key end |
#build_system_adjust(name, parent = nil, *args) ⇒ Object
178 179 180 181 182 |
# File 'lib/build-tool/configuration.rb', line 178 def build_system_adjust( name, parent = nil, *args ) bs = create_build_system( name, parent ) bs.defaults = build_system_defaults( name ) return bs end |
#build_system_defaults(name, *args) ⇒ Object
184 185 186 187 |
# File 'lib/build-tool/configuration.rb', line 184 def build_system_defaults( name, *args ) return @build_system[name] if @build_system[name] add_build_system( create_build_system( name ) ) end |
#complete_buildsets(name) ⇒ Object
Complete buildsets
272 273 274 275 276 |
# File 'lib/build-tool/configuration.rb', line 272 def complete_buildsets( name ) if name == ':all' return complete_modules( '*' ) end end |
#complete_module(name, include_templates = false, all = false, resume_from = nil, resume_after = nil) ⇒ Object
278 279 280 281 282 283 284 285 |
# File 'lib/build-tool/configuration.rb', line 278 def complete_module( name, include_templates = false, all = false, resume_from = nil, resume_after = nil ) modules = complete_modules( name, include_templates, all, resume_from, resume_after ) case modules.size when 0 then return nil when 1 then return modules[0] else raise BuildTool::ConfigurationError, "#{name} is ambiguous. Please be more specific" end end |
#complete_modules(name, include_templates = false, all = false, resume_from = nil, resume_after = nil) ⇒ Object
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 |
# File 'lib/build-tool/configuration.rb', line 287 def complete_modules( name, include_templates = false, all = false, resume_from = nil, resume_after = nil ) if name.start_with? ':' return complete_buildsets( name ) end res = [] found = false should_be_unique = false resume = ( resume_from.nil? and resume_after.nil? ) modules.each do |mod| take_module = false next if ( !include_templates and mod.is_template? ) # We match on the following conditions: # 1. name = mod.name # 2. name/ matches beginning of mod.name # 3. name equals last part of mod.name (behind /) and is unique if name.end_with?('/') and ( mod.name.index "/#{name}" or mod.name.start_with? name ) found = true # Now check if it is active. next if !( mod.active? || all ) take_module = true elsif mod.name == name or mod.name.end_with?( "/#{name}" ) found = true should_be_unique = true take_module = true elsif name == '*' found = true # Now check if it is active. next if !( mod.active? || @all ) take_module = true end if not resume and resume_from and mod.name == resume_from.name resume = true end res << mod if resume and take_module if not resume and resume_after and mod.name == resume_after.name resume = true end end # Raise an error if the module was not found if !found raise BuildTool::ConfigurationError, "Unknown module/package #{name}" end # Raise an error if the result should be unique but is not. if should_be_unique if res.size > 1 raise BuildTool::ConfigurationError, "#{name} is ambiguous (#{res.map { |m| m.name }.join( ', ' ) })." end mod = res[0] # If the module is inactive make sure the feature is active if not ( mod.active? || mod.feature.nil? || mod.feature.active? ) raise BuildTool::ConfigurationError, "Can't select module %s from inactive feature %s" % [ mod.name, mod.feature.name ] end end # Give a warning if all modules where warn( "All modules for #{name} are inactive! Will ignore it." ) if res.empty? return res end |
#create_build_system(name, parent = nil, *args) ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/build-tool/configuration.rb', line 157 def create_build_system( name, parent = nil, *args ) return case name when "none" BuildTool::BuildSystem::None.new( parent, *args ) when "cmake" BuildTool::BuildSystem::CMake.new( parent, *args ) when "kdel10n" BuildTool::BuildSystem::KdeL10n.new( parent, *args ) when "qt" BuildTool::BuildSystem::Qt.new( parent, *args ) when "qmake" BuildTool::BuildSystem::QMake.new( parent, *args ) when "custom" BuildTool::BuildSystem::Custom.new( parent, *args ) when "autoconf" BuildTool::BuildSystem::AutoConf.new( parent, *args ) else raise StandardError, "Unknown Version Control System #{name}" end end |
#environment(name) ⇒ Object
70 71 72 |
# File 'lib/build-tool/configuration.rb', line 70 def environment( name ) @environments[name] end |
#feature(name) ⇒ Object
78 79 80 |
# File 'lib/build-tool/configuration.rb', line 78 def feature( name ) @features[name] end |
#load ⇒ Object
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/build-tool/configuration.rb', line 211 def load logger.debug "Loading features from database." BuildTool::Feature.all.each do |f| logger.debug2 " - Feature %s" % [ f.name ] add_feature( f ) end logger.debug "Loading modules from database." BuildTool::Module.all.each do |m| logger.debug2 " - Module %s" % [ m.name ] add_module( m ) end logger.debug "Loading settings from database." BuildTool::Setting.all.each do |s| logger.debug2 " - Setting %s: %s" % [ s.name, s.value ] add_setting( s ) end end |
#log_directory ⇒ Object
57 58 59 60 |
# File 'lib/build-tool/configuration.rb', line 57 def log_directory return @log_directory if @log_directory raise BuildTool::ConfigurationError, "No log directory configured" end |
#log_directory=(path) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/build-tool/configuration.rb', line 62 def log_directory=( path ) path = Pathname.new( path.sub( /\$HOME/, '~' ) ) if path.to_s[0] != '~' and path.relative? raise ConfigurationError, "Log directory '#{path}' is relative!" end @log_directory = path. end |
#migrate ⇒ Object
Execute the necessary steps to adapt the configuration to the current state of the recipe.
The recipe has to be loaded before calling this method. With the configuration given. The method removes obsolete stuff from the database.
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
# File 'lib/build-tool/configuration.rb', line 247 def migrate() logger.debug( 'Checking for obsolete modules in db.' ) for mod in @modules do if not mod.found_in_recipe logger.info 'Module %s no longer supported by recipe. Removing it from db.' % [ mod.name ] # Remove it from our bookkeeping first. @module.delete( mod.name ) @modules.delete( mod ) # Remove it from the db mod.destroy() end end logger.debug( 'Checking for obsolete settings in db.' ) settings.each do |n, s| if not s.seen and not n.start_with? 'BUILD_TOOL.' logger.info 'Setting %s no longer supported by recipe. Removing it from db.' % [ s.name ] s.destroy() end end end |
#module(name) ⇒ Object
86 87 88 |
# File 'lib/build-tool/configuration.rb', line 86 def module( name ) @module[name] end |
#repository(name) ⇒ Object
95 96 97 |
# File 'lib/build-tool/configuration.rb', line 95 def repository( name ) @repository[name] end |
#save ⇒ Object
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/build-tool/configuration.rb', line 193 def save logger.debug "Saving features to database." @features.each do |name, f| logger.debug2( " Feature %s" % [ f.name ] ) if f.changed? f.save! if f.changed? end logger.debug "Saving modules to database." @modules.each do |m| logger.debug2( " Module %s" % [ m.name ] ) if m.changed? m.save! if m.changed? end logger.debug "Saving settings to database." @settings.each do |n, s| logger.debug2( " Setting %s: %s" % [ s.name, s.value ] ) if s.changed? s.save! if s.changed? end end |
#server(name) ⇒ Object
103 104 105 |
# File 'lib/build-tool/configuration.rb', line 103 def server( name ) @server[name] end |
#sshkey(name) ⇒ Object
111 112 113 |
# File 'lib/build-tool/configuration.rb', line 111 def sshkey( name ) @sshkey[name] end |
#truncate ⇒ Object
229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/build-tool/configuration.rb', line 229 def truncate logger.debug "Deleting all features from database." BuildTool::Feature.delete_all() @features = {} logger.debug "Deleting all modules from database." BuildTool::Module.delete_all() @module = {} @modules = [] logger.debug "Deleting all settings from database." BuildTool::Setting.delete_all() @settings = {} end |
#vcs(name) ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/build-tool/configuration.rb', line 138 def vcs( name ) case name when "git-svn" return BuildTool::VCS::GitSvnConfiguration.new when "git" return BuildTool::VCS::GitConfiguration.new when "svn" return BuildTool::VCS::SvnConfiguration.new when "archive" return BuildTool::VCS::ArchiveConfiguration.new when "mercurial" return BuildTool::VCS::MercurialConfiguration.new when "bazar" return BuildTool::VCS::BazarConfiguration.new else raise StandardError, "Unknown Version Control System #{name}" end end |