From: Ben Steffen Date: Mon, 25 Nov 2019 22:50:19 +0000 (-0500) Subject: Run python-modernize fixers X-Git-Url: http://xvm.mit.edu/gitweb/invirt/packages/invirt-base.git/commitdiff_plain/bc5aea727d21d72161e81becc5784cdf9a065cc5?hp=ae5be3680ee10c33ac65b186c3cf57e4cf652e45 Run python-modernize fixers --- diff --git a/python/invirt/authz.py b/python/invirt/authz.py index f5f02a0..791dbf3 100644 --- a/python/invirt/authz.py +++ b/python/invirt/authz.py @@ -9,6 +9,7 @@ a unique name. That name can then be configured in """ +from __future__ import absolute_import import pkg_resources from invirt.config import structs as cfg diff --git a/python/invirt/common.py b/python/invirt/common.py index 57fea45..923d672 100644 --- a/python/invirt/common.py +++ b/python/invirt/common.py @@ -1,5 +1,6 @@ from __future__ import with_statement +from __future__ import absolute_import import unittest from fcntl import flock, LOCK_EX, LOCK_SH, LOCK_UN import contextlib as clib @@ -55,7 +56,7 @@ def dicts2struct(x, prefix = None, default = None): @clib.contextmanager def lock_file(path, exclusive = True): - with clib.closing(file(path, 'w')) as f: + with clib.closing(open(path, 'w')) as f: if exclusive: locktype = LOCK_EX else: diff --git a/python/invirt/config.py b/python/invirt/config.py index 626b76a..1589889 100644 --- a/python/invirt/config.py +++ b/python/invirt/config.py @@ -1,5 +1,6 @@ from __future__ import with_statement +from __future__ import absolute_import import json from invirt.common import * import os @@ -63,7 +64,7 @@ def list_files(): def load_master(): config = dict() for filename in list_files(): - with closing(file(filename)) as f: + with closing(open(filename)) as f: augment(config, yaml.load(f, loader)) return config @@ -116,7 +117,7 @@ def load(force_refresh = False): # lock with other concurrent reads). This isolation is accomplished # using an atomic filesystem rename in the refreshing stage. try: - with closing(file(cache_path)) as f: + with closing(open(cache_path)) as f: ns.cfg = json.read(f.read()) except: do_refresh = True @@ -131,7 +132,7 @@ def load(force_refresh = False): with lock_file(lock_path): ns.cfg = load_master() try: - with closing(file(cache_path + '.tmp', 'w')) as f: + with closing(open(cache_path + '.tmp', 'w')) as f: f.write(json.write(ns.cfg)) except: pass # silent failure else: rename(cache_path + '.tmp', cache_path) diff --git a/python/invirt/remctl.py b/python/invirt/remctl.py index 956ca2d..5466375 100644 --- a/python/invirt/remctl.py +++ b/python/invirt/remctl.py @@ -2,6 +2,8 @@ Functions to perform remctls. """ +from __future__ import absolute_import +from __future__ import print_function from invirt.common import CodeError import subprocess import sys @@ -39,7 +41,7 @@ def remctl(host, *args, **kws): if kws.get('err'): return stdout, stderr if p.returncode: - print >> sys.stderr, 'Error', p.returncode, 'on remctl', args, ':' - print >> sys.stderr, stderr + print('Error', p.returncode, 'on remctl', args, ':', file=sys.stderr) + print(stderr, file=sys.stderr) raise CodeError('ERROR on remctl') return stdout