]> git.e2factory.org Git - e2factory.git/commitdiff
e2lib: add isglobaltool() and isglocaltool()
authorTobias Ulmer <tu@emlix.com>
Fri, 1 Feb 2013 17:29:56 +0000 (18:29 +0100)
committerTobias Ulmer <tu@emlix.com>
Tue, 26 Feb 2013 18:07:14 +0000 (19:07 +0100)
A tool may also be neither global nor local. An example would be "e2"
itself.

Signed-off-by: Tobias Ulmer <tu@emlix.com>
generic/e2lib.lua

index e782354add655dac05c4097d6a68c1cc27fb65bd..e8df45f201811cf5289c6e618d16fcaaa676c019 100644 (file)
@@ -1226,6 +1226,43 @@ function e2lib.locate_project_root(path)
     return nil, err.new("not in a project directory")
 end
 
+--- Checks whether the tool is an existing global e2factory tool. Note that
+-- there is third class of binaries living in BINDIR, which are not considered
+-- global (in a tool sense).
+-- @param tool Tool name such as 'e2-create-project', 'e2-build' etc.
+-- @return True or false.
+-- @return Error object when false.
+-- @see islocaltool
+function e2lib.isglobaltool(tool)
+    local tool = e2lib.join(buildconfig.TOOLDIR, tool)
+    if e2lib.isfile(tool) then
+        return true
+    end
+
+    return false, err.new('global tool "%s" does not exists', tool)
+end
+
+--- Check whether tool is an existing local e2factory tool.
+-- @param tool Tool name such as 'e2-install-e2', 'e2-build' etc.
+-- @param projectdir Optional directory where the tool should be searched in. If
+-- not specified, the current working directory will be used.
+-- @return True or false
+-- @return Error object when false.
+-- @see isglobaltool
+function e2lib.islocaltool(tool, projectdir)
+    local dir, re = e2lib.locate_project_root(projectdir)
+    if not dir then
+        return false, re
+    end
+
+    local tool = e2lib.join(dir, tool)
+    if e2lib.isfile(tool) then
+        return tool
+    end
+
+    return false, err.new('local tool "%s" does not exist', tool)
+end
+
 --- Parse version files.
 function e2lib.parse_versionfile(filename)
     local f = luafile.open(filename, "r")