All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] Rework the devshell
@ 2011-04-05 19:08 Chris Larson
  2011-04-05 19:08 ` [PATCH 1/3] oe.classutils: add module Chris Larson
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Chris Larson @ 2011-04-05 19:08 UTC (permalink / raw)
  To: openembedded-core; +Cc: Chris Larson

From: Chris Larson <chris_larson@mentor.com>

- Adds a utility metaclass for maintaining class registries
- Shifts the handling of spawning a terminal into a new 'terminal' python
  module
- Automatically selects an appropriate terminal based on what you have
  available on your machine
- Still allows manual selection, but in a more convenient way, and falls back
  to auto if you select an invalid or unavailable (not installed) terminal
- Improves how we spawn screen:

  - Shows a warning when spawning it, so do_devshell doesn't appear to hang
  - Spawns a named screen session 'devshell', to avoid confusion when the user
    already has other screen sessions running

Pull URL: https://github.com/kergoth/oe-core
  Branch: devshell
  Browse: https://github.com/kergoth/oe-core/commits/devshell

Thanks,
    Chris Larson <chris_larson@mentor.com>
---


Chris Larson (3):
  oe.classutils: add module
  Rework how the devshell functions
  oe.terminal: improve how we spawn screen

 meta/classes/devshell.bbclass |   26 ++++-------
 meta/lib/oe/classutils.py     |   24 +++++++++
 meta/lib/oe/terminal.py       |  105 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 138 insertions(+), 17 deletions(-)
 create mode 100644 meta/lib/oe/classutils.py
 create mode 100644 meta/lib/oe/terminal.py

-- 
1.7.4.1




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

* [PATCH 1/3] oe.classutils: add module
  2011-04-05 19:08 [PATCH 0/3] Rework the devshell Chris Larson
@ 2011-04-05 19:08 ` Chris Larson
  2011-04-05 19:08 ` [PATCH 2/3] Rework how the devshell functions Chris Larson
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Chris Larson @ 2011-04-05 19:08 UTC (permalink / raw)
  To: openembedded-core; +Cc: Chris Larson

From: Chris Larson <chris_larson@mentor.com>

This adds a ClassRegistry utility metaclass, as maintaining a class registry
is a fairly common thing to do.

Signed-off-by: Chris Larson <chris_larson@mentor.com>
---
 meta/lib/oe/classutils.py |   24 ++++++++++++++++++++++++
 1 files changed, 24 insertions(+), 0 deletions(-)
 create mode 100644 meta/lib/oe/classutils.py

diff --git a/meta/lib/oe/classutils.py b/meta/lib/oe/classutils.py
new file mode 100644
index 0000000..855d2fa
--- /dev/null
+++ b/meta/lib/oe/classutils.py
@@ -0,0 +1,24 @@
+class ClassRegistry(type):
+    """Maintain a registry of classes, indexed by name.
+
+    The name in the registry can be overridden via the 'name' attribute of the
+    class, and the 'priority' attribute controls priority.  The prioritized()
+    method returns the registered classes in priority order."""
+    registry = {}
+    priority = 0
+
+    def __init__(cls, name, bases, attrs):
+        super(ClassRegistry, cls).__init__(name, bases, attrs)
+        if not hasattr(cls, name):
+            cls.name = name
+        cls.registry[cls.name] = cls
+
+    @classmethod
+    def prioritized(tcls):
+        return sorted(tcls.registry.values(),
+                      key=lambda v: v.priority, reverse=True)
+
+    def unregister(cls):
+        for key in cls.registry.keys():
+            if cls.registry[key] is cls:
+                del cls.registry[key]
-- 
1.7.4.1




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

* [PATCH 2/3] Rework how the devshell functions
  2011-04-05 19:08 [PATCH 0/3] Rework the devshell Chris Larson
  2011-04-05 19:08 ` [PATCH 1/3] oe.classutils: add module Chris Larson
