summaryrefslogtreecommitdiffstats
path: root/base/common
diff options
context:
space:
mode:
authorChristian Heimes <cheimes@redhat.com>2015-08-16 19:00:00 +0200
committerChristian Heimes <cheimes@redhat.com>2015-08-17 21:14:11 +0200
commitf98ca7fa1903e12a4b2c49a70163077b3560dc1d (patch)
treea3446113d3a7d32c5ce79b1b359d5353ec49afee /base/common
parent71148b8f79a5d6ba0c949a3ca0acf5aec6321f0a (diff)
downloadpki-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/
Diffstat (limited to 'base/common')
-rw-r--r--base/common/python/pki/__init__.py3
-rw-r--r--base/common/python/pki/cert.py129
-rw-r--r--base/common/python/pki/cli.py17
-rw-r--r--base/common/python/pki/client.py3
-rw-r--r--base/common/python/pki/key.py15
-rw-r--r--base/common/python/pki/profile.py105
-rw-r--r--base/common/python/pki/upgrade.py77
-rwxr-xr-xbase/common/sbin/pki-upgrade51
8 files changed, 204 insertions, 196 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__':