Commit eddba455 authored by Anders Blomdell's avatar Anders Blomdell
Browse files

futurize -1 run on sources

parent 6be50cb4
/hostinfo
*.bak
*.pyc
*~
#!/usr/bin/python
from __future__ import print_function
import copy
import hostinfo
import hostinfo.automount
......@@ -331,7 +332,7 @@ if __name__ == '__main__':
if options.mio:
mio = hostinfo.mio.generate(tree)
print mio.encode("utf-8")
print(mio.encode("utf-8"))
if options.named:
for (f, c) in hostinfo.named.generate(tree, options):
......@@ -343,7 +344,7 @@ if __name__ == '__main__':
if options.pretty:
result = "<?xml version='1.0' encoding='utf-8'?>\n\n"
result += tree._xml(attr_sort=attr_sort, tag_sort=tag_sort)
print result.encode("utf-8")
print(result.encode("utf-8"))
sys.exit(0)
if options.role:
......@@ -353,7 +354,7 @@ if __name__ == '__main__':
if options.role_holder:
who = hostinfo.role.holder(tree, options.role_holder)
print who
print(who)
sys.exit(0)
if options.yp:
......@@ -371,11 +372,11 @@ if __name__ == '__main__':
conf = f.read()
f.close()
write = conf != file[name].encode("utf-8")
except IOError, e:
except IOError as e:
write = True
if write:
print name
print(name)
result = 0
f = open(name, "w")
f.write(file[name].encode("utf-8"))
......@@ -383,13 +384,13 @@ if __name__ == '__main__':
for name in symlink.keys():
if os.path.lexists(name) and not os.path.islink(name):
print "'%s' exists but is not a link" % name
print("'%s' exists but is not a link" % name)
elif not os.path.lexists(name):
print "Creating '%s' -> '%s'" % (name, symlink[name])
print("Creating '%s' -> '%s'" % (name, symlink[name]))
os.symlink(symlink[name], name)
result = 0
elif os.readlink(name) != symlink[name]:
print "Changing '%s' -> '%s'" % (name, symlink[name])
print("Changing '%s' -> '%s'" % (name, symlink[name]))
os.unlink(name)
os.symlink(symlink[name], name)
result = 0
......
import dhcpd
import dhcpd_ipv6
from __future__ import absolute_import
from . import dhcpd
from . import dhcpd_ipv6
......@@ -4,6 +4,7 @@ import re
import ipaddr
import sys
import uuid
from functools import reduce
def get_nm_extra(device):
result = ""
......
......@@ -6,8 +6,14 @@ import time
import xml.sax
import xml.parsers.expat
import traceback
import urlparse
import urllib2
try:
# Python 3
from urllib.request import urlopen
from urllib.parse import urlparse
except ImportError:
# Python 2 fallback
from urllib2 import urlopen
from urlparse import urlparse
__doc__ = """
Package for xml parsing
......@@ -233,6 +239,9 @@ class AttributeAccessor:
self._node = node
self._name = name
def __lt__(self, other):
return self._name < other._name
def __getattr__(self, attr):
message = "%s.%s not qualified with [...] for %s" % (
self._node._tag, self._name, attr)
......@@ -334,6 +343,9 @@ class Node:
raise Exception("Undefined attribute '%s' in '%s'" % (k, tag))
self._attribute[k] = attr[k]
def __lt__(self, other):
return self._tag < other._tag
def __copy__(self):
"""Copy node, but not children"""
result = Node(self._tag, self._line, self._attribute)
......@@ -351,7 +363,7 @@ class Node:
raise AttributeError(attr)
elif attr.startswith("_") and attr.endswith("_"):
return ChildAccessor(self, [attr[1:-1]])
elif self.__dict__.has_key(attr):
elif attr in self.__dict__:
return self.__dict__[attr]
elif attr.startswith("_"):
if self._parent:
......@@ -367,9 +379,9 @@ class Node:
result = ""
line = "%s<%s" % (" " * indent, self._tag)
blanks = " " * len(line)
key = self._attribute.keys()
key.sort(AttrSortWrapper(self, attr_sort))
for k in key:
for k in sorted(self._attribute.keys(),
key=(attr_sort and AttrSortWrapper(self, attr_sort)
or None)):
s = " %s='%s'" % (k, xml_escape(self._attribute[k]))
if len(line) + len(s) > width:
result += "%s\n" % line
......@@ -384,9 +396,11 @@ class Node:
result += '\n'.join(self._char)
result += '\n'
pass
child = self._children
child.sort(TagSortWrapper(self, tag_sort))
for c in child:
print("YYY", (tag_sort and TagSortWrapper(self, tag_sort)
or None), "\n")
for c in sorted(self._children,
key=(tag_sort and TagSortWrapper(self, tag_sort)
or None)):
result += c._xml(indent + 1, attr_sort, tag_sort, width)
result += "%s</%s>\n" % (" " * indent, self._tag)
return result
......@@ -523,7 +537,7 @@ class Parser:
def parse(source, include_comments=False, url=None):
"""Parse the given 'source' returning an easily traversable tree"""
(scheme, host, path, param, query, frag) = urlparse.urlparse(source)
(scheme, host, path, param, query, frag) = urlparse(source)
if not scheme:
data = open(source).read()
mtime = os.stat(source)[stat.ST_MTIME]
......
......@@ -6,7 +6,7 @@ def generate(tree, host, roles):
if not r in by_role:
raise Exception("Role '%s' not found in %s" %
(r, by_role.keys()))
return filter(lambda (k,v): k in roles and v == host,
return filter(lambda k_v: k_v[0] in roles and k_v[1] == host,
by_role.iteritems())
def holder(tree, role):
......
......@@ -13,7 +13,7 @@ def network(s):
return None
def address(ip):
if isinstance(ip, types.StringTypes):
if isinstance(ip, (str,)):
return ipaddr.IPAddress(ip)
elif ip.address[0]:
return ipaddr.IPAddress(ip.address[0])
......
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