From d763d01352627ae26c7410c12b735951904a57e6 Mon Sep 17 00:00:00 2001
From: Abhishek Koneru <akoneru@redhat.com>
Date: Wed, 3 Jul 2013 13:51:25 -0400
Subject: [PATCH] Fixes for issues reported by pylint.

Fixes for issues in other files.
Ticket #316
---
 base/common/python/pki/encoder.py         |    1 -
 base/common/sbin/pki-upgrade              |    1 -
 base/server/python/pki/server/__init__.py |    8 ++++----
 base/server/sbin/pki-server-upgrade       |    2 +-
 base/server/src/engine/pkiconfig.py       |    3 ++-
 base/server/src/engine/pkilogging.py      |   14 +++++++-------
 base/server/src/engine/pkiparser.py       |   21 +++++++++------------
 base/server/src/pkidestroy                |   10 ++++------
 base/server/src/pkispawn                  |   22 +++++++++++-----------
 9 files changed, 38 insertions(+), 44 deletions(-)

diff --git a/base/common/python/pki/encoder.py b/base/common/python/pki/encoder.py
index c100be3d50a62e8d951fd2c1a91a4a9cc9fd129a..8d8a9c10198cc189b10e1a1ae993c36ab9de25dd 100644
--- a/base/common/python/pki/encoder.py
+++ b/base/common/python/pki/encoder.py
@@ -1,5 +1,4 @@
 import json
-import pki.system
 
 TYPES = {}
 NOTYPES = {}
diff --git a/base/common/sbin/pki-upgrade b/base/common/sbin/pki-upgrade
index c739598d403fe3fc89ba7c18b1904bb82857d825..48fb48b933e65bfad6655955fb74b49dd0e3e5bf 100755
--- a/base/common/sbin/pki-upgrade
+++ b/base/common/sbin/pki-upgrade
@@ -20,7 +20,6 @@
 #
 
 import getopt
-import os
 import signal
 import sys
 
diff --git a/base/server/python/pki/server/__init__.py b/base/server/python/pki/server/__init__.py
index c60c5a325d56d9d7de06d6052ef1fecd6da06196..fab695bdcb23cfceeefba69122c32917ca9f7866 100644
--- a/base/server/python/pki/server/__init__.py
+++ b/base/server/python/pki/server/__init__.py
@@ -59,10 +59,10 @@ class PKISubsystem(object):
 
 class PKIInstance(object):
 
-    def __init__(self, name, type=10):
+    def __init__(self, name, vtype=10):
         self.name = name
-        self.type = type
-        if self.type >= 10:
+        self.vtype = vtype
+        if self.vtype >= 10:
             self.conf_dir = os.path.join(INSTANCE_BASE_DIR, name, 'conf')
             self.base_dir = os.path.join(INSTANCE_BASE_DIR, name)
         else:
@@ -77,7 +77,7 @@ class PKIInstance(object):
                 'Invalid instance: ' + self.__repr__(), None)
 
     def __repr__(self):
-        if self.type == 9:
+        if self.vtype == 9:
             return "Dogtag 9 " + self.name
         return self.name
 
diff --git a/base/server/sbin/pki-server-upgrade b/base/server/sbin/pki-server-upgrade
index 0b43f9b4be46d06e9a96fa34f14ee884668fe563..59db87ba2634139ddf077a0d6eadad3a2f4e3bf7 100755
--- a/base/server/sbin/pki-server-upgrade
+++ b/base/server/sbin/pki-server-upgrade
@@ -68,7 +68,7 @@ def main(argv):
     signal.signal(signal.SIGINT, interrupt_handler)
 
     try:
-        opts, args = getopt.getopt(argv[1:], 'hi:s:t:vX', [
+        opts, _ = getopt.getopt(argv[1:], 'hi:s:t:vX', [
             'instance=', 'subsystem=', 'instance-type=',
             'scriptlet-version=', 'scriptlet-index=',
             'silent', 'status', 'revert',
diff --git a/base/server/src/engine/pkiconfig.py b/base/server/src/engine/pkiconfig.py
index d9be80507cd4e87c952cf813f13c7ab86fcd63e9..2e9463b9d082e611007810729110bd7a14a7b995 100644
--- a/base/server/src/engine/pkiconfig.py
+++ b/base/server/src/engine/pkiconfig.py
@@ -18,7 +18,6 @@
 # Copyright (C) 2012 Red Hat, Inc.
 # All rights reserved.
 #
-import re
 
 # PKI Deployment Constants
 PKI_DEPLOYMENT_DEFAULT_CLIENT_DIR_PERMISSIONS = 00755
@@ -99,6 +98,8 @@ pki_install_time = None
 pki_timestamp = None
 pki_architecture = None
 pki_hostname = None
+pki_dns_domainname = None
+pki_certificate_timestamp = None
 
 
 # PKI Deployment Command-Line Variables
diff --git a/base/server/src/engine/pkilogging.py b/base/server/src/engine/pkilogging.py
index b73650ee5434d9afa6b86e4a9e25f3c94adffd0a..c91a7656f6767da91107ef72a65da01a1e333066 100644
--- a/base/server/src/engine/pkilogging.py
+++ b/base/server/src/engine/pkilogging.py
@@ -29,15 +29,15 @@ sensitive_parameters = []
 # Initialize 'pretty print' for objects
 pp = pprint.PrettyPrinter(indent=4)
 
-def format(dict):
+def log_format(given_dict):
     new_dict = {}
 
     # mask sensitive data
-    for key in dict:
+    for key in given_dict:
         if key in sensitive_parameters:
             value = 'XXXXXXXX'
         else:
-            value = dict[key]
+            value = given_dict[key]
         new_dict[key] = value
 
     return pp.pformat(new_dict)
@@ -64,13 +64,13 @@ def enable_pki_logger(log_dir, log_name, log_level, console_log_level, name):
     logger.addHandler(console)
 
     # Configure file handler
-    file = logging.FileHandler(log_dir + "/" + log_name, 'w')
-    file.setLevel(log_level)
+    log_file = logging.FileHandler(log_dir + "/" + log_name, 'w')
+    log_file.setLevel(log_level)
     file_format = logging.Formatter('%(asctime)s %(name)-12s: ' + \
                                     '%(levelname)-8s ' + \
                                     '%(indent)s%(message)s',
                                     '%Y-%m-%d %H:%M:%S')
-    file.setFormatter(file_format)
-    logger.addHandler(file)
+    log_file.setFormatter(file_format)
+    logger.addHandler(log_file)
 
     return logger
diff --git a/base/server/src/engine/pkiparser.py b/base/server/src/engine/pkiparser.py
index c740a06479d4289085f7514d1798f891486dec35..a70a8df6e16f0e9a266e098af396c7b02ee74d57 100644
--- a/base/server/src/engine/pkiparser.py
+++ b/base/server/src/engine/pkiparser.py
@@ -30,9 +30,6 @@ import random
 import requests
 import string
 import subprocess
-import sys
-import time
-
 
 # PKI Imports
 import pki
@@ -229,26 +226,26 @@ class PKIConfigParser:
         return values
 
 
-    def set_property(self, section, property, value):
+    def set_property(self, section, key, value):
         if section != "DEFAULT" and not self.pki_config.has_section(section):
             self.pki_config.add_section(section)
-        self.pki_config.set(section, property, value)
+        self.pki_config.set(section, key, value)
         self.flatten_master_dict()
 
         if section != "DEFAULT" and not config.user_config.has_section(section):
             config.user_config.add_section(section)
-        config.user_config.set(section, property, value)
+        config.user_config.set(section, key, value)
 
 
     def print_text(self, message):
         print ' ' * self.indent + message
 
     def read_text(self, message,
-        section=None, property=None, default=None,
+        section=None, key=None, default=None,
         options=None, sign=':', allowEmpty=True, caseSensitive=True):
 
-        if default is None and property is not None:
-            default = self.pki_master_dict[property]
+        if default is None and key is not None:
+            default = self.pki_master_dict[key]
         if default:
             message = message + ' [' + default + ']'
         message = ' ' * self.indent + message + sign + ' '
@@ -281,12 +278,12 @@ class PKIConfigParser:
 
         value = value.replace("%", "%%")
         if section:
-            self.set_property(section, property, value)
+            self.set_property(section, key, value)
 
         return value
 
 
-    def read_password(self, message, section=None, property=None,
+    def read_password(self, message, section=None, key=None,
         verifyMessage=None):
         message = ' ' * self.indent + message + ': '
         if verifyMessage is not None:
@@ -310,7 +307,7 @@ class PKIConfigParser:
 
         password = password.replace("%", "%%")
         if section:
-            self.set_property(section, property, password)
+            self.set_property(section, key, password)
 
         return password
 
diff --git a/base/server/src/pkidestroy b/base/server/src/pkidestroy
index deca8d586602e5927749523160974f9b04240a53..76fee7206483cd2ca09b71776e12ee36f6f1a1d6 100755
--- a/base/server/src/pkidestroy
+++ b/base/server/src/pkidestroy
@@ -28,8 +28,6 @@ if not hasattr(sys, "hexversion") or sys.hexversion < 0x020700f0:
     print "Please upgrade to at least Python 2.7.0."
     sys.exit(1)
 try:
-    import argparse
-    import logging
     import os
     import socket
     import struct
@@ -180,7 +178,7 @@ def main(argv):
         print "ERROR:  " + log.PKI_INSTANCE_DOES_NOT_EXIST_1 %\
               deployed_pki_instance_path
         print
-        parser.arg_parser.exit(-1);
+        parser.arg_parser.exit(-1)
 
     # verify that previously deployed subsystem for this instance exists
     deployed_pki_subsystem_path = deployed_pki_instance_path + "/" +\
@@ -189,7 +187,7 @@ def main(argv):
         print "ERROR:  " + log.PKI_SUBSYSTEM_DOES_NOT_EXIST_2 %\
               (config.pki_subsystem, deployed_pki_instance_path)
         print
-        parser.arg_parser.exit(-1);
+        parser.arg_parser.exit(-1)
 
     config.default_deployment_cfg = config.PKI_DEPLOYMENT_DEFAULT_CONFIGURATION_FILE
 
@@ -234,7 +232,7 @@ def main(argv):
                                                 config.pki_log_name
     config.pki_log.debug(log.PKI_DICTIONARY_MASTER,
                          extra=config.PKI_INDENTATION_LEVEL_0)
-    config.pki_log.debug(pkilogging.format(parser.pki_master_dict),
+    config.pki_log.debug(pkilogging.log_format(parser.pki_master_dict),
                          extra=config.PKI_INDENTATION_LEVEL_0)
 
     print "Uninstalling " + config.pki_subsystem + " from " + deployed_pki_instance_path + "."
@@ -253,7 +251,7 @@ def main(argv):
             sys.exit(1)
     config.pki_log.debug(log.PKI_DICTIONARY_MASTER,
                          extra=config.PKI_INDENTATION_LEVEL_0)
-    config.pki_log.debug(pkilogging.format(parser.pki_master_dict),
+    config.pki_log.debug(pkilogging.log_format(parser.pki_master_dict),
                          extra=config.PKI_INDENTATION_LEVEL_0)
 
     print
diff --git a/base/server/src/pkispawn b/base/server/src/pkispawn
index 6339b1096175610625f7907805c63af11af0b4eb..5b38b6e39598b8190bc5d7af76066454d95776ea 100755
--- a/base/server/src/pkispawn
+++ b/base/server/src/pkispawn
@@ -86,7 +86,6 @@ def main(argv):
     config.pki_hostname = socket.getfqdn()
 
     # Retrieve DNS domainname
-    config.pki_dns_domainname = None
     try:
         config.pki_dns_domainname = subprocess.check_output("dnsdomainname",
                                                             shell = True)
@@ -310,7 +309,7 @@ def main(argv):
     parser.compose_pki_slots_dictionary()
     config.pki_log.debug(log.PKI_DICTIONARY_SLOTS,
                          extra=config.PKI_INDENTATION_LEVEL_0)
-    config.pki_log.debug(pkilogging.format(parser.pki_slots_dict),
+    config.pki_log.debug(pkilogging.log_format(parser.pki_slots_dict),
                          extra=config.PKI_INDENTATION_LEVEL_0)
 
     # Combine the various sectional dictionaries into a PKI master dictionary
@@ -320,7 +319,7 @@ def main(argv):
                                               config.pki_log_name
     config.pki_log.debug(log.PKI_DICTIONARY_MASTER,
                          extra=config.PKI_INDENTATION_LEVEL_0)
-    config.pki_log.debug(pkilogging.format(parser.pki_master_dict),
+    config.pki_log.debug(pkilogging.log_format(parser.pki_master_dict),
                          extra=config.PKI_INDENTATION_LEVEL_0)
 
     if not interactive and\
@@ -370,6 +369,7 @@ def main(argv):
         instance = scriptlet.PkiScriptlet()
         try:
             rv = instance.spawn(deployer)
+        # pylint: disable-msg=W0703
         except Exception:
             log_error_details()
             print
@@ -382,7 +382,7 @@ def main(argv):
             sys.exit(1)
     config.pki_log.debug(log.PKI_DICTIONARY_MASTER,
                          extra=config.PKI_INDENTATION_LEVEL_0)
-    config.pki_log.debug(pkilogging.format(parser.pki_master_dict),
+    config.pki_log.debug(pkilogging.log_format(parser.pki_master_dict),
                          extra=config.PKI_INDENTATION_LEVEL_0)
 
     print_install_information(parser.pki_master_dict)
@@ -410,14 +410,14 @@ def print_install_information(pki_master_dict):
 
 def log_error_details():
 
-    type, value, stacktrace = sys.exc_info()
-    config.pki_log.debug("Error Type: " + type.__name__, extra=config.PKI_INDENTATION_LEVEL_2)
-    config.pki_log.debug("Error Message: " + str(value), extra=config.PKI_INDENTATION_LEVEL_2)
-    stacktrace_list = traceback.format_list(traceback.extract_tb(stacktrace))
-    stacktrace = ""
+    e_type, e_value, e_stacktrace = sys.exc_info()
+    config.pki_log.debug("Error Type: " + e_type.__name__, extra=config.PKI_INDENTATION_LEVEL_2)
+    config.pki_log.debug("Error Message: " + str(e_value), extra=config.PKI_INDENTATION_LEVEL_2)
+    stacktrace_list = traceback.format_list(traceback.extract_tb(e_stacktrace))
+    e_stacktrace = ""
     for l in stacktrace_list:
-        stacktrace += l
-    config.pki_log.debug(stacktrace, extra=config.PKI_INDENTATION_LEVEL_2)
+        e_stacktrace += l
+    config.pki_log.debug(e_stacktrace, extra=config.PKI_INDENTATION_LEVEL_2)
     sys.exc_clear()
 
 # PKI Deployment Entry Point
-- 
1.7.10.2