@ 2011-04-05 19:08 ` Chris Larson
  2011-04-05 19:08 ` [PATCH 3/3] oe.terminal: improve how we spawn screen Chris Larson
  2011-04-05 19:09 ` [PATCH 0/3] Rework the devshell Chris Larson
  3 siblings, 0 replies; 6+ messages in thread
From: Chris Larson @ 2011-04-05 19:08 UTC (permalink / raw)
  To: openembedded-core; +Cc: Chris Larson

From: Chris Larson <chris_larson@mentor.com>

In the new implementation, each known terminal is defined as a class in
oe.terminal, as a subclass of bb.process.Popen.  terminal.bbclass wraps this
functionality, providing the metadata pieces.  It obeys the OE_TERMINAL
variable, which is a 'choice' typed variable.  This variable may be 'auto',
'none', or any of the names of the defined terminals.

When using 'auto', or requesting an unsupported terminal, we attempt to spawn
them in priority order until we get one that's available on this system (and
in the case of the X terminals, has DISPLAY defined).  The 'none' value is
used when we're doing things like automated builds, and want to ensure that no
terminal is *ever* spawned, under any circumstances.

Current available terminals:

    gnome
    konsole
    xterm
    rxvt
    screen

Signed-off-by: Chris Larson <chris_larson@mentor.com>
---
 meta/classes/devshell.bbclass |   26 ++++-------
 meta/lib/oe/terminal.py       |  100 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 109 insertions(+), 17 deletions(-)
 create mode 100644 meta/lib/oe/terminal.py

diff --git a/meta/classes/devshell.bbclass b/meta/classes/devshell.bbclass
index 5f262f4..7317d64 100644
--- a/meta/classes/devshell.bbclass
+++ b/meta/classes/devshell.bbclass
@@ -1,22 +1,14 @@
-do_devshell[dirs] = "${S}"
-do_devshell[nostamp] = "1"
+inherit terminal
 
-XAUTHORITY ?= "${HOME}/.Xauthority"
 
-devshell_do_devshell() {
-	export DISPLAY='${DISPLAY}'
-	export DBUS_SESSION_BUS_ADDRESS='${DBUS_SESSION_BUS_ADDRESS}'
-	export XAUTHORITY='${XAUTHORITY}'
-	export TERMWINDOWTITLE="Bitbake Developer Shell"
-	export EXTRA_OEMAKE='${EXTRA_OEMAKE}'
-	export SHELLCMDS="bash"
-	${TERMCMDRUN}
-	if [ $? -ne 0 ]; then
-	    echo "Fatal: '${TERMCMD}' not found. Check TERMCMD variable."
-	    exit 1
-	fi
+export XAUTHORITY ?= "${HOME}/.Xauthority"
+export SHELL ?= 'bash'
+
+python do_devshell () {
+    oe_terminal(d.getVar('SHELL', True), 'OpenEmbedded Developer Shell', d)
 }
-addtask devshell after do_patch
 
-EXPORT_FUNCTIONS do_devshell
+addtask devshell after do_patch
 
+do_devshell[dirs] = "${S}"
+do_devshell[nostamp] = "1"
diff --git a/meta/lib/oe/terminal.py b/meta/lib/oe/terminal.py
new file mode 100644
index 0000000..8c8e5b2
--- /dev/null
+++ b/meta/lib/oe/terminal.py
@@ -0,0 +1,100 @@
+import logging
+import os
+import oe.classutils
+from bb.process import Popen, ExecutionError
+
+logger = logging.getLogger('BitBake.OE.Terminal')
+
+
+class UnsupportedTerminal(StandardError):
+    pass
+
+class NoSupportedTerminals(StandardError):
+    pass
+
+
+class Registry(oe.classutils.ClassRegistry):
+    registry = {}
+
+    def __init__(cls, name, bases, attrs):
+        super(Registry, cls).__init__(name.lower(), bases, attrs)
+        if not cls.cmd:
+            cls.unregister()
+
+
+class Terminal(Popen):
+    __metaclass__ = Registry
+    cmd = None
+
+    def __init__(self, cmd, title=None):
+        self.format_cmd(cmd, title)
+
+        try:
+            Popen.__init__(self, self.cmd, shell=True)
+        except OSError as exc:
+            import errno
+            if exc.errno == errno.ENOENT:
+                raise UnsupportedTerminal(self.name)
+            else:
+                raise
+
+    def format_cmd(self, cmd, title):
+        fmt = {'title': title or 'Terminal', 'cmd': cmd}
+        if isinstance(self.cmd, basestring):
+            self.cmd = self.cmd.format(**fmt)
+        else:
+            self.cmd = [element.format(**fmt) for element in self.cmd]
+
+class XTerminal(Terminal):
+    def __init__(self, cmd, title=None):
+        Terminal.__init__(self, cmd, title)
+        if not os.environ.get('DISPLAY'):
+            raise UnsupportedTerminal(self.name)
+
+class Gnome(XTerminal):
+    cmd = 'gnome-terminal --disable-factory -t "{title}" -x {cmd}'
+    priority = 2
+
+class Konsole(XTerminal):
+    cmd = 'konsole -T "{title}" -e {cmd}'
+    priority = 2
+
+class XTerm(XTerminal):
+    cmd = 'xterm -T "{title}" -e {cmd}'
+    priority = 1
+
+class Rxvt(XTerminal):
+    cmd = 'rxvt -T "{title}" -e {cmd}'
+    priority = 1
+
+class Screen(Terminal):
+    cmd = 'screen -D -m -t "{title}" {cmd}'
+
+
+def prioritized():
+    return Registry.prioritized()
+
+def spawn_preferred(cmd, title=None):
+    """Spawn the first supported terminal, by priority"""
+    for terminal in Registry.prioritized():
+        try:
+            spawn(terminal.name, cmd, title)
+            break
+        except UnsupportedTerminal:
+            continue
+    else:
+        raise NoSupportedTerminals()
+
+def spawn(name, cmd, title=None):
+    """Spawn the specified terminal, by name"""
+    logger.debug(1, 'Attempting to spawn terminal "%s"' %
+                    name)
+    try:
+        terminal = Registry.registry[name]
+    except KeyError:
+        raise UnsupportedTerminal(name)
+
+    pipe = terminal(cmd, title)
+    output = pipe.communicate()[0]
+    if pipe.returncode != 0:
+        raise ExecutionError(pipe.cmd, pipe.returncode, output)
-- 
1.7.4.1




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

* [PATCH 3/3] oe.terminal: improve how we spawn screen
  2011-04-05 19:08 [PATCH 0/3] Rework the devshell Chris Larson
  2011-04-05 19:08 ` [PATCH 1/3] oe.classutils: add module Chris Larson
  2011-04-05 19:08 ` [PATCH 2/3] Rework how the devshell functions Chris Larson
@ 2011-04-05 19:08 ` Chris Larson
  2011-04-05 19:09 ` [PATCH 0/3] Rework the devshell Chris Larson
  3 siblings, 0 replies; 6+ messages in thread
From: Chris Larson @ 2011-04-05 19:08 UTC (permalink / raw)
  To: openembedded-core; +Cc: Chris Larson

From: Chris Larson <chris_larson@mentor.com>

- Name the screen session 'devshell', to avoid confusion if running bitbake
  itself under a screen session.
- Display a warning message when spawning screen, so it's clear to the user
  that screen has been run (otherwise do_devshell just appears to hang).

Signed-off-by: Chris Larson <chris_larson@mentor.com>
---
 meta/lib/oe/terminal.py |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/meta/lib/oe/terminal.py b/meta/lib/oe/terminal.py
index 8c8e5b2..a94b113 100644
--- a/meta/lib/oe/terminal.py
+++ b/meta/lib/oe/terminal.py
@@ -68,7 +68,12 @@ class Rxvt(XTerminal):
     priority = 1
 
 class Screen(Terminal):
-    cmd = 'screen -D -m -t "{title}" {cmd}'
+    cmd = 'screen -D -m -t "{title}" -S devshell {cmd}'
+
+    def __init__(self, cmd, title=None):
+        logger.warn('Screen started. Please connect in another terminal with '
+                    '"screen -r devshell"')
+        Terminal.__init__(self, cmd, title)
 
 
 def prioritized():
-- 
1.7.4.1




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

* Re: [PATCH 0/3] Rework the devshell
  2011-04-05 19:08 [PATCH 0/3] Rework the devshell Chris Larson
                   ` (2 preceding siblings ...)
  2011-04-05 19:08 ` [PATCH 3/3] oe.terminal: improve how we spawn screen Chris Larson
@ 2011-04-05 19:09 ` Chris Larson
  2011-04-05 19:10   ` Chris Larson
  3 siblings, 1 reply; 6+ messages in thread
From: Chris Larson @ 2011-04-05 19:09 UTC (permalink / raw)
  To: openembedded-core; +Cc: Chris Larson

On Tue, Apr 5, 2011 at 12:08 PM, Chris Larson <kergoth@gmail.com> wrote:
> From: Chris Larson <chris_larson@mentor.com>
>
> - Adds a utility metaclass for maintaining class registries
> - Shifts the handling of spawning a terminal into a new 'terminal' python
>  module
> - Automatically selects an appropriate terminal based on what you have
>  available on your machine
> - Still allows manual selection, but in a more convenient way, and falls back
>  to auto if you select an invalid or unavailable (not installed) terminal
> - Improves how we spawn screen:
>
>  - Shows a warning when spawning it, so do_devshell doesn't appear to hang
>  - Spawns a named screen session 'devshell', to avoid confusion when the user
>    already has other screen sessions running
>
> Pull URL: https://github.com/kergoth/oe-core
>  Branch: devshell
>  Browse: https://github.com/kergoth/oe-core/commits/devshell

Note: this depends on the variable typing from the previous pull
request, forgot to add that to the cover letter.
-- 
Christopher Larson
clarson at kergoth dot com
Founder - BitBake, OpenEmbedded, OpenZaurus
Maintainer - Tslib
Senior Software Engineer, Mentor Graphics



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

* Re: [PATCH 0/3] Rework the devshell
  2011-04-05 19:09 ` [PATCH 0/3] Rework the devshell Chris Larson
