diff options
author | Christian Heimes <cheimes@redhat.com> | 2015-08-16 19:00:00 +0200 |
---|---|---|
committer | Christian Heimes <cheimes@redhat.com> | 2015-08-17 21:14:11 +0200 |
commit | f98ca7fa1903e12a4b2c49a70163077b3560dc1d (patch) | |
tree | a3446113d3a7d32c5ce79b1b359d5353ec49afee | |
parent | 71148b8f79a5d6ba0c949a3ca0acf5aec6321f0a (diff) | |
download | pki-f98ca7fa1903e12a4b2c49a70163077b3560dc1d.tar.gz pki-f98ca7fa1903e12a4b2c49a70163077b3560dc1d.tar.xz pki-f98ca7fa1903e12a4b2c49a70163077b3560dc1d.zip |
Py3 modernization: libmodernize.fixes.fix_print
Replace print statement with Python 3's print() function.
For Python 2 'from __future__ import print_function' turns the print
statement into Python 3 compatible print function.
See https://www.python.org/dev/peps/pep-3105/
24 files changed, 636 insertions, 612 deletions
diff --git a/base/common/python/pki/__init__.py b/base/common/python/pki/__init__.py index a6f01ff82..717c4fdeb 100644 --- a/base/common/python/pki/__init__.py +++ b/base/common/python/pki/__init__.py @@ -22,6 +22,7 @@ This module contains top-level classes and functions used by the Dogtag project. """ from __future__ import absolute_import +from __future__ import print_function from functools import wraps import os import re @@ -376,7 +377,7 @@ class PropertyFile(object): :return: None """ for line in self.lines: - print line + print(line) def insert_line(self, index, line): """ diff --git a/base/common/python/pki/cert.py b/base/common/python/pki/cert.py index 5590b35ee..6d0d40833 100644 --- a/base/common/python/pki/cert.py +++ b/base/common/python/pki/cert.py @@ -21,6 +21,7 @@ # Ade Lee <alee@redhat.com> from __future__ import absolute_import +from __future__ import print_function import copy import json @@ -1046,8 +1047,8 @@ def main(): cert_client.get_enrollment_template('caUserCert') # Enrolling an user certificate - print 'Enrolling an user certificate' - print '-----------------------------' + print('Enrolling an user certificate') + print('-----------------------------') inputs = dict() inputs['cert_request_type'] = 'crmf' @@ -1073,19 +1074,19 @@ def main(): for enrollment_result in enrollment_results: request_data = enrollment_result.request cert_data = enrollment_result.cert - print 'Request ID: ' + request_data.request_id - print 'Request Status:' + request_data.request_status - print 'Serial Number: ' + cert_data.serial_number - print 'Issuer: ' + cert_data.issuer_dn - print 'Subject: ' + cert_data.subject_dn - print 'Pretty Print:' - print cert_data.pretty_repr + print('Request ID: ' + request_data.request_id) + print('Request Status:' + request_data.request_status) + print('Serial Number: ' + cert_data.serial_number) + print('Issuer: ' + cert_data.issuer_dn) + print('Subject: ' + cert_data.subject_dn) + print('Pretty Print:') + print(cert_data.pretty_repr) - print + print() # Enrolling a server certificate - print "Enrolling a server certificate" - print '------------------------------' + print("Enrolling a server certificate") + print('------------------------------') inputs = dict() inputs['cert_request_type'] = 'pkcs10' @@ -1110,41 +1111,41 @@ def main(): for enrollment_result in enrollment_results_2: request_data = enrollment_result.request cert_data = enrollment_result.cert - print 'Request ID: ' + request_data.request_id - print 'Request Status:' + request_data.request_status + print('Request ID: ' + request_data.request_id) + print('Request Status:' + request_data.request_status) if cert_data is not None: # store cert_id for usage later cert_id = cert_data.serial_number - print 'Serial Number: ' + cert_id - print 'Issuer: ' + cert_data.issuer_dn - print 'Subject: ' + cert_data.subject_dn - print 'Pretty Print:' - print cert_data.pretty_repr + print('Serial Number: ' + cert_id) + print('Issuer: ' + cert_data.issuer_dn) + print('Subject: ' + cert_data.subject_dn) + print('Pretty Print:') + print(cert_data.pretty_repr) - print + print() # List all the VALID certs - print 'An example listing all VALID certs' - print '----------------------------------' + print('An example listing all VALID certs') + print('----------------------------------') search_params = {'status': 'VALID'} cert_data_list = cert_client.list_certs(**search_params) for cert_data_info in cert_data_list: - print "Serial Number: " + cert_data_info.serial_number - print "Subject DN: " + cert_data_info.subject_dn - print "Status: " + cert_data_info.status - print + print("Serial Number: " + cert_data_info.serial_number) + print("Subject DN: " + cert_data_info.subject_dn) + print("Status: " + cert_data_info.status) + print() # Trying to get a non-existing cert # Assuming that there is no certificate with serial number = 100 try: cert_data = cert_client.get_cert(100) - print 'Serial Number: ' + cert_data.serial_number - print 'Issuer: ' + cert_data.issuer_dn - print 'Subject: ' + cert_data.subject_dn + print('Serial Number: ' + cert_data.serial_number) + print('Issuer: ' + cert_data.issuer_dn) + print('Subject: ' + cert_data.subject_dn) except pki.CertNotFoundException: - print "Certificate with ID 100 does not exist" - print + print("Certificate with ID 100 does not exist") + print() # Certificate Serial Number used for CertClient methods. # 7, 0x7 and '0x7' are also valid values @@ -1152,55 +1153,55 @@ def main(): # before. # Get certificate data - print 'Getting information of a certificate' - print '------------------------------------' + print('Getting information of a certificate') + print('------------------------------------') cert_data = cert_client.get_cert(cert_id) # Print the certificate information - print 'Serial Number: ' + cert_data.serial_number - print 'Issuer: ' + cert_data.issuer_dn - print 'Subject: ' + cert_data.subject_dn - print 'Status: ' + cert_data.status - print 'Not Before: ' + cert_data.not_before - print 'Not After: ' + cert_data.not_after - print 'Encoded: ' - print cert_data.encoded - print "Pretty print format: " - print cert_data.pretty_repr - print + print('Serial Number: ' + cert_data.serial_number) + print('Issuer: ' + cert_data.issuer_dn) + print('Subject: ' + cert_data.subject_dn) + print('Status: ' + cert_data.status) + print('Not Before: ' + cert_data.not_before) + print('Not After: ' + cert_data.not_after) + print('Encoded: ') + print(cert_data.encoded) + print("Pretty print format: ") + print(cert_data.pretty_repr) + print() # Review a certificate - used to get a nonce for revoke request. - print 'Reviewing a certificate' - print '-----------------------' + print('Reviewing a certificate') + print('-----------------------') cert_data = cert_client.review_cert(cert_id) - print 'Serial Number: ' + cert_data.serial_number - print 'Issuer: ' + cert_data.issuer_dn - print 'Subject: ' + cert_data.subject_dn - print 'Status: ' + cert_data.status - print 'Nonce: ' + str(cert_data.nonce) - print + print('Serial Number: ' + cert_data.serial_number) + print('Issuer: ' + cert_data.issuer_dn) + print('Subject: ' + cert_data.subject_dn) + print('Status: ' + cert_data.status) + print('Nonce: ' + str(cert_data.nonce)) + print() # Revoke a certificate - print 'Revoking a certificate' - print '----------------------' + print('Revoking a certificate') + print('----------------------') cert_request_info = cert_client.hold_cert(cert_data.serial_number, comments="Test revoking a cert") - print 'Request ID: ' + cert_request_info.request_id - print 'Request Type: ' + cert_request_info.request_type - print 'Request Status: ' + cert_request_info.request_status - print + print('Request ID: ' + cert_request_info.request_id) + print('Request Type: ' + cert_request_info.request_type) + print('Request Status: ' + cert_request_info.request_status) + print() # Un-revoke a certificate - print 'Un-revoking a certificate' - print '-------------------------' + print('Un-revoking a certificate') + print('-------------------------') cert_request_info = cert_client.unrevoke_cert(cert_data.serial_number) - print 'Request ID: ' + cert_request_info.request_id - print 'Request Type: ' + cert_request_info.request_type - print 'Request Status: ' + cert_request_info.request_status - print + print('Request ID: ' + cert_request_info.request_id) + print('Request Type: ' + cert_request_info.request_type) + print('Request Status: ' + cert_request_info.request_status) + print() if __name__ == "__main__": diff --git a/base/common/python/pki/cli.py b/base/common/python/pki/cli.py index dd8b388fb..57d13a0fa 100644 --- a/base/common/python/pki/cli.py +++ b/base/common/python/pki/cli.py @@ -20,6 +20,7 @@ # from __future__ import absolute_import +from __future__ import print_function import collections import getopt import sys @@ -66,17 +67,17 @@ class CLI(object): return self.modules.get(name) def print_message(self, message): - print '-' * len(message) - print message - print '-' * len(message) + print('-' * len(message)) + print(message) + print('-' * len(message)) def print_help(self): - print 'Commands:' + print('Commands:') for module in self.modules.itervalues(): full_name = module.get_full_name() - print ' {:30}{:30}'.format(full_name, module.description) + print(' {:30}{:30}'.format(full_name, module.description)) def find_module(self, command): @@ -119,7 +120,7 @@ class CLI(object): sub_command = None if self.debug: - print 'Module: %s' % module_name + print('Module: %s' % module_name) m = self.get_module(module_name) if m: @@ -173,7 +174,7 @@ class CLI(object): 'verbose', 'help']) except getopt.GetoptError as e: - print 'ERROR: ' + str(e) + print('ERROR: ' + str(e)) self.print_help() sys.exit(1) @@ -190,7 +191,7 @@ class CLI(object): sys.exit() else: - print 'ERROR: unknown option %s' % o + print('ERROR: unknown option %s' % o) self.print_help() sys.exit(1) diff --git a/base/common/python/pki/client.py b/base/common/python/pki/client.py index 7f59c2f2a..581f0b0ad 100644 --- a/base/common/python/pki/client.py +++ b/base/common/python/pki/client.py @@ -20,6 +20,7 @@ # from __future__ import absolute_import +from __future__ import print_function import functools import warnings @@ -210,7 +211,7 @@ def main(): headers = {'Content-type': 'application/json', 'Accept': 'application/json'} conn.set_authentication_cert('/root/temp4.pem') - print conn.get("", headers).json() + print(conn.get("", headers).json()) if __name__ == "__main__": main() diff --git a/base/common/python/pki/key.py b/base/common/python/pki/key.py index 3433bce03..8064ffc19 100644 --- a/base/common/python/pki/key.py +++ b/base/common/python/pki/key.py @@ -25,6 +25,7 @@ Module containing the Python client classes for the KeyClient and KeyRequestClient REST API on a DRM """ from __future__ import absolute_import +from __future__ import print_function import base64 import json import urllib @@ -1009,23 +1010,23 @@ encoder.NOTYPES['AsymKeyGenerationRequest'] = AsymKeyGenerationRequest def main(): """ Some unit tests - basically printing different types of requests """ - print "printing symkey generation request" + print("printing symkey generation request") client_key_id = "vek 123" usages = [SymKeyGenerationRequest.DECRYPT_USAGE, SymKeyGenerationRequest.ENCRYPT_USAGE] gen_request = SymKeyGenerationRequest(client_key_id, 128, "AES", usages) - print json.dumps(gen_request, cls=encoder.CustomTypeEncoder, sort_keys=True) + print(json.dumps(gen_request, cls=encoder.CustomTypeEncoder, sort_keys=True)) - print "printing key recovery request" + print("printing key recovery request") key_request = KeyRecoveryRequest("25", "MX12345BBBAAA", None, "1234ABC", None, None) - print json.dumps(key_request, cls=encoder.CustomTypeEncoder, sort_keys=True) + print(json.dumps(key_request, cls=encoder.CustomTypeEncoder, sort_keys=True)) - print "printing key archival request" + print("printing key archival request") archival_request = KeyArchivalRequest(client_key_id, "symmetricKey", "MX123AABBCD", "AES", 128) - print json.dumps(archival_request, cls=encoder.CustomTypeEncoder, - sort_keys=True) + print(json.dumps(archival_request, cls=encoder.CustomTypeEncoder, + sort_keys=True)) if __name__ == '__main__': diff --git a/base/common/python/pki/profile.py b/base/common/python/pki/profile.py index 70eec4083..b9c55a4e7 100644 --- a/base/common/python/pki/profile.py +++ b/base/common/python/pki/profile.py @@ -18,6 +18,7 @@ # @author: Abhishek Koneru <akoneru@redhat.com> from __future__ import absolute_import +from __future__ import print_function import json import os @@ -1171,46 +1172,46 @@ def main(): # Fetching a list of profiles profile_data_infos = profile_client.list_profiles() - print 'List of profiles:' - print '-----------------' + print('List of profiles:') + print('-----------------') for profile_data_info in profile_data_infos: - print ' Profile ID: ' + profile_data_info.profile_id - print ' Profile Name: ' + profile_data_info.profile_name - print ' Profile Description: ' + profile_data_info.profile_description - print + print(' Profile ID: ' + profile_data_info.profile_id) + print(' Profile Name: ' + profile_data_info.profile_name) + print(' Profile Description: ' + profile_data_info.profile_description) + print() # Get a specific profile profile_data = profile_client.get_profile('caUserCert') - print 'Profile Data for caUserCert:' - print '----------------------------' - print ' Profile ID: ' + profile_data.profile_id - print ' Profile Name: ' + profile_data.name - print ' Profile Description: ' + profile_data.description - print ' Is profile enabled? ' + str(profile_data.enabled) - print ' Is profile visible? ' + str(profile_data.visible) - print + print('Profile Data for caUserCert:') + print('----------------------------') + print(' Profile ID: ' + profile_data.profile_id) + print(' Profile Name: ' + profile_data.name) + print(' Profile Description: ' + profile_data.description) + print(' Is profile enabled? ' + str(profile_data.enabled)) + print(' Is profile visible? ' + str(profile_data.visible)) + print() # Disabling a profile - print 'Disabling a profile:' - print '--------------------' + print('Disabling a profile:') + print('--------------------') profile_client.disable_profile('caUserCert') profile = profile_client.get_profile('caUserCert') - print ' Profile ID: ' + profile.profile_id - print ' Is profile enabled? ' + str(profile.enabled) - print + print(' Profile ID: ' + profile.profile_id) + print(' Is profile enabled? ' + str(profile.enabled)) + print() # Disabling a profile - print 'Enabling a profile:' - print '-------------------' + print('Enabling a profile:') + print('-------------------') profile_client.enable_profile('caUserCert') profile = profile_client.get_profile('caUserCert') - print ' Profile ID: ' + profile_data.profile_id - print ' Is profile enabled? ' + str(profile.enabled) - print + print(' Profile ID: ' + profile_data.profile_id) + print(' Is profile enabled? ' + str(profile.enabled)) + print() # profile_client.delete_profile('MySampleProfile') # Create a new sample profile - print 'Creating a new profile:' - print '-----------------------' + print('Creating a new profile:') + print('-----------------------') profile_data = Profile(name="My Sample User Cert Enrollment", profile_id="MySampleProfile", @@ -1328,12 +1329,12 @@ def main(): sort_keys=True, indent=4)) # Create a new profile created_profile = profile_client.create_profile(profile_data) - print created_profile - print + print(created_profile) + print() # Test creating a new profile with a duplicate profile id - print "Create a profile with duplicate profile id." - print "-------------------------------------------" + print("Create a profile with duplicate profile id.") + print("-------------------------------------------") try: profile_data = Profile(name="My Sample User Cert Enrollment", @@ -1358,12 +1359,12 @@ def main(): profile_client.create_profile(profile_data) # pylint: disable=W0703 except pki.BadRequestException as e: - print 'MySampleProfile ' + str(e) - print + print('MySampleProfile ' + str(e)) + print() # Modify the above created profile - print 'Modifying the profile MySampleProfile.' - print '-----------------------------------' + print('Modifying the profile MySampleProfile.') + print('-----------------------------------') fetch = profile_client.get_profile('MySampleProfile') profile_input2 = ProfileInput("i2", "keyGenInputImpl") @@ -1378,41 +1379,41 @@ def main(): output_file.write(json.dumps(fetch, cls=encoder.CustomTypeEncoder, sort_keys=True, indent=4)) - print modified_profile - print + print(modified_profile) + print() # Delete a profile - print "Deleting the profile MySampleProfile." - print "----------------------------------" + print("Deleting the profile MySampleProfile.") + print("----------------------------------") profile_client.delete_profile('MySampleProfile') - print "Deleted profile MySampleProfile." - print + print("Deleted profile MySampleProfile.") + print() # Testing deletion of a profile - print 'Test profile deletion.' - print '----------------------' + print('Test profile deletion.') + print('----------------------') try: profile_client.get_profile('MySampleProfile') # pylint: disable=W0703 except pki.ProfileNotFoundException as e: - print str(e) - print + print(str(e)) + print() # Creating a profile from file - print 'Creating a profile using file input.' - print '------------------------------------' + print('Creating a profile using file input.') + print('------------------------------------') original = profile_client.create_profile_from_file( file_path + 'original.json') - print original - print + print(original) + print() # Modifying a profile from file - print 'Modifying a profile using file input.' - print '------------------------------------' + print('Modifying a profile using file input.') + print('------------------------------------') modified = profile_client.modify_profile_from_file( file_path + 'modified.json') - print modified - print + print(modified) + print() # Test clean up profile_client.delete_profile('MySampleProfile') diff --git a/base/common/python/pki/upgrade.py b/base/common/python/pki/upgrade.py index 1206ef8ba..3e16723ed 100644 --- a/base/common/python/pki/upgrade.py +++ b/base/common/python/pki/upgrade.py @@ -20,6 +20,7 @@ # from __future__ import absolute_import +from __future__ import print_function import functools import os import re @@ -118,7 +119,7 @@ class PKIUpgradeTracker(object): def remove(self): if verbose: - print 'Removing ' + self.name + ' tracker.' + print('Removing ' + self.name + ' tracker.') self.remove_version() self.remove_index() @@ -126,24 +127,24 @@ class PKIUpgradeTracker(object): def set(self, version): if verbose: - print 'Setting ' + self.name + ' tracker to version ' +\ - str(version) + '.' + print('Setting ' + self.name + ' tracker to version ' + + str(version) + '.') self.set_version(version) self.remove_index() def show(self): - print self.name + ':' + print(self.name + ':') version = self.get_version() - print ' Configuration version: ' + str(version) + print(' Configuration version: ' + str(version)) index = self.get_index() if index > 0: - print ' Last completed scriptlet: ' + str(index) + print(' Last completed scriptlet: ' + str(index)) - print + print() def get_index(self): @@ -295,11 +296,11 @@ class PKIUpgradeScriptlet(object): try: if not self.can_upgrade(): if verbose: - print 'Skipping system.' + print('Skipping system.') return if verbose: - print 'Upgrading system.' + print('Upgrading system.') self.upgrade_system() self.update_tracker() @@ -308,11 +309,11 @@ class PKIUpgradeScriptlet(object): if verbose: traceback.print_exc() else: - print 'ERROR: %s' % e + print('ERROR: %s' % e) message = 'Failed upgrading system.' if self.upgrader.silent: - print message + print(message) else: result = pki.read_text( message + ' Continue (Yes/No)', @@ -343,7 +344,7 @@ class PKIUpgradeScriptlet(object): if not os.path.isdir(destpath): if verbose: - print 'Restoring ' + destpath + print('Restoring ' + destpath) pki.util.copydirs(sourcepath, destpath) for filename in filenames: @@ -351,7 +352,7 @@ class PKIUpgradeScriptlet(object): targetfile = os.path.join(destpath, filename) if verbose: - print 'Restoring ' + targetfile + print('Restoring ' + targetfile) pki.util.copyfile(sourcefile, targetfile) newfiles = backup_dir + '/newfiles' @@ -371,7 +372,7 @@ class PKIUpgradeScriptlet(object): if not os.path.exists(path): continue if verbose: - print 'Deleting ' + path + print('Deleting ' + path) if os.path.isfile(path): os.remove(path) @@ -402,7 +403,7 @@ class PKIUpgradeScriptlet(object): if os.path.isfile(path): if verbose: - print 'Saving ' + path + print('Saving ' + path) # do not overwrite initial backup pki.util.copyfile(path, dest, overwrite=False) @@ -413,7 +414,7 @@ class PKIUpgradeScriptlet(object): destpath = dest + relpath if verbose: - print 'Saving ' + sourcepath + print('Saving ' + sourcepath) pki.util.copydirs(sourcepath, destpath) for filename in filenames: @@ -421,7 +422,7 @@ class PKIUpgradeScriptlet(object): targetfile = os.path.join(destpath, filename) if verbose: - print 'Saving ' + sourcefile + print('Saving ' + sourcefile) # do not overwrite initial backup pki.util.copyfile(sourcefile, targetfile, overwrite=False) @@ -431,7 +432,7 @@ class PKIUpgradeScriptlet(object): # otherwise, record the name if verbose: - print 'Recording ' + path + print('Recording ' + path) with open(backup_dir + '/newfiles', 'a') as f: f.write(path + '\n') @@ -588,14 +589,14 @@ class PKIUpgrader(object): def upgrade_version(self, version): - print 'Upgrading from version ' + str(version) + ' to ' +\ - str(version.next) + ':' + print('Upgrading from version ' + str(version) + ' to ' + + str(version.next) + ':') scriptlets = self.scriptlets(version) if len(scriptlets) == 0: - print 'No upgrade scriptlets.' + print('No upgrade scriptlets.') self.set_tracker(version.next) return @@ -606,7 +607,7 @@ class PKIUpgrader(object): message = str(scriptlet.index) + '. ' + scriptlet.message if self.silent: - print message + print(message) else: result = pki.read_text( @@ -627,16 +628,16 @@ class PKIUpgrader(object): except Exception as e: # pylint: disable=W0703 - print + print() message = 'Upgrade failed: ' + e.message if verbose: traceback.print_exc() else: - print e + print(e) - print + print() result = pki.read_text( 'Continue (Yes/No)', @@ -654,18 +655,18 @@ class PKIUpgrader(object): for version in versions: self.upgrade_version(version) - print + print() if self.is_complete(): - print 'Upgrade complete.' + print('Upgrade complete.') else: self.show_tracker() - print 'Upgrade incomplete.' + print('Upgrade incomplete.') def revert_version(self, version): - print 'Reverting to version ' + str(version) + ':' + print('Reverting to version ' + str(version) + ':') scriptlets = self.scriptlets(version) scriptlets.reverse() @@ -675,7 +676,7 @@ class PKIUpgrader(object): message = str(scriptlet.index) + '. ' + scriptlet.message if self.silent: - print message + print(message) else: result = pki.read_text( @@ -694,16 +695,16 @@ class PKIUpgrader(object): except Exception as e: # pylint: disable=W0703 - print + print() message = 'Revert failed: %s' % e if verbose: traceback.print_exc() else: - print e + print(e) - print + print() result = pki.read_text( 'Continue (Yes/No)', options=['Y', 'N'], @@ -730,7 +731,7 @@ class PKIUpgrader(object): self.revert_version(version) return - print 'Unable to revert from version ' + str(current_version) + '.' + print('Unable to revert from version ' + str(current_version) + '.') def show_tracker(self): @@ -742,17 +743,17 @@ class PKIUpgrader(object): self.show_tracker() if self.is_complete(): - print 'Upgrade complete.' + print('Upgrade complete.') else: - print 'Upgrade incomplete.' + print('Upgrade incomplete.') def set_tracker(self, version): tracker = self.get_tracker() tracker.set(version) - print 'Tracker has been set to version ' + str(version) + '.' + print('Tracker has been set to version ' + str(version) + '.') def reset_tracker(self): @@ -764,4 +765,4 @@ class PKIUpgrader(object): tracker = self.get_tracker() tracker.remove() - print 'Tracker has been removed.' + print('Tracker has been removed.') diff --git a/base/common/sbin/pki-upgrade b/base/common/sbin/pki-upgrade index 72553ad5c..1833de845 100755 --- a/base/common/sbin/pki-upgrade +++ b/base/common/sbin/pki-upgrade @@ -20,6 +20,7 @@ # from __future__ import absolute_import +from __future__ import print_function import getopt import signal import sys @@ -31,34 +32,34 @@ import pki.upgrade def interrupt_handler(event, frame): - print - print - print 'Upgrade canceled.' + print() + print() + print('Upgrade canceled.') sys.exit(1) def usage(): - print 'Usage: pki-upgrade [OPTIONS]' - print - print ' --silent Upgrade in silent mode.' - print ' --status Show upgrade status only. Do not perform upgrade.' - print ' --revert Revert the last version.' - print - print ' -X Show advanced options.' - print ' -v, --verbose Run in verbose mode.' - print ' -h, --help Show this help message.' + print('Usage: pki-upgrade [OPTIONS]') + print() + print(' --silent Upgrade in silent mode.') + print(' --status Show upgrade status only. Do not perform upgrade.') + print(' --revert Revert the last version.') + print() + print(' -X Show advanced options.') + print(' -v, --verbose Run in verbose mode.') + print(' -h, --help Show this help message.') def advancedOptions(): - print - print 'WARNING: These options may render the system unusable.' - print - print ' --scriptlet-version <version> Run scriptlets for a specific version only.' - print ' --scriptlet-index <index> Run a specific scriptlet only.' - print - print ' --remove-tracker Remove tracker.' - print ' --reset-tracker Reset tracker to match package version.' - print ' --set-tracker <version> Set tracker to a specific version.' + print() + print('WARNING: These options may render the system unusable.') + print() + print(' --scriptlet-version <version> Run scriptlets for a specific version only.') + print(' --scriptlet-index <index> Run a specific scriptlet only.') + print() + print(' --remove-tracker Remove tracker.') + print(' --reset-tracker Reset tracker to match package version.') + print(' --set-tracker <version> Set tracker to a specific version.') def main(argv): @@ -73,7 +74,7 @@ def main(argv): 'verbose', 'help']) except getopt.GetoptError as e: - print 'ERROR: ' + str(e) + print('ERROR: ' + str(e)) usage() sys.exit(1) @@ -127,12 +128,12 @@ def main(argv): sys.exit() else: - print 'ERROR: unknown option ' + o + print('ERROR: unknown option ' + o) usage() sys.exit(1) if scriptlet_index and not scriptlet_version: - print 'ERROR: --scriptlet-index requires --scriptlet-version' + print('ERROR: --scriptlet-index requires --scriptlet-version') usage() sys.exit(1) @@ -161,7 +162,7 @@ def main(argv): upgrader.upgrade() except pki.PKIException as e: - print e.message + print(e.message) if __name__ == '__main__': diff --git a/base/kra/functional/drmclient_deprecated.py b/base/kra/functional/drmclient_deprecated.py index 99c70a184..0ebece27d 100644 --- a/base/kra/functional/drmclient_deprecated.py +++ b/base/kra/functional/drmclient_deprecated.py @@ -35,6 +35,7 @@ A sample test execution is provided at the end of the file. ''' from __future__ import absolute_import +from __future__ import print_function from lxml import etree import nss.nss as nss import httplib @@ -486,7 +487,7 @@ class KRA: return encoding_ctx, decoding_ctx def debug(self, message, *args): - print message % args + print(message % args) def _request(self, url, port, operation, args): """ @@ -1044,11 +1045,11 @@ test_kra = KRA(work_dir, kra_host, kra_port, kra_nickname) # list requests requests = test_kra.list_key_requests() -print requests +print(requests) # get transport cert transport_cert = test_kra.get_transport_cert() -print transport_cert +print(transport_cert) # archive symmetric key f = open(work_dir + "/" + options_file) @@ -1058,44 +1059,44 @@ response = test_kra.archive_security_data( client_id, wrapped_key, "symmetricKey") -print response +print(response) # list keys with client_id response = test_kra.list_security_data(client_id, "active") -print response +print(response) # create recovery request key_id = response.keys()[0] -print key_id +print(key_id) response = test_kra.submit_recovery_request(key_id) -print response +print(response) # approve recovery request request_id = response['request_id'] test_kra.approve_recovery_request(request_id) # test invalid request -print "Testing invalid request ID" +print("Testing invalid request ID") try: response = test_kra.retrieve_security_data("INVALID") - print "Failure: No exception thrown" + print("Failure: No exception thrown") except CertificateOperationError as e: if 'Error in retrieving security data (Bad Request)' == e.error: - print "Success: " + e.error + print("Success: " + e.error) else: - print "Failure: Wrong error message: " + e.error + print("Failure: Wrong error message: " + e.error) # retrieve key response = test_kra.retrieve_security_data(request_id) -print response -print "retrieved data is " + base64.encodestring(response['data']) +print(response) +print("retrieved data is " + base64.encodestring(response['data'])) # read original symkey from file f = open(work_dir + "/" + symkey_file) orig_key = f.read() -print "orig key is " + orig_key +print("orig key is " + orig_key) if orig_key.strip() == base64.encodestring(response['data']).strip(): - print "Success: the keys match" + print("Success: the keys match") else: - print "Failure: keys do not match" + print("Failure: keys do not match") diff --git a/base/kra/functional/drmtest.py b/base/kra/functional/drmtest.py index 1d7eb3270..6fe05ab43 100755 --- a/base/kra/functional/drmtest.py +++ b/base/kra/functional/drmtest.py @@ -33,6 +33,7 @@ See drmtest.readme.txt. """ from __future__ import absolute_import +from __future__ import print_function import base64 import getopt import random @@ -52,36 +53,36 @@ from pki.kra import KRAClient def print_key_request(request): """ Prints the relevant fields of a KeyRequestInfo object """ - print "RequestURL: " + str(request.request_url) - print "RequestType: " + str(request.request_type) - print "RequestStatus: " + str(request.request_status) - print "KeyURL: " + str(request.key_url) + print("RequestURL: " + str(request.request_url)) + print("RequestType: " + str(request.request_type)) + print("RequestStatus: " + str(request.request_status)) + print("KeyURL: " + str(request.key_url)) def print_key_info(key_info): """ Prints the relevant fields of a KeyInfo object """ - print "Key URL: " + str(key_info.key_url) - print "Client Key ID: " + str(key_info.client_key_id) - print "Algorithm: " + str(key_info.algorithm) - print "Status: " + str(key_info.status) - print "Owner Name: " + str(key_info.owner_name) - print "Size: " + str(key_info.size) + print("Key URL: " + str(key_info.key_url)) + print("Client Key ID: " + str(key_info.client_key_id)) + print("Algorithm: " + str(key_info.algorithm)) + print("Status: " + str(key_info.status)) + print("Owner Name: " + str(key_info.owner_name)) + print("Size: " + str(key_info.size)) if key_info.public_key is not None: - print "Public key: " - print + print("Public key: ") + print() pub_key = base64.encodestring(key_info.public_key) - print pub_key + print(pub_key) def print_key_data(key_data): """ Prints the relevant fields of a KeyData object """ - print "Key Algorithm: " + str(key_data.algorithm) - print "Key Size: " + str(key_data.size) - print "Nonce Data: " + base64.encodestring(key_data.nonce_data) - print "Wrapped Private Data: " + \ - base64.encodestring(key_data.encrypted_data) + print("Key Algorithm: " + str(key_data.algorithm)) + print("Key Size: " + str(key_data.size)) + print("Nonce Data: " + base64.encodestring(key_data.nonce_data)) + print("Wrapped Private Data: " + + base64.encodestring(key_data.encrypted_data)) if key_data.data is not None: - print "Private Data: " + base64.encodestring(key_data.data) + print("Private Data: " + base64.encodestring(key_data.data)) def run_test(protocol, hostname, port, client_cert, certdb_dir, @@ -100,8 +101,8 @@ def run_test(protocol, hostname, port, client_cert, certdb_dir, # Get transport cert and insert in the certdb transport_nick = "kra transport cert" transport_cert = kraclient.system_certs.get_transport_cert() - print "Subject DN: " + transport_cert.subject_dn - print transport_cert.encoded + print("Subject DN: " + transport_cert.subject_dn) + print(transport_cert.encoded) crypto.import_cert(transport_nick, transport_cert) # initialize the certdb for crypto operations @@ -112,7 +113,7 @@ def run_test(protocol, hostname, port, client_cert, certdb_dir, keyclient.set_transport_cert(transport_nick) # Test 2: Get key request info - print "Now getting key request" + print("Now getting key request") try: key_request = keyclient.get_request_info('2') print_key_request(key_request) @@ -120,14 +121,14 @@ def run_test(protocol, hostname, port, client_cert, certdb_dir, pass # Test 3: List requests - print "Now listing some requests" + print("Now listing some requests") keyrequests = keyclient.list_requests('complete', 'securityDataRecovery') - print keyrequests.key_requests + print(keyrequests.key_requests) for request in keyrequests.key_requests: print_key_request(request) # Test 4: generate symkey -- same as barbican_encode() - print "Now generating symkey on KRA" + print("Now generating symkey on KRA") client_key_id = "Vek #1" + time.strftime('%c') algorithm = "AES" key_size = 128 @@ -138,11 +139,11 @@ def run_test(protocol, hostname, port, client_cert, certdb_dir, size=key_size, usages=usages) print_key_request(response.request_info) - print "Request ID is " + response.request_info.get_request_id() + print("Request ID is " + response.request_info.get_request_id()) key_id = response.get_key_id() # Test 5: Confirm the key_id matches - print "Now getting key ID for clientKeyID=\"" + client_key_id + "\"" + print("Now getting key ID for clientKeyID=\"" + client_key_id + "\"") key_infos = keyclient.list_keys(client_key_id=client_key_id, status=keyclient.KEY_STATUS_ACTIVE) key_id2 = None @@ -150,16 +151,16 @@ def run_test(protocol, hostname, port, client_cert, certdb_dir, print_key_info(key_info) key_id2 = key_info.get_key_id() if key_id == key_id2: - print "Success! The keys from generation and search match." + print("Success! The keys from generation and search match.") else: - print "Failure - key_ids for generation do not match!" + print("Failure - key_ids for generation do not match!") # Test 6: Barbican_decode() - Retrieve while providing # trans_wrapped_session_key session_key = crypto.generate_session_key() wrapped_session_key = crypto.asymmetric_wrap(session_key, keyclient.transport_cert) - print "My key id is " + str(key_id) + print("My key id is " + str(key_id)) key_data = keyclient.retrieve_key( key_id, trans_wrapped_session_key=wrapped_session_key) print_key_data(key_data) @@ -175,70 +176,70 @@ def run_test(protocol, hostname, port, client_cert, certdb_dir, # Test 8 - Confirm that keys returned are the same if key1 == key2: - print "Success: The keys returned match! Key = " + str(key1) + print("Success: The keys returned match! Key = " + str(key1)) else: - print "Failure: The returned keys do not match!" - print "key1: " + key1 - print "key2: " + key2 + print("Failure: The returned keys do not match!") + print("key1: " + key1) + print("key2: " + key2) # Test 10 = test BadRequestException on create() - print "Trying to generate a new symkey with the same client ID" + print("Trying to generate a new symkey with the same client ID") try: keyclient.generate_symmetric_key(client_key_id, algorithm=algorithm, size=key_size, usages=usages) except pki.BadRequestException as exc: - print "BadRequestException thrown - Code:" + exc.code +\ - " Message: " + exc.message + print("BadRequestException thrown - Code:" + exc.code + + " Message: " + exc.message) # Test 11 - Test RequestNotFoundException on get_request_info - print "Try to list a nonexistent request" + print("Try to list a nonexistent request") try: keyclient.get_request_info('200000034') except pki.RequestNotFoundException as exc: - print "RequestNotFoundException thrown - Code:" + exc.code +\ - " Message: " + exc.message + print("RequestNotFoundException thrown - Code:" + exc.code + + " Message: " + exc.message) # Test 12 - Test exception on retrieve_key. - print "Try to retrieve an invalid key" + print("Try to retrieve an invalid key") try: keyclient.retrieve_key('2000003434') except pki.KeyNotFoundException as exc: - print "KeyNotFoundException thrown - Code:" + exc.code + \ - " Message: " + exc.message + print("KeyNotFoundException thrown - Code:" + exc.code + + " Message: " + exc.message) # Test 13 = getKeyInfo - print "Get key info for existing key" + print("Get key info for existing key") key_info = keyclient.get_key_info(key_id) print_key_info(key_info) # Test 14: get the active key - print "Get the active key for client id: " + client_key_id + print("Get the active key for client id: " + client_key_id) key_info = keyclient.get_active_key_info(client_key_id) print_key_info(key_info) # Test 15: change the key status - print "Change the key status" + print("Change the key status") keyclient.modify_key_status(key_id, keyclient.KEY_STATUS_INACTIVE) print_key_info(keyclient.get_key_info(key_id)) # Test 16: Get key info for non-existent key - print "Get key info for non-existent key" + print("Get key info for non-existent key") try: keyclient.get_key_info('200004556') except pki.KeyNotFoundException as exc: - print "KeyNotFoundException thrown - Code:" + exc.code +\ - " Message: " + exc.message + print("KeyNotFoundException thrown - Code:" + exc.code + + " Message: " + exc.message) # Test 17: Get key info for non-existent active key - print "Get non-existent active key" + print("Get non-existent active key") try: key_info = keyclient.get_active_key_info(client_key_id) print_key_info(key_info) except pki.ResourceNotFoundException as exc: - print "ResourceNotFoundException thrown - Code: " + exc.code +\ - "Message: " + exc.message + print("ResourceNotFoundException thrown - Code: " + exc.code + + "Message: " + exc.message) # Test 18: Generate a symmetric key with default parameters client_key_id = "Vek #3" + time.strftime('%c') @@ -246,8 +247,8 @@ def run_test(protocol, hostname, port, client_cert, certdb_dir, print_key_request(response.request_info) # Test 19: Try to archive key - print "try to archive key" - print "key to archive: " + key1 + print("try to archive key") + print("key to archive: " + key1) client_key_id = "Vek #4" + time.strftime('%c') response = keyclient.archive_key(client_key_id, @@ -266,13 +267,13 @@ def run_test(protocol, hostname, port, client_cert, certdb_dir, key2 = base64.encodestring(key_data.data) if key1 == key2: - print "Success: archived and recovered keys match" + print("Success: archived and recovered keys match") else: - print "Error: archived and recovered keys do not match" - print + print("Error: archived and recovered keys do not match") + print() # Test 20: Generating asymmetric keys - print "Generating asymmetric keys" + print("Generating asymmetric keys") try: response = keyclient.generate_asymmetric_key( "Vek #5" + time.strftime('%c'), @@ -282,24 +283,24 @@ def run_test(protocol, hostname, port, client_cert, certdb_dir, ) print_key_request(response.request_info) except pki.BadRequestException as exc: - print "BadRequestException thrown - Code:" + exc.code +\ - " Message: " + exc.message + print("BadRequestException thrown - Code:" + exc.code + + " Message: " + exc.message) # Test 21: Get key information of the newly generated asymmetric keys - print "Retrieving key information" + print("Retrieving key information") key_info = keyclient.get_key_info(response.request_info.get_key_id()) print_key_info(key_info) def usage(): - print 'Usage: drmtest.py [OPTIONS]' - print - print ' -P <protocol> KRA server protocol (default: https).' - print ' -h <hostname> KRA server hostname (default: localhost).' - print ' -p <port> KRA server port (default: 8443).' - print ' -n <path> KRA agent certificate and private key (default: kraagent.pem).' # nopep8 - print - print ' --help Show this help message.' + print('Usage: drmtest.py [OPTIONS]') + print() + print(' -P <protocol> KRA server protocol (default: https).') + print(' -h <hostname> KRA server hostname (default: localhost).') + print(' -p <port> KRA server port (default: 8443).') + print(' -n <path> KRA agent certificate and private key (default: kraagent.pem).') # nopep8 + print() + print(' --help Show this help message.') def main(argv): @@ -307,7 +308,7 @@ def main(argv): opts, _ = getopt.getopt(argv[1:], 'h:P:p:n:d:c:', ['help']) except getopt.GetoptError as e: - print 'ERROR: ' + str(e) + print('ERROR: ' + str(e)) usage() sys.exit(1) @@ -334,18 +335,18 @@ def main(argv): sys.exit() else: - print 'ERROR: unknown option ' + o + print('ERROR: unknown option ' + o) usage() sys.exit(1) certdb_dir = tempfile.mkdtemp(prefix='pki-kra-test-') - print "NSS database dir: %s" % certdb_dir + print("NSS database dir: %s" % certdb_dir) certdb_password = ''.join( random.choice( string.ascii_letters + string.digits) for i in range(8)) - print "NSS database password: %s" % certdb_password + print("NSS database password: %s" % certdb_password) try: run_test( diff --git a/base/server/python/pki/server/cli/instance.py b/base/server/python/pki/server/cli/instance.py index f9e971e8a..f74d251ca 100644 --- a/base/server/python/pki/server/cli/instance.py +++ b/base/server/python/pki/server/cli/instance.py @@ -20,6 +20,7 @@ # from __future__ import absolute_import +from __future__ import print_function import getopt import os import sys @@ -45,8 +46,8 @@ class InstanceCLI(pki.cli.CLI): @staticmethod def print_instance(instance): - print ' Instance ID: %s' % instance.name - print ' Active: %s' % instance.is_active() + print(' Instance ID: %s' % instance.name) + print(' Active: %s' % instance.is_active()) class InstanceFindCLI(pki.cli.CLI): @@ -55,11 +56,11 @@ class InstanceFindCLI(pki.cli.CLI): super(InstanceFindCLI, self).__init__('find', 'Find instances') def print_help(self): - print 'Usage: pki-server instance-find [OPTIONS]' - print - print ' -v, --verbose Run in verbose mode.' - print ' --help Show help message.' - print + print('Usage: pki-server instance-find [OPTIONS]') + print() + print(' -v, --verbose Run in verbose mode.') + print(' --help Show help message.') + print() def execute(self, argv): @@ -68,7 +69,7 @@ class InstanceFindCLI(pki.cli.CLI): 'verbose', 'help']) except getopt.GetoptError as e: - print 'ERROR: ' + str(e) + print('ERROR: ' + str(e)) self.print_help() sys.exit(1) @@ -81,7 +82,7 @@ class InstanceFindCLI(pki.cli.CLI): sys.exit() else: - print 'ERROR: unknown option ' + o + print('ERROR: unknown option ' + o) self.print_help() sys.exit(1) @@ -101,7 +102,7 @@ class InstanceFindCLI(pki.cli.CLI): if first: first = False else: - print + print() instance = pki.server.PKIInstance(instance_name) instance.load() @@ -115,11 +116,11 @@ class InstanceShowCLI(pki.cli.CLI): super(InstanceShowCLI, self).__init__('show', 'Show instance') def print_help(self): - print 'Usage: pki-server instance-show [OPTIONS] <instance ID>' - print - print ' -v, --verbose Run in verbose mode.' - print ' --help Show help message.' - print + print('Usage: pki-server instance-show [OPTIONS] <instance ID>') + print() + print(' -v, --verbose Run in verbose mode.') + print(' --help Show help message.') + print() def execute(self, argv): @@ -128,12 +129,12 @@ class InstanceShowCLI(pki.cli.CLI): 'verbose', 'help']) except getopt.GetoptError as e: - print 'ERROR: ' + str(e) + print('ERROR: ' + str(e)) self.print_help() sys.exit(1) if len(args) != 1: - print 'ERROR: missing instance ID' + print('ERROR: missing instance ID') self.print_help() sys.exit(1) @@ -148,7 +149,7 @@ class InstanceShowCLI(pki.cli.CLI): sys.exit() else: - print 'ERROR: unknown option ' + o + print('ERROR: unknown option ' + o) self.print_help() sys.exit(1) @@ -164,11 +165,11 @@ class InstanceStartCLI(pki.cli.CLI): super(InstanceStartCLI, self).__init__('start', 'Start instance') def print_help(self): - print 'Usage: pki-server instance-start [OPTIONS] <instance ID>' - print - print ' -v, --verbose Run in verbose mode.' - print ' --help Show help message.' - print + print('Usage: pki-server instance-start [OPTIONS] <instance ID>') + print() + print(' -v, --verbose Run in verbose mode.') + print(' --help Show help message.') + print() def execute(self, argv): @@ -177,12 +178,12 @@ class InstanceStartCLI(pki.cli.CLI): 'verbose', 'help']) except getopt.GetoptError as e: - print 'ERROR: ' + str(e) + print('ERROR: ' + str(e)) self.print_help() sys.exit(1) if len(args) != 1: - print 'ERROR: missing instance ID' + print('ERROR: missing instance ID') self.print_help() sys.exit(1) @@ -197,7 +198,7 @@ class InstanceStartCLI(pki.cli.CLI): sys.exit() else: - print 'ERROR: unknown option ' + o + print('ERROR: unknown option ' + o) self.print_help() sys.exit(1) @@ -214,11 +215,11 @@ class InstanceStopCLI(pki.cli.CLI): super(InstanceStopCLI, self).__init__('stop', 'Stop instance') def print_help(self): - print 'Usage: pki-server instance-stop [OPTIONS] <instance ID>' - print - print ' -v, --verbose Run in verbose mode.' - print ' --help Show help message.' - print + print('Usage: pki-server instance-stop [OPTIONS] <instance ID>') + print() + print(' -v, --verbose Run in verbose mode.') + print(' --help Show help message.') + print() def execute(self, argv): @@ -227,12 +228,12 @@ class InstanceStopCLI(pki.cli.CLI): 'verbose', 'help']) except getopt.GetoptError as e: - print 'ERROR: ' + str(e) + print('ERROR: ' + str(e)) self.print_help() sys.exit(1) if len(args) != 1: - print 'ERROR: missing instance ID' + print('ERROR: missing instance ID') self.print_help() sys.exit(1) @@ -247,7 +248,7 @@ class InstanceStopCLI(pki.cli.CLI): sys.exit() else: - print 'ERROR: unknown option ' + o + print('ERROR: unknown option ' + o) self.print_help() sys.exit(1) @@ -264,13 +265,13 @@ class InstanceMigrateCLI(pki.cli.CLI): super(InstanceMigrateCLI, self).__init__('migrate', 'Migrate instance') def print_help(self): - print 'Usage: pki-server instance-migrate [OPTIONS] <instance ID>' - print - print ' --tomcat <version> Use the specified Tomcat version.' - print ' -v, --verbose Run in verbose mode.' - print ' --debug Show debug messages.' - print ' --help Show help message.' - print + print('Usage: pki-server instance-migrate [OPTIONS] <instance ID>') + print() + print(' --tomcat <version> Use the specified Tomcat version.') + print(' -v, --verbose Run in verbose mode.') + print(' --debug Show debug messages.') + print(' --help Show help message.') + print() def execute(self, argv): @@ -279,12 +280,12 @@ class InstanceMigrateCLI(pki.cli.CLI): 'tomcat=', 'verbose', 'debug', 'help']) except getopt.GetoptError as e: - print 'ERROR: ' + str(e) + print('ERROR: ' + str(e)) self.print_help() sys.exit(1) if len(args) != 1: - print 'ERROR: missing instance ID' + print('ERROR: missing instance ID') self.print_help() sys.exit(1) @@ -307,12 +308,12 @@ class InstanceMigrateCLI(pki.cli.CLI): sys.exit() else: - print 'ERROR: unknown option ' + o + print('ERROR: unknown option ' + o) self.print_help() sys.exit(1) if not tomcat_version: - print 'ERROR: missing Tomcat version' + print('ERROR: missing Tomcat version') self.print_help() sys.exit(1) @@ -338,11 +339,11 @@ class InstanceNuxwdogEnableCLI(pki.cli.CLI): 'Instance enable nuxwdog') def print_help(self): - print 'Usage: pki-server instance-nuxwdog-enable [OPTIONS] <instance ID>' - print - print ' -v, --verbose Run in verbose mode.' - print ' --help Show help message.' - print + print('Usage: pki-server instance-nuxwdog-enable [OPTIONS] <instance ID>') + print() + print(' -v, --verbose Run in verbose mode.') + print(' --help Show help message.') + print() def execute(self, argv): try: @@ -350,12 +351,12 @@ class InstanceNuxwdogEnableCLI(pki.cli.CLI): 'verbose', 'help']) except getopt.GetoptError as e: - print 'ERROR: ' + str(e) + print('ERROR: ' + str(e)) self.print_help() sys.exit(1) if len(args) != 1: - print 'ERROR: missing instance ID' + print('ERROR: missing instance ID') self.print_help() sys.exit(1) @@ -368,7 +369,7 @@ class InstanceNuxwdogEnableCLI(pki.cli.CLI): self.print_help() sys.exit() else: - print 'ERROR: unknown option ' + o + print('ERROR: unknown option ' + o) self.print_help() sys.exit(1) @@ -393,11 +394,11 @@ class InstanceNuxwdogDisableCLI(pki.cli.CLI): 'Instance disable nuxwdog') def print_help(self): - print 'Usage: pki-server instance-nuxwdog-disable [OPTIONS] <instance ID>' - print - print ' -v, --verbose Run in verbose mode.' - print ' --help Show help message.' - print + print('Usage: pki-server instance-nuxwdog-disable [OPTIONS] <instance ID>') + print() + print(' -v, --verbose Run in verbose mode.') + print(' --help Show help message.') + print() def execute(self, argv): try: @@ -405,12 +406,12 @@ class InstanceNuxwdogDisableCLI(pki.cli.CLI): 'verbose', 'help']) except getopt.GetoptError as e: - print 'ERROR: ' + str(e) + print('ERROR: ' + str(e)) self.print_help() sys.exit(1) if len(args) != 1: - print 'ERROR: missing instance ID' + print('ERROR: missing instance ID') self.print_help() sys.exit(1) @@ -423,7 +424,7 @@ class InstanceNuxwdogDisableCLI(pki.cli.CLI): self.print_help() sys.exit() else: - print 'ERROR: unknown option ' + o + print('ERROR: unknown option ' + o) self.print_help() sys.exit(1) diff --git a/base/server/python/pki/server/cli/migrate.py b/base/server/python/pki/server/cli/migrate.py index 325462048..98330eff4 100644 --- a/base/server/python/pki/server/cli/migrate.py +++ b/base/server/python/pki/server/cli/migrate.py @@ -20,6 +20,7 @@ # from __future__ import absolute_import +from __future__ import print_function import getopt import os import sys @@ -38,13 +39,13 @@ class MigrateCLI(pki.cli.CLI): self.parser = etree.XMLParser(remove_blank_text=True) def print_help(self): - print 'Usage: pki-server migrate [OPTIONS]' - print - print ' --tomcat <version> Use the specified Tomcat version.' - print ' -v, --verbose Run in verbose mode.' - print ' --debug Show debug messages.' - print ' --help Show help message.' - print + print('Usage: pki-server migrate [OPTIONS]') + print() + print(' --tomcat <version> Use the specified Tomcat version.') + print(' -v, --verbose Run in verbose mode.') + print(' --debug Show debug messages.') + print(' --help Show help message.') + print() def execute(self, argv): try: @@ -52,7 +53,7 @@ class MigrateCLI(pki.cli.CLI): 'tomcat=', 'verbose', 'debug', 'help']) except getopt.GetoptError as e: - print 'ERROR: ' + str(e) + print('ERROR: ' + str(e)) self.print_help() sys.exit(1) @@ -74,12 +75,12 @@ class MigrateCLI(pki.cli.CLI): sys.exit() else: - print 'ERROR: unknown option ' + o + print('ERROR: unknown option ' + o) self.print_help() sys.exit(1) if not tomcat_version: - print 'ERROR: missing Tomcat version' + print('ERROR: missing Tomcat version') self.print_help() sys.exit(1) @@ -116,7 +117,7 @@ class MigrateCLI(pki.cli.CLI): def migrate_server_xml(self, filename, tomcat_version): if self.verbose: - print 'Migrating %s' % filename + print('Migrating %s' % filename) document = etree.parse(filename, self.parser) @@ -127,7 +128,7 @@ class MigrateCLI(pki.cli.CLI): self.migrate_server_xml_to_tomcat8(document) elif tomcat_version: - print 'ERROR: invalid Tomcat version %s' % tomcat_version + print('ERROR: invalid Tomcat version %s' % tomcat_version) self.print_help() sys.exit(1) @@ -188,7 +189,7 @@ class MigrateCLI(pki.cli.CLI): 'org.apache.catalina.core.JreMemoryLeakPreventionListener', 'org.apache.catalina.core.ThreadLocalLeakPreventionListener'}: if self.debug: - print '* removing %s' % class_name + print('* removing %s' % class_name) server.remove(child) elif class_name == 'org.apache.catalina.core.JasperListener': @@ -210,7 +211,7 @@ class MigrateCLI(pki.cli.CLI): if jasper_listener is not None: if self.debug: - print '* adding %s' % jasper_listener.get('className') + print('* adding %s' % jasper_listener.get('className')) server.insert(index, jasper_listener) index += 1 @@ -231,7 +232,7 @@ class MigrateCLI(pki.cli.CLI): index += 1 if self.debug: - print '* updating secure Connector' + print('* updating secure Connector') connectors = server.findall('Service/Connector') for connector in connectors: @@ -239,7 +240,7 @@ class MigrateCLI(pki.cli.CLI): connector.set('protocol', 'HTTP/1.1') if self.debug: - print '* updating AccessLogValve' + print('* updating AccessLogValve') valves = server.findall('Service/Engine/Host/Valve') for valve in valves: @@ -297,7 +298,7 @@ class MigrateCLI(pki.cli.CLI): if class_name == 'org.apache.catalina.core.JasperListener'\ or class_name == 'org.apache.catalina.mbeans.ServerLifecycleListener': if self.debug: - print '* removing %s' % class_name + print('* removing %s' % class_name) server.remove(child) elif class_name == 'org.apache.catalina.startup.VersionLoggerListener': version_logger_listener = None @@ -313,7 +314,7 @@ class MigrateCLI(pki.cli.CLI): if version_logger_listener is not None: if self.debug: - print '* adding VersionLoggerListener' + print('* adding VersionLoggerListener') server.insert(index, version_logger_listener) index += 1 @@ -331,7 +332,7 @@ class MigrateCLI(pki.cli.CLI): if jre_memory_leak_prevention_listener is not None: if self.debug: - print '* adding JreMemoryLeakPreventionListener' + print('* adding JreMemoryLeakPreventionListener') server.insert(index, jre_memory_leak_prevention_listener) index += 1 @@ -341,12 +342,12 @@ class MigrateCLI(pki.cli.CLI): if thread_local_leak_prevention_listener is not None: if self.debug: - print '* adding ThreadLocalLeakPreventionListener' + print('* adding ThreadLocalLeakPreventionListener') server.insert(index, thread_local_leak_prevention_listener) index += 1 if self.debug: - print '* updating secure Connector' + print('* updating secure Connector') connectors = server.findall('Service/Connector') for connector in connectors: @@ -357,7 +358,7 @@ class MigrateCLI(pki.cli.CLI): 'org.apache.coyote.http11.Http11Protocol') if self.debug: - print '* updating AccessLogValve' + print('* updating AccessLogValve') valves = server.findall('Service/Engine/Host/Valve') for valve in valves: @@ -378,7 +379,7 @@ class MigrateCLI(pki.cli.CLI): return if self.verbose: - print 'Migrating %s' % filename + print('Migrating %s' % filename) document = etree.parse(filename, self.parser) @@ -389,7 +390,7 @@ class MigrateCLI(pki.cli.CLI): self.migrate_context_xml_to_tomcat8(document) elif tomcat_version: - print 'ERROR: invalid Tomcat version %s' % tomcat_version + print('ERROR: invalid Tomcat version %s' % tomcat_version) self.print_help() sys.exit(1) @@ -405,7 +406,7 @@ class MigrateCLI(pki.cli.CLI): if resources is not None: if self.debug: - print '* removing Resources' + print('* removing Resources') context.remove(resources) @@ -419,7 +420,7 @@ class MigrateCLI(pki.cli.CLI): if resources is None: if self.debug: - print '* adding Resources' + print('* adding Resources') resources = etree.Element('Resources') context.append(resources) @@ -436,7 +437,7 @@ class MigrateCLI(pki.cli.CLI): path = os.path.join(instance.lib_dir, filename) if self.verbose: - print 'Removing %s' % path + print('Removing %s' % path) os.remove(path) @@ -452,7 +453,7 @@ class MigrateCLI(pki.cli.CLI): dest = os.path.join(instance.lib_dir, filename) if self.verbose: - print 'Creating %s' % dest + print('Creating %s' % dest) os.symlink(source, dest) os.lchown(dest, instance.uid, instance.gid) diff --git a/base/server/python/pki/server/cli/nuxwdog.py b/base/server/python/pki/server/cli/nuxwdog.py index 36ff3c5d5..674fc0340 100644 --- a/base/server/python/pki/server/cli/nuxwdog.py +++ b/base/server/python/pki/server/cli/nuxwdog.py @@ -20,6 +20,7 @@ # from __future__ import absolute_import +from __future__ import print_function import getopt import fileinput import os @@ -59,11 +60,11 @@ class NuxwdogEnableCLI(pki.cli.CLI): 'Enable nuxwdog') def print_help(self): - print 'Usage: pki-server nuxwdog-enable [OPTIONS]' - print - print ' -v, --verbose Run in verbose mode.' - print ' --help Show help message.' - print + print('Usage: pki-server nuxwdog-enable [OPTIONS]') + print() + print(' -v, --verbose Run in verbose mode.') + print(' --help Show help message.') + print() def execute(self, argv): try: @@ -71,7 +72,7 @@ class NuxwdogEnableCLI(pki.cli.CLI): 'verbose', 'help']) except getopt.GetoptError as e: - print 'ERROR: ' + str(e) + print('ERROR: ' + str(e)) self.print_help() sys.exit(1) @@ -84,7 +85,7 @@ class NuxwdogEnableCLI(pki.cli.CLI): sys.exit() else: - print 'ERROR: unknown option ' + o + print('ERROR: unknown option ' + o) self.print_help() sys.exit(1) @@ -172,7 +173,7 @@ class NuxwdogEnableCLI(pki.cli.CLI): def enable_nuxwdog_server_xml(self, filename, instance): if self.verbose: - print 'Enabling nuxwdog in %s' % filename + print('Enabling nuxwdog in %s' % filename) conf_file = self.get_conf_file(instance) @@ -265,11 +266,11 @@ class NuxwdogDisableCLI(pki.cli.CLI): 'Disable nuxwdog') def print_help(self): - print 'Usage: pki-server nuxwdog-disable [OPTIONS]' - print - print ' -v, --verbose Run in verbose mode.' - print ' --help Show help message.' - print + print('Usage: pki-server nuxwdog-disable [OPTIONS]') + print() + print(' -v, --verbose Run in verbose mode.') + print(' --help Show help message.') + print() def execute(self, argv): try: @@ -277,7 +278,7 @@ class NuxwdogDisableCLI(pki.cli.CLI): 'verbose', 'help']) except getopt.GetoptError as e: - print 'ERROR: ' + str(e) + print('ERROR: ' + str(e)) self.print_help() sys.exit(1) @@ -290,7 +291,7 @@ class NuxwdogDisableCLI(pki.cli.CLI): sys.exit() else: - print 'ERROR: unknown option ' + o + print('ERROR: unknown option ' + o) self.print_help() sys.exit(1) @@ -351,7 +352,7 @@ class NuxwdogDisableCLI(pki.cli.CLI): def disable_nuxwdog_server_xml(self, filename, instance): if self.verbose: - print 'Disabling nuxwdog in %s' % filename + print('Disabling nuxwdog in %s' % filename) pw_conf = os.path.join(instance.conf_dir, 'password.conf') diff --git a/base/server/python/pki/server/cli/subsystem.py b/base/server/python/pki/server/cli/subsystem.py index 2f1e7e2f8..b1c20af59 100644 --- a/base/server/python/pki/server/cli/subsystem.py +++ b/base/server/python/pki/server/cli/subsystem.py @@ -20,6 +20,7 @@ # from __future__ import absolute_import +from __future__ import print_function import getopt import os import sys @@ -41,9 +42,9 @@ class SubsystemCLI(pki.cli.CLI): @staticmethod def print_subsystem(subsystem): - print ' Subsystem ID: %s' % subsystem.name - print ' Instance ID: %s' % subsystem.instance.name - print ' Enabled: %s' % subsystem.is_enabled() + print(' Subsystem ID: %s' % subsystem.name) + print(' Instance ID: %s' % subsystem.instance.name) + print(' Enabled: %s' % subsystem.is_enabled()) class SubsystemFindCLI(pki.cli.CLI): @@ -52,12 +53,12 @@ class SubsystemFindCLI(pki.cli.CLI): super(SubsystemFindCLI, self).__init__('find', 'Find subsystems') def usage(self): - print 'Usage: pki-server subsystem-find [OPTIONS]' - print - print ' -i, --instance <instance ID> Instance ID.' - print ' -v, --verbose Run in verbose mode.' - print ' --help Show help message.' - print + print('Usage: pki-server subsystem-find [OPTIONS]') + print() + print(' -i, --instance <instance ID> Instance ID.') + print(' -v, --verbose Run in verbose mode.') + print(' --help Show help message.') + print() def execute(self, args): @@ -67,7 +68,7 @@ class SubsystemFindCLI(pki.cli.CLI): 'verbose', 'help']) except getopt.GetoptError as e: - print 'ERROR: ' + str(e) + print('ERROR: ' + str(e)) self.usage() sys.exit(1) @@ -85,12 +86,12 @@ class SubsystemFindCLI(pki.cli.CLI): sys.exit() else: - print 'ERROR: unknown option ' + o + print('ERROR: unknown option ' + o) self.usage() sys.exit(1) if not instance_name: - print 'ERROR: missing instance ID' + print('ERROR: missing instance ID') self.usage() sys.exit(1) @@ -114,7 +115,7 @@ class SubsystemFindCLI(pki.cli.CLI): if first: first = False else: - print + print() SubsystemCLI.print_subsystem(subsystem) @@ -125,12 +126,12 @@ class SubsystemShowCLI(pki.cli.CLI): super(SubsystemShowCLI, self).__init__('show', 'Show subsystem') def usage(self): - print 'Usage: pki-server subsystem-show [OPTIONS] <subsystem ID>' - print - print ' -i, --instance <instance ID> Instance ID.' - print ' -v, --verbose Run in verbose mode.' - print ' --help Show help message.' - print + print('Usage: pki-server subsystem-show [OPTIONS] <subsystem ID>') + print() + print(' -i, --instance <instance ID> Instance ID.') + print(' -v, --verbose Run in verbose mode.') + print(' --help Show help message.') + print() def execute(self, argv): @@ -140,12 +141,12 @@ class SubsystemShowCLI(pki.cli.CLI): 'verbose', 'help']) except getopt.GetoptError as e: - print 'ERROR: ' + str(e) + print('ERROR: ' + str(e)) self.usage() sys.exit(1) if len(args) != 1: - print 'ERROR: missing subsystem ID' + print('ERROR: missing subsystem ID') self.usage() sys.exit(1) @@ -164,12 +165,12 @@ class SubsystemShowCLI(pki.cli.CLI): sys.exit() else: - print 'ERROR: unknown option ' + o + print('ERROR: unknown option ' + o) self.usage() sys.exit(1) if not instance_name: - print 'ERROR: missing instance ID' + print('ERROR: missing instance ID') self.usage() sys.exit(1) @@ -187,12 +188,12 @@ class SubsystemEnableCLI(pki.cli.CLI): super(SubsystemEnableCLI, self).__init__('enable', 'Enable subsystem') def usage(self): - print 'Usage: pki-server subsystem-enable [OPTIONS] <subsystem ID>' - print - print ' -i, --instance <instance ID> Instance ID.' - print ' -v, --verbose Run in verbose mode.' - print ' --help Show help message.' - print + print('Usage: pki-server subsystem-enable [OPTIONS] <subsystem ID>') + print() + print(' -i, --instance <instance ID> Instance ID.') + print(' -v, --verbose Run in verbose mode.') + print(' --help Show help message.') + print() def execute(self, argv): @@ -202,12 +203,12 @@ class SubsystemEnableCLI(pki.cli.CLI): 'verbose', 'help']) except getopt.GetoptError as e: - print 'ERROR: ' + str(e) + print('ERROR: ' + str(e)) self.usage() sys.exit(1) if len(args) != 1: - print 'ERROR: missing subsystem ID' + print('ERROR: missing subsystem ID') self.usage() sys.exit(1) @@ -226,12 +227,12 @@ class SubsystemEnableCLI(pki.cli.CLI): sys.exit() else: - print 'ERROR: unknown option ' + o + print('ERROR: unknown option ' + o) self.usage() sys.exit(1) if not instance_name: - print 'ERROR: missing instance ID' + print('ERROR: missing instance ID') self.usage() sys.exit(1) @@ -254,12 +255,12 @@ class SubsystemDisableCLI(pki.cli.CLI): 'Disable subsystem') def usage(self): - print 'Usage: pki-server subsystem-disable [OPTIONS] <subsystem ID>' - print - print ' -i, --instance <instance ID> Instance ID.' - print ' -v, --verbose Run in verbose mode.' - print ' --help Show help message.' - print + print('Usage: pki-server subsystem-disable [OPTIONS] <subsystem ID>') + print() + print(' -i, --instance <instance ID> Instance ID.') + print(' -v, --verbose Run in verbose mode.') + print(' --help Show help message.') + print() def execute(self, argv): @@ -269,12 +270,12 @@ class SubsystemDisableCLI(pki.cli.CLI): 'verbose', 'help']) except getopt.GetoptError as e: - print 'ERROR: ' + str(e) + print('ERROR: ' + str(e)) self.usage() sys.exit(1) if len(args) != 1: - print 'ERROR: missing subsystem ID' + print('ERROR: missing subsystem ID') self.usage() sys.exit(1) @@ -293,12 +294,12 @@ class SubsystemDisableCLI(pki.cli.CLI): sys.exit() else: - print 'ERROR: unknown option ' + o + print('ERROR: unknown option ' + o) self.usage() sys.exit(1) if not instance_name: - print 'ERROR: missing instance ID' + print('ERROR: missing instance ID') self.usage() sys.exit(1) diff --git a/base/server/python/pki/server/deployment/pkiconfig.py b/base/server/python/pki/server/deployment/pkiconfig.py index 8bca657de..c22698cb6 100644 --- a/base/server/python/pki/server/deployment/pkiconfig.py +++ b/base/server/python/pki/server/deployment/pkiconfig.py @@ -20,6 +20,7 @@ # # PKI Deployment Constants +from __future__ import print_function PKI_DEPLOYMENT_DEFAULT_CLIENT_DIR_PERMISSIONS = 0o0755 PKI_DEPLOYMENT_DEFAULT_DIR_PERMISSIONS = 0o0770 PKI_DEPLOYMENT_DEFAULT_EXE_PERMISSIONS = 0o0770 @@ -127,38 +128,38 @@ def str2bool(string): # 'pki_enable_java_debugger=True' in the appropriate # deployment configuration file. def prepare_for_an_external_java_debugger(instance): - print - print PKI_DEPLOYMENT_INTERRUPT_BANNER - print - print "The following 'JAVA_OPTS' MUST be edited in" - print "'%s':" % instance - print - print " JAVA_OPTS=\"-DRESTEASY_LIB=/usr/share/java/resteasy \"" - print " \"-Xdebug -Xrunjdwp:transport=dt_socket,\"" - print " \"address=8000,server=y,suspend=n \"" - print " \"-Djava.awt.headless=true -Xmx128M\"" - print + print() + print(PKI_DEPLOYMENT_INTERRUPT_BANNER) + print() + print("The following 'JAVA_OPTS' MUST be edited in") + print("'%s':" % instance) + print() + print(" JAVA_OPTS=\"-DRESTEASY_LIB=/usr/share/java/resteasy \"") + print(" \"-Xdebug -Xrunjdwp:transport=dt_socket,\"") + print(" \"address=8000,server=y,suspend=n \"") + print(" \"-Djava.awt.headless=true -Xmx128M\"") + print() raw_input("Enable external java debugger 'JAVA_OPTS' " "and press return to continue . . . ") - print - print PKI_DEPLOYMENT_INTERRUPT_BANNER - print + print() + print(PKI_DEPLOYMENT_INTERRUPT_BANNER) + print() return def wait_to_attach_an_external_java_debugger(): - print - print PKI_DEPLOYMENT_INTERRUPT_BANNER - print - print "Attach the java debugger to this process on the port specified by" - print "the 'address' selected by 'JAVA_OPTS' (e. g. - port 8000) and" - print "set any desired breakpoints" - print + print() + print(PKI_DEPLOYMENT_INTERRUPT_BANNER) + print() + print("Attach the java debugger to this process on the port specified by") + print("the 'address' selected by 'JAVA_OPTS' (e. g. - port 8000) and") + print("set any desired breakpoints") + print() raw_input("Please attach an external java debugger " "and press return to continue . . . ") - print - print PKI_DEPLOYMENT_INTERRUPT_BANNER - print + print() + print(PKI_DEPLOYMENT_INTERRUPT_BANNER) + print() return diff --git a/base/server/python/pki/server/deployment/pkihelper.py b/base/server/python/pki/server/deployment/pkihelper.py index 589da5c74..de3b1bc55 100644 --- a/base/server/python/pki/server/deployment/pkihelper.py +++ b/base/server/python/pki/server/deployment/pkihelper.py @@ -22,6 +22,7 @@ # System Imports from __future__ import absolute_import +from __future__ import print_function import errno import sys import os @@ -4455,7 +4456,7 @@ class ConfigClient: data.adminCertRequest = b64 else: - print "log.PKI_CONFIG_PKCS10_SUPPORT_ONLY" + print("log.PKI_CONFIG_PKCS10_SUPPORT_ONLY") raise Exception(log.PKI_CONFIG_PKCS10_SUPPORT_ONLY) def set_issuing_ca_parameters(self, data): diff --git a/base/server/python/pki/server/deployment/pkimanifest.py b/base/server/python/pki/server/deployment/pkimanifest.py index d959efb4a..09c9ac668 100644 --- a/base/server/python/pki/server/deployment/pkimanifest.py +++ b/base/server/python/pki/server/deployment/pkimanifest.py @@ -21,6 +21,7 @@ # System Imports from __future__ import absolute_import +from __future__ import print_function import csv # PKI Deployment Imports @@ -97,7 +98,7 @@ class File: with open(self.filename, "r") as fd: cr = csv.reader(fd) for row in cr: - print tuple(row) + print(tuple(row)) except IOError as exc: config.pki_log.error(log.PKI_IOERROR_1, exc, extra=config.PKI_INDENTATION_LEVEL_1) diff --git a/base/server/python/pki/server/deployment/pkiparser.py b/base/server/python/pki/server/deployment/pkiparser.py index 08815a6b1..84e14bfec 100644 --- a/base/server/python/pki/server/deployment/pkiparser.py +++ b/base/server/python/pki/server/deployment/pkiparser.py @@ -21,6 +21,7 @@ # System Imports from __future__ import absolute_import +from __future__ import print_function import ConfigParser import argparse import getpass @@ -136,20 +137,20 @@ class PKIConfigParser: if len(config.pki_root_prefix) > 0: if not os.path.exists(config.pki_root_prefix) or \ not os.path.isdir(config.pki_root_prefix): - print "ERROR: " + \ - log.PKI_DIRECTORY_MISSING_OR_NOT_A_DIRECTORY_1 % \ - config.pki_root_prefix - print + print("ERROR: " + + log.PKI_DIRECTORY_MISSING_OR_NOT_A_DIRECTORY_1 % + config.pki_root_prefix) + print() self.arg_parser.print_help() self.arg_parser.exit(-1) # always default that configuration file exists if not os.path.exists(config.default_deployment_cfg) or \ not os.path.isfile(config.default_deployment_cfg): - print "ERROR: " + \ - log.PKI_FILE_MISSING_OR_NOT_A_FILE_1 % \ - config.default_deployment_cfg - print + print("ERROR: " + + log.PKI_FILE_MISSING_OR_NOT_A_FILE_1 % + config.default_deployment_cfg) + print() self.arg_parser.print_help() self.arg_parser.exit(-1) @@ -157,10 +158,10 @@ class PKIConfigParser: # verify user configuration file exists if not os.path.exists(config.user_deployment_cfg) or \ not os.path.isfile(config.user_deployment_cfg): - print "ERROR: " + \ - log.PKI_FILE_MISSING_OR_NOT_A_FILE_1 % \ - config.user_deployment_cfg - print + print("ERROR: " + + log.PKI_FILE_MISSING_OR_NOT_A_FILE_1 % + config.user_deployment_cfg) + print() self.arg_parser.print_help() self.arg_parser.exit(-1) @@ -247,7 +248,7 @@ class PKIConfigParser: config.user_config.set(section, key, value) def print_text(self, message): - print ' ' * self.indent + message + print(' ' * self.indent + message) def read_text(self, message, section=None, key=None, default=None, options=None, sign=':', allow_empty=True, @@ -337,8 +338,8 @@ class PKIConfigParser: 'pki_replicationdb_password', 'pki_security_domain_password') - print 'Loading deployment configuration from ' + \ - config.user_deployment_cfg + '.' + print('Loading deployment configuration from ' + + config.user_deployment_cfg + '.') self.pki_config.read([config.user_deployment_cfg]) config.user_config.read([config.user_deployment_cfg]) @@ -372,7 +373,7 @@ class PKIConfigParser: except ConfigParser.NoOptionError: continue except ConfigParser.ParsingError as err: - print err + print(err) rv = err return rv diff --git a/base/server/python/pki/server/deployment/scriptlets/infrastructure_layout.py b/base/server/python/pki/server/deployment/scriptlets/infrastructure_layout.py index 365bfb763..f7ef82825 100644 --- a/base/server/python/pki/server/deployment/scriptlets/infrastructure_layout.py +++ b/base/server/python/pki/server/deployment/scriptlets/infrastructure_layout.py @@ -22,6 +22,7 @@ from __future__ import absolute_import # PKI Deployment Imports +from __future__ import print_function from .. import pkiconfig as config from .. import pkimessages as log from .. import pkiscriptlet @@ -63,8 +64,8 @@ class PkiScriptlet(pkiscriptlet.AbstractBasePkiScriptlet): deployer.mdict['pki_default_deployment_cfg'], deployer.mdict['pki_default_deployment_cfg_replica']) - print "Storing deployment configuration into " + \ - deployer.mdict['pki_user_deployment_cfg_replica'] + "." + print("Storing deployment configuration into " + + deployer.mdict['pki_user_deployment_cfg_replica'] + ".") # Archive the user deployment configuration excluding the sensitive # parameters diff --git a/base/server/python/pki/server/upgrade.py b/base/server/python/pki/server/upgrade.py index cc9db48e4..a0e52b22b 100644 --- a/base/server/python/pki/server/upgrade.py +++ b/base/server/python/pki/server/upgrade.py @@ -20,6 +20,7 @@ # from __future__ import absolute_import +from __future__ import print_function import os import traceback @@ -78,12 +79,12 @@ class PKIServerUpgradeScriptlet(pki.upgrade.PKIUpgradeScriptlet): if not self.can_upgrade_server(instance): if verbose: - print 'Skipping ' + str(instance) + ' instance.' + print('Skipping ' + str(instance) + ' instance.') continue try: if verbose: - print 'Upgrading ' + str(instance) + ' instance.' + print('Upgrading ' + str(instance) + ' instance.') self.upgrade_instance(instance) self.update_server_tracker(instance) @@ -92,11 +93,11 @@ class PKIServerUpgradeScriptlet(pki.upgrade.PKIUpgradeScriptlet): if verbose: traceback.print_exc() else: - print 'ERROR: %s' % e + print('ERROR: %s' % e) message = 'Failed upgrading ' + str(instance) + ' instance.' if self.upgrader.silent: - print message + print(message) else: result = pki.read_text( message + ' Continue (Yes/No)', @@ -113,12 +114,12 @@ class PKIServerUpgradeScriptlet(pki.upgrade.PKIUpgradeScriptlet): if not self.can_upgrade_server(instance, subsystem): if verbose: - print 'Skipping ' + str(subsystem) + ' subsystem.' + print('Skipping ' + str(subsystem) + ' subsystem.') continue try: if verbose: - print 'Upgrading ' + str(subsystem) + ' subsystem.' + print('Upgrading ' + str(subsystem) + ' subsystem.') self.upgrade_subsystem(instance, subsystem) self.update_server_tracker(instance, subsystem) @@ -127,11 +128,11 @@ class PKIServerUpgradeScriptlet(pki.upgrade.PKIUpgradeScriptlet): if verbose: traceback.print_exc() else: - print 'ERROR: %s' % e + print('ERROR: %s' % e) message = 'Failed upgrading ' + str(subsystem) + ' subsystem.' if self.upgrader.silent: - print message + print(message) else: result = pki.read_text( message + ' Continue (Yes/No)', @@ -326,7 +327,7 @@ class PKIServerUpgrader(pki.upgrade.PKIUpgrader): tracker = self.get_server_tracker(instance, subsystem) tracker.set(version) - print 'Tracker has been set to version ' + str(version) + '.' + print('Tracker has been set to version ' + str(version) + '.') def remove_tracker(self): for instance in self.instances(): @@ -340,4 +341,4 @@ class PKIServerUpgrader(pki.upgrade.PKIUpgrader): tracker = self.get_server_tracker(instance, subsystem) tracker.remove() - print 'Tracker has been removed.' + print('Tracker has been removed.') diff --git a/base/server/sbin/pki-server b/base/server/sbin/pki-server index ad70a4838..d479788de 100644 --- a/base/server/sbin/pki-server +++ b/base/server/sbin/pki-server @@ -20,6 +20,7 @@ # from __future__ import absolute_import +from __future__ import print_function import getopt import sys @@ -46,12 +47,12 @@ class PKIServerCLI(pki.cli.CLI): return module_name def print_help(self): - print 'Usage: pki-server [OPTIONS]' - print - print ' -v, --verbose Run in verbose mode.' - print ' --debug Show debug messages.' - print ' --help Show help message.' - print + print('Usage: pki-server [OPTIONS]') + print() + print(' -v, --verbose Run in verbose mode.') + print(' --debug Show debug messages.') + print(' --help Show help message.') + print() super(PKIServerCLI, self).print_help() @@ -61,7 +62,7 @@ class PKIServerCLI(pki.cli.CLI): 'verbose', 'debug', 'help']) except getopt.GetoptError as e: - print 'ERROR: ' + str(e) + print('ERROR: ' + str(e)) self.print_help() sys.exit(1) @@ -78,12 +79,12 @@ class PKIServerCLI(pki.cli.CLI): sys.exit() else: - print 'ERROR: unknown option ' + o + print('ERROR: unknown option ' + o) self.print_help() sys.exit(1) if self.verbose: - print 'Command: %s' % ' '.join(args) + print('Command: %s' % ' '.join(args)) super(PKIServerCLI, self).execute(args) diff --git a/base/server/sbin/pki-server-upgrade b/base/server/sbin/pki-server-upgrade index 6f4bed802..73e0e4a17 100755 --- a/base/server/sbin/pki-server-upgrade +++ b/base/server/sbin/pki-server-upgrade @@ -20,6 +20,7 @@ # from __future__ import absolute_import +from __future__ import print_function import getopt import signal import sys @@ -31,39 +32,39 @@ import pki.server.upgrade # pylint: disable=W0613 def interrupt_handler(event, frame): - print - print - print 'Upgrade canceled.' + print() + print() + print('Upgrade canceled.') sys.exit(1) def usage(): - print 'Usage: pki-server-upgrade [OPTIONS]' - print - print ' --silent Upgrade in silent mode.' - print ' --status Show upgrade status only. Do not perform upgrade.' - print ' --revert Revert the last version.' - print - print ' -i, --instance <instance> Upgrade a specific instance only.' - print ' -s, --subsystem <subsystem> Upgrade a specific subsystem in an instance only.' - print ' -t, --instance-type <type> Upgrade a specific instance type.' - print ' Specify 9 for Dogtag 9 instances, 10 for Dogtag 10.' - print - print ' -X Show advanced options.' - print ' -v, --verbose Run in verbose mode.' - print ' -h, --help Show this help message.' + print('Usage: pki-server-upgrade [OPTIONS]') + print() + print(' --silent Upgrade in silent mode.') + print(' --status Show upgrade status only. Do not perform upgrade.') + print(' --revert Revert the last version.') + print() + print(' -i, --instance <instance> Upgrade a specific instance only.') + print(' -s, --subsystem <subsystem> Upgrade a specific subsystem in an instance only.') + print(' -t, --instance-type <type> Upgrade a specific instance type.') + print(' Specify 9 for Dogtag 9 instances, 10 for Dogtag 10.') + print() + print(' -X Show advanced options.') + print(' -v, --verbose Run in verbose mode.') + print(' -h, --help Show this help message.') def advancedOptions(): - print - print 'WARNING: These options may render the system unusable.' - print - print ' --scriptlet-version <version> Run scriptlets for a specific version only.' - print ' --scriptlet-index <index> Run a specific scriptlet only.' - print - print ' --remove-tracker Remove tracker.' - print ' --reset-tracker Reset tracker to match package version.' - print ' --set-tracker <version> Set tracker to a specific version.' + print() + print('WARNING: These options may render the system unusable.') + print() + print(' --scriptlet-version <version> Run scriptlets for a specific version only.') + print(' --scriptlet-index <index> Run a specific scriptlet only.') + print() + print(' --remove-tracker Remove tracker.') + print(' --reset-tracker Reset tracker to match package version.') + print(' --set-tracker <version> Set tracker to a specific version.') def main(argv): @@ -79,7 +80,7 @@ def main(argv): 'verbose', 'help']) except getopt.GetoptError as e: - print 'ERROR: ' + str(e) + print('ERROR: ' + str(e)) usage() sys.exit(1) @@ -146,17 +147,17 @@ def main(argv): sys.exit() else: - print 'ERROR: unknown option ' + o + print('ERROR: unknown option ' + o) usage() sys.exit(1) if subsystemName and not instanceName: - print 'ERROR: --subsystem requires --instance' + print('ERROR: --subsystem requires --instance') usage() sys.exit(1) if scriptlet_index and not scriptlet_version: - print 'ERROR: --scriptlet-index requires --scriptlet-version' + print('ERROR: --scriptlet-index requires --scriptlet-version') usage() sys.exit(1) @@ -188,7 +189,7 @@ def main(argv): upgrader.upgrade() except pki.PKIException as e: - print e.message + print(e.message) if __name__ == '__main__': diff --git a/base/server/sbin/pkidestroy b/base/server/sbin/pkidestroy index 252c504da..ff7296f7b 100755 --- a/base/server/sbin/pkidestroy +++ b/base/server/sbin/pkidestroy @@ -21,12 +21,13 @@ # System Imports from __future__ import absolute_import +from __future__ import print_function import sys import signal if not hasattr(sys, "hexversion") or sys.hexversion < 0x020700f0: - print "Python version %s.%s.%s is too old." % sys.version_info[:3] - print "Please upgrade to at least Python 2.7.0." + print("Python version %s.%s.%s is too old." % sys.version_info[:3]) + print("Please upgrade to at least Python 2.7.0.") sys.exit(1) try: import os @@ -41,20 +42,20 @@ try: from pki.server.deployment import pkimessages as log import pki.server.deployment.pkihelper as util except ImportError: - print >> sys.stderr, """\ + print("""\ There was a problem importing one of the required Python modules. The error was: %s -""" % sys.exc_info()[1] +""" % sys.exc_info()[1], file=sys.stderr) sys.exit(1) # Handle the Keyboard Interrupt # pylint: disable=W0613 def interrupt_handler(event, frame): - print - print '\nUninstallation canceled.' + print() + print('\nUninstallation canceled.') sys.exit(1) @@ -91,10 +92,10 @@ def main(argv): # workaround for pylint error E1103 config.pki_dns_domainname = str(dnsdomainname).rstrip('\n') if not len(config.pki_dns_domainname): - print log.PKI_DNS_DOMAIN_NOT_SET + print(log.PKI_DNS_DOMAIN_NOT_SET) sys.exit(1) except subprocess.CalledProcessError as exc: - print log.PKI_SUBPROCESS_ERROR_1 % exc + print(log.PKI_SUBPROCESS_ERROR_1 % exc) sys.exit(1) # Read and process command-line arguments. @@ -153,7 +154,7 @@ def main(argv): str(args.pki_deployed_instance_name).strip('[\']') if interactive: - print + print() parser.indent = 0 begin = parser.read_text( @@ -161,10 +162,10 @@ def main(argv): options=['Yes', 'Y', 'No', 'N', 'Quit', 'Q'], sign='?', allow_empty=False, case_sensitive=False).lower() - print + print() if begin == 'q' or begin == 'quit': - print "Uninstallation canceled." + print("Uninstallation canceled.") sys.exit(0) elif begin == 'y' or begin == 'yes': @@ -188,18 +189,18 @@ def main(argv): config.pki_root_prefix + config.PKI_DEPLOYMENT_BASE_ROOT + "/" + \ config.pki_deployed_instance_name if not os.path.exists(deployed_pki_instance_path): - print "ERROR: " + log.PKI_INSTANCE_DOES_NOT_EXIST_1 %\ - deployed_pki_instance_path - print + print("ERROR: " + log.PKI_INSTANCE_DOES_NOT_EXIST_1 % + deployed_pki_instance_path) + print() parser.arg_parser.exit(-1) # verify that previously deployed subsystem for this instance exists deployed_pki_subsystem_path = \ deployed_pki_instance_path + "/" + config.pki_subsystem.lower() if not os.path.exists(deployed_pki_subsystem_path): - print "ERROR: " + log.PKI_SUBSYSTEM_DOES_NOT_EXIST_2 %\ - (config.pki_subsystem, deployed_pki_instance_path) - print + print("ERROR: " + log.PKI_SUBSYSTEM_DOES_NOT_EXIST_2 % + (config.pki_subsystem, deployed_pki_instance_path)) + print() parser.arg_parser.exit(-1) config.default_deployment_cfg = \ @@ -222,7 +223,7 @@ def main(argv): config.pki_subsystem.lower() +\ "-" + "destroy" + "." +\ config.pki_timestamp + "." + "log" - print 'Log file: %s/%s' % (config.pki_log_dir, config.pki_log_name) + print('Log file: %s/%s' % (config.pki_log_dir, config.pki_log_name)) rv = pkilogging.enable_pki_logger(config.pki_log_dir, config.pki_log_name, @@ -232,7 +233,7 @@ def main(argv): if rv != OSError: config.pki_log = rv else: - print log.PKI_UNABLE_TO_CREATE_LOG_DIRECTORY_1 % config.pki_log_dir + print(log.PKI_UNABLE_TO_CREATE_LOG_DIRECTORY_1 % config.pki_log_dir) sys.exit(1) # Read the specified PKI configuration file. @@ -251,8 +252,8 @@ def main(argv): config.pki_log.debug(pkilogging.log_format(parser.mdict), extra=config.PKI_INDENTATION_LEVEL_0) - print "Uninstalling " + config.pki_subsystem + " from " + \ - deployed_pki_instance_path + "." + print("Uninstalling " + config.pki_subsystem + " from " + + deployed_pki_instance_path + ".") # Process the various "scriptlets" to remove the specified PKI subsystem. pki_subsystem_scriptlets = parser.mdict['destroy_scriplets'].split() @@ -271,8 +272,8 @@ def main(argv): config.pki_log.debug(pkilogging.log_format(parser.mdict), extra=config.PKI_INDENTATION_LEVEL_0) - print - print "Uninstallation complete." + print() + print("Uninstallation complete.") # PKI Deployment Entry Point diff --git a/base/server/sbin/pkispawn b/base/server/sbin/pkispawn index 5666531c6..3f51b8328 100755 --- a/base/server/sbin/pkispawn +++ b/base/server/sbin/pkispawn @@ -21,12 +21,13 @@ # System Imports from __future__ import absolute_import +from __future__ import print_function import sys import signal if not hasattr(sys, "hexversion") or sys.hexversion < 0x020700f0: - print "Python version %s.%s.%s is too old." % sys.version_info[:3] - print "Please upgrade to at least Python 2.7.0." + print("Python version %s.%s.%s is too old." % sys.version_info[:3]) + print("Please upgrade to at least Python 2.7.0.") sys.exit(1) try: import ldap @@ -44,20 +45,20 @@ try: from pki.server.deployment import pkimessages as log import pki.server.deployment.pkihelper as util except ImportError: - print >> sys.stderr, """\ + print("""\ There was a problem importing one of the required Python modules. The error was: %s -""" % sys.exc_info()[1] +""" % sys.exc_info()[1], file=sys.stderr) sys.exit(1) # Handle the Keyboard Interrupt # pylint: disable=W0613 def interrupt_handler(event, frame): - print - print '\nInstallation canceled.' + print() + print('\nInstallation canceled.') sys.exit(1) @@ -92,10 +93,10 @@ def main(argv): # workaround for pylint error E1103 config.pki_dns_domainname = str(dnsdomainname).rstrip('\n') if not len(config.pki_dns_domainname): - print log.PKI_DNS_DOMAIN_NOT_SET + print(log.PKI_DNS_DOMAIN_NOT_SET) sys.exit(1) except subprocess.CalledProcessError as exc: - print log.PKI_SUBPROCESS_ERROR_1 % exc + print(log.PKI_SUBPROCESS_ERROR_1 % exc) sys.exit(1) # Read and process command-line arguments. @@ -126,7 +127,7 @@ def main(argv): if config.user_deployment_cfg is None: interactive = True parser.indent = 0 - print log.PKISPAWN_INTERACTIVE_INSTALLATION + print(log.PKISPAWN_INTERACTIVE_INSTALLATION) # Only run this program as "root". if not os.geteuid() == 0: @@ -142,7 +143,7 @@ def main(argv): 'Subsystem (CA/KRA/OCSP/TKS/TPS)', options=['CA', 'KRA', 'OCSP', 'TKS', 'TPS'], default='CA', case_sensitive=False).upper() - print + print() else: config.pki_subsystem = str(args.pki_subsystem).strip('[\']') @@ -152,7 +153,7 @@ def main(argv): interactive = True parser.indent = 2 - print "Tomcat:" + print("Tomcat:") instance_name = parser.read_text( 'Instance', 'DEFAULT', 'pki_instance_name') existing_data = parser.read_existing_deployment_data(instance_name) @@ -177,9 +178,9 @@ def main(argv): 'Management port', existing_data) - print + print() - print "Administrator:" + print("Administrator:") parser.read_text('Username', config.pki_subsystem, 'pki_admin_uid') admin_password = parser.read_password( @@ -254,7 +255,7 @@ def main(argv): # libfile) # print - print "Directory Server:" + print("Directory Server:") while True: parser.read_text('Hostname', config.pki_subsystem, @@ -272,7 +273,7 @@ def main(argv): sign='?', case_sensitive=False).lower() if secure == 'q' or secure == 'quit': - print "Installation canceled." + print("Installation canceled.") sys.exit(0) if secure == 'y' or secure == 'yes': @@ -328,15 +329,15 @@ def main(argv): sign='?', allow_empty=False, case_sensitive=False).lower() if remove == 'q' or remove == 'quit': - print "Installation canceled." + print("Installation canceled.") sys.exit(0) if remove == 'y' or remove == 'yes': break - print + print() - print "Security Domain:" + print("Security Domain:") if config.pki_subsystem == "CA": parser.read_text('Name', @@ -378,10 +379,10 @@ def main(argv): except requests.exceptions.HTTPError as e: parser.print_text('ERROR: ' + str(e)) - print + print() if config.pki_subsystem == "TPS": - print "External Servers:" + print("External Servers:") while True: parser.read_text('CA URL', @@ -435,9 +436,9 @@ def main(argv): 'False') break - print + print() - print "Authentication Database:" + print("Authentication Database:") while True: parser.read_text('Hostname', @@ -461,7 +462,7 @@ def main(argv): except ldap.LDAPError as e: parser.print_text('ERROR: ' + e.message['desc']) - print + print() if interactive: parser.indent = 0 @@ -470,10 +471,10 @@ def main(argv): 'Begin installation (Yes/No/Quit)', options=['Yes', 'Y', 'No', 'N', 'Quit', 'Q'], sign='?', allow_empty=False, case_sensitive=False).lower() - print + print() if begin == 'q' or begin == 'quit': - print "Installation canceled." + print("Installation canceled.") sys.exit(0) if begin == 'y' or begin == 'yes': @@ -484,8 +485,8 @@ def main(argv): if not os.path.exists(config.PKI_DEPLOYMENT_SOURCE_ROOT + "/" + config.pki_subsystem.lower()): - print "ERROR: " + log.PKI_SUBSYSTEM_NOT_INSTALLED_1 % \ - config.pki_subsystem.lower() + print("ERROR: " + log.PKI_SUBSYSTEM_NOT_INSTALLED_1 % + config.pki_subsystem.lower()) sys.exit(1) # Enable 'pkispawn' logging. @@ -495,7 +496,7 @@ def main(argv): config.pki_subsystem.lower() + \ "-" + "spawn" + "." + \ config.pki_timestamp + "." + "log" - print 'Log file: %s/%s' % (config.pki_log_dir, config.pki_log_name) + print('Log file: %s/%s' % (config.pki_log_dir, config.pki_log_name)) rv = pkilogging.enable_pki_logger(config.pki_log_dir, config.pki_log_name, @@ -505,7 +506,7 @@ def main(argv): if rv != OSError: config.pki_log = rv else: - print log.PKI_UNABLE_TO_CREATE_LOG_DIRECTORY_1 % config.pki_log_dir + print(log.PKI_UNABLE_TO_CREATE_LOG_DIRECTORY_1 % config.pki_log_dir) sys.exit(1) # Read the specified PKI configuration file. @@ -549,12 +550,12 @@ def main(argv): if parser.ds_base_dn_exists() and\ not config.str2bool(parser.mdict['pki_ds_remove_data']): - print 'ERROR: Base DN already exists.' + print('ERROR: Base DN already exists.') sys.exit(1) except ldap.LDAPError as e: - print 'ERROR: Unable to access directory server: ' + \ - e.message['desc'] + print('ERROR: Unable to access directory server: ' + + e.message['desc']) sys.exit(1) if parser.mdict['pki_security_domain_type'] != "new": @@ -577,15 +578,15 @@ def main(argv): parser.sd_authenticate() except requests.exceptions.ConnectionError as e: - print('ERROR: Unable to access security domain: ' + str(e)) + print(('ERROR: Unable to access security domain: ' + str(e))) sys.exit(1) except requests.exceptions.HTTPError as e: - print('ERROR: Unable to access security domain: ' + str(e)) + print(('ERROR: Unable to access security domain: ' + str(e))) sys.exit(1) - print "Installing " + config.pki_subsystem + " into " + \ - parser.mdict['pki_instance_path'] + "." + print("Installing " + config.pki_subsystem + " into " + + parser.mdict['pki_instance_path'] + ".") # Process the various "scriptlets" to create the specified PKI subsystem. pki_subsystem_scriptlets = parser.mdict['spawn_scriplets'].split() @@ -601,13 +602,13 @@ def main(argv): # pylint: disable=W0703 except Exception: log_error_details() - print - print "Installation failed." - print + print() + print("Installation failed.") + print() sys.exit(1) if rv != 0: - print "Nothing here!!!" - print "Installation failed." + print("Nothing here!!!") + print("Installation failed.") sys.exit(1) config.pki_log.debug(log.PKI_DICTIONARY_MASTER, extra=config.PKI_INDENTATION_LEVEL_0) @@ -627,40 +628,40 @@ def set_port(parser, tag, prompt, existing_data): def print_install_information(mdict): skip_configuration = config.str2bool(mdict['pki_skip_configuration']) - print log.PKI_SPAWN_INFORMATION_HEADER + print(log.PKI_SPAWN_INFORMATION_HEADER) if skip_configuration: - print " The %s subsystem of the '%s' instance\n" \ - " must still be configured!" % \ - (config.pki_subsystem, mdict['pki_instance_name']) + print(" The %s subsystem of the '%s' instance\n" + " must still be configured!" % + (config.pki_subsystem, mdict['pki_instance_name'])) else: - print " Administrator's username: %s" % \ - mdict['pki_admin_uid'] + print(" Administrator's username: %s" % + mdict['pki_admin_uid']) if os.path.isfile(mdict['pki_client_admin_cert_p12']): - print " Administrator's PKCS #12 file:\n %s" % \ - mdict['pki_client_admin_cert_p12'] + print(" Administrator's PKCS #12 file:\n %s" % + mdict['pki_client_admin_cert_p12']) if not config.str2bool(mdict['pki_client_database_purge']): - print - print " Administrator's certificate nickname:\n %s"\ - % mdict['pki_admin_nickname'] - print " Administrator's certificate database:\n %s"\ - % mdict['pki_client_database_dir'] - print log.PKI_CHECK_STATUS_MESSAGE % mdict['pki_instance_name'] - print log.PKI_INSTANCE_RESTART_MESSAGE % mdict['pki_instance_name'] + print() + print(" Administrator's certificate nickname:\n %s" + % mdict['pki_admin_nickname']) + print(" Administrator's certificate database:\n %s" + % mdict['pki_client_database_dir']) + print(log.PKI_CHECK_STATUS_MESSAGE % mdict['pki_instance_name']) + print(log.PKI_INSTANCE_RESTART_MESSAGE % mdict['pki_instance_name']) if (((config.pki_subsystem == "KRA" or config.pki_subsystem == "OCSP") and config.str2bool(mdict['pki_standalone'])) and not config.str2bool(mdict['pki_external_step_two'])): # Stand-alone PKI KRA/OCSP (External CA Step 1) - print log.PKI_CONFIGURATION_STANDALONE_1 % config.pki_subsystem + print(log.PKI_CONFIGURATION_STANDALONE_1 % config.pki_subsystem) else: - print log.PKI_ACCESS_URL % (mdict['pki_hostname'], + print(log.PKI_ACCESS_URL % (mdict['pki_hostname'], mdict['pki_https_port'], - config.pki_subsystem.lower()) + config.pki_subsystem.lower())) if not config.str2bool(mdict['pki_enable_on_system_boot']): - print log.PKI_SYSTEM_BOOT_STATUS_MESSAGE % "disabled" + print(log.PKI_SYSTEM_BOOT_STATUS_MESSAGE % "disabled") else: - print log.PKI_SYSTEM_BOOT_STATUS_MESSAGE % "enabled" - print log.PKI_SPAWN_INFORMATION_FOOTER + print(log.PKI_SYSTEM_BOOT_STATUS_MESSAGE % "enabled") + print(log.PKI_SPAWN_INFORMATION_FOOTER) def log_error_details(): |