Skip to content

Futurize pass 1 #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ diff_cover
mock
pytest
pytest-cov
# dependencies also in setup.py until they can be used
six
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@
],
requires=[
'branding',
'six',
],
)
3 changes: 2 additions & 1 deletion tests/test_cpio.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import os
import shutil
import subprocess
Expand Down Expand Up @@ -113,7 +114,7 @@ def test_bz2(self):
def test_xz(self):
if not self.doXZ:
raise unittest.SkipTest("lzma package or xz tool not available")
print 'Running test for XZ'
print('Running test for XZ')
self.doArchive('archive.cpio.xz', 'xz')

# CpioFileCompat testing
Expand Down
29 changes: 15 additions & 14 deletions tests/test_ifrename_logic.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import logging
import sys
import unittest
Expand Down Expand Up @@ -43,15 +44,15 @@ def tearDown(self):
self.siobuff.close()

def debug_state(self, ts):
print >>sys.stderr, ""
print >>sys.stderr, self.siobuff.getvalue()
print >>sys.stderr, ""
print("", file=sys.stderr)
print(self.siobuff.getvalue(), file=sys.stderr)
print("", file=sys.stderr)
if len(ts):
for (s,d) in ts:
print >>sys.stderr, "'%s' -> '%s'" % (s, d)
print("'%s' -> '%s'" % (s, d), file=sys.stderr)
else:
print >>sys.stderr, "No transactions"
print >>sys.stderr, ""
print("No transactions", file=sys.stderr)
print("", file=sys.stderr)


def test_newhw_norules_1eth(self):
Expand Down Expand Up @@ -268,16 +269,16 @@ def tearDown(self):
self.siobuff.close()

def debug_state(self, ts):
print >>sys.stderr, ""
print >>sys.stderr, self.siobuff.getvalue()
print >>sys.stderr, ""
print("", file=sys.stderr)
print(self.siobuff.getvalue(), file=sys.stderr)
print("", file=sys.stderr)
if len(ts):
print >>sys.stderr, "Transactions:"
print("Transactions:", file=sys.stderr)
for (s,d) in ts:
print >>sys.stderr, "'%s' -> '%s'" % (s, d)
print("'%s' -> '%s'" % (s, d), file=sys.stderr)
else:
print >>sys.stderr, "No transactions"
print >>sys.stderr, ""
print("No transactions", file=sys.stderr)
print("", file=sys.stderr)

