2015-09-03 18:36:46 +00:00
|
|
|
# encoding: utf-8
|
2015-06-07 19:41:54 +00:00
|
|
|
# Copyright 2015 Dominik Richter. All rights reserved.
|
2015-10-06 16:55:44 +00:00
|
|
|
# author: Dominik Richter
|
|
|
|
# author: Christoph Hartmann
|
|
|
|
|
2015-06-07 19:41:54 +00:00
|
|
|
require 'vulcano/log'
|
|
|
|
|
|
|
|
module Vulcano
|
|
|
|
# Extract vmetadata.rb information
|
|
|
|
class Metadata
|
|
|
|
attr_reader :dict
|
2015-09-05 14:07:54 +00:00
|
|
|
def initialize(log = nil)
|
2015-06-07 19:41:54 +00:00
|
|
|
@log = log || Log.new
|
|
|
|
@dict = {}
|
|
|
|
end
|
|
|
|
|
|
|
|
%w{
|
|
|
|
name
|
2015-06-19 23:04:05 +00:00
|
|
|
title
|
2015-06-07 19:41:54 +00:00
|
|
|
maintainer
|
|
|
|
maintainer_email
|
|
|
|
copyright
|
|
|
|
copyright_email
|
|
|
|
license
|
|
|
|
summary
|
|
|
|
description
|
|
|
|
version
|
|
|
|
}.each do |name|
|
|
|
|
define_method name do |arg|
|
|
|
|
@dict[name] = arg
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-09-05 14:07:54 +00:00
|
|
|
def supports(sth, version = nil)
|
2015-06-07 19:41:54 +00:00
|
|
|
@dict['supports'] ||= []
|
2015-09-25 17:46:46 +00:00
|
|
|
@dict['supports'].push(
|
|
|
|
{
|
|
|
|
'os' => sth,
|
|
|
|
'version' => version,
|
|
|
|
},
|
|
|
|
)
|
2015-06-07 19:41:54 +00:00
|
|
|
end
|
|
|
|
|
2015-06-10 15:53:25 +00:00
|
|
|
def valid?
|
|
|
|
is_valid = true
|
2015-09-25 17:46:46 +00:00
|
|
|
err = lambda do |msg|
|
|
|
|
@log.error msg
|
|
|
|
is_valid = false
|
|
|
|
end
|
|
|
|
warn = lambda do |msg|
|
|
|
|
@log.warn msg
|
|
|
|
is_valid = false
|
|
|
|
end
|
|
|
|
err.call('Missing profile name in vmetadata.rb') if @dict['name'].nil?
|
|
|
|
err.call('Missing profile title in vmetadata.rb') if @dict['title'].nil?
|
|
|
|
err.call('Missing profile version in vmetadata.rb') if @dict['version'].nil?
|
|
|
|
err.call('Missing summary in vmetadata.rb') if @dict['summary'].nil?
|
|
|
|
warn.call('Missing maintainer in vmetadata.rb') if @dict['maintainer'].nil?
|
|
|
|
warn.call('Missing copyright in vmetadata.rb') if @dict['copyright'].nil?
|
2015-06-10 15:53:25 +00:00
|
|
|
is_valid
|
2015-06-07 19:41:54 +00:00
|
|
|
end
|
|
|
|
|
2015-09-03 18:43:58 +00:00
|
|
|
def method_missing(sth, *args)
|
2015-06-07 19:41:54 +00:00
|
|
|
@log.warn "vmetadata.rb doesn't support: #{sth} #{args}"
|
|
|
|
end
|
|
|
|
|
2015-09-03 18:43:58 +00:00
|
|
|
def self.for_path(path, profile_id, log = nil)
|
2015-06-07 19:41:54 +00:00
|
|
|
log ||= Log.new
|
2015-09-05 14:07:54 +00:00
|
|
|
dpath = File.join(path, 'vmetadata.rb')
|
|
|
|
if !File.file?(dpath)
|
2015-06-07 19:41:54 +00:00
|
|
|
log.error "Missing vmetadata.rb in #{path}"
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
res = Metadata.new(log)
|
2015-09-25 17:46:46 +00:00
|
|
|
res.instance_eval(File.read(dpath), dpath, 1)
|
2015-06-25 15:45:46 +00:00
|
|
|
res.dict['name'] = profile_id unless profile_id.nil? or profile_id.empty?
|
2015-09-04 07:59:30 +00:00
|
|
|
res
|
2015-06-07 19:41:54 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|