[elbe-devel] [PATCH v2 1/1] Add decorator for FinetuningAction registration
dion at linutronix.de
dion at linutronix.de
Wed Jun 5 16:42:14 CEST 2019
From: Olivier Dion <dion at linutronix.de>
The decorator takes 1 argument, 'tag', and 1 optional argument,
'register' set to 'True' by default.
The 'tag' argument is a string that represent the xml tag for the
finetuning action.
The 'register' argument can be set to 'False' to ignore the
registration in the decorator.
Example
=======
``````````````````````````````````````````````````````````````````````
@FinetuningAction.register("my-xml-tag")
MyAction(FinetuningAction):
<...>
@FinetuningAction.register("my-xml-tag-not-ready", register=False)
MyActionNotReady(FinetuningAction):
<...>
````````````````````````````````````````````````````````````
Signed-off-by: Olivier Dion <dion at linutronix.de>
---
elbepack/finetuning.py | 182 ++++++++++---------------------------------------
1 file changed, 36 insertions(+), 146 deletions(-)
diff --git a/elbepack/finetuning.py b/elbepack/finetuning.py
index 426097aa..7f20436e 100644
--- a/elbepack/finetuning.py
+++ b/elbepack/finetuning.py
@@ -34,8 +34,13 @@ class FinetuningAction(object):
actiondict = {}
@classmethod
- def register(cls, action):
- cls.actiondict[action.tag] = action
+ def register(cls, tag, register=True):
+ def _register(action):
+ action.tag = tag
+ if register is True:
+ cls.actiondict[tag] = action
+ return action
+ return _register
def __new__(cls, node):
action = cls.actiondict[node.tag]
@@ -51,10 +56,9 @@ class FinetuningAction(object):
self.execute(log, buildenv, target)
+ at FinetuningAction.register('image_finetuning', False)
class ImageFinetuningAction(FinetuningAction):
- tag = 'image_finetuning'
-
def __init__(self, node):
FinetuningAction.__init__(self, node)
@@ -66,10 +70,9 @@ class ImageFinetuningAction(FinetuningAction):
raise NotImplementedError('execute_img() not implemented')
+ at FinetuningAction.register('rm')
class RmAction(FinetuningAction):
- tag = 'rm'
-
def __init__(self, node):
FinetuningAction.__init__(self, node)
@@ -88,13 +91,9 @@ class RmAction(FinetuningAction):
log.do("rm -rvf '%s'" % f)
-FinetuningAction.register(RmAction)
-
-
+ at FinetuningAction.register('mkdir')
class MkdirAction(FinetuningAction):
- tag = 'mkdir'
-
def __init__(self, node):
FinetuningAction.__init__(self, node)
@@ -102,13 +101,9 @@ class MkdirAction(FinetuningAction):
log.do("mkdir -p " + target.fname(self.node.et.text))
-FinetuningAction.register(MkdirAction)
-
-
+ at FinetuningAction.register('mknod')
class MknodAction(FinetuningAction):
- tag = 'mknod'
-
def __init__(self, node):
FinetuningAction.__init__(self, node)
@@ -120,14 +115,9 @@ class MknodAction(FinetuningAction):
" " +
self.node.et.attrib['opts'])
-
-FinetuningAction.register(MknodAction)
-
-
+ at FinetuningAction.register('buildenv_mkdir')
class BuildenvMkdirAction(FinetuningAction):
- tag = 'buildenv_mkdir'
-
def __init__(self, node):
FinetuningAction.__init__(self, node)
@@ -135,13 +125,9 @@ class BuildenvMkdirAction(FinetuningAction):
log.do("mkdir -p " + buildenv.rfs.fname(self.node.et.text))
-FinetuningAction.register(BuildenvMkdirAction)
-
-
+ at FinetuningAction.register('cp')
class CpAction(FinetuningAction):
- tag = 'cp'
-
def __init__(self, node):
FinetuningAction.__init__(self, node)
@@ -151,13 +137,9 @@ class CpAction(FinetuningAction):
log.do("cp -av " + f + " " + target.fname(self.node.et.text))
-FinetuningAction.register(CpAction)
-
-
+ at FinetuningAction.register('buildenv_cp')
class BuildenvCpAction(FinetuningAction):
- tag = 'buildenv_cp'
-
def __init__(self, node):
FinetuningAction.__init__(self, node)
@@ -167,13 +149,9 @@ class BuildenvCpAction(FinetuningAction):
log.do("cp -av " + f + " " + buildenv.rfs.fname(self.node.et.text))
-FinetuningAction.register(BuildenvCpAction)
-
-
+ at FinetuningAction.register('b2t_cp')
class B2TCpAction(FinetuningAction):
- tag = 'b2t_cp'
-
def __init__(self, node):
FinetuningAction.__init__(self, node)
@@ -183,13 +161,9 @@ class B2TCpAction(FinetuningAction):
log.do("cp -av " + f + " " + target.fname(self.node.et.text))
-FinetuningAction.register(B2TCpAction)
-
-
+ at FinetuningAction.register('t2b_cp')
class T2BCpAction(FinetuningAction):
- tag = 't2b_cp'
-
def __init__(self, node):
FinetuningAction.__init__(self, node)
@@ -198,14 +172,9 @@ class T2BCpAction(FinetuningAction):
for f in src:
log.do("cp -av " + f + " " + buildenv.rfs.fname(self.node.et.text))
-
-FinetuningAction.register(T2BCpAction)
-
-
+ at FinetuningAction.register('t2p_mv')
class T2PMvAction(FinetuningAction):
- tag = 't2p_mv'
-
def __init__(self, node):
FinetuningAction.__init__(self, node)
@@ -221,13 +190,9 @@ class T2PMvAction(FinetuningAction):
log.do("mv -v " + f + " " + dest)
-FinetuningAction.register(T2PMvAction)
-
-
+ at FinetuningAction.register('mv')
class MvAction(FinetuningAction):
- tag = 'mv'
-
def __init__(self, node):
FinetuningAction.__init__(self, node)
@@ -237,13 +202,9 @@ class MvAction(FinetuningAction):
log.do("mv -v " + f + " " + target.fname(self.node.et.text))
-FinetuningAction.register(MvAction)
-
-
+ at FinetuningAction.register('ln')
class LnAction(FinetuningAction):
- tag = 'ln'
-
def __init__(self, node):
FinetuningAction.__init__(self, node)
@@ -254,13 +215,9 @@ class LnAction(FinetuningAction):
(self.node.et.attrib['path'], self.node.et.text))
-FinetuningAction.register(LnAction)
-
-
+ at FinetuningAction.register('buildenv_mv')
class BuildenvMvAction(FinetuningAction):
- tag = 'buildenv_mv'
-
def __init__(self, node):
FinetuningAction.__init__(self, node)
@@ -269,14 +226,9 @@ class BuildenvMvAction(FinetuningAction):
for f in src:
log.do("mv -v " + f + " " + buildenv.rfs.fname(self.node.et.text))
-
-FinetuningAction.register(BuildenvMvAction)
-
-
+ at FinetuningAction.register('adduser')
class AddUserAction(FinetuningAction):
- tag = 'adduser'
-
def __init__(self, node):
FinetuningAction.__init__(self, node)
@@ -319,13 +271,9 @@ class AddUserAction(FinetuningAction):
self.node.et.text))
-FinetuningAction.register(AddUserAction)
-
-
+ at FinetuningAction.register('addgroup')
class AddGroupAction(FinetuningAction):
- tag = 'addgroup'
-
def __init__(self, node):
FinetuningAction.__init__(self, node)
@@ -343,13 +291,9 @@ class AddGroupAction(FinetuningAction):
self.node.et.text))
-FinetuningAction.register(AddGroupAction)
-
-
+ at FinetuningAction.register('file')
class AddFileAction(FinetuningAction):
- tag = 'file'
-
def __init__(self, node):
FinetuningAction.__init__(self, node)
@@ -406,13 +350,10 @@ class AddFileAction(FinetuningAction):
if mode is not None:
log.chroot(target.path, 'chmod "%s" "%s"' % (mode, dst))
-FinetuningAction.register(AddFileAction)
-
+ at FinetuningAction.register('raw_cmd')
class RawCmdAction(FinetuningAction):
- tag = 'raw_cmd'
-
def __init__(self, node):
FinetuningAction.__init__(self, node)
@@ -421,13 +362,9 @@ class RawCmdAction(FinetuningAction):
log.chroot(target.path, self.node.et.text)
-FinetuningAction.register(RawCmdAction)
-
-
+ at FinetuningAction.register('command')
class CmdAction(FinetuningAction):
- tag = 'command'
-
def __init__(self, node):
FinetuningAction.__init__(self, node)
@@ -436,13 +373,9 @@ class CmdAction(FinetuningAction):
log.chroot(target.path, "/bin/sh", stdin=self.node.et.text)
-FinetuningAction.register(CmdAction)
-
-
+ at FinetuningAction.register('buildenv_command')
class BuildenvCmdAction(FinetuningAction):
- tag = 'buildenv_command'
-
def __init__(self, node):
FinetuningAction.__init__(self, node)
@@ -451,13 +384,9 @@ class BuildenvCmdAction(FinetuningAction):
log.chroot(buildenv.path, "/bin/sh", stdin=self.node.et.text)
-FinetuningAction.register(BuildenvCmdAction)
-
-
+ at FinetuningAction.register('purge')
class PurgeAction(FinetuningAction):
- tag = 'purge'
-
def __init__(self, node):
FinetuningAction.__init__(self, node)
@@ -466,13 +395,9 @@ class PurgeAction(FinetuningAction):
log.chroot(target.path, "dpkg --purge " + self.node.et.text)
-FinetuningAction.register(PurgeAction)
-
-
+ at FinetuningAction.register('updated')
class UpdatedAction(FinetuningAction):
- tag = 'updated'
-
def __init__(self, node):
FinetuningAction.__init__(self, node)
@@ -560,13 +485,9 @@ class UpdatedAction(FinetuningAction):
target.touch_file('/var/cache/elbe/.downgrade_allowed')
-FinetuningAction.register(UpdatedAction)
-
-
+ at FinetuningAction.register('artifact')
class ArtifactAction(FinetuningAction):
- tag = 'artifact'
-
def __init__(self, node):
FinetuningAction.__init__(self, node)
@@ -577,13 +498,9 @@ class ArtifactAction(FinetuningAction):
target.images.append(self.node.et.text)
-FinetuningAction.register(ArtifactAction)
-
-
+ at FinetuningAction.register('rm_artifact')
class RmArtifactAction(FinetuningAction):
- tag = 'rm_artifact'
-
def __init__(self, node):
FinetuningAction.__init__(self, node)
@@ -595,13 +512,9 @@ class RmArtifactAction(FinetuningAction):
target.images.remove(self.node.et.text)
-FinetuningAction.register(ArtifactAction)
-
-
+ at FinetuningAction.register('losetup')
class LosetupAction(FinetuningAction):
- tag = 'losetup'
-
def __init__(self, node):
FinetuningAction.__init__(self, node)
@@ -624,13 +537,9 @@ class LosetupAction(FinetuningAction):
log.do(cmd)
-FinetuningAction.register(LosetupAction)
-
-
+ at FinetuningAction.register('img_convert')
class ImgConvertAction(FinetuningAction):
- tag = 'img_convert'
-
def __init__(self, node):
FinetuningAction.__init__(self, node)
@@ -666,13 +575,9 @@ class ImgConvertAction(FinetuningAction):
del target.image_packers[src]
-FinetuningAction.register(ImgConvertAction)
-
-
+ at FinetuningAction.register('set_packer')
class SetPackerAction(FinetuningAction):
- tag = 'set_packer'
-
def __init__(self, node):
FinetuningAction.__init__(self, node)
@@ -687,13 +592,9 @@ class SetPackerAction(FinetuningAction):
target.image_packers[img] = packers[packer]
-FinetuningAction.register(SetPackerAction)
-
-
+ at FinetuningAction.register('extract_partition')
class ExtractPartitionAction(ImageFinetuningAction):
- tag = 'extract_partition'
-
def __init__(self, node):
ImageFinetuningAction.__init__(self, node)
@@ -713,13 +614,9 @@ class ExtractPartitionAction(ImageFinetuningAction):
target.image_packers[self.node.et.text] = default_packer
-FinetuningAction.register(ExtractPartitionAction)
-
-
+ at FinetuningAction.register('copy_from_partition')
class CopyFromPartition(ImageFinetuningAction):
- tag = 'copy_from_partition'
-
def __init__(self, node):
ImageFinetuningAction.__init__(self, node)
@@ -753,13 +650,9 @@ class CopyFromPartition(ImageFinetuningAction):
target.images.append(aname)
-FinetuningAction.register(CopyFromPartition)
-
-
+ at FinetuningAction.register('copy_to_partition')
class CopyToPartition(ImageFinetuningAction):
- tag = 'copy_to_partition'
-
def __init__(self, node):
ImageFinetuningAction.__init__(self, node)
@@ -781,9 +674,6 @@ class CopyToPartition(ImageFinetuningAction):
log.do(cmd)
-FinetuningAction.register(CopyToPartition)
-
-
def do_finetuning(xml, log, buildenv, target):
if not xml.has('target/finetuning'):
--
2.11.0
More information about the elbe-devel
mailing list