[libvirt] [PATCH python 01/14] examples: Invoke print(...) instead of print ...

2013-12-09 Thread Daniel P. Berrange
From: Daniel P. Berrange berra...@redhat.com

The 'print' method must be called as a function in python3,
ie with brackets.

Signed-off-by: Daniel P. Berrange berra...@redhat.com
---
 examples/consolecallback.py |  6 ++--
 examples/dominfo.py | 14 +-
 examples/domrestore.py  | 17 ++--
 examples/domsave.py | 15 +-
 examples/domstart.py| 19 ++---
 examples/esxlist.py | 14 +-
 examples/event-test.py  | 68 ++---
 examples/topology.py| 14 +-
 8 files changed, 82 insertions(+), 85 deletions(-)

diff --git a/examples/consolecallback.py b/examples/consolecallback.py
index d8e33a9..c539a92 100644
--- a/examples/consolecallback.py
+++ b/examples/consolecallback.py
@@ -62,14 +62,14 @@ def lifecycle_callback (connection, domain, event, detail, 
console):
 
 # main
 if len(sys.argv) != 3:
-print Usage:, sys.argv[0], URI UUID
-print for example:, sys.argv[0], 'qemu:///system' 
'32ad945f-7e78-c33a-e96d-39f25e025d81'
+print(Usage:, sys.argv[0], URI UUID)
+print(for example:, sys.argv[0], 'qemu:///system' 
'32ad945f-7e78-c33a-e96d-39f25e025d81')
 sys.exit(1)
 
 uri = sys.argv[1]
 uuid = sys.argv[2]
 
-print Escape character is ^]
+print(Escape character is ^])
 logging.basicConfig(filename='msg.log', level=logging.DEBUG)
 logging.info(URI: %s, uri)
 logging.info(UUID: %s, uuid)
diff --git a/examples/dominfo.py b/examples/dominfo.py
index bfa3ca3..d3049cd 100755
--- a/examples/dominfo.py
+++ b/examples/dominfo.py
@@ -8,15 +8,15 @@ import libxml2
 import pdb
 
 def usage():
-   print 'Usage: %s DOMAIN' % sys.argv[0]
-   print '   Print information about the domain DOMAIN'
+   print('Usage: %s DOMAIN' % sys.argv[0])
+   print('   Print information about the domain DOMAIN')
 
 def print_section(title):
-print \n%s % title
-print = * 60
+print(\n%s % title)
+print(= * 60)
 
 def print_entry(key, value):
-print %-10s %-10s % (key, value)
+print(%-10s %-10s % (key, value))
 
 def print_xml(key, ctx, path):
 res = ctx.xpathEval(path)
@@ -36,14 +36,14 @@ name = sys.argv[1]
 # Connect to libvirt
 conn = libvirt.openReadOnly(None)
 if conn is None:
-print 'Failed to open connection to the hypervisor'
+print('Failed to open connection to the hypervisor')
 sys.exit(1)
 
 try:
 dom = conn.lookupByName(name)
 # Annoyiingly, libvirt prints its own error message here
 except libvirt.libvirtError:
-print Domain %s is not running % name
+print(Domain %s is not running % name)
 sys.exit(0)
 
 info = dom.info()
diff --git a/examples/domrestore.py b/examples/domrestore.py
index fffc90f..06fdfbc 100755
--- a/examples/domrestore.py
+++ b/examples/domrestore.py
@@ -8,10 +8,10 @@ import libxml2
 import pdb
 
 def usage():
-   print 'Usage: %s DIR' % sys.argv[0]
-   print '   Restore all the domains contained in DIR'
-   print '   It is assumed that all files in DIR are'
-   print '   images of domU\'s previously created with save'
+   print('Usage: %s DIR' % sys.argv[0])
+   print('   Restore all the domains contained in DIR')
+   print('   It is assumed that all files in DIR are')
+   print('   images of domU\'s previously created with save')
 
 if len(sys.argv) != 2:
 usage()
