From: Tobias Ulmer Date: Thu, 19 Jan 2017 16:51:59 +0000 (+0100) Subject: source: add iterator over registered source types and classes X-Git-Tag: e2factory-2.3.17~70 X-Git-Url: https://git.e2factory.org/?a=commitdiff_plain;h=d6383261c98c07c16e7c237179f8a73aa26e38fc;p=e2factory.git source: add iterator over registered source types and classes Signed-off-by: Tobias Ulmer --- diff --git a/local/source.lua b/local/source.lua index 42bb5df..42d5d20 100644 --- a/local/source.lua +++ b/local/source.lua @@ -1,7 +1,7 @@ --- Source base class. Implements the base source class and config loader. -- @module local.source --- Copyright (C) 2007-2016 emlix GmbH, see file AUTHORS +-- Copyright (C) 2007-2017 emlix GmbH, see file AUTHORS -- -- This file is part of e2factory, the emlix embedded build system. -- For more information see http://www.e2factory.org @@ -279,6 +279,30 @@ function source.register_source_class(typ, source_class) return true end +--- Iterate over registered source classes. +-- @return Iterator function that returns a sorted typ, source class pair. +function source.iterate_source_classes() + local i, t + + t = {} + for typ,_ in pairs(source_types) do + table.insert(t, typ) + end + table.sort(t) + + i = 0 + + return function () + i = i + 1 + + if t[i] then + return t[i], source_types[t[i]] + end + + return nil + end +end + --- Validate licences attribute in rawsrc and set licences in src if successful. -- @param rawsrc e2source config table -- @param src Object of class basic_source.