]> git.e2factory.org Git - e2factory.git/commitdiff
Convert write_extension_config() to eio and move into e2-create-project
authorTobias Ulmer <tu@emlix.com>
Fri, 25 Oct 2013 10:33:28 +0000 (12:33 +0200)
committerTobias Ulmer <tu@emlix.com>
Wed, 16 Nov 2016 14:01:23 +0000 (15:01 +0100)
Signed-off-by: Tobias Ulmer <tu@emlix.com>
generic/e2lib.lua
global/e2-create-project.lua

index aecd590fd0421582def9ec3c2c76afb5263ba5e6..47b442556851daa80495524b777850b6e9af39ee 100644 (file)
@@ -930,26 +930,6 @@ function e2lib.read_global_config(e2_config_file)
     return false, err.new("no config file available")
 end
 
---- Create a extensions config.
-function e2lib.write_extension_config(extensions)
-    local e = err.new("writing extensions config: %s", e2lib.globals.extension_config)
-    local f, re = io.open(e2lib.globals.extension_config, "w")
-    if not f then
-        return false, e:cat(re)
-    end
-    f:write(string.format("extensions {\n"))
-    for _,ex in ipairs(extensions) do
-        f:write(string.format("  {\n"))
-        for k,v in pairs(ex) do
-            f:write(string.format("    %s=\"%s\",\n", k, v))
-        end
-        f:write(string.format("  },\n"))
-    end
-    f:write(string.format("}\n"))
-    f:close()
-    return true, nil
-end
-
 --- read the local extension configuration
 -- This function must run while being located in the projects root directory
 -- @return the extension configuration table
index fa26ff0f4b0358306a823f87a83887212336adde..0de0e57c040bac9b55855f224813b1fd0c362caa 100644 (file)
@@ -36,6 +36,42 @@ local err = require("err")
 local e2option = require("e2option")
 local buildconfig = require("buildconfig")
 
+--- Create a extensions config.
+-- @param extensions Table.
+-- @return True on success, false on error.
+-- @return Error object on failure.
+local function write_extension_config(extensions)
+    local e, rc, re, file, out
+
+    e = err.new("writing extensions config: %s", e2lib.globals.extension_config)
+    file, re = eio.fopen(e2lib.globals.extension_config, "w")
+    if not file then
+        return false, e:cat(re)
+    end
+
+    out = "extensions {\n"
+    for _,ex in ipairs(extensions) do
+        out = out .. "  {\n"
+        for k,v in pairs(ex) do
+            out = out .. string.format("    %s=\"%s\",\n", k, v)
+        end
+        out = out .. "  },\n"
+    end
+    out = out .. "}\n"
+
+    rc, re = eio.fwrite(file, out)
+    if not rc then
+        return false, e:cat(re)
+    end
+
+    rc, re = eio.fclose(file)
+    if not rc then
+        return false, e:cat(re)
+    end
+
+    return true
+end
+
 --- Read a template file, located relative to the current template directory.
 -- @param path Filename relative to the template directory.
 -- @return File contents as a string, or false on error.
@@ -243,7 +279,7 @@ local function e2_create_project(arg)
             return false, e:cat(re)
         end
     end
-    rc, re = e2lib.write_extension_config(config.site.default_extensions)
+    rc, re = write_extension_config(config.site.default_extensions)
     if not rc then
         return false, e:cat(re)
     end