class ManifestHandler

Copyright (C) 2011-2013 Cornelius Schumacher <schumacher@kde.org>

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

Attributes

manifests[R]
settings[R]

Public Class Methods

new(settings) click to toggle source
# File lib/manifest_handler.rb, line 21
def initialize settings
  @settings = settings

  @libraries = Array.new
  @manifests = Array.new

  @topics_cache = Hash.new
  @no_of_libraries_cache = Hash.new
end

Public Instance Methods

commercial_libraries() click to toggle source
# File lib/manifest_handler.rb, line 53
def commercial_libraries
  return @libraries.select do |l|
    manifest = l.latest_manifest
    manifest.licenses.include? "Commercial"
  end
end
fetch_remote() click to toggle source
# File lib/manifest_handler.rb, line 160
def fetch_remote
  if File.exists? @settings.manifest_path
    if !File.exists? @settings.manifest_path + "/.git"
      raise "Can't fetch data into '#{@settings.manifest_path}' because it's not a git repository."
    else
      system "cd #{@settings.manifest_path}; git pull >/dev/null"
    end
  else
    system "git clone git://anongit.kde.org/websites/inqlude-data " +
      "#{@settings.manifest_path}"
  end
end
generate_inqlude_all() click to toggle source
# File lib/manifest_handler.rb, line 173
def generate_inqlude_all
  all = []
  libraries.each do |l|
    all.push(l.latest_manifest.to_hash)
  end
  JSON.pretty_generate(all)
end
group(name) click to toggle source
# File lib/manifest_handler.rb, line 81
def group name
  return @libraries.select do |l|
    manifest = l.latest_manifest
    manifest.group == name
  end
end
latest_libraries() click to toggle source
# File lib/manifest_handler.rb, line 60
def latest_libraries
  releases = Array.new
  is_kde_added = false

  libraries.select do |library|
    if library.latest_manifest.has_version? && library.latest_manifest.group != "kde-frameworks"
      releases.push library
    elsif library.latest_manifest.has_version? && library.latest_manifest.group == "kde-frameworks"
      if !is_kde_added
        is_kde_added = true
        releases.push library
      end
    end
  end

  releases.sort! {|a,b| a.latest_manifest.release_date <=> b.latest_manifest.release_date}
  releases.reverse!

  return releases[0 .. 4]
end
libraries(maturity = nil) click to toggle source
# File lib/manifest_handler.rb, line 35
def libraries maturity = nil
  if !maturity
    return @libraries
  else
    return @libraries.select do |l|
      manifest = l.latest_manifest
      manifest.maturity == maturity.to_s &&
        manifest.licenses != [ "Commercial" ]
    end
  end
end
library(name) click to toggle source
# File lib/manifest_handler.rb, line 88
def library name
  @libraries.each do |library|
    if library.name == name
      return library
    end
  end
  nil
end
manifest(name) click to toggle source
# File lib/manifest_handler.rb, line 97
def manifest name
  @libraries.each do |library|
    if library.name == name
      return library.latest_manifest
    end
  end
  raise InqludeError.new("Unable to find manifest '#{name}'")
end
manifest_path(manifest) click to toggle source
# File lib/manifest_handler.rb, line 31
def manifest_path manifest
  File.join(@settings.manifest_path, manifest.path)
end
no_of_libraries(topic) click to toggle source
# File lib/manifest_handler.rb, line 118
def no_of_libraries topic
  if !@no_of_libraries_cache.has_key?(topic)
    count = 0
    @libraries.each do |l|
      topics = l.latest_manifest.topics
      if topics
        if l.latest_manifest.topics.include? topic
          count += 1
        end
      end
    end
    @no_of_libraries_cache[topic] = count
  end
  @no_of_libraries_cache[topic]
end
read_remote() click to toggle source
# File lib/manifest_handler.rb, line 134
def read_remote
  @libraries.clear
  @manifests.clear
  @topics_cache.clear
  @no_of_libraries_cache.clear

  if !@settings.offline
    fetch_remote
  end

  Dir.glob( "#{@settings.manifest_path}/*" ).sort.each do |dirname|
    next if !File.directory?( dirname )

    library = Library.new
    library.name = File.basename dirname
    local_manifests = Array.new
    Dir.glob( "#{dirname}/*.manifest" ).sort.each do |filename|
      manifest = Manifest.parse_file filename
      local_manifests.push manifest
      manifests.push manifest
    end
    library.manifests = local_manifests
    libraries.push library
  end
end
topic(name) click to toggle source
# File lib/manifest_handler.rb, line 106
def topic name
  if !@topics_cache.has_key?(name)
    @topics_cache[name] = @libraries.select do |l|
      manifest = l.latest_manifest
      if manifest.topics
        manifest.topics.include? name
      end
    end
  end
  @topics_cache[name]
end
unreleased_libraries() click to toggle source
# File lib/manifest_handler.rb, line 47
def unreleased_libraries
  return @libraries.select do |l|
    !l.latest_manifest.is_released?
  end
end