]> git.ipfire.org Git - oddments/fireinfo.git/commitdiff
Run 2to3
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 6 May 2021 15:44:06 +0000 (15:44 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 6 May 2021 15:44:06 +0000 (15:44 +0000)
This is the result of running the automatic conversion tool and I have
not tested this, yet. There might be some bugs being introduced by this.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/fireinfo/cpu.py
src/fireinfo/hypervisor.py
src/fireinfo/network.py
src/fireinfo/system.py
src/sendprofile

index dc76caf9f1f10bcfea551e6a5cb3955ed2050289..e433a04f3dd90c59c74c4c3ac3af03186dc9b746 100644 (file)
@@ -21,7 +21,7 @@
 
 import os
 
-import system
+from . import system
 
 PROC_CPUINFO = "/proc/cpuinfo"
 
@@ -188,12 +188,12 @@ class CPU(object):
 if __name__ == "__main__":
        c = CPU()
 
-       print "Vendor:", c.vendor
-       print "Model:", c.model
-       print "Stepping:", c.stepping
-       print "Flags:", c.flags
-       print "Bogomips:", c.bogomips
-       print "Speed:", c.speed
-       print "Family:", c.family
-       print "Count:", c.count
-       print "Model string:", c.model_string
+       print("Vendor:", c.vendor)
+       print("Model:", c.model)
+       print("Stepping:", c.stepping)
+       print("Flags:", c.flags)
+       print("Bogomips:", c.bogomips)
+       print("Speed:", c.speed)
+       print("Family:", c.family)
+       print("Count:", c.count)
+       print("Model string:", c.model_string)
index 0c07cfad71a1d8aa7996547c598126c2733a469f..e76aad5d88045a80df87a081cd9d4ff4d53261c4 100644 (file)
@@ -20,7 +20,7 @@
 ###############################################################################
 
 import _fireinfo
-import system
+from . import system
 
 class Hypervisor(object):
        def __init__(self):
@@ -115,5 +115,5 @@ class Hypervisor(object):
 if __name__ == "__main__":
        h = Hypervisor()
 
-       print "Vendor:", h.vendor
-       print "Virtual:", h.virtual
+       print("Vendor:", h.vendor)
+       print("Virtual:", h.virtual)
index 063e9ec3abe3f5bb640f1a332407df0302d7800a..de58be30b6633a1fa9116cb4ffe3b9e2d5b30321 100644 (file)
@@ -47,7 +47,7 @@ class Network(object):
 if __name__ == "__main__":
        n = Network()
 
-       print "has_green", n.has_green()
-       print "has_red", n.has_red()
-       print "has_blue", n.has_blue()
-       print "has_orange", n.has_orange()
+       print("has_green", n.has_green())
+       print("has_red", n.has_red())
+       print("has_blue", n.has_blue())
+       print("has_orange", n.has_orange())
index 73c3882e9d7e80339af96d6fafbd9a7530bf8e9d..cfeb171d60038644f00b37b7eb03fdf2f516a3b1 100644 (file)
@@ -26,11 +26,11 @@ import string
 
 import _fireinfo
 
-import bios
-import cpu
-import device
-import hypervisor
-import network
+from . import bios
+from . import cpu
+from . import device
+from . import hypervisor
+from . import network
 
 PROFILE_VERSION = 0
 
@@ -84,9 +84,7 @@ def read_from_file(filename):
        except IOError:
                pass
 
-class System(object):
-       __metaclass__ = Singleton
-
+class System(object, metaclass=Singleton):
        def __init__(self):
                self.bios = bios.BIOS(self)
 
@@ -338,7 +336,7 @@ class System(object):
                if s is None:
                        return
 
-               return filter(lambda x: x in string.printable, s)
+               return [x for x in s if x in string.printable]
 
        @property
        def vendor(self):
@@ -373,7 +371,7 @@ class System(object):
                ret = read_from_file("/proc/device-tree/model")
                if ret:
                        # replace the NULL byte with which the DT string ends
-                       ret = ret.replace(u"\u0000", "")
+                       ret = ret.replace("\u0000", "")
 
                # Fall back to read /proc/cpuinfo
                if not ret:
@@ -485,13 +483,13 @@ class System(object):
 
 if __name__ == "__main__":
        s=System()
-       print s.arch
-       print s.language
-       print s.release
-       print s.bios_vendor
-       print s.memory
-       print s.kernel
-       print s.root_disk
-       print s.root_size
-       print "------------\n", s.devices, "\n------------\n"
-       print json.dumps(s.profile(), sort_keys=True, indent=4)
+       print(s.arch)
+       print(s.language)
+       print(s.release)
+       print(s.bios_vendor)
+       print(s.memory)
+       print(s.kernel)
+       print(s.root_disk)
+       print(s.root_size)
+       print("------------\n", s.devices, "\n------------\n")
+       print(json.dumps(s.profile(), sort_keys=True, indent=4))
index 3ce68b9e733c5eeec389cd64299cc6e611320f4c..5fc6c866aad74f1ea148ecc99d762cfdb1222ebd 100755 (executable)
@@ -24,8 +24,8 @@ import logging
 import logging.handlers
 import os
 import sys
-import urllib
-import urllib2
+import urllib.request, urllib.parse, urllib.error
+import urllib.request, urllib.error, urllib.parse
 
 import fireinfo
 
@@ -67,8 +67,8 @@ def send_profile(profile):
        for line in json.dumps(profile, sort_keys=True, indent=4).splitlines():
                logging.debug(line)
 
-       request = urllib2.Request(PROFILE_URL % profile,
-               data = urllib.urlencode({"profile" : json.dumps(profile)}),
+       request = urllib.request.Request(PROFILE_URL % profile,
+               data = urllib.parse.urlencode({"profile" : json.dumps(profile)}),
        )
        request.add_header("User-Agent", "fireinfo/%s" % fireinfo.__version__)
 
@@ -80,22 +80,22 @@ def send_profile(profile):
                if proxy["user"] and proxy["pass"]:
                        prx_auth_string = "http://%s:%s@%s/" % (proxy["user"], proxy["pass"], proxy["host"])
 
-                       proxy_handler = urllib2.ProxyHandler({'http': prx_auth_string, 'https': prx_auth_string})
-                       auth = urllib2.HTTPBasicAuthHandler()
-                       opener = urllib2.build_opener(proxy_handler, auth, urllib2.HTTPHandler)
-                       urllib2.install_opener(opener)
+                       proxy_handler = urllib.request.ProxyHandler({'http': prx_auth_string, 'https': prx_auth_string})
+                       auth = urllib.request.HTTPBasicAuthHandler()
+                       opener = urllib.request.build_opener(proxy_handler, auth, urllib.request.HTTPHandler)
+                       urllib.request.install_opener(opener)
                else:
                        request.set_proxy(proxy["host"], "http")
                        request.set_proxy(proxy["host"], "https")
 
        try:
-               urllib2.urlopen(request, timeout=60)
-       except (urllib2.HTTPError, urllib2.URLError), e:
+               urllib.request.urlopen(request, timeout=60)
+       except (urllib.error.HTTPError, urllib.error.URLError) as e:
                reason = "Unknown reason"
 
-               if isinstance(e, urllib2.HTTPError):
+               if isinstance(e, urllib.error.HTTPError):
                        reason = "%s" % e
-               elif isinstance(e, urllib2.URLError):
+               elif isinstance(e, urllib.error.URLError):
                        reason = e.reason
 
                logging.error("Profile was not sent propertly: %s" % reason)
@@ -114,19 +114,19 @@ def main():
                # it contains no information and may confuse people.
                del profile["private_id"]
 
-               print json.dumps(profile, sort_keys=True, indent=4)
+               print(json.dumps(profile, sort_keys=True, indent=4))
                return 0
 
        if "--secret-id" in sys.argv:
-               print system.secret_id
+               print(system.secret_id)
                return 0
 
        if "--hardware-string" in sys.argv:
-               print system._unique_id
+               print(system._unique_id)
                return 0
 
        if "--public-id" in sys.argv:
-               print system.public_id
+               print(system.public_id)
                return 0
 
        if not os.path.exists(ENABLED_FILE):
@@ -134,7 +134,7 @@ def main():
 
        try:
                send_profile(profile)
-       except urllib2.URLError:
+       except urllib.error.URLError:
                return 1
 
        return 0