@@ -22,15 +22,14 @@ imgs = os.listdir(dir)
 
 conn = libvirt.open(None)
 if conn is None:
-print 'Failed to open connection to the hypervisor'
+print('Failed to open connection to the hypervisor')
 sys.exit(1)
 
 for img in imgs:
 file = os.path.join(dir, img)
-print Restoring %s ...  % img,
-sys.stdout.flush()
+print(Restoring %s ...  % img)
 ret = conn.restore(file)
 if ret == 0:
-print done
+print(done)
 else:
-print error %d % ret
+print(error %d % ret)
diff --git a/examples/domsave.py b/examples/domsave.py
index bac4536..727217c 100755
--- a/examples/domsave.py
+++ b/examples/domsave.py
@@ -8,9 +8,9 @@ import libxml2
 import pdb
 
 def usage():
-   print 'Usage: %s DIR' % sys.argv[0]
-   print '   Save all currently running domU\'s into DIR'
-   print '   DIR must exist and be writable by this process'
+   print('Usage: %s DIR' % sys.argv[0])
+   print('   Save all currently running domU\'s into DIR')
+   print('   DIR must exist and be writable by this process')
 
 if len(sys.argv) != 2:
 usage()
@@ -20,7 +20,7 @@ dir = sys.argv[1]
 
 conn = libvirt.open(None)
 if conn is None:
-print 'Failed to open connection to the hypervisor'
+print('Failed to open connection to the hypervisor')
 sys.exit(1)
 
 doms = conn.listDomainsID()
@@ -28,13 +28,12 @@ for id in doms:
 if id == 0:
 continue
 dom = conn.lookupByID(id)
-print Saving %s[%d] ...  % (dom.name(), id),
-sys.stdout.flush()
+print(Saving %s[%d] ...  % (dom.name(), id))
 path = os.path.join(dir, dom.name())
 ret = dom.save(path)
 

Re: [libvirt] [PATCH python 01/14] examples: Invoke print(...) instead of print ...