def test_usecase1(self):
"""
Expand Down Expand Up @@ -559,7 +560,7 @@ def assertNotRaises(self, excp, fn, *argl, **kwargs):
"""Because unittest.TestCase seems to be missing this functionality"""
try:
fn(*argl, **kwargs)
except excp, e:
except excp as e:
self.fail("function raised %s unexpectedly: %s"
% (excp, e))

Expand Down
1 change: 0 additions & 1 deletion tests/test_pci.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class TestInvalid(unittest.TestCase):
def test_invalid_types(self):

self.assertRaises(TypeError, PCI, 0)
self.assertRaises(TypeError, PCI, 0L)
self.assertRaises(TypeError, PCI, (0,))
self.assertRaises(TypeError, PCI, [])
self.assertRaises(TypeError, PCI, {})
Expand Down
5 changes: 2 additions & 3 deletions xcp/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import ftplib
import os
import tempfile
import types
import urllib
import urllib2
import urlparse
Expand Down Expand Up @@ -118,7 +117,7 @@ def openAddress(self, addr):

class MountingAccessor(FilesystemAccessor):
def __init__(self, mount_types, mount_source, mount_options = None):
ro = isinstance(mount_options, types.ListType) and 'ro' in mount_options
ro = isinstance(mount_options, list) and 'ro' in mount_options
super(MountingAccessor, self).__init__(None, ro)

self.mount_types = mount_types
Expand All @@ -135,7 +134,7 @@ def start(self):
try:
opts = self.mount_options
if fs == 'iso9660':
if isinstance(opts, types.ListType):
if isinstance(opts, list):
if 'ro' not in opts:
opts.append('ro')
else:
Expand Down
115 changes: 58 additions & 57 deletions xcp/bootloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from __future__ import print_function
import os
import os.path
import re
Expand Down Expand Up @@ -431,7 +432,7 @@ def create_label(title):
# If this fails, it is probably a string, so leave it unchanged.
try:
default = menu_order[int(default)]
except ValueError, KeyError:
except (ValueError, KeyError):
pass
finally:
fh.close()
Expand All @@ -455,47 +456,47 @@ def loadExisting(cls, root = '/'):
elif os.path.exists(os.path.join(root, "boot/grub/menu.lst")):
return cls.readGrub(os.path.join(root, "boot/grub/menu.lst"))
else:
raise RuntimeError, "No existing bootloader configuration found"
raise RuntimeError("No existing bootloader configuration found")

def writeExtLinux(self, dst_file = None):
if hasattr(dst_file, 'name'):
fh = dst_file
else:
fh = open(dst_file, 'w')
print >> fh, "# location " + self.location
print("# location " + self.location, file=fh)

if self.serial:
if self.serial.get('flow', None) is None:
print >> fh, "serial %s %s" % (self.serial['port'],
self.serial['baud'])
print("serial %s %s" % (self.serial['port'],
self.serial['baud']), file=fh)
else:
print >> fh, "serial %s %s %s" % (self.serial['port'],
self.serial['baud'],
self.serial['flow'])
print("serial %s %s %s" % (self.serial['port'],
self.serial['baud'],
self.serial['flow']), file=fh)
if self.default:
print >> fh, "default " + self.default
print >> fh, "prompt 1"
print("default " + self.default, file=fh)
print("prompt 1", file=fh)
if self.timeout:
print >> fh, "timeout %d" % self.timeout
print("timeout %d" % self.timeout, file=fh)

for label in self.menu_order:
print >> fh, "\nlabel " + label
print("\nlabel " + label, file=fh)
m = self.menu[label]
if m.title:
print >> fh, " # " + m.title
print(" # " + m.title, file=fh)
if m.tboot:
print >> fh, " kernel mboot.c32"
print >> fh, " append %s %s --- %s %s --- %s %s --- %s" % \
(m.tboot, m.tboot_args, m.hypervisor, m.hypervisor_args,
m.kernel, m.kernel_args, m.initrd)
print(" kernel mboot.c32", file=fh)
print(" append %s %s --- %s %s --- %s %s --- %s" %
(m.tboot, m.tboot_args, m.hypervisor, m.hypervisor_args,
m.kernel, m.kernel_args, m.initrd), file=fh)
elif m.hypervisor:
print >> fh, " kernel mboot.c32"
print >> fh, " append %s %s --- %s %s --- %s" % \
(m.hypervisor, m.hypervisor_args, m.kernel, m.kernel_args, m.initrd)
print(" kernel mboot.c32", file=fh)
print(" append %s %s --- %s %s --- %s" %
(m.hypervisor, m.hypervisor_args, m.kernel, m.kernel_args, m.initrd), file=fh)
else:
print >> fh, " kernel " + m.kernel
print >> fh, " append " + m.kernel_args
print >> fh, " initrd " + m.initrd
print(" kernel " + m.kernel, file=fh)
print(" append " + m.kernel_args, file=fh)
print(" initrd " + m.initrd, file=fh)
if not hasattr(dst_file, 'name'):
fh.close()

Expand All @@ -504,32 +505,32 @@ def writeGrub(self, dst_file = None):
fh = dst_file
else:
fh = open(dst_file, 'w')
print >> fh, "# location " + self.location
print("# location " + self.location, file=fh)

if self.serial:
print >> fh, "serial --unit=%s --speed=%s" % (self.serial['port'],
self.serial['baud'])
print >> fh, "terminal --timeout=10 console serial"
print("serial --unit=%s --speed=%s" %
(self.serial['port'], self.serial['baud']), file=fh)
print("terminal --timeout=10 console serial", file=fh)
else:
print >> fh, "terminal console"
print("terminal console", file=fh)
if self.default:
for i in range(len(self.menu_order)):
if self.menu_order[i] == self.default:
print >> fh, "default %d" % i
print("default %d" % i, file=fh)
break
if self.timeout:
print >> fh, "timeout %d" % (self.timeout / 10)
print("timeout %d" % (self.timeout / 10), file=fh)

for label in self.menu_order:
m = self.menu[label]
print >> fh, "\ntitle " + m.title
print("\ntitle " + m.title, file=fh)
if m.hypervisor:
print >> fh, " kernel " + m.hypervisor + " " + m.hypervisor_args
print >> fh, " module " + m.kernel + " " + m.kernel_args
print >> fh, " module " + m.initrd
print(" kernel " + m.hypervisor + " " + m.hypervisor_args, file=fh)
print(" module " + m.kernel + " " + m.kernel_args, file=fh)
print(" module " + m.initrd, file=fh)
else:
print >> fh, " kernel " + m.kernel + " " + m.kernel_args
print >> fh, " initrd " + m.initrd
print(" kernel " + m.kernel + " " + m.kernel_args, file=fh)
print(" initrd " + m.initrd, file=fh)
if not hasattr(dst_file, 'name'):
fh.close()

Expand All @@ -540,19 +541,19 @@ def writeGrub2(self, dst_file = None):
fh = open(dst_file, 'w')

if self.serial:
print >> fh, "serial --unit=%s --speed=%s" % (self.serial['port'],
self.serial['baud'])
print >> fh, "terminal_input serial console"
print >> fh, "terminal_output serial console"
print("serial --unit=%s --speed=%s" % (self.serial['port'],
self.serial['baud']), file=fh)
print("terminal_input serial console", file=fh)
print("terminal_output serial console", file=fh)
if self.default:
for i in range(len(self.menu_order)):
if self.menu_order[i] == self.default:
print >> fh, "set default=%d" % i
print("set default=%d" % i, file=fh)
break
else:
print >> fh, "set default='%s'" % str(self.default)
print("set default='%s'" % str(self.default), file=fh)
if self.timeout:
print >> fh, "set timeout=%d" % (self.timeout / 10)
print("set timeout=%d" % (self.timeout / 10), file=fh)

boilerplate = getattr(self, 'boilerplate', [])[:]
boilerplate.reverse()
Expand All @@ -563,41 +564,41 @@ def writeGrub2(self, dst_file = None):
if boilerplate:
text = boilerplate.pop()
if text:
print >> fh, "\n".join(text)
print("\n".join(text), file=fh)

extra = ' '
try:
extra = m.extra
except AttributeError:
pass
print >> fh, "menuentry '%s'%s{" % (m.title, extra)
print("menuentry '%s'%s{" % (m.title, extra), file=fh)

try:
contents = "\n".join(m.contents)
if contents:
print >> fh, contents
print(contents, file=fh)
except AttributeError:
pass

if m.root:
print >> fh, "\tsearch --label --set root %s" % m.root
print("\tsearch --label --set root %s" % m.root, file=fh)

if m.hypervisor:
if m.tboot:
print >> fh, "\tmultiboot2 %s %s" % (m.tboot, m.tboot_args)
print >> fh, "\tmodule2 %s %s" % (m.hypervisor, m.hypervisor_args)
print("\tmultiboot2 %s %s" % (m.tboot, m.tboot_args), file=fh)
print("\tmodule2 %s %s" % (m.hypervisor, m.hypervisor_args), file=fh)
else:
print >> fh, "\tmultiboot2 %s %s" % (m.hypervisor, m.hypervisor_args)
print("\tmultiboot2 %s %s" % (m.hypervisor, m.hypervisor_args), file=fh)
if m.kernel:
print >> fh, "\tmodule2 %s %s" % (m.kernel, m.kernel_args)
print("\tmodule2 %s %s" % (m.kernel, m.kernel_args), file=fh)
if m.initrd:
print >> fh, "\tmodule2 %s" % m.initrd
print("\tmodule2 %s" % m.initrd, file=fh)
else:
if m.kernel:
print >> fh, "\tlinux %s %s" % (m.kernel, m.kernel_args)
print("\tlinux %s %s" % (m.kernel, m.kernel_args), file=fh)
if m.initrd:
print >> fh, "\tinitrd %s" % m.initrd
print >> fh, "}"
print("\tinitrd %s" % m.initrd, file=fh)
print("}", file=fh)
if not hasattr(dst_file, 'name'):
fh.close()

Expand Down Expand Up @@ -642,9 +643,9 @@ def newDefault(cls, kernel_link_name, initrd_link_name, root = '/'):
if b.menu[b.default].kernel != kernel_link_name:
backup = []
if not os.path.exists(os.path.join(root, kernel_link_name[1:])):
raise RuntimeError, "kernel symlink not found"
raise RuntimeError("kernel symlink not found")
if not os.path.exists(os.path.join(root, initrd_link_name[1:])):
raise RuntimeError, "initrd symlink not found"
raise RuntimeError("initrd symlink not found")
old_kernel_link = b.menu[b.default].kernel
old_ver = 'old'
m = re.search(r'(-\d+\.\d+)-', old_kernel_link)
Expand Down
Loading