[elbe-devel] [PATCH v2 09/13] Debianize - More panels

dion at linutronix.de dion at linutronix.de
Thu Aug 1 17:49:30 CEST 2019


From: Olivier Dion <dion at linutronix.de>

Changing the old forms to panels using the urwid API.

Signed-off-by: Olivier Dion <dion at linutronix.de>
---
 elbepack/debianize/panels/barebox.py | 60 +++++++++++++++++++++++++
 elbepack/debianize/panels/base.py    | 14 ++----
 elbepack/debianize/panels/kernel.py  | 86 ++++++++++++++++++++++++++++++++++++
 elbepack/debianize/panels/uboot.py   | 86 ++++++++++++++++++++++++++++++++++++
 4 files changed, 236 insertions(+), 10 deletions(-)
 create mode 100644 elbepack/debianize/panels/barebox.py
 create mode 100644 elbepack/debianize/panels/kernel.py
 create mode 100644 elbepack/debianize/panels/uboot.py

diff --git a/elbepack/debianize/panels/barebox.py b/elbepack/debianize/panels/barebox.py
new file mode 100644
index 00000000..f6ee16fb
--- /dev/null
+++ b/elbepack/debianize/panels/barebox.py
@@ -0,0 +1,60 @@
+# ELBE - Debian Based Embedded Rootfilesystem Builder
+# Copyright (c) 2017 Torben Hohn <torben.hohn at linutronix.de>
+# Copyright (c) 2017 Manuel Traut <manut at linutronix.de>
+# Copyright (c) 2019 Olivier Dion <dion at linutronix.de>
+#
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+import os
+
+from shutil import copyfile
+
+from elbepack.debianize.panels.base import Panel
+from elbepack.debianize.widgets.edit import Edit
+
+from elbepack.directories import mako_template_dir
+from elbepack.templates import template
+from elbepack.shellhelper import system
+
+
+class BareBox(Panel):
+
+    match_files = ['Kbuild', 'Kconfig', 'README', 'Documentation/barebox.svg']
+
+    def __init__(self):
+
+        imgname = Edit("Image name", "barebox-phytec-phycore-imx6dl-som-nand-256mb.img")
+        defconfig = Edit("Def config", "imx_v7_defconfig")
+        cross = Edit("CROSS_COMPILE", "arm-linux-gnueabihf-")
+        k_version = Edit("BareBox Version", "2016.10")
+
+        grid_elements = [
+            {"imgname":imgname, "defconfig":defconfig},
+            {"cross":cross, "k_version":k_version}
+        ]
+
+        super(BareBox, self).__init__(grid_elements)
+
+    def debianize(self):
+
+        self.tmpl_dir = os.path.join(mako_template_dir, 'debianize/barebox')
+        pkg_name = self.deb['p_name'] + '-' + self.deb['k_version']
+
+        for tmpl in ['control', 'rules']:
+            with open(os.path.join('debian/', tmpl), 'w') as f:
+                mako = os.path.join(self.tmpl_dir, tmpl + '.mako')
+                f.write(template(mako, self.deb))
+
+        cmd = 'dch --package barebox-' + pkg_name + \
+            ' -v ' + self.deb['p_version'] + \
+            ' --create -M -D ' + self.deb['release'] + \
+            ' "generated by elbe debianize"'
+        system(cmd)
+
+        copyfile(os.path.join(self.tmpl_dir, 'barebox-image.install'),
+                 'debian/barebox-image-' + pkg_name + '.install')
+        copyfile(os.path.join(self.tmpl_dir, 'barebox-tools.install'),
+                 'debian/barebox-tools-' + pkg_name + '.install')
+
+        self.hint = "use 'dpkg-buildpackage -a%s' to build the package" % (
+                self.deb['p_arch'])
diff --git a/elbepack/debianize/panels/base.py b/elbepack/debianize/panels/base.py
index 54ab089e..a350e33f 100644
--- a/elbepack/debianize/panels/base.py
+++ b/elbepack/debianize/panels/base.py
@@ -8,7 +8,6 @@
 
 
 import os
-from enum import Enum
 
 from shutil import copyfile
 
