All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/11] toaster script improvements
@ 2015-12-11 13:37 Ed Bartosh
  2015-12-11 13:37 ` [PATCH 01/11] toaster: implement checksocket command Ed Bartosh
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: Ed Bartosh @ 2015-12-11 13:37 UTC (permalink / raw)
  To: toaster

Hi,

This patchset includes bunch of readability, usability and code style
fixes for toaster script. It was started as a fix for #8775 and then
I just couldn't stop and decided to make the script a bit better.

The following changes since commit 8e8b585191cafe9420e31de58d786afffe93d532:

  toasterconf: remove SDKMACHINE variable (2015-12-10 16:28:21 +0200)

are available in the git repository at:

  git://git.yoctoproject.org/poky-contrib ed/toaster/improve-toaster-script
  http://git.yoctoproject.org/cgit.cgi/poky-contrib/log/?h=ed/toaster/improve-toaster-script

Ed Bartosh (11):
  toaster: implement checksocket command
  toaster: check if address:port is in use
  toaster: split long lines, add/remove witespaces
  toaster: remove unused variable
  toaster: add MANAGE variable
  toaster: updated header of the toaster script
  toaster: remove addtoConfiguration function
  toaster: remove 2 unused functions
  toaster: move checks to another place
  toaster: move setting of default values
  toaster: remove 2 confusing parameters

 bitbake/bin/toaster                                | 144 +++++++++------------
 .../toastermain/management/commands/checksocket.py |  69 ++++++++++
 2 files changed, 129 insertions(+), 84 deletions(-)
 create mode 100644 bitbake/lib/toaster/toastermain/management/commands/checksocket.py

--
Regards,
Ed



^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 01/11] toaster: implement checksocket command
  2015-12-11 13:37 [PATCH 00/11] toaster script improvements Ed Bartosh
@ 2015-12-11 13:37 ` Ed Bartosh
  2015-12-11 13:37 ` [PATCH 02/11] toaster: check if address:port is in use Ed Bartosh
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Ed Bartosh @ 2015-12-11 13:37 UTC (permalink / raw)
  To: toaster

Implemented new management command to check if it's
possible to listen on specified address:port.

[YOCTO #8775]

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
---
 .../toastermain/management/commands/checksocket.py | 69 ++++++++++++++++++++++
 1 file changed, 69 insertions(+)
 create mode 100644 bitbake/lib/toaster/toastermain/management/commands/checksocket.py

diff --git a/bitbake/lib/toaster/toastermain/management/commands/checksocket.py b/bitbake/lib/toaster/toastermain/management/commands/checksocket.py
new file mode 100644
index 0000000..0399b86
--- /dev/null
+++ b/bitbake/lib/toaster/toastermain/management/commands/checksocket.py
@@ -0,0 +1,69 @@
+#!/usr/bin/env python
+# ex:ts=4:sw=4:sts=4:et
+# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
+#
+# BitBake Toaster Implementation
+#
+# Copyright (C) 2015 Intel Corporation
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# 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, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+"""Custom management command checksocket."""
+
+import errno
+import socket
+
+from django.core.management.base import BaseCommand, CommandError
+from django.utils.encoding import force_text
+
+DEFAULT_ADDRPORT = "0.0.0.0:8000"
+
+class Command(BaseCommand):
+    """Custom management command."""
+
+    help = 'Check if Toaster can listen on address:port'
+
+    def add_arguments(self, parser):
+        parser.add_argument('addrport', nargs='?', default=DEFAULT_ADDRPORT,
+                            help='ipaddr:port to check, %s by default' % \
+                                 DEFAULT_ADDRPORT)
+
+    def handle(self, *args, **options):
+        addrport = options['addrport']
+        if ':' not in addrport:
+            raise CommandError('Invalid addr:port specified: %s' % addrport)
+        splitted = addrport.split(':')
+        try:
+            splitted[1] = int(splitted[1])
+        except ValueError:
+            raise CommandError('Invalid port specified: %s' % splitted[1])
+        self.stdout.write('Check if toaster can listen on %s' % addrport)
+        try:
+            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+            sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+            sock.bind(tuple(splitted))
+        except (socket.error, OverflowError) as err:
+            errors = {
+                errno.EACCES: 'You don\'t have permission to access port %s' \
+                              % splitted[1],
+                errno.EADDRINUSE: 'Port %s is already in use' % splitted[1],
+                errno.EADDRNOTAVAIL: 'IP address can\'t be assigned to',
+            }
+            if hasattr(err, 'errno') and err.errno in errors:
+                errtext = errors[err.errno]
+            else:
+                errtext = force_text(err)
+            raise CommandError(errtext)
+
+        self.stdout.write("OK")
-- 
2.1.4



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 02/11] toaster: check if address:port is in use
  2015-12-11 13:37 [PATCH 00/11] toaster script improvements Ed Bartosh
  2015-12-11 13:37 ` [PATCH 01/11] toaster: implement checksocket command Ed Bartosh
