[mousetrap/gnome3-wip: 30/240] Rework command-line interface and reorganized.



commit c3c3c7aa7fb332756434ab8762d2e77790abe1cc
Author: Stoney Jackson <dr stoney gmail com>
Date:   Thu May 8 14:49:53 2014 -0400

    Rework command-line interface and reorganized.
    
    Renamed some commands to make them more consistent and descriptive.
    Moved all commands to bin/.  README gives a quick overview of new and
    renamed commands. So if you can't find what you are looking for, try the
    README and/or bin/.
    
    Simplified build-install-run cycle. Now bin/install.sh will build (if
    any changes were made since the last build) and install mousetrap.  You
    may manually build using bin/build.sh. Key bash scripts that implement
    this new interface have unit tests via the shunit2 framework.  You'll
    need this installed to run these tests. (I still need to test the top
    level scripts; I won't push until I'm in a place to finish debugging
    these.)
    
    Integrated devel/ back into the normal heirarchy. I know I can't make up
    my mind. But I think this is better. devel/ is gone.

 .gitignore                                         |    1 +
 README                                             |   19 ++++++----
 autogen.sh => bin/autogen.sh                       |    4 +-
 bin/build.sh                                       |    5 +++
 bin/install.sh                                     |   15 ++++++++
 bin/lib/environment_up.sh                          |   17 +++++++++
 bin/lib/test_environment_up.sh                     |   37 ++++++++++++++++++++
 devel/bin/test.py => bin/mousetrap.py              |    8 +++--
 run_pylint.sh.in => bin/pylint.sh.in               |    0
 bin/test.py                                        |   29 +++++++++++++++
 bin/test_pylint.sh                                 |   21 +++++++++++
 {devel/docs => docs/developer}/MouseTrap.dia       |  Bin 4234 -> 4234 bytes
 {devel/docs => docs/developer}/MouseTrap.jpeg      |  Bin 69046 -> 69046 bytes
 .../developer}/Mousetrap_Call Diagram.pdf          |  Bin 27507 -> 27507 bytes
 {devel/docs => docs/developer}/autotools.md        |    0
 runtests.py                                        |    9 -----
 16 files changed, 143 insertions(+), 22 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index f20c61f..b195bd8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -69,3 +69,4 @@ aclocal.m4
 po/POTFILES
 
 /INSTALL
+/.last_built
diff --git a/README b/README
index affb55a..05908c7 100644
--- a/README
+++ b/README
@@ -1,16 +1,19 @@
-## LICENSE
+# MouseTrap
+
+## License
 
 See COPYING
 
-## INSTALL
+## Quick start
 
 From the mousetrap project directory:
 
-       $ ./autogen.sh
-       $ make
-       $ sudo make install
-
-## RUN
+    $ bin/install.sh   # builds and installs
+    $ mousetrap
 
-       $ mousetrap
+## Other commands (primarily for developers)
 
+* bin/build.sh   # builds (no install)
+* bin/pylint.sh
+* bin/test.py
+* bin/mousetrap.py   # runs mousetrap from project directory (i.e., no build or install)
diff --git a/autogen.sh b/bin/autogen.sh
similarity index 91%
rename from autogen.sh
rename to bin/autogen.sh
index a164985..bc5979f 100755
--- a/autogen.sh
+++ b/bin/autogen.sh
@@ -1,7 +1,7 @@
-#!/bin/sh
+#!/bin/bash
 # Run this to generate all the initial makefiles, etc.
 
-srcdir=`dirname $0`
+srcdir=`dirname $0 | xargs dirname`
 test -z "$srcdir" && srcdir=.
 
 PKG_NAME="mouseTrap"
