URL: https://github.com/freeipa/freeipa/pull/1312
Author: slaykovsky
 Title: #1312: ipalib/frontend.py output_for_cli loops optimization
Action: opened

PR body:
"""
Trivial fix which removes unnecessary for loops.
"""

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/1312/head:pr1312
git checkout pr1312
From 528ab542e95722f25006c7d1886b44842a9ae0f9 Mon Sep 17 00:00:00 2001
From: Aleksei Slaikovskii <aslai...@redhat.com>
Date: Tue, 21 Nov 2017 11:32:14 +0100
Subject: [PATCH] ipalib/frontend.py output_for_cli loops optimization

Trivial fix which removes unnecessary for loops.
---
 ipalib/frontend.py | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/ipalib/frontend.py b/ipalib/frontend.py
index 3a05bb6eb8..5d253a0977 100644
--- a/ipalib/frontend.py
+++ b/ipalib/frontend.py
@@ -22,6 +22,8 @@
 """
 import logging
 
+from collections import deque
+
 import six
 
 from ipapython.version import API_VERSION
@@ -1041,18 +1043,23 @@ def output_for_cli(self, textui, output, *args, **options):
 
         self.log_messages(output)
 
-        order = [p.name for p in self.output_params()]
+        order = deque()
+        labels = dict()
+        flags = dict()
+
+        for p in self.output_params():
+            order.append(p.name)
+            labels[p.name] = unicode(p.label)
+            flags[p.name] = p.flags
+
         if options.get('all', False):
-            order.insert(0, 'dn')
+            order.appendleft('dn')
             print_all = True
         else:
             print_all = False
 
         if options.get('raw', False):
             labels = None
-        else:
-            labels = dict((p.name, unicode(p.label)) for p in self.output_params())
-        flags = dict((p.name, p.flags) for p in self.output_params())
 
         for o in self.output:
             outp = self.output[o]
_______________________________________________
FreeIPA-devel mailing list -- freeipa-devel@lists.fedorahosted.org
To unsubscribe send an email to freeipa-devel-le...@lists.fedorahosted.org

Reply via email to