@ 2015-12-11 13:37 ` Ed Bartosh
  2015-12-11 13:37 ` [PATCH 03/11] toaster: split long lines, add/remove witespaces Ed Bartosh
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Ed Bartosh @ 2015-12-11 13:37 UTC (permalink / raw)
  To: toaster

Used new management command checksocket to check if
Toaster can listen on address:port.

[YOCTO #8775]

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
---
 bitbake/bin/toaster | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/bitbake/bin/toaster b/bitbake/bin/toaster
index 1c1e029..f43bcb1 100755
--- a/bitbake/bin/toaster
+++ b/bitbake/bin/toaster
@@ -309,6 +309,11 @@ fi
 
 echo "The system will $CMD."
 
+# check if addr:port is not in use
+if [ "$CMD" == 'start' ]; then
+    python $BBBASEDIR/lib/toaster/manage.py checksocket "0.0.0.0:$WEB_PORT" || return 1
+fi
+
 # Make sure it's safe to run by checking bitbake lock
 
 lock=1
-- 
2.1.4



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 03/11] toaster: split long lines, add/remove witespaces
  2015-12-11 13:37 [PATCH 00/11] toaster script improvements Ed Bartosh
  2015-12-11 13:37 ` [PATCH 01/11] toaster: implement checksocket command Ed Bartosh
  2015-12-11 13:37 ` [PATCH 02/11] toaster: check if address:port is in use Ed Bartosh
@ 2015-12-11 13:37 ` Ed Bartosh
  2015-12-11 13:38 ` [PATCH 04/11] toaster: remove unused variable Ed Bartosh
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Ed Bartosh @ 2015-12-11 13:37 UTC (permalink / raw)
  To: toaster

Made toaster script more readable by splitting long lines and
removing and adding whitespaces.

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
---
 bitbake/bin/toaster | 31 +++++++++++++++++++------------
 1 file changed, 19 insertions(+), 12 deletions(-)

diff --git a/bitbake/bin/toaster b/bitbake/bin/toaster
index f43bcb1..a849559 100755
--- a/bitbake/bin/toaster
+++ b/bitbake/bin/toaster
@@ -37,7 +37,8 @@ webserverKillAll()
             while kill -0 $pid 2>/dev/null; do
                 kill -SIGTERM -$pid 2>/dev/null
                 sleep 1
-                # Kill processes if they are still running - may happen in interactive shells
+                # Kill processes if they are still running - may happen
+                # in interactive shells
                 ps fux | grep "python.*manage.py runserver" | awk '{print $2}' | xargs kill
             done
             rm  ${pidfile}
@@ -55,7 +56,7 @@ webserverStartAll()
 
     retval=0
     # you can always add a superuser later via
-    # python bitbake/lib/toaster/manage.py python manage.py createsuperuser --username=<ME>
+    # ../bitbake/lib/toaster/manage.py createsuperuser --username=<ME>
     python $BBBASEDIR/lib/toaster/manage.py migrate --noinput || retval=1
 
     if [ $retval -eq 1 ]; then
@@ -72,7 +73,9 @@ webserverStartAll()
 
     echo "Starting webserver..."
 
-    python $BBBASEDIR/lib/toaster/manage.py runserver "0.0.0.0:$WEB_PORT" </dev/null >>${BUILDDIR}/toaster_web.log 2>&1 & echo $! >${BUILDDIR}/.toastermain.pid
+    python $BBBASEDIR/lib/toaster/manage.py runserver "0.0.0.0:$WEB_PORT" \
+           </dev/null >>${BUILDDIR}/toaster_web.log 2>&1 \
+           & echo $! >${BUILDDIR}/.toastermain.pid
 
     sleep 1
 