2013-12-09 Thread Doug Goldstein
On Mon, Dec 9, 2013 at 9:15 AM, Daniel P. Berrange berra...@redhat.com wrote:
 From: Daniel P. Berrange berra...@redhat.com

 The 'print' method must be called as a function in python3,
 ie with brackets.

 Signed-off-by: Daniel P. Berrange berra...@redhat.com
 ---
  examples/consolecallback.py |  6 ++--
  examples/dominfo.py | 14 +-
  examples/domrestore.py  | 17 ++--
  examples/domsave.py | 15 +-
  examples/domstart.py| 19 ++---
  examples/esxlist.py | 14 +-
  examples/event-test.py  | 68 
 ++---
  examples/topology.py| 14 +-
  8 files changed, 82 insertions(+), 85 deletions(-)

 diff --git a/examples/consolecallback.py b/examples/consolecallback.py
 index d8e33a9..c539a92 100644
 --- a/examples/consolecallback.py
 +++ b/examples/consolecallback.py
 @@ -62,14 +62,14 @@ def lifecycle_callback (connection, domain, event, 
 detail, console):

  # main
  if len(sys.argv) != 3:
 -print Usage:, sys.argv[0], URI UUID
 -print for example:, sys.argv[0], 'qemu:///system' 
 '32ad945f-7e78-c33a-e96d-39f25e025d81'
 +print(Usage:, sys.argv[0], URI UUID)
 +print(for example:, sys.argv[0], 'qemu:///system' 
 '32ad945f-7e78-c33a-e96d-39f25e025d81')
  sys.exit(1)

  uri = sys.argv[1]
  uuid = sys.argv[2]

 -print Escape character is ^]
 +print(Escape character is ^])
  logging.basicConfig(filename='msg.log', level=logging.DEBUG)
  logging.info(URI: %s, uri)
  logging.info(UUID: %s, uuid)
 diff --git a/examples/dominfo.py b/examples/dominfo.py
 index bfa3ca3..d3049cd 100755
 --- a/examples/dominfo.py
 +++ b/examples/dominfo.py
 @@ -8,15 +8,15 @@ import libxml2
  import pdb

  def usage():
 -   print 'Usage: %s DOMAIN' % sys.argv[0]
 -   print '   Print information about the domain DOMAIN'
 +   print('Usage: %s DOMAIN' % sys.argv[0])
 +   print('   Print information about the domain DOMAIN')

  def print_section(title):
 -print \n%s % title
 -print = * 60
 +print(\n%s % title)
 +print(= * 60)

  def print_entry(key, value):
 -print %-10s %-10s % (key, value)
 +print(%-10s %-10s % (key, value))

  def print_xml(key, ctx, path):
  res = ctx.xpathEval(path)
 @@ -36,14 +36,14 @@ name = sys.argv[1]
  # Connect to libvirt
  conn = libvirt.openReadOnly(None)
  if conn is None:
 -print 'Failed to open connection to the hypervisor'
 +print('Failed to open connection to the hypervisor')
  sys.exit(1)

  try:
  dom = conn.lookupByName(name)
  # Annoyiingly, libvirt prints its own error message here
  except libvirt.libvirtError:
 -print Domain %s is not running % name
 +print(Domain %s is not running % name)
  sys.exit(0)

  info = dom.info()
 diff --git a/examples/domrestore.py b/examples/domrestore.py
 index fffc90f..06fdfbc 100755
 --- a/examples/domrestore.py
 +++ b/examples/domrestore.py
 @@ -8,10 +8,10 @@ import libxml2
  import pdb

  def usage():
 -   print 'Usage: %s DIR' % sys.argv[0]
 -   print '   Restore all the domains contained in DIR'
 -   print '   It is assumed that all files in DIR are'
 -   print '   images of domU\'s previously created with save'
 +   print('Usage: %s DIR' % sys.argv[0])
 +   print('   Restore all the domains contained in DIR')
 +   print('   It is assumed that all files in DIR are')
 +   print('   images of domU\'s previously created with save')

  if len(sys.argv) != 2:
  usage()
 @@ -22,15 +22,14 @@ imgs = os.listdir(dir)

  conn = libvirt.open(None)
  if conn is None:
 -print 'Failed to open connection to the hypervisor'
 +print('Failed to open connection to the hypervisor')
  sys.exit(1)

  for img in imgs:
  file = os.path.join(dir, img)
 -print Restoring %s ...  % img,
 -sys.stdout.flush()
 +print(Restoring %s ...  % img)
  ret = conn.restore(file)
  if ret == 0:
 -print done
 +print(done)
  else:
 -print error %d % ret
 +print(error %d % ret)
 diff --git a/examples/domsave.py b/examples/domsave.py
 index bac4536..727217c 100755
 --- a/examples/domsave.py
 +++ b/examples/domsave.py
 @@ -8,9 +8,9 @@ import libxml2
  import pdb

  def usage():
 -   print 'Usage: %s DIR' % sys.argv[0]
 -   print '   Save all currently running domU\'s into DIR'
 -   print '   DIR must exist and be writable by this process'
 +   print('Usage: %s DIR' % sys.argv[0])
 +   print('   Save all currently running domU\'s into DIR')
 +   print('   DIR must exist and be writable by this process')

  if len(sys.argv) != 2:
  usage()
 @@ -20,7 +20,7 @@ dir = sys.argv[1]

  conn = libvirt.open(None)
  if conn is None:
 -print 'Failed to open connection to the hypervisor'
 +print('Failed to open connection to the hypervisor')
  sys.exit(1)

  doms = conn.listDomainsID()
 @@ -28,13 +28,12 @@ for id in doms:
  if id == 0:
  continue
  dom = conn.lookupByID(id)