@@ -20,12 +19,7 @@ from elbepack.debianize.widgets.radio import RadioGroup
 from elbepack.templates import template
 
 
-class StrEnum(Enum):
-    def __str__(self):
-        return self.value
-
-
-class Arch(StrEnum):
+class Arch(object):
     ARM64 = "arm64"
     ARMHF = "armhf"
     ARMEL = "armel"
@@ -34,13 +28,13 @@ class Arch(StrEnum):
     POWER = "powerpc"
 
 
-class Format(StrEnum):
+class Format(object):
     NATIVE = "native"
     GIT = "git"
     QUILT = "quilt"
 
 
-class Release(StrEnum):
+class Release(object):
     STABLE = "stable"
     OLDSTABLE = "oldstable"
     TESTING = "testing"
@@ -80,7 +74,7 @@ class Panel(Form):
         for element in grid_elements:
             grid.append(element)
 
-        super().__init__(grid)
+        super(Panel, self).__init__(grid)
 
 
     def get_k_arch(self):
diff --git a/elbepack/debianize/panels/kernel.py b/elbepack/debianize/panels/kernel.py
new file mode 100644
index 00000000..655f134f
--- /dev/null
+++ b/elbepack/debianize/panels/kernel.py
@@ -0,0 +1,86 @@
+# ELBE - Debian Based Embedded Rootfilesystem Builder
+# Copyright (c) 2016-2017 John Ogness <john.ogness at linutronix.de>
+# Copyright (c) 2016-2017 Manuel Traut <manut at linutronix.de>
+# Copyright (c) 2017 Torben Hohn <torben.hohn at linutronix.de>
+# Copyright (c) 2019 Olivier Dion <dion at linutronix.de>
+#
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+import os
+
+from shutil import copyfile
+
+from elbepack.debianize.panels.base import Panel
+from elbepack.debianize.widgets.edit import Edit
+from elbepack.debianize.widgets.radio import RadioGroup
+
+from elbepack.directories import mako_template_dir
+from elbepack.templates import template
+from elbepack.shellhelper import system
+
+
+class ImgType(object):
+    BZ = "bzImage"
+    ZI = "zImage"
+    UI = "uImage"
+    I = "Image"
+
+class Kernel(Panel):
+
+    match_files = ['Kbuild', 'Kconfig', 'MAINTAINERS', 'kernel/futex.c']
+
+    def __init__(self):
+
+        loadaddr = Edit("Load Addr", "0x800800")
+        defconfig = Edit("defconfig", "omap2plus_defconfig")
+        imgtype = RadioGroup("Image Format", ImgType, ImgType.BZ)
+        cross = Edit("Cross compile", "arm-linux-gnueabihf-")
+        k_version = Edit("Kernel version", "4.4")
+
+        grid_elements = [
+            {"loadaddr":loadaddr, "defconfig":defconfig},
+            {"imgtype":imgtype, "cross_compile":cross},
+            {"k_version":k_version}
+        ]
+
+        super(Kernel, self).__init__(grid_elements)
+
+    @staticmethod
+    def imgtype_to_install(imgtype):
+        c = imgtype[0]
+        if c == 'z':
+            return "zinstall"
+        if c == 'u':
+            return "uinstall"
+        return "install"
+
+    def debianize(self):
+
+        self.deb['imgtype_install'] = Kernel.imgtype_to_install(self.deb['imgtype'])
+        self.tmpl_dir = os.path.join(mako_template_dir, 'debianize/kernel')
+        pkg_name = self.deb['k_version'] + '-' + self.deb['p_name']
+
+        for tmpl in [
+            'control',
+            'rules',
+            'preinst',
+            'postinst',
+            'prerm',
+                'postrm']:
+            with open(os.path.join('debian/', tmpl), 'w') as f:
+                mako = os.path.join(self.tmpl_dir, tmpl + '.mako')
+                f.write(template(mako, self.deb))
+
+        cmd = 'dch --package linux-' + pkg_name + \
+            ' -v ' + self.deb['p_version'] + \
+            ' --create -M -D ' + self.deb['release'] + \
+            ' "generated by elbe debianize"'
+        system(cmd)
+
+        copyfile(os.path.join(self.tmpl_dir, 'linux-image.install'),
+                 'debian/linux-image-' + pkg_name + '.install')
+        copyfile(os.path.join(self.tmpl_dir, 'linux-headers.install'),
+                 'debian/linux-headers-' + pkg_name + '.install')
+
+        self.hint = "use 'dpkg-buildpackage -a%s' to build the package" % (
+                self.deb['p_arch'])
diff --git a/elbepack/debianize/panels/uboot.py b/elbepack/debianize/panels/uboot.py
new file mode 100644
index 00000000..ed2fb663
--- /dev/null
+++ b/elbepack/debianize/panels/uboot.py
@@ -0,0 +1,86 @@
+# ELBE - Debian Based Embedded Rootfilesystem Builder
+# Copyright (c) 2018 Philipp Rosenberger <p.rosenberger at linutronix.de>
+# Copyright (c) 2018 Torben Hohn <torben.hohn at linutronix.de>
+# Copyright (c) 2019 Olivier Dion <dion at linutronix.de>
+#
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+import os
+
+from shutil import copyfile
+
+from pkg_resources import parse_version as V
+
+from elbepack.debianize.base.tui import TUI
+from elbepack.debianize.panels.base import Panel
+from elbepack.debianize.widgets.edit import Edit
+
+from elbepack.templates import template
+from elbepack.directories import mako_template_dir
+from elbepack.shellhelper import system
+
+
+class UBoot(Panel):
+
+    copyright_fname = 'Licenses/README'
+    match_files = ['Makefile', 'Kbuild', 'Kconfig', 'MAINTAINERS', 'config.mk']
+
+    def __init__(self):
+
+        defconfig = Edit("defconfig", "mx7dsabresd_defconfig")
+        cross = Edit("Cross compile", "arm-linux-gnueabihf-")
+        imgname = Edit("Image name", "u-boot-dtb.imx")
+        k_version = Edit("U-Boot Version")
+
+        grid_elements = [
+            {"defconfig": defconfig, "imgname": imgname},
+            {"cross_compile": cross, "k_version": k_version},
+        ]
+
+        super(UBoot, self).__init__(grid_elements)
+
+        self.get_version()
+        k_version.base_widget.set_edit_text(self.verstr)
+
+    def get_version(self):
+        with open('Makefile', 'r') as f:
+            for line in f:
+                if line.startswith('VERSION = '):
+                    version = line.split('=')[1].strip()
+                elif line.startswith('PATCHLEVEL = '):
+                    patchlevel = line.split('=')[1].strip()
+                    break
+
+        self.verstr = version + '.' + patchlevel
+        # With v2014.04 the u-boot Makefile knows the 'tools-only' target.
+        if V(self.verstr) < V('2014.04'):
+            TUI.printf("Only U-Boot >= 2014.04 is supported.\n"
+                      "This is version '%s'" % self.verstr)
+
+        if V(self.verstr) >= V('2017.09'):
+            self.deb['envtools'] = 'envtools'
+        else:
+            self.deb['envtools'] = 'env'
+
+    def debianize(self):
+
+        self.tmpl_dir = os.path.join(mako_template_dir, 'debianize/u-boot')
+        pkg_name = self.deb['p_name'] + '-' + self.deb['k_version']
+
+        for tmpl in ['control', 'rules']:
+            with open(os.path.join('debian/', tmpl), 'w') as f:
+                mako = os.path.join(self.tmpl_dir, tmpl + '.mako')
+                f.write(template(mako, self.deb))
+
+        cmd = 'dch --package u-boot-' + pkg_name + \
+            ' -v ' + self.deb['p_version'] + \
+            ' --create -M -D ' + self.deb['release'] + \
+            ' "generated by elbe debianize"'
+        system(cmd)
+
+        copyfile(os.path.join(self.tmpl_dir, 'u-boot-image.install'),
+                 'debian/u-boot-image-' + pkg_name + '.install')
+        copyfile(os.path.join(self.tmpl_dir, 'u-boot-tools.install'),
+                 'debian/u-boot-tools-' + pkg_name + '.install')
+
+        TUI.printf("use 'dpkg-buildpackage -a%s' to build the package" % self.deb['p_arch'])
-- 
2.11.0




More information about the elbe-devel mailing list