@ 2011-04-05 19:10   ` Chris Larson
  0 siblings, 0 replies; 6+ messages in thread
From: Chris Larson @ 2011-04-05 19:10 UTC (permalink / raw)
  To: openembedded-core

On Tue, Apr 5, 2011 at 12:09 PM, Chris Larson <kergoth@gmail.com> wrote:
> On Tue, Apr 5, 2011 at 12:08 PM, Chris Larson <kergoth@gmail.com> wrote:
>> From: Chris Larson <chris_larson@mentor.com>
>>
>> - Adds a utility metaclass for maintaining class registries
>> - Shifts the handling of spawning a terminal into a new 'terminal' python
>>  module
>> - Automatically selects an appropriate terminal based on what you have
>>  available on your machine
>> - Still allows manual selection, but in a more convenient way, and falls back
>>  to auto if you select an invalid or unavailable (not installed) terminal
>> - Improves how we spawn screen:
>>
>>  - Shows a warning when spawning it, so do_devshell doesn't appear to hang
>>  - Spawns a named screen session 'devshell', to avoid confusion when the user
>>    already has other screen sessions running
>>
>> Pull URL: https://github.com/kergoth/oe-core
>>  Branch: devshell
>>  Browse: https://github.com/kergoth/oe-core/commits/devshell
>
> Note: this depends on the variable typing from the previous pull
> request, forgot to add that to the cover letter.

Er, ignore this pull request, a v2 will be forthcoming (missed a file).
-- 
Christopher Larson
clarson at kergoth dot com
Founder - BitBake, OpenEmbedded, OpenZaurus
Maintainer - Tslib
Senior Software Engineer, Mentor Graphics



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

end of thread, other threads:[~2011-04-05 19:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-05 19:08 [PATCH 0/3] Rework the devshell Chris Larson
2011-04-05 19:08 ` [PATCH 1/3] oe.classutils: add module Chris Larson
2011-04-05 19:08 ` [PATCH 2/3] Rework how the devshell functions Chris Larson
2011-04-05 19:08 ` [PATCH 3/3] oe.terminal: improve how we spawn screen Chris Larson
2011-04-05 19:09 ` [PATCH 0/3] Rework the devshell Chris Larson
2011-04-05 19:10   ` Chris Larson

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.