]> git.e2factory.org Git - e2factory.git/commitdiff
source: add iterator over registered source types and classes
authorTobias Ulmer <tu@emlix.com>
Thu, 19 Jan 2017 16:51:59 +0000 (17:51 +0100)
committerTobias Ulmer <tu@emlix.com>
Mon, 30 Jan 2017 13:33:34 +0000 (14:33 +0100)
Signed-off-by: Tobias Ulmer <tu@emlix.com>
local/source.lua

index 42bb5dfc4132dbefa063967c83cf4ee805cf378e..42d5d2096bcab2c54850511546dccfcfa9a8b133 100644 (file)
@@ -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.