diff options
author | kennyballou <kballou@onyx.boisestate.edu> | 2013-03-09 20:22:42 -0700 |
---|---|---|
committer | kennyballou <kballou@onyx.boisestate.edu> | 2013-03-09 20:22:42 -0700 |
commit | 793bdd9d0fd2403e665ea2e117fb72096cec091b (patch) | |
tree | f608895ddf02d9bd3092d10c0ba0aedd65d0b2aa /xnt | |
parent | 2467c3a3bdefd1d06f02afc1a6b9ac5bf272ca0e (diff) | |
download | xnt-793bdd9d0fd2403e665ea2e117fb72096cec091b.tar.gz xnt-793bdd9d0fd2403e665ea2e117fb72096cec091b.tar.xz |
Add build-file specification option
Diffstat (limited to 'xnt')
-rw-r--r-- | xnt/tasks.py | 6 | ||||
-rw-r--r-- | xnt/tests/xenantargparsertests.py | 26 | ||||
-rw-r--r-- | xnt/xenant.py | 27 |
3 files changed, 50 insertions, 9 deletions
diff --git a/xnt/tasks.py b/xnt/tasks.py index 679701c..02cde24 100644 --- a/xnt/tasks.py +++ b/xnt/tasks.py @@ -120,7 +120,7 @@ def log(msg="", lvl=logging.INFO): """Log message using tasks global logger""" LOGGER.log(lvl, msg) -def xntcall(path, targets=None, props=None): +def xntcall(buildfile, targets=None, props=None): """Invoke xnt on another build file in a different directory param: path - to the build file (including build file) @@ -128,9 +128,11 @@ def xntcall(path, targets=None, props=None): param: props - dictionary of properties to pass to the build module """ from xnt.xenant import invoke_build, load_build + build = load_build(buildfile) + path = os.path.dirname(buildfile) cwd = os.getcwd() os.chdir(path) - error_code = invoke_build(load_build(path), targets=targets, props=props) + error_code = invoke_build(build, targets=targets, props=props) os.chdir(cwd) return error_code diff --git a/xnt/tests/xenantargparsertests.py b/xnt/tests/xenantargparsertests.py index 3a22b33..04c8d1c 100644 --- a/xnt/tests/xenantargparsertests.py +++ b/xnt/tests/xenantargparsertests.py @@ -128,5 +128,31 @@ class XenantArgParserTests(unittest.TestCase): self.assertIsNotNone(args["targets"]) self.assertEqual(len(args["targets"]), 0) + def test_build_file_spec_short(self): + """Test build file option""" + args_in = ["-b", "mybuildfile.py"] + args = xnt.xenant.parse_args(args_in) + self.assertIsNotNone(args) + self.assertFalse(args["verbose"]) + self.assertFalse(args["list-targets"]) + self.assertIsNotNone(args["build-file"]) + self.assertEqual(args["build-file"], "mybuildfile.py") + self.assertIsNone(args["properties"]) + self.assertIsNotNone(args["targets"]) + self.assertEqual(len(args["targets"]), 0) + + def test_build_file_spec_long(self): + """Test build file option""" + args_in = ["--build-file", "mybuildfile.py"] + args = xnt.xenant.parse_args(args_in) + self.assertIsNotNone(args) + self.assertFalse(args["verbose"]) + self.assertFalse(args["list-targets"]) + self.assertIsNotNone(args["build-file"]) + self.assertEqual(args["build-file"], "mybuildfile.py") + self.assertIsNone(args["properties"]) + self.assertIsNotNone(args["targets"]) + self.assertEqual(len(args["targets"]), 0) + if __name__ == "__main__": unittest.main() diff --git a/xnt/xenant.py b/xnt/xenant.py index 9e5a3df..5e8dc66 100644 --- a/xnt/xenant.py +++ b/xnt/xenant.py @@ -33,12 +33,15 @@ def main(): """Xnt Entry Point""" start_time = time.time() args = parse_args(sys.argv[1:]) + build_file = "./build.py" if args["verbose"]: LOGGER.setLevel(logging.DEBUG) + if args["build-file"]: + build_file = args["build-file"] if args["list-targets"]: - error_code = list_targets(load_build()) + error_code = list_targets(load_build(build_file)) else: - error_code = invoke_build(load_build(), + error_code = invoke_build(load_build(build_file), args["targets"], args["properties"]) elapsed_time = time.time() - start_time @@ -47,15 +50,20 @@ def main(): LOGGER.info("Failure") from xnt.tasks import rm rm("build.pyc", - "__pycache__") + "__pycache__", + build_file + "c", + os.path.join(os.path.dirname(build_file), "__pycache__")) if error_code != 0: sys.exit(error_code) -def load_build(path=""): +def load_build(buildfile="./build.py"): """Load build file Load the build.py and return the resulting import """ + path = os.path.dirname(buildfile) + build = os.path.basename(buildfile) + buildmodule = os.path.splitext(build)[0] if not path: path = os.getcwd() else: @@ -63,17 +71,17 @@ def load_build(path=""): sys.path.append(path) cwd = os.getcwd() os.chdir(path) - if not os.path.exists("build.py"): + if not os.path.exists(build): LOGGER.error("There was no build file") sys.exit(1) try: - return __import__("build", fromlist=[]) + return __import__(buildmodule, fromlist=[]) except ImportError: LOGGER.error("HOW?!") return None finally: sys.path.remove(path) - del sys.modules["build"] + del sys.modules[buildmodule] os.chdir(cwd) def invoke_build(build, targets=None, props=None): @@ -147,6 +155,11 @@ def parse_args(args_in): action="version", version=__version__, help="Print Xnt Version and quit") + parser.add_argument( + "-b", "--build-file", + dest="build-file", + help="""Specify a build file if different than defaut or in different + path""") parser.add_argument("-l", "--list-targets", action="store_true", dest="list-targets", |