Commit 093a0a1a authored by Tom Niget's avatar Tom Niget

run modernize

parent 3f7c5715
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
...@@ -24,6 +24,7 @@ and run and test programs in them. ...@@ -24,6 +24,7 @@ and run and test programs in them.
""" """
# pylint: disable=W0401,R0903 # pylint: disable=W0401,R0903
from __future__ import absolute_import
import os, pwd import os, pwd
from nemu.node import * from nemu.node import *
from nemu.interface import * from nemu.interface import *
......
...@@ -17,8 +17,10 @@ ...@@ -17,8 +17,10 @@
# You should have received a copy of the GNU General Public License along with # You should have received a copy of the GNU General Public License along with
# Nemu. If not, see <http://www.gnu.org/licenses/>. # Nemu. If not, see <http://www.gnu.org/licenses/>.
from __future__ import absolute_import
import errno, os, os.path, socket, subprocess, sys, syslog import errno, os, os.path, socket, subprocess, sys, syslog
from syslog import LOG_ERR, LOG_WARNING, LOG_NOTICE, LOG_INFO, LOG_DEBUG from syslog import LOG_ERR, LOG_WARNING, LOG_NOTICE, LOG_INFO, LOG_DEBUG
from six.moves import range
__all__ = ["IP_PATH", "TC_PATH", "BRCTL_PATH", "SYSCTL_PATH", "HZ"] __all__ = ["IP_PATH", "TC_PATH", "BRCTL_PATH", "SYSCTL_PATH", "HZ"]
...@@ -110,11 +112,11 @@ def eintr_wrapper(func, *args): ...@@ -110,11 +112,11 @@ def eintr_wrapper(func, *args):
while True: while True:
try: try:
return func(*args) return func(*args)
except OSError, ex: # pragma: no cover except OSError as ex: # pragma: no cover
if ex.errno == errno.EINTR: if ex.errno == errno.EINTR:
continue continue
raise raise
except IOError, ex: # pragma: no cover except IOError as ex: # pragma: no cover
if ex.errno == errno.EINTR: if ex.errno == errno.EINTR:
continue continue
raise raise
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
# You should have received a copy of the GNU General Public License along with # You should have received a copy of the GNU General Public License along with
# Nemu. If not, see <http://www.gnu.org/licenses/>. # Nemu. If not, see <http://www.gnu.org/licenses/>.
from __future__ import absolute_import
import os, weakref import os, weakref
import nemu.iproute import nemu.iproute
from nemu.environ import * from nemu.environ import *
...@@ -505,6 +506,6 @@ class Switch(ExternalInterface): ...@@ -505,6 +506,6 @@ class Switch(ExternalInterface):
self._parameters = parameters self._parameters = parameters
def _apply_parameters(self, parameters, port = None): def _apply_parameters(self, parameters, port = None):
for i in [port] if port else self._ports.values(): for i in [port] if port else list(self._ports.values()):
nemu.iproute.set_tc(i.index, **parameters) nemu.iproute.set_tc(i.index, **parameters)
...@@ -17,8 +17,10 @@ ...@@ -17,8 +17,10 @@
# You should have received a copy of the GNU General Public License along with # You should have received a copy of the GNU General Public License along with
# Nemu. If not, see <http://www.gnu.org/licenses/>. # Nemu. If not, see <http://www.gnu.org/licenses/>.
from __future__ import absolute_import
import copy, fcntl, os, re, socket, struct, subprocess, sys import copy, fcntl, os, re, socket, struct, subprocess, sys
from nemu.environ import * from nemu.environ import *
import six
# helpers # helpers
def _any_to_bool(any): def _any_to_bool(any):
...@@ -361,7 +363,7 @@ def create_if_pair(if1, if2): ...@@ -361,7 +363,7 @@ def create_if_pair(if1, if2):
del_if(if2) del_if(if2)
except: except:
pass pass
raise t, v, bt six.reraise(t, v, bt)
interfaces = get_if_data()[1] interfaces = get_if_data()[1]
return interfaces[if1.name], interfaces[if2.name] return interfaces[if1.name], interfaces[if2.name]
...@@ -511,7 +513,7 @@ def set_addr(iface, addresses, recover = True): ...@@ -511,7 +513,7 @@ def set_addr(iface, addresses, recover = True):
# Bridge handling # Bridge handling
def _sysfs_read_br(brname): def _sysfs_read_br(brname):
def readval(fname): def readval(fname):
f = file(fname) f = open(fname)
return f.readline().strip() return f.readline().strip()
p = "/sys/class/net/%s/bridge/" % brname p = "/sys/class/net/%s/bridge/" % brname
...@@ -565,7 +567,7 @@ def create_bridge(br): ...@@ -565,7 +567,7 @@ def create_bridge(br):
del_bridge(br) del_bridge(br)
except: except:
pass pass
raise t, v, bt six.reraise(t, v, bt)
return get_if_data()[1][br.name] return get_if_data()[1][br.name]
def del_bridge(br): def del_bridge(br):
...@@ -574,7 +576,7 @@ def del_bridge(br): ...@@ -574,7 +576,7 @@ def del_bridge(br):
def set_bridge(br, recover = True): def set_bridge(br, recover = True):
def saveval(fname, val): def saveval(fname, val):
f = file(fname, "w") f = open(fname, "w")
f.write(str(val)) f.write(str(val))
f.close() f.close()
def do_cmds(basename, cmds, orig_br): def do_cmds(basename, cmds, orig_br):
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
# You should have received a copy of the GNU General Public License along with # You should have received a copy of the GNU General Public License along with
# Nemu. If not, see <http://www.gnu.org/licenses/>. # Nemu. If not, see <http://www.gnu.org/licenses/>.
from __future__ import absolute_import
import os, socket, sys, traceback, unshare, weakref import os, socket, sys, traceback, unshare, weakref
from nemu.environ import * from nemu.environ import *
import nemu.interface, nemu.protocol, nemu.subprocess_ import nemu.interface, nemu.protocol, nemu.subprocess_
...@@ -28,7 +29,7 @@ class Node(object): ...@@ -28,7 +29,7 @@ class Node(object):
_nextnode = 0 _nextnode = 0
@staticmethod @staticmethod
def get_nodes(): def get_nodes():
s = sorted(Node._nodes.items(), key = lambda x: x[0]) s = sorted(list(Node._nodes.items()), key = lambda x: x[0])
return [x[1] for x in s] return [x[1] for x in s]
def __init__(self, nonetns = False, forward_X11 = False): def __init__(self, nonetns = False, forward_X11 = False):
...@@ -157,7 +158,7 @@ class Node(object): ...@@ -157,7 +158,7 @@ class Node(object):
self._interfaces[i].destroy() self._interfaces[i].destroy()
del self._interfaces[i] del self._interfaces[i]
return sorted(self._interfaces.values(), key = lambda x: x.index) return sorted(list(self._interfaces.values()), key = lambda x: x.index)
def route(self, tipe = 'unicast', prefix = None, prefix_len = 0, def route(self, tipe = 'unicast', prefix = None, prefix_len = 0,
nexthop = None, interface = None, metric = 0): nexthop = None, interface = None, metric = 0):
...@@ -206,7 +207,7 @@ def _start_child(nonetns): ...@@ -206,7 +207,7 @@ def _start_child(nonetns):
execute([SYSCTL_PATH, '-w', 'net.ipv4.ip_forward=1']) execute([SYSCTL_PATH, '-w', 'net.ipv4.ip_forward=1'])
execute([SYSCTL_PATH, '-w', 'net.ipv6.conf.default.forwarding=1']) execute([SYSCTL_PATH, '-w', 'net.ipv6.conf.default.forwarding=1'])
srv.run() srv.run()
except BaseException, e: except BaseException as e:
s = "Slave node aborting: %s\n" % str(e) s = "Slave node aborting: %s\n" % str(e)
sep = "=" * 70 + "\n" sep = "=" * 70 + "\n"
sys.stderr.write(s + sep) sys.stderr.write(s + sep)
......
...@@ -17,13 +17,16 @@ ...@@ -17,13 +17,16 @@
# You should have received a copy of the GNU General Public License along with # You should have received a copy of the GNU General Public License along with
# Nemu. If not, see <http://www.gnu.org/licenses/>. # Nemu. If not, see <http://www.gnu.org/licenses/>.
from __future__ import absolute_import
import base64, errno, os, passfd, re, select, signal, socket, sys, tempfile import base64, errno, os, passfd, re, select, signal, socket, sys, tempfile
import time, traceback, unshare import time, traceback, unshare
import nemu.subprocess_, nemu.iproute import nemu.subprocess_, nemu.iproute
from nemu.environ import * from nemu.environ import *
from six.moves import map
from six.moves import range
try: try:
from cPickle import loads, dumps from six.moves.cPickle import loads, dumps
except: except:
from pickle import loads, dumps from pickle import loads, dumps
...@@ -121,7 +124,7 @@ class Server(object): ...@@ -121,7 +124,7 @@ class Server(object):
try: try:
if nemu.subprocess_.poll(pid): if nemu.subprocess_.poll(pid):
self._children.remove(pid) self._children.remove(pid)
except OSError, e: except OSError as e:
if e.errno == errno.ECHILD: if e.errno == errno.ECHILD:
self._children.remove(pid) self._children.remove(pid)
else: else:
...@@ -137,7 +140,7 @@ class Server(object): ...@@ -137,7 +140,7 @@ class Server(object):
for pid in self._children: for pid in self._children:
try: try:
nemu.subprocess_.poll(pid) nemu.subprocess_.poll(pid)
except OSError, e: except OSError as e:
if e.errno != errno.ECHILD: if e.errno != errno.ECHILD:
raise raise
finally: finally:
...@@ -172,7 +175,7 @@ class Server(object): ...@@ -172,7 +175,7 @@ class Server(object):
while True: while True:
try: try:
line = self._rfd.readline() line = self._rfd.readline()
except IOError, e: except IOError as e:
line = None line = None
if e.errno == errno.EINTR: if e.errno == errno.EINTR:
continue continue
...@@ -202,7 +205,7 @@ class Server(object): ...@@ -202,7 +205,7 @@ class Server(object):
cmd2 = None cmd2 = None
subcommands = self._commands[cmd1] subcommands = self._commands[cmd1]
if subcommands.keys() != [ None ]: if list(subcommands.keys()) != [ None ]:
if len(args) < 1: if len(args) < 1:
self.reply(500, "Incomplete command.") self.reply(500, "Incomplete command.")
return None return None
...@@ -331,7 +334,7 @@ class Server(object): ...@@ -331,7 +334,7 @@ class Server(object):
cmdname) cmdname)
try: try:
fd, payload = passfd.recvfd(self._rfd, len(cmdname) + 1) fd, payload = passfd.recvfd(self._rfd, len(cmdname) + 1)
except (IOError, RuntimeError), e: except (IOError, RuntimeError) as e:
self.reply(500, "Error receiving FD: %s" % str(e)) self.reply(500, "Error receiving FD: %s" % str(e))
return return
...@@ -374,7 +377,7 @@ class Server(object): ...@@ -374,7 +377,7 @@ class Server(object):
params['env']['DISPLAY'] = "127.0.0.1:%d" % display params['env']['DISPLAY'] = "127.0.0.1:%d" % display
params['env']['XAUTHORITY'] = xauth params['env']['XAUTHORITY'] = xauth
except Exception, e: except Exception as e:
warning("Cannot forward X: %s" % e) warning("Cannot forward X: %s" % e)
try: try:
os.unlink(xauth) os.unlink(xauth)
...@@ -804,8 +807,8 @@ def _b64(text): ...@@ -804,8 +807,8 @@ def _b64(text):
# easier this way # easier this way
text = '' text = ''
text = str(text) text = str(text)
if len(text) == 0 or filter(lambda x: ord(x) <= ord(" ") or if len(text) == 0 or [x for x in text if ord(x) <= ord(" ") or
ord(x) > ord("z") or x == "=", text): ord(x) > ord("z") or x == "="]:
return "=" + base64.b64encode(text) return "=" + base64.b64encode(text)
else: else:
return text return text
...@@ -908,7 +911,7 @@ def _x11_forwarder(server, xsock, xaddr): ...@@ -908,7 +911,7 @@ def _x11_forwarder(server, xsock, xaddr):
chan = idx[fd] chan = idx[fd]
try: try:
s = os.read(fd.fileno(), 4096) s = os.read(fd.fileno(), 4096)
except OSError, e: except OSError as e:
if e.errno == errno.ECONNRESET: if e.errno == errno.ECONNRESET:
clean(idx, toread, fd) clean(idx, toread, fd)
continue continue
...@@ -934,7 +937,7 @@ def _x11_forwarder(server, xsock, xaddr): ...@@ -934,7 +937,7 @@ def _x11_forwarder(server, xsock, xaddr):
chan = idx[idx[fd]["wr"]] chan = idx[idx[fd]["wr"]]
try: try:
x = os.write(fd.fileno(), chan["buf"][0]) x = os.write(fd.fileno(), chan["buf"][0])
except OSError, e: except OSError as e:
if e.errno == errno.EINTR: if e.errno == errno.EINTR:
continue continue
if e.errno == errno.EPIPE or e.errno == errno.ECONNRESET: if e.errno == errno.EPIPE or e.errno == errno.ECONNRESET:
......
...@@ -17,8 +17,10 @@ ...@@ -17,8 +17,10 @@
# You should have received a copy of the GNU General Public License along with # You should have received a copy of the GNU General Public License along with
# Nemu. If not, see <http://www.gnu.org/licenses/>. # Nemu. If not, see <http://www.gnu.org/licenses/>.
from __future__ import absolute_import
import fcntl, grp, os, pickle, pwd, signal, select, sys, time, traceback import fcntl, grp, os, pickle, pwd, signal, select, sys, time, traceback
from nemu.environ import eintr_wrapper from nemu.environ import eintr_wrapper
from six.moves import range
__all__ = [ 'PIPE', 'STDOUT', 'Popen', 'Subprocess', 'spawn', 'wait', 'poll', __all__ = [ 'PIPE', 'STDOUT', 'Popen', 'Subprocess', 'spawn', 'wait', 'poll',
'get_user', 'system', 'backticks', 'backticks_raise' ] 'get_user', 'system', 'backticks', 'backticks_raise' ]
...@@ -288,7 +290,7 @@ def spawn(executable, argv = None, cwd = None, env = None, close_fds = False, ...@@ -288,7 +290,7 @@ def spawn(executable, argv = None, cwd = None, env = None, close_fds = False,
is not supported here. Also, the original descriptors are not closed. is not supported here. Also, the original descriptors are not closed.
""" """
userfd = [stdin, stdout, stderr] userfd = [stdin, stdout, stderr]
filtered_userfd = filter(lambda x: x != None and x >= 0, userfd) filtered_userfd = [x for x in userfd if x != None and x >= 0]
for i in range(3): for i in range(3):
if userfd[i] != None and not isinstance(userfd[i], int): if userfd[i] != None and not isinstance(userfd[i], int):
userfd[i] = userfd[i].fileno() # pragma: no cover userfd[i] = userfd[i].fileno() # pragma: no cover
...@@ -323,7 +325,7 @@ def spawn(executable, argv = None, cwd = None, env = None, close_fds = False, ...@@ -323,7 +325,7 @@ def spawn(executable, argv = None, cwd = None, env = None, close_fds = False,
fcntl.fcntl(w, fcntl.F_SETFD, flags | fcntl.FD_CLOEXEC) fcntl.fcntl(w, fcntl.F_SETFD, flags | fcntl.FD_CLOEXEC)
if close_fds == True: if close_fds == True:
for i in xrange(3, MAXFD): for i in range(3, MAXFD):
if i != w: if i != w:
try: try:
os.close(i) os.close(i)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment