[elbe-devel] [PATCH v2 07/13] Debianize - Panel widget

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


From: Olivier Dion <dion at linutronix.de>

A panel is really just a form with less abstraction.

Signed-off-by: Olivier Dion <dion at linutronix.de>
Reviewed-by: Bastian Germann <bage at linutronix.de>
---
 elbepack/debianize/panels/base.py | 118 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 118 insertions(+)
 create mode 100644 elbepack/debianize/panels/base.py

diff --git a/elbepack/debianize/panels/base.py b/elbepack/debianize/panels/base.py
new file mode 100644
index 00000000..54ab089e
--- /dev/null
+++ b/elbepack/debianize/panels/base.py
@@ -0,0 +1,118 @@
+# ELBE - Debian Based Embedded Rootfilesystem Builder
+# Copyright (c) 2016-2017 Manuel Traut <manut at linutronix.de>
+# Copyright (c) 2017 Torben Hohn <torben.hohn at linutronix.de>
+# Copyright (c) 2017 Martin Kaistra <martin.kaistra at linutronix.de>
+# Copyright (c) 2019 Olivier Dion <dion at linutronix.de>
+#
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+
+import os
+from enum import Enum
+
+from shutil import copyfile
+
+from elbepack.debianize.base.tui import TUI
+from elbepack.debianize.widgets.form import Form
+from elbepack.debianize.widgets.edit import Edit
+from elbepack.debianize.widgets.radio import RadioGroup
+
+from elbepack.templates import template
+
+
+class StrEnum(Enum):
+    def __str__(self):
+        return self.value
+
+
+class Arch(StrEnum):
+    ARM64 = "arm64"
+    ARMHF = "armhf"
+    ARMEL = "armel"
+    AMD64 = "amd64"
+    I386  = "i386"
+    POWER = "powerpc"
+
+
+class Format(StrEnum):
+    NATIVE = "native"
+    GIT = "git"
+    QUILT = "quilt"
+
+
+class Release(StrEnum):
+    STABLE = "stable"
+    OLDSTABLE = "oldstable"
+    TESTING = "testing"
+    UNSTABLE = "unstable"
+    EXPERIMENTAL = "experimental"
+
+
+class Panel(Form):
+
+    copyright_fname = "COPYING"
+
+    def __init__(self, grid_elements):
+
+        self.deb = {}
+        self.tmpl_dir = None
+        self.hint = None
+
+        fullname = os.environ.get('DEBFULLNAME', "Max Mustermann")
+        email = os.environ.get('DEBEMAIL', "max at mustermann.org")
+
+        p_name = Edit("Name", "elbe")
+        p_version = Edit("Version", "1.0")
+        p_arch = RadioGroup("Arch", Arch, Arch.ARM64)
+        src_fmt = RadioGroup("Format", Format, Format.NATIVE)
+        release = RadioGroup("Release", Release, Release.STABLE)
+
+        m_name = Edit("Maintainer", fullname)
+        m_mail = Edit("Mail", email)
+
+        grid = [
+            {"p_name":p_name, "p_version":p_version},
+            {"p_arch":p_arch,"release":release},
+            {"source_format":src_fmt},
+            {"m_name":m_name, "m_mail":m_mail},
+        ]
+
+        for element in grid_elements:
+            grid.append(element)
+
+        super().__init__(grid)
+
+
+    def get_k_arch(self):
+        """ get_k_arch() may be used in debianize() """
+
+        if self.deb['p_arch'] == 'armhf':
+            return 'arm'
+        elif self.deb['p_arch'] == 'armel':
+            return 'arm'
+        elif self.deb['p_arch'] == 'amd64':
+            return 'x86_64'
+        else:
+            return self.deb['p_arch']
+
+    def on_submit(self, datas):
+
+        for key, value in datas.items():
+            self.deb[key] = str(value)
+
+        self.deb['k_arch'] = self.get_k_arch()
+
+        os.mkdir('debian')
+        os.mkdir('debian/source')
+
+        self.debianize()
+
+        with open('debian/source/format', 'w') as f:
+            mako = os.path.join(self.tmpl_dir, 'format.mako')
+            f.write(template(mako, self.deb))
+
+        copyfile(self.copyright_fname, 'debian/copyright')
+        with open('debian/compat', 'w') as f:
+            f.write('9')
+
+        TUI.quit()
-- 
2.11.0




More information about the elbe-devel mailing list