Rework the devshell
cover Rework the devshell
From: Chris Larson <[email protected]>
- 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 <[email protected]>
---
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
Signature · 1 line
1.7.4.1
PATCH 1/3 oe.classutils: add module
From: Chris Larson <[email protected]>
This adds a ClassRegistry utility metaclass, as maintaining a class registry is a fairly common thing to do.
--- meta/lib/oe/classutils.py | 24 ++++++++++++++++++++++++ 1 files changed, 24 insertions(+), 0 deletions(-) create mode 100644 meta/lib/oe/classutils.py
meta/lib/oe/classutils.py new file +24 -0
@@ -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]
Signature · 1 line
1.7.4.1
PATCH 2/3 Rework how the devshell functions
In reply to Chris LarsonFrom: Chris Larson <[email protected]>
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
--- 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
meta/classes/devshell.bbclass +9 -17
@@ -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"
meta/lib/oe/terminal.py new file +100 -0
100 lines not on this page · raw message
Signature · 1 line
1.7.4.1
PATCH 3/3 oe.terminal: improve how we spawn screen
In reply to Chris LarsonFrom: Chris Larson <[email protected]>
- 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).
--- meta/lib/oe/terminal.py | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-)
meta/lib/oe/terminal.py +6 -1
@@ -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():
Signature · 1 line
1.7.4.1
Quoted 11 lines · Chris Larson
From: Chris Larson <[email protected]>
- 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:
Quoted 7 lines
- Shows a warning when spawning it, so
do_devshelldoesn't appear to hang
- Spawns a named screen session 'devshell', to avoid confusion when the user already has other screen sessions runningPull 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.
Signature · 5 lines
Christopher Larson clarson at kergoth dot com Founder - BitBake, OpenEmbedded, OpenZaurus Maintainer - Tslib Senior Software Engineer, Mentor Graphics
Quoted 16 lines · Chris Larson
Quoted 15 lines · Chris Larson
From: Chris Larson <[email protected]>
- 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_devshelldoesn't appear to hang
- Spawns a named screen session 'devshell', to avoid confusion when the user already has other screen sessions running
Quoted 6 lines
Quoted 3 lines
Pull URL: https://github.com/kergoth/oe-core
Branch: devshell
Browse: https://github.com/kergoth/oe-core/commits/devshellNote: 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).
Signature · 5 lines
Christopher Larson clarson at kergoth dot com Founder - BitBake, OpenEmbedded, OpenZaurus Maintainer - Tslib Senior Software Engineer, Mentor Graphics