@@ -128,8 +131,10 @@ start_bitbake() {
     fi
     export BBSERVER=0.0.0.0:-1
     export DATABASE_URL=`$BBBASEDIR/lib/toaster/manage.py get-dburl`
-    if [ $NOTOASTERUI -eq 0 ]; then        # we start the TOASTERUI only if not inhibited
-        bitbake --observe-only -u toasterui --remote-server=$BBSERVER -t xmlrpc >>${BUILDDIR}/toaster_ui.log 2>&1 \
+    # we start the TOASTERUI only if not inhibited
+    if [ $NOTOASTERUI -eq 0 ]; then
+        bitbake --observe-only -u toasterui --remote-server=$BBSERVER -t xmlrpc \
+            >>${BUILDDIR}/toaster_ui.log 2>&1 \
             & echo $! >${BUILDDIR}/.toasterui.pid
     fi
     return 0
@@ -146,7 +151,6 @@ check_pidbyfile() {
     [ -e $1 ] && kill -0 `cat $1` 2>/dev/null
 }
 
-
 notify_chldexit() {
     if [ $NOTOASTERUI -eq 0 ]; then
         check_pidbyfile ${BUILDDIR}/.toasterui.pid && return
@@ -154,7 +158,6 @@ notify_chldexit() {
     fi
 }
 
-
 verify_prereq() {
     # Verify Django version
     reqfile=$(python -c "import os; print os.path.realpath('$BBBASEDIR/toaster-requirements.txt')")
@@ -171,7 +174,6 @@ verify_prereq() {
     return 0
 }
 
-
 # read command line parameters
 if [ -n "$BASH_SOURCE" ] ; then
     TOASTER=${BASH_SOURCE}
@@ -207,7 +209,7 @@ if [ -n "$TEMPLATECONF" ]; then
         fi
         if [ ! -d "$TEMPLATECONF" ]; then
             echo >&2 "Error: '$TEMPLATECONF' must be a directory containing toasterconf.json"
-	    [ "$TOASTER_MANAGED" = '1' ] && exit 1 || return 1
+            [ "$TOASTER_MANAGED" = '1' ] && exit 1 || return 1
         fi
     fi
 fi
@@ -216,10 +218,12 @@ if [ "$TOASTER_CONF" = "" ]; then
     TOASTER_CONF="$TEMPLATECONF/toasterconf.json"
     export TOASTER_CONF=$(python -c "import os; print os.path.realpath('$TOASTER_CONF')")
 fi
+
 if [ ! -f $TOASTER_CONF ]; then
     echo "$TOASTER_CONF configuration file not found. Set TOASTER_CONF to specify file or fix .templateconf"
     [ "$TOASTER_MANAGED" = '1' ] && exit 1 || return 1
 fi
+
 # this defines the dir toaster will use for
 # 1) clones of layers (in _toaster_clones )
 # 2) the build dir (in build)
@@ -284,7 +288,8 @@ if [ "$TOASTER_CONF" = "" ]; then
     export TOASTER_CONF=$(python -c "import os; print os.path.realpath('$TOASTER_CONF')")
 fi
 if [ ! -f $TOASTER_CONF ]; then
-    echo "$TOASTER_CONF configuration file not found. set TOASTER_CONF to specify a path"
+    echo "$TOASTER_CONF configuration file not found."
+    echo " set TOASTER_CONF to specify a path"
     return 1
 fi
 # this defines the dir toaster will use for
@@ -293,7 +298,8 @@ fi
 # 3) the sqlite db if that is being used.
 # 4) pid's we need to clean up on exit/shutdown
 # note: for future. in order to make this an arbitrary directory, we need to
-# make sure that the toaster.sqlite file doesn't default to `pwd` like it currently does.
+# make sure that the toaster.sqlite file doesn't default to `pwd`
+# like it currently does.
 export TOASTER_DIR=`dirname $BUILDDIR`
 
 # Determine the action. If specified by arguments, fine, if not, toggle it
@@ -328,7 +334,8 @@ if [ ${CMD} = 'start' ] && [ $lock -eq 0 ]; then
 fi
 
 if [ ${CMD} = 'start' ] && [ -e $BUILDDIR/.toastermain.pid ] && kill -0 `cat $BUILDDIR/.toastermain.pid`; then
-    echo "Warning: bitbake appears to be dead, but the Toaster web server is running. Something fishy is going on." 1>&2
+    echo "Warning: bitbake appears to be dead, but the Toaster web server is running." 1>&2
+    echo " Something fishy is going on." 1>&2
     echo "Cleaning up the web server to start from a clean slate."
     webserverKillAll
 fi
-- 
2.1.4



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 04/11] toaster: remove unused variable
  2015-12-11 13:37 [PATCH 00/11] toaster script improvements Ed Bartosh
                   ` (2 preceding siblings ...)
  2015-12-11 13:37 ` [PATCH 03/11] toaster: split long lines, add/remove witespaces Ed Bartosh
@ 2015-12-11 13:38 ` Ed Bartosh
  2015-12-11 13:38 ` [PATCH 05/11] toaster: add MANAGE variable Ed Bartosh
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Ed Bartosh @ 2015-12-11 13:38 UTC (permalink / raw)
  To: toaster

Removed unused variable RUNNING from the toaster script.

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
---
 bitbake/bin/toaster | 1 -
 1 file changed, 1 deletion(-)

diff --git a/bitbake/bin/toaster b/bitbake/bin/toaster
index a849559..ccbfdb3 100755
--- a/bitbake/bin/toaster
+++ b/bitbake/bin/toaster
@@ -185,7 +185,6 @@ fi
 
 BBBASEDIR=`dirname $TOASTER`/..
 OEROOT=`dirname $TOASTER`/../..
-RUNNING=0
 NOTOASTERUI=0
 WEBSERVER=1
 TOASTER_BRBE=""
-- 
2.1.4



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 05/11] toaster: add MANAGE variable
  2015-12-11 13:37 [PATCH 00/11] toaster script improvements Ed Bartosh
                   ` (3 preceding siblings ...)
  2015-12-11 13:38 ` [PATCH 04/11] toaster: remove unused variable Ed Bartosh
@ 2015-12-11 13:38 ` Ed Bartosh
  2015-12-11 13:38 ` [PATCH 06/11] toaster: updated header of the toaster script Ed Bartosh
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Ed Bartosh @ 2015-12-11 13:38 UTC (permalink / raw)
  To: toaster

Used MANAGE variable to avoid repeating path to
manage.py in many places in toaster script.

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
---
 bitbake/bin/toaster | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/bitbake/bin/toaster b/bitbake/bin/toaster
index ccbfdb3..087e3f9 100755
--- a/bitbake/bin/toaster
+++ b/bitbake/bin/toaster
@@ -57,14 +57,14 @@ webserverStartAll()
     retval=0
     # you can always add a superuser later via
     # ../bitbake/lib/toaster/manage.py createsuperuser --username=<ME>
-    python $BBBASEDIR/lib/toaster/manage.py migrate --noinput || retval=1
+    $MANAGE migrate --noinput || retval=1
 
     if [ $retval -eq 1 ]; then
         echo "Failed migrations, aborting system start" 1>&2
         return $retval
     fi
 
-    python $BBBASEDIR/lib/toaster/manage.py checksettings --traceback || retval=1
+    $MANAGE checksettings --traceback || retval=1
 
     if [ $retval -eq 1 ]; then
         printf "\nError while checking settings; aborting\n"
@@ -73,7 +73,7 @@ webserverStartAll()
 
     echo "Starting webserver..."
 
-    python $BBBASEDIR/lib/toaster/manage.py runserver "0.0.0.0:$WEB_PORT" \
+    $MANAGE runserver "0.0.0.0:$WEB_PORT" \
            </dev/null >>${BUILDDIR}/toaster_web.log 2>&1 \
            & echo $! >${BUILDDIR}/.toastermain.pid
 
@@ -130,7 +130,7 @@ start_bitbake() {
         return 1
     fi
     export BBSERVER=0.0.0.0:-1
-    export DATABASE_URL=`$BBBASEDIR/lib/toaster/manage.py get-dburl`
+    export DATABASE_URL=`$MANAGE get-dburl`
     # we start the TOASTERUI only if not inhibited
     if [ $NOTOASTERUI -eq 0 ]; then
         bitbake --observe-only -u toasterui --remote-server=$BBSERVER -t xmlrpc \
@@ -184,6 +184,7 @@ else
 fi
 
 BBBASEDIR=`dirname $TOASTER`/..
+MANAGE=$BBBASEDIR/lib/toaster/manage.py
 OEROOT=`dirname $TOASTER`/../..
 NOTOASTERUI=0
 WEBSERVER=1
@@ -316,7 +317,7 @@ echo "The system will $CMD."
 
 # check if addr:port is not in use
 if [ "$CMD" == 'start' ]; then
-    python $BBBASEDIR/lib/toaster/manage.py checksocket "0.0.0.0:$WEB_PORT" || return 1
+    $MANAGE checksocket "0.0.0.0:$WEB_PORT" || return 1
 fi
 
 # Make sure it's safe to run by checking bitbake lock
@@ -351,7 +352,7 @@ case $CMD in
         fi
         start_bitbake
         if [ $? -eq 0 ]; then
-            python $BBBASEDIR/lib/toaster/manage.py runbuilds & echo $! >${BUILDDIR}/.runbuilds.pid
+            $MANAGE runbuilds & echo $! >${BUILDDIR}/.runbuilds.pid
             # set fail safe stop system on terminal exit
             trap stop_system SIGHUP
             echo "Successful ${CMD}."
-- 
2.1.4



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 06/11] toaster: updated header of the toaster script
  2015-12-11 13:37 [PATCH 00/11] toaster script improvements Ed Bartosh
                   ` (4 preceding siblings ...)
  2015-12-11 13:38 ` [PATCH 05/11] toaster: add MANAGE variable Ed Bartosh
@ 2015-12-11 13:38 ` Ed Bartosh
  2015-12-11 13:38 ` [PATCH 07/11] toaster: remove addtoConfiguration function Ed Bartosh
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Ed Bartosh @ 2015-12-11 13:38 UTC (permalink / raw)
  To: toaster

Updated GPL information, years of development and
usage information. Removed outdated information about
2 ways of starting Toaster.

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
---
 bitbake/bin/toaster | 20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)

