Alon Bar-Lev has uploaded a new change for review.

Change subject: core: reduce the use of lists
......................................................................

core: reduce the use of lists

apparently the default object initialization is happening once per
process execution, so must be avoided.

also reduce other usages.

Change-Id: I33078e67c7235f9cdd7e82e1ec2714a5f90426b2
Reported-By: Antoni Segura Puimedon <[email protected]>
Signed-off-by: Alon Bar-Lev <[email protected]>
---
M src/otopi/filetransaction.py
M src/otopi/miniyum.py
M src/otopi/plugin.py
M src/otopi/transaction.py
M src/plugins/otopi/dialog/cli.py
M src/plugins/otopi/network/hostname.py
M src/plugins/otopi/packagers/yumpackager.py
M src/plugins/otopi/services/openrc.py
M src/plugins/otopi/services/rhel.py
M src/plugins/otopi/services/systemd.py
10 files changed, 20 insertions(+), 19 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/otopi refs/changes/96/17496/1

diff --git a/src/otopi/filetransaction.py b/src/otopi/filetransaction.py
index a181b30..30239fd 100644
--- a/src/otopi/filetransaction.py
+++ b/src/otopi/filetransaction.py
@@ -113,7 +113,7 @@
         dgroup=None,
         enforcePermissions=False,
         visibleButUnsafe=False,
-        modifiedList=[],
+        modifiedList=None,
     ):
         """Constructor.
 
@@ -296,7 +296,8 @@
                     source=self._tmpname,
                     destination=self._name,
                 )
-            self._modifiedList.append(self._name)
+            if self._modifiedList is not None:
+                self._modifiedList.append(self._name)
 
 
 # vim: expandtab tabstop=4 shiftwidth=4
diff --git a/src/otopi/miniyum.py b/src/otopi/miniyum.py
index 2a6a474..03f1068 100755
--- a/src/otopi/miniyum.py
+++ b/src/otopi/miniyum.py
@@ -996,7 +996,7 @@
             miniyum.clean(['expire-cache'])
 
         miniyumsink.info('Search Summary:')
-        for p in miniyum.queryPackages(patterns=['vdsm']):
+        for p in miniyum.queryPackages(patterns=('vdsm',)):
             miniyumsink.info(
                 _('    {operation} - {package}').format(
                     operation=p['operation'],
diff --git a/src/otopi/plugin.py b/src/otopi/plugin.py
index 779eab9..8a4de0f 100644
--- a/src/otopi/plugin.py
+++ b/src/otopi/plugin.py
@@ -234,8 +234,8 @@
 def event(
     name=None,
     stage=None,
-    before=[],
-    after=[],
+    before=(),
+    after=(),
     priority=Stages.PRIORITY_DEFAULT,
     condition=None,
 ):
diff --git a/src/otopi/transaction.py b/src/otopi/transaction.py
index 2eef80c..e4aef93 100644
--- a/src/otopi/transaction.py
+++ b/src/otopi/transaction.py
@@ -84,7 +84,7 @@
                 self._failed = True
                 raise
 
-    def __init__(self, elements=[]):
+    def __init__(self, elements=()):
         """Constructor.
 
         Keyword arguments:
diff --git a/src/plugins/otopi/dialog/cli.py b/src/plugins/otopi/dialog/cli.py
index 20162ed..835dc20 100644
--- a/src/plugins/otopi/dialog/cli.py
+++ b/src/plugins/otopi/dialog/cli.py
@@ -51,7 +51,7 @@
         Queries.TERMINATION_COMMAND -- termination command.
 
     """
-    def _command(command, description, stages=[]):
+    def _command(command, description, stages=()):
         def decorator(f):
             f.decoration_command = {
                 'method': f,
@@ -211,7 +211,7 @@
     @_command(
         command='abort',
         description=_('Abort process'),
-        stages=[plugin.Stages.STAGE_CUSTOMIZATION],
+        stages=(plugin.Stages.STAGE_CUSTOMIZATION,),
     )
     def _cmd_abort(self, cmd):
         parser = self._MyOptionParser(cmd[0], logger=self.logger)
@@ -227,7 +227,7 @@
     @_command(
         command='install',
         description=_('Install software'),
-        stages=[plugin.Stages.STAGE_CUSTOMIZATION],
+        stages=(plugin.Stages.STAGE_CUSTOMIZATION,),
     )
     def _cmd_install(self, cmd):
         parser = self._MyOptionParser(cmd[0], logger=self.logger)
@@ -243,7 +243,7 @@
     @_command(
         command='quit',
         description=_('Quit'),
-        stages=[plugin.Stages.STAGE_PRE_TERMINATE],
+        stages=(plugin.Stages.STAGE_PRE_TERMINATE,),
     )
     def _cmd_quit(self, cmd):
         parser = self._MyOptionParser(cmd[0], logger=self.logger)
diff --git a/src/plugins/otopi/network/hostname.py 
b/src/plugins/otopi/network/hostname.py
index 55c5f0f..50e2bbc 100644
--- a/src/plugins/otopi/network/hostname.py
+++ b/src/plugins/otopi/network/hostname.py
@@ -63,7 +63,7 @@
         stage=plugin.Stages.STAGE_INTERNAL_PACKAGES,
     )
     def _internal_packages(self):
-        self.packager.install(packages=['iproute'])
+        self.packager.install(packages=('iproute',))
 
     @plugin.event(
         stage=plugin.Stages.STAGE_VALIDATION,
diff --git a/src/plugins/otopi/packagers/yumpackager.py 
b/src/plugins/otopi/packagers/yumpackager.py
index c9e55b0..292f55a 100644
--- a/src/plugins/otopi/packagers/yumpackager.py
+++ b/src/plugins/otopi/packagers/yumpackager.py
@@ -63,8 +63,8 @@
 
     def _getMiniYum(
         self,
-        disabledPlugins=[],
-        enabledPlugins=[]
+        disabledPlugins=(),
+        enabledPlugins=(),
     ):
         from otopi import miniyum
 
diff --git a/src/plugins/otopi/services/openrc.py 
b/src/plugins/otopi/services/openrc.py
index 4e99c19..5dcb310 100644
--- a/src/plugins/otopi/services/openrc.py
+++ b/src/plugins/otopi/services/openrc.py
@@ -48,9 +48,9 @@
 
     @plugin.event(
         stage=plugin.Stages.STAGE_VALIDATION,
-        after=[
+        after=(
             constants.Stages.SYSTEM_COMMAND_DETECTION,
-        ],
+        ),
     )
     def _programs(self):
         rc = self.command.get('rc', optional=True)
diff --git a/src/plugins/otopi/services/rhel.py 
b/src/plugins/otopi/services/rhel.py
index d91e386..4f80b72 100644
--- a/src/plugins/otopi/services/rhel.py
+++ b/src/plugins/otopi/services/rhel.py
@@ -50,9 +50,9 @@
 
     @plugin.event(
         stage=plugin.Stages.STAGE_PROGRAMS,
-        after=[
+        after=(
             constants.Stages.SYSTEM_COMMAND_DETECTION,
-        ],
+        ),
     )
     def _programs(self):
         haveSystemd = False
diff --git a/src/plugins/otopi/services/systemd.py 
b/src/plugins/otopi/services/systemd.py
index 208cfe5..e7857b8 100644
--- a/src/plugins/otopi/services/systemd.py
+++ b/src/plugins/otopi/services/systemd.py
@@ -46,9 +46,9 @@
 
     @plugin.event(
         stage=plugin.Stages.STAGE_PROGRAMS,
-        after=[
+        after=(
             constants.Stages.SYSTEM_COMMAND_DETECTION,
-        ],
+        ),
     )
     def _programs(self):
         systemctl = self.command.get('systemctl', optional=True)


-- 
To view, visit http://gerrit.ovirt.org/17496
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I33078e67c7235f9cdd7e82e1ec2714a5f90426b2
Gerrit-PatchSet: 1
Gerrit-Project: otopi
Gerrit-Branch: master
Gerrit-Owner: Alon Bar-Lev <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to