summaryrefslogtreecommitdiff
path: root/xnt
diff options
context:
space:
mode:
Diffstat (limited to 'xnt')
-rw-r--r--xnt/__init__.py14
-rw-r--r--xnt/build/make.py8
-rw-r--r--xnt/build/tex.py11
-rw-r--r--xnt/tasks.py22
-rw-r--r--xnt/tests/compilercollectiontests.py27
-rw-r--r--xnt/tests/taskmisctests.py18
-rw-r--r--xnt/version.py2
-rw-r--r--xnt/xenant.py5
8 files changed, 74 insertions, 33 deletions
diff --git a/xnt/__init__.py b/xnt/__init__.py
index 71c7358..61de895 100644
--- a/xnt/__init__.py
+++ b/xnt/__init__.py
@@ -41,7 +41,19 @@ __license__ = """
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
-from xnt.tasks import cp, mv, mkdir, rm, create_zip, log, xntcall, call, setup
+VERBOSE = False
+
+from xnt.tasks import cp
+from xnt.tasks import mv
+from xnt.tasks import mkdir
+from xnt.tasks import rm
+from xnt.tasks import create_zip
+from xnt.tasks import log
+from xnt.tasks import xntcall
+from xnt.tasks import call
+from xnt.tasks import setup
+from xnt.tasks import which
+from xnt.tasks import in_path
def target(target_fn):
"""Decorator function for marking a method in
diff --git a/xnt/build/make.py b/xnt/build/make.py
index 30d96f1..74dcf49 100644
--- a/xnt/build/make.py
+++ b/xnt/build/make.py
@@ -20,7 +20,7 @@
import os
import subprocess
-def ant(path="", target="", flags=None, pkeys=None, pvalues=None):
+def ant(target, path="", flags=None, pkeys=None, pvalues=None):
"""Wrapper around Apache Ant"""
cmd = __add_params(["ant"],
__build_param_list(pkeys, pvalues),
@@ -29,14 +29,14 @@ def ant(path="", target="", flags=None, pkeys=None, pvalues=None):
cmd.append(target)
return __run_in(path, lambda: subprocess.call(cmd))
-def make(path="", target="", flags=None, pkeys=None, pvalues=None):
+def make(target, path="", flags=None, pkeys=None, pvalues=None):
"""Wrapper around GNU Make"""
cmd = __add_params(["make"], __build_param_list(pkeys, pvalues))
cmd = __add_flags(cmd, flags)
cmd.append(target)
return __run_in(path, lambda: subprocess.call(cmd))
-def nant(path="", target="", flags=None, pkeys=None, pvalues=None):
+def nant(target, path="", flags=None, pkeys=None, pvalues=None):
"""Wrapper around .NET Ant"""
cmd = __add_params(["nant"],
__build_param_list(pkeys, pvalues),
@@ -47,6 +47,8 @@ def nant(path="", target="", flags=None, pkeys=None, pvalues=None):
def __add_flags(cmd, flags):
"""Add flags to command and return new list"""
+ if not flags:
+ return cmd
command = list(cmd)
for flag in flags:
command.append(flag)
diff --git a/xnt/build/tex.py b/xnt/build/tex.py
index 91a5edd..15bb6fb 100644
--- a/xnt/build/tex.py
+++ b/xnt/build/tex.py
@@ -20,6 +20,7 @@
import os
import logging
import xnt.tasks
+from xnt import VERBOSE
LOGGER = logging.getLogger(__name__)
@@ -28,6 +29,7 @@ def pdflatex(document,
bibtex=False,
makeglossary=False):
"""Generate PDF LaTeX Document"""
+ devnull = None if VERBOSE else open(os.devnull, 'w')
documentbase = os.path.splitext(document)[0]
cwd = os.getcwd()
os.chdir(path)
@@ -36,15 +38,16 @@ def pdflatex(document,
cmd = ["pdflatex", document, "-halt-on-error",]
if draftmode:
cmd.append('-draftmode')
- return xnt.tasks.call(cmd)
+ return xnt.tasks.call(cmd, stdout=devnull)
def run_bibtex():
"""Generate BibTex References"""
- return xnt.tasks.call(["bibtex", documentbase + ".aux"])
+ return xnt.tasks.call(["bibtex", documentbase + ".aux"],
+ stdout=devnull)
def makeglossaries():
"""Generate Glossary"""
- return xnt.tasks.call(["makeglossaries", documentbase])
+ return xnt.tasks.call(["makeglossaries", documentbase], stdout=devnull)
error_codes = []
error_codes.append(pdf(draftmode=True))
@@ -55,6 +58,8 @@ def pdflatex(document,
error_codes.append(pdf(draftmode=True))
error_codes.append(pdf(draftmode=False))
os.chdir(cwd)
+ if devnull:
+ devnull.close()
return sum(error_codes)
def clean(path="./", remove_pdf=False):
diff --git a/xnt/tasks.py b/xnt/tasks.py
index ab93f97..c11a13b 100644
--- a/xnt/tasks.py
+++ b/xnt/tasks.py
@@ -162,3 +162,25 @@ def setup(commands, directory=""):
error_code = call(cmd)
os.chdir(cwd)
return error_code
+
+def which(program):
+ """Similar to Linux/Unix `which`: return (first) path of executable"""
+ def is_exe(fpath):
+ """Determine if argument exists and is executable"""
+ return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
+
+ fpath = os.path.split(program)
+ if fpath[0]:
+ if is_exe(program):
+ return program
+ else:
+ for path in os.environ["PATH"].split(os.pathsep):
+ path = path.strip('"')
+ exe_file = os.path.join(path, program)
+ if is_exe(exe_file):
+ return exe_file
+ return None
+
+def in_path(program):
+ """Return boolean result if program is in PATH environment variable"""
+ return which(program)
diff --git a/xnt/tests/compilercollectiontests.py b/xnt/tests/compilercollectiontests.py
index 76891a9..be72c81 100644
--- a/xnt/tests/compilercollectiontests.py
+++ b/xnt/tests/compilercollectiontests.py
@@ -19,31 +19,12 @@
import os
import shutil
+import xnt
import xnt.build.cc as cc
import unittest
-#http://stackoverflow.com/questions/377017/test-if-executable-exists-in-python
-def which(program):
- """Similar to Linux/Unix `which`: return path of executable"""
- def is_exe(fpath):
- """Determine if arguement exists and is executable"""
- return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
-
- fpath = os.path.split(program)
- if fpath[0]:
- if is_exe(program):
- return program
- else:
- for path in os.environ["PATH"].split(os.pathsep):
- path = path.strip('"')
- exe_file = os.path.join(path, program)
- if is_exe(exe_file):
- return exe_file
-
- return None
-
#pylint: disable-msg=C0103
-@unittest.skipUnless(which("gcc"), "gcc is not in your path")
+@unittest.skipUnless(xnt.in_path("gcc"), "gcc is not in your path")
class GccTests(unittest.TestCase):
"""Test GCC"""
def setUp(self):
@@ -75,7 +56,7 @@ class GccTests(unittest.TestCase):
cc.gcc_o("temp/hello.c", "temp/hello")
self.assertTrue(os.path.isfile("temp/hello"))
-@unittest.skipUnless(which("g++"), "g++ is not in your path")
+@unittest.skipUnless(xnt.in_path("g++"), "g++ is not in your path")
class GppTests(unittest.TestCase):
"""Test G++ (C++ GCC)"""
def setUp(self):
@@ -107,7 +88,7 @@ class GppTests(unittest.TestCase):
cc.gpp_o("temp/hello.cpp", "temp/hello")
self.assertTrue(os.path.isfile("temp/hello"))
-@unittest.skipUnless(which("javac"), "javac is not in your path")
+@unittest.skipUnless(xnt.in_path("javac"), "javac is not in your path")
class JavacTests(unittest.TestCase):
"""Test Javac"""
def setUp(self):
diff --git a/xnt/tests/taskmisctests.py b/xnt/tests/taskmisctests.py
index f9d9adf..bcabf3d 100644
--- a/xnt/tests/taskmisctests.py
+++ b/xnt/tests/taskmisctests.py
@@ -58,5 +58,23 @@ class TaskMiscTests(unittest.TestCase):
with open("temp/testerr", "r") as std_err:
self.assertEqual("hello", std_err.read())
+ def test_which_finds_python(self):
+ """Test which can find python"""
+ path = xnt.tasks.which("python")
+ self.assertIsNotNone(path)
+
+ def test_which_dne(self):
+ """Test which cannot find not existent program"""
+ path = xnt.tasks.which("arst")
+ self.assertIsNone(path)
+
+ def test_python_in_path(self):
+ """Test in_path task"""
+ self.assertTrue(xnt.tasks.in_path("python"))
+
+ def test_arst_not_in_path(self):
+ """Test not in_path"""
+ self.assertFalse(xnt.tasks.in_path("arst"))
+
if __name__ == "__main__":
unittest.main()
diff --git a/xnt/version.py b/xnt/version.py
index 4d717f7..e0c5eca 100644
--- a/xnt/version.py
+++ b/xnt/version.py
@@ -17,5 +17,5 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-__version_info__ = (0, 6, 1, "dev")
+__version_info__ = (0, 6, 2, 'dev')
__version__ = '.'.join(list(str(i) for i in __version_info__ if True))
diff --git a/xnt/xenant.py b/xnt/xenant.py
index f084e83..3dc4a70 100644
--- a/xnt/xenant.py
+++ b/xnt/xenant.py
@@ -22,7 +22,7 @@ import sys
import time
import logging
import argparse
-from xnt import __version__
+import xnt
from xnt.status_codes import SUCCESS, ERROR, UNKNOWN_ERROR
logging.basicConfig(format="%(message)s")
@@ -36,6 +36,7 @@ def main():
args = parse_args(sys.argv[1:])
build_file = "./build.py"
if args["verbose"]:
+ xnt.VERBOSE = True
LOGGER.setLevel(logging.INFO)
logging.getLogger("xnt.tasks").setLevel(logging.INFO)
if args["build-file"]:
@@ -155,7 +156,7 @@ def parse_args(args_in):
parser.add_argument(
"--version",
action="version",
- version=__version__,
+ version=xnt.__version__,
help="print the version information and quit")
parser.add_argument(
"-b", "--build-file",