diff --git a/bitbake/bin/toaster b/bitbake/bin/toaster
index 087e3f9..40c3c35 100755
--- a/bitbake/bin/toaster
+++ b/bitbake/bin/toaster
@@ -1,5 +1,8 @@
 #!/bin/echo ERROR: This script needs to be sourced. Please run as .
-# (c) 2013 Intel Corp.
+
+# toaster - shell script to start Toaster
+
+# Copyright (C) 2013-2015 Intel Corp.
 
 # 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
@@ -12,19 +15,10 @@
 # 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, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-
-
-# This script can be run in two modes.
-
-# When used with "source", from a build directory,
-# it enables toaster event logging and starts the bitbake resident server.
-# use as:  source toaster [start|stop] [noweb] [noui]
+# along with this program. If not, see http://www.gnu.org/licenses/.
 
-# When it is called as a stand-alone script, it starts just the
-# web server, and the building shall be done through the web interface.
-# As script, it will not return to the command prompt. Stop with Ctrl-C.
+# Usage: source toaster [start|stop|restart-bitbake] [webport=<port>]
+#                       [noui] [noweb] [nobrowser] [brbe=<BRBE>]
 
 # Helper function to kill a background toaster development server
 
-- 
2.1.4



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 07/11] toaster: remove addtoConfiguration function
  2015-12-11 13:37 [PATCH 00/11] toaster script improvements Ed Bartosh
                   ` (5 preceding siblings ...)
  2015-12-11 13:38 ` [PATCH 06/11] toaster: updated header of the toaster script Ed Bartosh
