summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkennyballou <kballou@onyx.boisestate.edu>2013-02-01 18:52:53 -0700
committerkennyballou <kballou@onyx.boisestate.edu>2013-02-01 19:10:33 -0700
commit7ab6083f53f180ff49b2739a2fb1d3b6269a4a56 (patch)
treefb67934dab91c5643d7d07686e9b7998f2771d58
parentd4117776b4eaaa1b0e1d0cae20b1def8625e37b0 (diff)
downloadxnt-7ab6083f53f180ff49b2739a2fb1d3b6269a4a56.tar.gz
xnt-7ab6083f53f180ff49b2739a2fb1d3b6269a4a56.tar.xz
Refactor, Fix, and Further hack Xenant's rewrite
My first hack toward this (major) refactor had a number of mistakes that were (hopefully) corrected. I intend to now write tests for these (may require a bit more refactoring...). But there is also probably a lot more that needs to be done for this.
-rw-r--r--setup.py6
-rw-r--r--xnt/__init__.py2
-rw-r--r--xnt/cmdoptions.py26
-rw-r--r--xnt/commands/__init__.py6
-rw-r--r--xnt/commands/help.py3
-rw-r--r--xnt/commands/listtargets.py12
-rw-r--r--xnt/commands/target.py9
-rw-r--r--xnt/commands/version.py3
-rw-r--r--xnt/runner.py26
-rw-r--r--xnt/status_codes.py21
-rw-r--r--xnt/xenant.py1
11 files changed, 90 insertions, 25 deletions
diff --git a/setup.py b/setup.py
index c81da5c..c283570 100644
--- a/setup.py
+++ b/setup.py
@@ -25,21 +25,21 @@ def read(fname):
setup(
name="Xnt",
- version="0.4.1",
+ version="0.5.0dev1",
author="Kenny Ballou",
author_email="kennethmgballou@gmail.com",
url="https://bitbucket.org/devnulltao/xnt",
description=("High-Level build script for doing more complex build tasks"),
packages=find_packages(),
test_suite="xnt.tests",
- scripts=["xnt/xenant.py",],
+ scripts=["xnt/runner.py",],
package_data={
},
long_description=read("README"),
platforms=["Linux", "Windows",],
entry_points={
'console_scripts': [
- 'xnt = xnt.xenant:main',
+ 'xnt = xnt.runner:main',
],
},
install_requires=['distribute',],
diff --git a/xnt/__init__.py b/xnt/__init__.py
index 810a83c..9d9f2a3 100644
--- a/xnt/__init__.py
+++ b/xnt/__init__.py
@@ -16,7 +16,7 @@
# 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__ = "Xnt 0.4.1"
+__version__ = "Xnt 0.5.0dev1"
__license__ = """
Xnt -- A Wrapper Build Tool
Copyright (C) 2012 Kenny Ballou
diff --git a/xnt/cmdoptions.py b/xnt/cmdoptions.py
new file mode 100644
index 0000000..9f3c944
--- /dev/null
+++ b/xnt/cmdoptions.py
@@ -0,0 +1,26 @@
+#!/usr/bin/env python
+
+# Xnt -- A Wrapper Build Tool
+# Copyright (C) 2012 Kenny Ballou
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+import logging
+
+def flipVerboseFlag():
+ logging.getLogger("xnt").setLevel(logging.INFO)
+
+options = {
+ "-v": flipVerboseFlag,
+}
diff --git a/xnt/commands/__init__.py b/xnt/commands/__init__.py
index 473d61a..d50ab3a 100644
--- a/xnt/commands/__init__.py
+++ b/xnt/commands/__init__.py
@@ -19,19 +19,13 @@
from xnt.commands.help import HelpCommand
from xnt.commands.listtargets import ListTargetsCommand
from xnt.commands.version import VersionCommand
-from xnt.commands.target import TargetCommand
commands = {
HelpCommand.name: HelpCommand,
ListTargetsCommand.name: ListTargetsCommand,
VersionCommand.name: VersionCommand,
- TargetCommand.name: TargetCommand,
}
-SUCCESS = 0
-ERROR = 1
-UNKNOWN_ERROR = 2
-
def get_summaries(ignore_hidden=True):
items = []
diff --git a/xnt/commands/help.py b/xnt/commands/help.py
index ea84551..88fd01a 100644
--- a/xnt/commands/help.py
+++ b/xnt/commands/help.py
@@ -16,7 +16,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-from xnt.basecommands import Command, SUCCESS
+from xnt.basecommand import Command
+from xnt.status_codes import SUCCESS
class HelpCommand(Command):
name = 'help'
diff --git a/xnt/commands/listtargets.py b/xnt/commands/listtargets.py
index f5d48c3..5dddb92 100644
--- a/xnt/commands/listtargets.py
+++ b/xnt/commands/listtargets.py
@@ -16,11 +16,12 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-from xnt.basecommand import Command, SUCCESS, ERROR
+from xnt.basecommand import Command
+from xnt.status_codes import SUCCESS, ERROR
from xnt.xenant import loadBuild
import logging
-logger = logging.getLogger("xnt")
+logger = logging.getLogger(__name__)
class ListTargetsCommand(Command):
name = 'list-targets'
@@ -28,9 +29,11 @@ class ListTargetsCommand(Command):
summary = "Prints targets in build file"
def run(self, arguments=[]):
- build = loadBuild
+ build = loadBuild()
+ logger.debug("build is null? %s", build == None)
try:
for f in dir(build):
+ logger.debug("Attribute %s:", f)
try:
fa = getattr(build, f)
if fa.decorator == "target":
@@ -44,6 +47,3 @@ class ListTargetsCommand(Command):
logger.error(ex)
return ERROR
return SUCCESS
- except Exception as ex:
- logger.error(ex)
- return ERROR
diff --git a/xnt/commands/target.py b/xnt/commands/target.py
index e06b58a..b1f3d2b 100644
--- a/xnt/commands/target.py
+++ b/xnt/commands/target.py
@@ -16,7 +16,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-from xnt.basecommand import Command, SUCCESS, ERROR, UNKNOWN_ERROR
+from xnt.basecommand import Command
+from xnt.status_codes import SUCCESS, ERROR, UNKNOWN_ERROR
from xnt.xenant import loadBuild
import logging
@@ -55,9 +56,9 @@ class TargetCommand(Command):
setattr(build,
"properties",
processParams(props, __getProperties()))
- target = getattr(build, targetName)
- ec = target()
- return ec if ec else 0
+ target = getattr(build, targetName)
+ ec = target()
+ return ec if ec else 0
except AttributeError:
logger.warning("There was no target: %s", targetName)
return ERROR
diff --git a/xnt/commands/version.py b/xnt/commands/version.py
index 09bd239..34853c4 100644
--- a/xnt/commands/version.py
+++ b/xnt/commands/version.py
@@ -16,7 +16,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-from xnt.basecommands import Command, SUCCESS
+from xnt.basecommand import Command
+from xnt.status_codes import SUCCESS
class VersionCommand(Command):
name = 'version'
diff --git a/xnt/runner.py b/xnt/runner.py
index 6960356..55f7ea3 100644
--- a/xnt/runner.py
+++ b/xnt/runner.py
@@ -18,7 +18,11 @@
import os
import sys
-import logger
+import time
+import logging
+from xnt.cmdoptions import options
+from xnt.commands import commands
+from xnt.commands.target import TargetCommand
logging.basicConfig(format="%(asctime)s:%(levelname)s:%(message)s")
logger = logging.Logger(name=__name__)
@@ -29,9 +33,25 @@ def main():
params = list(p for p in sys.argv[1:] if p.startswith('-D'))
flags = list(o for o in sys.argv[1:]
if o.startswith('-') and o not in params)
- commands = list(c for c in sys.argv[1:]
- if c not in opts and c not in params)
+ cmds = list(c for c in sys.argv[1:]
+ if c not in flags and c not in params)
+ #Loop flags and apply them
+ for flag in flags:
+ if flag in options:
+ options[flag]()
+ else:
+ logger.debug("%s is not a vaild option", flag)
#run things
+ cmd_found = False
+ for cmd in cmds:
+ if cmd in commands:
+ cmd_found = True
+ command = commands[cmd]()
+ ec = command.run()
+ logger.debug("cmd_found = %s", cmd_found)
+ if cmd_found == False:
+ command = TargetCommand()
+ ec = command.run(targets=cmds, props=params)
elapsed_time = time.time() - start_time
logger.info("Execution time: %.3f", elapsed_time)
logger.info("Success" if ec == 0 else "Failure")
diff --git a/xnt/status_codes.py b/xnt/status_codes.py
new file mode 100644
index 0000000..3549a14
--- /dev/null
+++ b/xnt/status_codes.py
@@ -0,0 +1,21 @@
+#!/usr/bin/env python
+
+# Xnt -- A Wrapper Build Tool
+# Copyright (C) 2012 Kenny Ballou
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+SUCCESS = 0
+ERROR = 1
+UNKNOWN_ERROR = 2
diff --git a/xnt/xenant.py b/xnt/xenant.py
index 453c4a2..783f99f 100644
--- a/xnt/xenant.py
+++ b/xnt/xenant.py
@@ -21,6 +21,7 @@ import sys
import time
import logging
+logger = logging.getLogger(__name__)
def verboseAction():
logging.getLogger("xnt").setLevel(logging.INFO)