[elbe-devel] [PATCH 03/10] debianize: refactor debianize to make it more similar to finetuning

Torben Hohn torben.hohn at linutronix.de
Wed Mar 22 17:44:10 CET 2017


---
 elbepack/commands/debianize.py  | 25 +++++++++++--------------
 elbepack/debianize/base.py      | 19 +++++++++++++++++++
 elbepack/debianize/debianize.py | 11 ++---------
 elbepack/debianize/kernel.py    |  6 ++++++
 elbepack/debianize/uboot.py     |  6 ++++++
 5 files changed, 44 insertions(+), 23 deletions(-)

diff --git a/elbepack/commands/debianize.py b/elbepack/commands/debianize.py
index 252d531..32ca7c9 100644
--- a/elbepack/commands/debianize.py
+++ b/elbepack/commands/debianize.py
@@ -21,22 +21,19 @@
 import os
 import sys
 
-from elbepack.debianize.debianize import files, debianizer, Debianize
+from elbepack.debianize.debianize import Debianize, DebianizeBase
 
 def run_command ( args ):
     if os.path.exists ('debian'):
         print 'debian folder already exists, nothing to do'
-        sys.exit (-1)
+        sys.exit (10)
 
-    for key in files.keys ():
-       match = True
-       for f in files[key]:
-           if not os.path.exists (f):
-               match = False
-       if match:
-           Debianize (debianizer[key]).run ()
-           sys.exit(-1)
-
-    print ("this creates a debinization of a kernel source")
-    print ("please run the command from kernel source dir")
-    sys.exit (-2)
+    try:
+        debianizer = DebianizeBase.get_debianizer ()
+        Debianize (debianizer).run ()
+        sys.exit(10)
+    except KeyError:
+        print ("This creates a debinization of a source directory.")
+        print ("The software was not able to identify the current directory.")
+        print ("Please run the command from source directory")
+        sys.exit (20)
diff --git a/elbepack/debianize/base.py b/elbepack/debianize/base.py
index 14e3a41..7718f7f 100644
--- a/elbepack/debianize/base.py
+++ b/elbepack/debianize/base.py
@@ -31,6 +31,25 @@ from shutil import copyfile
 from elbepack.templates import template
 
 class DebianizeBase (FormMultiPage):
+
+    srctypes = {}
+
+    @classmethod
+    def register (cls, srctype):
+        cls.srctypes[srctype.name] = srctype
+
+    @classmethod
+    def get_debianizer (cls):
+        for t in cls.srctypes.values ():
+           match = True
+           for f in t.files:
+               if not os.path.exists (f):
+                   match = False
+           if match:
+               return t
+
+        raise KeyError
+
     def __init__ (self):
         self.deb = { }
         self.tmpl_dir = None
diff --git a/elbepack/debianize/debianize.py b/elbepack/debianize/debianize.py
index 9a97492..b6cf5a9 100644
--- a/elbepack/debianize/debianize.py
+++ b/elbepack/debianize/debianize.py
@@ -26,18 +26,11 @@ from npyscreen import TitleText, TitleSelectOne, ButtonPress
 
 from shutil import copyfile
 
-##############################################################################
-#TODO before adding another helper, refactor the code to be 'plugin-like',
-# see finetuning for example.
-
 from elbepack.debianize.kernel import Kernel
 from elbepack.debianize.uboot  import UBoot
-debianizer = {'kernel': Kernel,
-              'uboot':  UBoot}
 
-files = {'kernel': ['Kbuild', 'Kconfig', 'MAINTAINERS', 'REPORTING-BUGS'],
-         'uboot':  ['Kbuild', 'Kconfig', 'MAINTAINERS', 'config.mk'],}
-##############################################################################
+from elbepack.debianize.base import DebianizeBase
+
 
 class Debianize (NPSAppManaged):
     def __init__ (self, debianizer):
diff --git a/elbepack/debianize/kernel.py b/elbepack/debianize/kernel.py
index 6030843..eea4736 100644
--- a/elbepack/debianize/kernel.py
+++ b/elbepack/debianize/kernel.py
@@ -29,6 +29,10 @@ from elbepack.directories import mako_template_dir
 from elbepack.debianize.base import DebianizeBase, template
 
 class Kernel (DebianizeBase):
+
+    name  = "kernel"
+    files = ['Kbuild', 'Kconfig', 'MAINTAINERS', 'REPORTING-BUGS']
+
     def __init__ (self):
         self.imgtypes = ["bzImage", "zImage", "uImage", "Image"]
         self.imgtypes_install = ["install", "zinstall", "uinstall", "install"]
@@ -89,3 +93,5 @@ class Kernel (DebianizeBase):
                   'debian/linux-headers-'+pkg_name+'.install')
 
         self.hint = "use 'dpkg-buildpackage -a%s' to build the package" % self.deb['p_arch']
+
+DebianizeBase.register (Kernel)
diff --git a/elbepack/debianize/uboot.py b/elbepack/debianize/uboot.py
index 99c4152..0467620 100644
--- a/elbepack/debianize/uboot.py
+++ b/elbepack/debianize/uboot.py
@@ -31,6 +31,10 @@ from elbepack.debianize.base import DebianizeBase, template
 # this is just a template to show how debianizing another component should work
 
 class UBoot (DebianizeBase):
+
+    name  = "uboot"
+    files = ['Kbuild', 'Kconfig', 'MAINTAINERS', 'config.mk']
+
     def __init__ (self):
         print ("debianization of uboot is not supported at the moment")
         sys.exit (-2)
@@ -41,3 +45,5 @@ class UBoot (DebianizeBase):
 
     def debianize (self):
         pass
+
+DebianizeBase.register (UBoot)
-- 
2.1.4





More information about the elbe-devel mailing list