@ 2015-12-11 13:38 ` Ed Bartosh
  2015-12-11 13:38 ` [PATCH 08/11] toaster: remove 2 unused functions Ed Bartosh
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Ed Bartosh @ 2015-12-11 13:38 UTC (permalink / raw)
  To: toaster

This function is useless as it's called just once
and makes code less readable.

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
---
 bitbake/bin/toaster | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/bitbake/bin/toaster b/bitbake/bin/toaster
index 40c3c35..97ca177 100755
--- a/bitbake/bin/toaster
+++ b/bitbake/bin/toaster
@@ -83,16 +83,6 @@ webserverStartAll()
     return $retval
 }
 
-# Helper functions to add a special configuration file
-
-addtoConfiguration()
-{
-    file=$1
-    shift
-    echo "#Created by toaster start script" > ${BUILDDIR}/conf/$file
-    for var in "$@"; do echo $var >> ${BUILDDIR}/conf/$file; done
-}
-
 INSTOPSYSTEM=0
 
 # define the stop command
@@ -339,7 +329,12 @@ fi
 
 case $CMD in
     start )
-        addtoConfiguration toaster.conf "INHERIT+=\"toaster buildhistory\"" $TOASTER_BRBE
+        # Create configuration file
+        conf=${BUILDDIR}/conf/toaster.conf
+        echo "# Created by toaster start script" > $conf
+        echo "INHERIT+=\"toaster buildhistory\"" >> $conf
+        [ -n "$TOASTER_BRBE" ] && echo $TOASTER_BRBE >> $conf
+
         if [ $WEBSERVER -gt 0 ] && ! webserverStartAll; then
             echo "Failed ${CMD}."
             return 4
-- 
2.1.4



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 08/11] toaster: remove 2 unused functions
  2015-12-11 13:37 [PATCH 00/11] toaster script improvements Ed Bartosh
                   ` (6 preceding siblings ...)
  2015-12-11 13:38 ` [PATCH 07/11] toaster: remove addtoConfiguration function Ed Bartosh
@ 2015-12-11 13:38 ` Ed Bartosh
  2015-12-11 13:38 ` [PATCH 09/11] toaster: move checks to another place Ed Bartosh
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Ed Bartosh @ 2015-12-11 13:38 UTC (permalink / raw)
  To: toaster

Removed check_pidbyfile and notify_chldexit functions from
toaster script as they're not called in the script.

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
---
 bitbake/bin/toaster | 12 ------------
 1 file changed, 12 deletions(-)

diff --git a/bitbake/bin/toaster b/bitbake/bin/toaster
index 97ca177..1f4c400 100755
--- a/bitbake/bin/toaster
+++ b/bitbake/bin/toaster
@@ -131,17 +131,6 @@ stop_bitbake() {
     lsof bitbake.lock | awk '{print $2}' | grep "[0-9]\+" | xargs -n1 -r kill
 }
 
-check_pidbyfile() {
-    [ -e $1 ] && kill -0 `cat $1` 2>/dev/null
-}
-
-notify_chldexit() {
-    if [ $NOTOASTERUI -eq 0 ]; then
-        check_pidbyfile ${BUILDDIR}/.toasterui.pid && return
-        stop_system
-    fi
-}
-
 verify_prereq() {
     # Verify Django version
     reqfile=$(python -c "import os; print os.path.realpath('$BBBASEDIR/toaster-requirements.txt')")
@@ -355,7 +344,6 @@ case $CMD in
         # stop system on terminal exit
         set -o monitor
         trap stop_system SIGHUP
-        #trap notify_chldexit SIGCHLD
     ;;
     stop )
         stop_system
-- 
2.1.4



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 09/11] toaster: move checks to another place
  2015-12-11 13:37 [PATCH 00/11] toaster script improvements Ed Bartosh
                   ` (7 preceding siblings ...)
  2015-12-11 13:38 ` [PATCH 08/11] toaster: remove 2 unused functions Ed Bartosh