diff --git a/bin/build.sh b/bin/build.sh
new file mode 100755
index 0000000..5d006c1
--- /dev/null
+++ b/bin/build.sh
@@ -0,0 +1,5 @@
+#!/bin/bash
+test -z "$PROJECT_DIRECTORY" && . "$(dirname "$0")"/lib/environment_up.sh
+cd "$PROJECT_DIRECTORY"
+bin/autogen.sh $@ && make
+cd -
diff --git a/bin/install.sh b/bin/install.sh
new file mode 100755
index 0000000..f27af2e
--- /dev/null
+++ b/bin/install.sh
@@ -0,0 +1,15 @@
+#!/bin/bash
+test -z "$PROJECT_DIRECTORY" && . "$(dirname "$0")"/lib/environment_up.sh
+cd "$PROJECT_DIRECTORY"
+
+last_mod="$(find . \( -path './.git/*' -o -name "*.swp" -prune \) -o -type f -exec stat -f '%m %N' {} \; | 
sort -n | tail -1)"
+read -ra ADDR <<< "$last_mod"
+last_mod_file="${ADDR[1]}"
+
+if [ "$last_mod_file" -nt .last_built ] ; then
+    "$PROJECT_DIRECTORY/bin/build.sh"
+fi
+
+sudo make install
+touch .last_install
+cd -
diff --git a/bin/lib/environment_up.sh b/bin/lib/environment_up.sh
new file mode 100644
index 0000000..69079cd
--- /dev/null
+++ b/bin/lib/environment_up.sh
@@ -0,0 +1,17 @@
+#!/bin/bash
+set -e
+absolute_directory(){
+    cd "$1" >& /dev/null || return ''
+    pwd
+    cd - >& /dev/null
+}
+project_directory(){
+    original_directory="$PWD"
+    while [ ! -d './src' ] ; do
+        cd .. >& /dev/null
+    done
+    echo "$PWD"
+    cd "$original_directory" >& /dev/null
+}
+SCRIPT_DIRECTORY="$(absolute_directory "$(dirname "$0")")"
+PROJECT_DIRECTORY="$(project_directory)"
diff --git a/bin/lib/test_environment_up.sh b/bin/lib/test_environment_up.sh
new file mode 100755
index 0000000..e95729b
--- /dev/null
+++ b/bin/lib/test_environment_up.sh
@@ -0,0 +1,37 @@
+#!/bin/bash
+
+oneTimeSetUp() {
+    . "$(dirname "$0")/environment_up.sh"
+}
+
+test_absolute_directory() {
+    assertEquals "$(pwd)" "$(absolute_directory .)"
+}
+
+test_project_directory() {
+    assertEquals \
+        "$(absolute_directory "$(dirname "$0")/../..")" \
+        "$(project_directory)"
+}
+
+test_SCRIPT_DIRECTORY_defined() {
+    assertNotNull "$SCRIPT_DIRECTORY"
+}
+
+test_SCRIPT_DIRECTORY_correct() {
+    assertEquals \
+        "$(absolute_directory "$(dirname "$0")")" \
+        "$SCRIPT_DIRECTORY"
+}
+
+test_PROJECT_DIRECTORY_defined() {
+    assertNotNull "$PROJECT_DIRECTORY"
+}
+
+test_PROJECT_DIRECTORY_correct() {
+    assertEquals \
+        "$(absolute_directory "$(dirname "$0")/../..")" \
+        "$PROJECT_DIRECTORY"
+}
+
+. shunit2
diff --git a/devel/bin/test.py b/bin/mousetrap.py
old mode 100644
new mode 100755
similarity index 85%
rename from devel/bin/test.py
rename to bin/mousetrap.py
index b65a5a2..f7b970a
--- a/devel/bin/test.py
+++ b/bin/mousetrap.py
@@ -28,8 +28,10 @@ __copyright__ = "Copyright (c) 2008 Flavio Percoco Premoli"
 __license__   = "GPLv2"
 
 import sys
-import mousetrap.main as mousetrap
+from pathlib import Path
+sys.path.append(Path('.').absolute().parent/'src/mousetrap/')
+
+from mousetrap.controller import Controller
 
 if __name__ == '__main__':
-    sys.path.append("./")
-    mousetrap.Controller().start()
\ No newline at end of file
+    Controller().start()
diff --git a/run_pylint.sh.in b/bin/pylint.sh.in
similarity index 100%
rename from run_pylint.sh.in
rename to bin/pylint.sh.in
diff --git a/bin/test.py b/bin/test.py
new file mode 100755
index 0000000..9f485e3
--- /dev/null
+++ b/bin/test.py
@@ -0,0 +1,29 @@
+#!/usr/bin/env python3
+from unittest import TestLoader
+from unittest.runner import TextTestRunner
+from pathlib import Path
+
+
+def main():
+    tests = load_tests()
+    run_tests(tests)
+
+
+def load_tests():
+    directory = get_package_root_directory()
+    tests = TestLoader().discover(directory)
+    return tests
+
+
+def get_package_root_directory():
+    this_file = Path(__file__).absolute()
+    package_root = this_file.parent.parent/'src/mousetrap'
+    return str(package_root)
+
+
+def run_tests(tests):
+    TextTestRunner().run(tests)
+
+
+if __name__ == '__main__':
+    main()
diff --git a/bin/test_pylint.sh b/bin/test_pylint.sh
new file mode 100755
index 0000000..e9f664a
--- /dev/null
+++ b/bin/test_pylint.sh
@@ -0,0 +1,21 @@
+#!/usr/bin/env bash
+
+SCRIPT_DIRECTORY=$(dirname "$0")
+PROJECT_DIRECTORY=$(dirname "$SCRIPT_DIRECTORY")
+
+FILE_TO_MODIFY="$PROJECT_DIRECTORY/src/mousetrap/controller.py"
+
+setUp() {
+    echo "print('Hi')" >> "${FILE_TO_MODIFY}"
+}
+
+tearDown() {
+    git checkout -- "${FILE_TO_MODIFY}"
+}
+
+testPylint() {
+    ${SCRIPT_DIRECTORY}/pylint.sh
+    assertEquals 'Exit w/o error expected.' 0 $?
+}
+
+. shunit2
diff --git a/devel/docs/autotools.md b/docs/developer/autotools.md
similarity index 100%
rename from devel/docs/autotools.md
rename to docs/developer/autotools.md


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]