From e090025874947cd924a1985ba2aec226b365558c Mon Sep 17 00:00:00 2001 From: Arvin Schnell Date: Tue, 28 Mar 2023 15:00:27 +0200 Subject: [PATCH] - convert python examples to python 3 --- examples/python/comparison.py | 5 ++--- examples/python/create.py | 5 ++--- examples/python/debug.py | 5 ++--- examples/python/delete.py | 3 +-- examples/python/get-config.py | 7 +++---- examples/python/get-snapshot.py | 11 +++++------ examples/python/list-configs.py | 5 ++--- examples/python/list-snapshots.py | 15 +++++++-------- examples/python/lock-config.py | 3 +-- examples/python/set-config.py | 4 ++-- examples/python/set-snapshot.py | 3 +-- examples/python/signals.py | 21 ++++++++++----------- 12 files changed, 38 insertions(+), 49 deletions(-) diff --git a/examples/python/comparison.py b/examples/python/comparison.py index 5c6461c7..d3066459 100755 --- a/examples/python/comparison.py +++ b/examples/python/comparison.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 import dbus @@ -17,5 +17,4 @@ snapper.CreateComparison(config_name, num_pre, num_post) files = snapper.GetFiles(config_name, num_pre, num_post) for file in files: - print file[0], file[1] - + print(file[0], file[1]) diff --git a/examples/python/create.py b/examples/python/create.py index 3d739571..3e1778b5 100755 --- a/examples/python/create.py +++ b/examples/python/create.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 import dbus @@ -8,5 +8,4 @@ snapper = dbus.Interface(bus.get_object('org.opensuse.Snapper', '/org/opensuse/S dbus_interface='org.opensuse.Snapper') -print snapper.CreateSingleSnapshot("root", "test", "", { "id" : "123" }) - +print(snapper.CreateSingleSnapshot("root", "test", "", { "id" : "123" })) diff --git a/examples/python/debug.py b/examples/python/debug.py index 9bd998c7..1520519a 100755 --- a/examples/python/debug.py +++ b/examples/python/debug.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 import dbus @@ -11,5 +11,4 @@ snapper = dbus.Interface(bus.get_object('org.opensuse.Snapper', '/org/opensuse/S lines = snapper.Debug() for line in lines: - print line - + print(line) diff --git a/examples/python/delete.py b/examples/python/delete.py index 63b93d14..0ef7e64e 100755 --- a/examples/python/delete.py +++ b/examples/python/delete.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 import dbus @@ -9,4 +9,3 @@ snapper = dbus.Interface(bus.get_object('org.opensuse.Snapper', '/org/opensuse/S snapper.DeleteSnapshots("root", [ 510 ]) - diff --git a/examples/python/get-config.py b/examples/python/get-config.py index c383c4ce..35ef9254 100755 --- a/examples/python/get-config.py +++ b/examples/python/get-config.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 import dbus @@ -10,8 +10,7 @@ snapper = dbus.Interface(bus.get_object('org.opensuse.Snapper', '/org/opensuse/S config = snapper.GetConfig("root") -print config[0], config[1] +print(config[0], config[1]) for k, v in config[2].items(): - print "%s=%s" % (k, v) - + print("%s=%s" % (k, v)) diff --git a/examples/python/get-snapshot.py b/examples/python/get-snapshot.py index e940812c..29b0f864 100755 --- a/examples/python/get-snapshot.py +++ b/examples/python/get-snapshot.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 from time import gmtime, asctime from pwd import getpwuid @@ -12,9 +12,8 @@ snapper = dbus.Interface(bus.get_object('org.opensuse.Snapper', '/org/opensuse/S snapshot = snapper.GetSnapshot("root", 1) -print snapshot[0], snapshot[1], snapshot[2], asctime(gmtime(snapshot[3])), -print getpwuid(snapshot[4])[0], snapshot[5], snapshot[6], +print(snapshot[0], snapshot[1], snapshot[2], asctime(gmtime(snapshot[3])), + getpwuid(snapshot[4])[0], snapshot[5], snapshot[6], end='') for k, v in snapshot[7].items(): - print "%s=%s" % (k, v), -print - + print("", "%s=%s" % (k, v), end='') +print() diff --git a/examples/python/list-configs.py b/examples/python/list-configs.py index bc1ab981..d33f317e 100755 --- a/examples/python/list-configs.py +++ b/examples/python/list-configs.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 import dbus @@ -11,5 +11,4 @@ snapper = dbus.Interface(bus.get_object('org.opensuse.Snapper', '/org/opensuse/S configs = snapper.ListConfigs() for config in configs: - print config[0], config[1] - + print(config[0], config[1]) diff --git a/examples/python/list-snapshots.py b/examples/python/list-snapshots.py index 31c10b5c..f00346f4 100755 --- a/examples/python/list-snapshots.py +++ b/examples/python/list-snapshots.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 from time import gmtime, asctime from pwd import getpwuid @@ -13,15 +13,14 @@ snapper = dbus.Interface(bus.get_object('org.opensuse.Snapper', '/org/opensuse/S snapshots = snapper.ListSnapshots("root") for snapshot in snapshots: - print snapshot[0], snapshot[1], snapshot[2], + print(snapshot[0], snapshot[1], snapshot[2], end='') if snapshot[3] != -1: - print asctime(gmtime(snapshot[3])), + print("", asctime(gmtime(snapshot[3])), end='') else: - print "now", + print("", "now", end='') - print getpwuid(snapshot[4])[0], snapshot[5], snapshot[6], + print("", getpwuid(snapshot[4])[0], snapshot[5], snapshot[6], end='') for k, v in snapshot[7].items(): - print "%s=%s" % (k, v), - print - + print("", "%s=%s" % (k, v), end='') + print() diff --git a/examples/python/lock-config.py b/examples/python/lock-config.py index 89afe0d9..0a626428 100755 --- a/examples/python/lock-config.py +++ b/examples/python/lock-config.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 from time import sleep import dbus @@ -14,4 +14,3 @@ snapper.LockConfig("root") sleep(10) snapper.UnlockConfig("root") - diff --git a/examples/python/set-config.py b/examples/python/set-config.py index be4f8afe..f1751f49 100755 --- a/examples/python/set-config.py +++ b/examples/python/set-config.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 import dbus @@ -7,7 +7,7 @@ bus = dbus.SystemBus() snapper = dbus.Interface(bus.get_object('org.opensuse.Snapper', '/org/opensuse/Snapper'), dbus_interface='org.opensuse.Snapper') + data = { "NUMBER_CLEANUP" : "yes", "NUMBER_LIMIT" : "10" } snapper.SetConfig("root", data) - diff --git a/examples/python/set-snapshot.py b/examples/python/set-snapshot.py index 8db0e83f..73991a99 100755 --- a/examples/python/set-snapshot.py +++ b/examples/python/set-snapshot.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 import dbus @@ -9,4 +9,3 @@ snapper = dbus.Interface(bus.get_object('org.opensuse.Snapper', '/org/opensuse/S snapper.SetSnapshot("root", 1, "test", "", { "id" : "123" }) - diff --git a/examples/python/signals.py b/examples/python/signals.py index fecead56..c2dce41c 100755 --- a/examples/python/signals.py +++ b/examples/python/signals.py @@ -1,8 +1,8 @@ -#!/usr/bin/python +#!/usr/bin/python3 import dbus from dbus.mainloop.glib import DBusGMainLoop -from gobject import MainLoop +from gi.repository.GLib import MainLoop DBusGMainLoop(set_as_default=True) @@ -31,28 +31,27 @@ class MessageListener: def config_created(self, config): - print "ConfigCreated", config + print("ConfigCreated", config) def config_modified(self, config): - print "ConfigModified", config + print("ConfigModified", config) def config_deleted(self, config): - print "ConfigDeleted", config + print("ConfigDeleted", config) def snapshot_created(self, config, number): - print "SnapshotCreated", config, number + print("SnapshotCreated", config, number) def snapshot_modified(self, config, number): - print "SnapshotModified", config, number + print("SnapshotModified", config, number) def snapshots_deleted(self, config, numbers): - print "SnapshotsDeleted", config, + print("SnapshotsDeleted", config, end='') for number in numbers: - print number, - print + print("", number, end='') + print() MessageListener() MainLoop().run() - -- 2.47.3