@ 2015-12-11 13:38 ` Ed Bartosh
  2015-12-11 13:38 ` [PATCH 10/11] toaster: move setting of default values Ed Bartosh
  2015-12-11 13:38 ` [PATCH 11/11] toaster: remove 2 confusing parameters Ed Bartosh
  10 siblings, 0 replies; 12+ messages in thread
From: Ed Bartosh @ 2015-12-11 13:38 UTC (permalink / raw)
  To: toaster

Moved addr:port, bitbake.lock and toastermain.pid checks
to the place where the rest of Toaster starting happens.

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
---
 bitbake/bin/toaster | 49 +++++++++++++++++++++++--------------------------
 1 file changed, 23 insertions(+), 26 deletions(-)

diff --git a/bitbake/bin/toaster b/bitbake/bin/toaster
index 1f4c400..6dd20c1 100755
--- a/bitbake/bin/toaster
+++ b/bitbake/bin/toaster
@@ -288,36 +288,33 @@ fi
 
 echo "The system will $CMD."
 
-# check if addr:port is not in use
-if [ "$CMD" == 'start' ]; then
-    $MANAGE checksocket "0.0.0.0:$WEB_PORT" || return 1
-fi
-
-# Make sure it's safe to run by checking bitbake lock
-
-lock=1
-if [ -e $BUILDDIR/bitbake.lock ]; then
-    python -c "import fcntl; fcntl.flock(open(\"$BUILDDIR/bitbake.lock\"), fcntl.LOCK_EX|fcntl.LOCK_NB)" 2>/dev/null || lock=0
-fi
-
-if [ ${CMD} = 'start' ] && [ $lock -eq 0 ]; then
-    echo "Error: bitbake lock state error. File locks show that the system is on." 1>&2
-    echo "Please wait for the current build to finish, stop and then start the system again." 1>&2
-    return 3
-fi
-
-if [ ${CMD} = 'start' ] && [ -e $BUILDDIR/.toastermain.pid ] && kill -0 `cat $BUILDDIR/.toastermain.pid`; then
-    echo "Warning: bitbake appears to be dead, but the Toaster web server is running." 1>&2
-    echo " Something fishy is going on." 1>&2
-    echo "Cleaning up the web server to start from a clean slate."
-    webserverKillAll
-fi
-
-
 # Execute the commands
 
 case $CMD in
     start )
+        # check if addr:port is not in use
+        if [ "$CMD" == 'start' ]; then
+             $MANAGE checksocket "0.0.0.0:$WEB_PORT" || return 1
+        fi
+
+        # Make sure it's safe to start by checking bitbake lock
+        if [ -e $BUILDDIR/bitbake.lock ]; then
+            python -c "import fcntl; fcntl.flock(open(\"$BUILDDIR/bitbake.lock\"), fcntl.LOCK_EX|fcntl.LOCK_NB)" 2>/dev/null
+            if [ $? -ne 0 ] ; then
+                echo "Error: bitbake lock state error. File locks show that the system is on." 1>&2
+                echo "Please wait for the current build to finish, stop and then start the system again." 1>&2
+                return 3
+            fi
+        fi
+
+        # kill Toaster web server if it's alive
+        if [ -e $BUILDDIR/.toastermain.pid ] && kill -0 `cat $BUILDDIR/.toastermain.pid`; then
+            echo "Warning: bitbake appears to be dead, but the Toaster web server is running." 1>&2
+            echo " Something fishy is going on." 1>&2
+            echo "Cleaning up the web server to start from a clean slate."
+            webserverKillAll
+        fi
+
         # Create configuration file
         conf=${BUILDDIR}/conf/toaster.conf
         echo "# Created by toaster start script" > $conf
-- 
2.1.4



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 10/11] toaster: move setting of default values
  2015-12-11 13:37 [PATCH 00/11] toaster script improvements Ed Bartosh
                   ` (8 preceding siblings ...)
  2015-12-11 13:38 ` [PATCH 09/11] toaster: move checks to another place Ed Bartosh
@ 2015-12-11 13:38 ` Ed Bartosh
  2015-12-11 13:38 ` [PATCH 11/11] toaster: remove 2 confusing parameters Ed Bartosh
  10 siblings, 0 replies; 12+ messages in thread
From: Ed Bartosh @ 2015-12-11 13:38 UTC (permalink / raw)
  To: toaster

Set default values of script parameters just before
they are parsed to increase readability.

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
---
 bitbake/bin/toaster | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/bitbake/bin/toaster b/bitbake/bin/toaster
index 6dd20c1..7cecc7b 100755
--- a/bitbake/bin/toaster
+++ b/bitbake/bin/toaster
@@ -159,12 +159,7 @@ fi
 BBBASEDIR=`dirname $TOASTER`/..
 MANAGE=$BBBASEDIR/lib/toaster/manage.py
 OEROOT=`dirname $TOASTER`/../..
-NOTOASTERUI=0
-WEBSERVER=1
-TOASTER_BRBE=""
-if [ "$WEB_PORT" = "" ]; then
-    WEB_PORT="8000"
-fi
+
 # this is the configuraton file we are using for toaster
 # we are using the same logic that oe-setup-builddir uses
 # (based on TEMPLATECONF and .templateconf) to determine
@@ -206,7 +201,11 @@ fi
 # make sure that the toaster.sqlite file doesn't default to `pwd` like it currently does.
 export TOASTER_DIR=`pwd`
 
+NOTOASTERUI=0
+WEBSERVER=1
 NOBROWSER=0
+TOASTER_BRBE=""
+WEB_PORT="8000"
 
 for param in $*; do
     case $param in
-- 
2.1.4



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 11/11] toaster: remove 2 confusing parameters
  2015-12-11 13:37 [PATCH 00/11] toaster script improvements Ed Bartosh
                   ` (9 preceding siblings ...)
  2015-12-11 13:38 ` [PATCH 10/11] toaster: move setting of default values Ed Bartosh
@ 2015-12-11 13:38 ` Ed Bartosh
  10 siblings, 0 replies; 12+ messages in thread
From: Ed Bartosh @ 2015-12-11 13:38 UTC (permalink / raw)
  To: toaster

Removed nobrowser and brbe script parameters as both
are confusing and nobrowser is not used anywhere.

brbe parameter usage can only be justified if toaster
doesn't work properly and user has to manually connect
toaster to running bitbake server. Even in this scenario
it's very unlikely to achieve as toaster script is not
designed for this kind of usage.

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
---
 bitbake/bin/toaster | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)

diff --git a/bitbake/bin/toaster b/bitbake/bin/toaster
index 7cecc7b..1f98490 100755
--- a/bitbake/bin/toaster
+++ b/bitbake/bin/toaster
@@ -17,8 +17,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/.
 
-# Usage: source toaster [start|stop|restart-bitbake] [webport=<port>]
-#                       [noui] [noweb] [nobrowser] [brbe=<BRBE>]
+# Usage: source toaster [start|stop|restart-bitbake]
+#                       [webport=<port>] [noui] [noweb]
 
 # Helper function to kill a background toaster development server
 
@@ -203,8 +203,6 @@ export TOASTER_DIR=`pwd`
 
 NOTOASTERUI=0
 WEBSERVER=1
-NOBROWSER=0
-TOASTER_BRBE=""
 WEB_PORT="8000"
 
 for param in $*; do
@@ -215,12 +213,6 @@ for param in $*; do
     noweb )
             WEBSERVER=0
     ;;
-    nobrowser )
-            NOBROWSER=1
-    ;;
-    brbe=* )
-            TOASTER_BRBE=$'\n'"TOASTER_BRBE=\""${param#*=}"\""
-    ;;
     webport=*)
             WEB_PORT="${param#*=}"
     esac
@@ -318,7 +310,6 @@ case $CMD in
         conf=${BUILDDIR}/conf/toaster.conf
         echo "# Created by toaster start script" > $conf
         echo "INHERIT+=\"toaster buildhistory\"" >> $conf
-        [ -n "$TOASTER_BRBE" ] && echo $TOASTER_BRBE >> $conf
 
         if [ $WEBSERVER -gt 0 ] && ! webserverStartAll; then
             echo "Failed ${CMD}."
-- 
2.1.4



^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2015-12-11 14:13 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-11 13:37 [PATCH 00/11] toaster script improvements Ed Bartosh
2015-12-11 13:37 ` [PATCH 01/11] toaster: implement checksocket command Ed Bartosh
2015-12-11 13:37 ` [PATCH 02/11] toaster: check if address:port is in use Ed Bartosh
2015-12-11 13:37 ` [PATCH 03/11] toaster: split long lines, add/remove witespaces Ed Bartosh
2015-12-11 13:38 ` [PATCH 04/11] toaster: remove unused variable Ed Bartosh
2015-12-11 13:38 ` [PATCH 05/11] toaster: add MANAGE variable Ed Bartosh
2015-12-11 13:38 ` [PATCH 06/11] toaster: updated header of the toaster script Ed Bartosh
2015-12-11 13:38 ` [PATCH 07/11] toaster: remove addtoConfiguration function Ed Bartosh
2015-12-11 13:38 ` [PATCH 08/11] toaster: remove 2 unused functions Ed Bartosh
2015-12-11 13:38 ` [PATCH 09/11] toaster: move checks to another place Ed Bartosh
2015-12-11 13:38 ` [PATCH 10/11] toaster: move setting of default values Ed Bartosh
2015-12-11 13:38 ` [PATCH 11/11] toaster: remove 2 confusing parameters Ed Bartosh

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.