[Libguestfs] [v2v PATCH 1/6] PEP 8: adapt whitespaces in lines

Pino Toscano ptoscano at redhat.com
Fri Jan 10 15:47:24 UTC 2020


Fix continuation indentation, and whitespaces around operators.

This is just code reformatting, with no behaviour changes; no content
changed beside whitespaces, so "git diff -w" gives an empty diff
---
 .../ovirtsdk4/__init__.py                     | 16 ++---
 .../ovirtsdk4/types.py                        | 28 ++++----
 v2v/rhv-upload-createvm.py                    | 18 ++---
 v2v/rhv-upload-deletedisks.py                 | 12 ++--
 v2v/rhv-upload-plugin.py                      | 72 +++++++++----------
 v2v/rhv-upload-precheck.py                    | 16 ++---
 v2v/rhv-upload-vmcheck.py                     | 14 ++--
 7 files changed, 88 insertions(+), 88 deletions(-)

diff --git a/tests/test-v2v-o-rhv-upload-module/ovirtsdk4/__init__.py b/tests/test-v2v-o-rhv-upload-module/ovirtsdk4/__init__.py
index 09d861d3..774c7a5c 100644
--- a/tests/test-v2v-o-rhv-upload-module/ovirtsdk4/__init__.py
+++ b/tests/test-v2v-o-rhv-upload-module/ovirtsdk4/__init__.py
@@ -26,12 +26,12 @@ class NotFoundError(Error):
 class Connection(object):
     def __init__(
             self,
-            url = None,
-            username = None,
-            password = None,
-            ca_file = None,
-            log = None,
-            insecure = False,
+            url=None,
+            username=None,
+            password=None,
+            ca_file=None,
+            log=None,
+            insecure=False,
             debug=True,
     ):
         pass
@@ -119,7 +119,7 @@ class ImageTransfersService(object):
 
 class StorageDomainsService(object):
     def list(self, search=None, case_sensitive=False):
-        return [ StorageDomain() ]
+        return [StorageDomain()]
 
 class VmsService(object):
     def add(self, vm):
@@ -179,5 +179,5 @@ imageio_port = httpd.server_address[1]
 def server():
     httpd.serve_forever()
 
-thread = threading.Thread(target = server, args = [], daemon = True)
+thread = threading.Thread(target=server, args=[], daemon=True)
 thread.start()
diff --git a/tests/test-v2v-o-rhv-upload-module/ovirtsdk4/types.py b/tests/test-v2v-o-rhv-upload-module/ovirtsdk4/types.py
index 0b165c24..3b5cd0ac 100644
--- a/tests/test-v2v-o-rhv-upload-module/ovirtsdk4/types.py
+++ b/tests/test-v2v-o-rhv-upload-module/ovirtsdk4/types.py
@@ -63,14 +63,14 @@ class DiskStatus(Enum):
 class Disk(object):
     def __init__(
             self,
-            id = None,
-            name = None,
-            description = None,
-            format = None,
-            initial_size = None,
-            provisioned_size = None,
-            sparse = False,
-            storage_domains = None
+            id=None,
+            name=None,
+            description=None,
+            format=None,
+            initial_size=None,
+            provisioned_size=None,
+            sparse=False,
+            storage_domains=None
     ):
         self.id = id
 
@@ -98,9 +98,9 @@ class ImageTransferPhase(Enum):
 class ImageTransfer(object):
     def __init__(
             self,
-            disk = None,
-            host = None,
-            inactivity_timeout = None,
+            disk=None,
+            host=None,
+            inactivity_timeout=None,
     ):
         pass
 
@@ -113,7 +113,7 @@ class Initialization(object):
         pass
 
 class StorageDomain(object):
-    def __init__(self, name = None):
+    def __init__(self, name=None):
         pass
 
     id = "ba87af68-b630-4211-a73a-694c1a689405"
@@ -122,8 +122,8 @@ class StorageDomain(object):
 class Vm(object):
     def __init__(
             self,
-            cluster = None,
-            initialization = None
+            cluster=None,
+            initialization=None
     ):
         pass
 
diff --git a/v2v/rhv-upload-createvm.py b/v2v/rhv-upload-createvm.py
index ed57a9b2..f0b747ec 100644
--- a/v2v/rhv-upload-createvm.py
+++ b/v2v/rhv-upload-createvm.py
@@ -55,12 +55,12 @@ username = parsed.username or "admin at internal"
 
 # Connect to the server.
 connection = sdk.Connection(
-    url = params['output_conn'],
-    username = username,
-    password = output_password,
-    ca_file = params['rhv_cafile'],
-    log = logging.getLogger(),
-    insecure = params['insecure'],
+    url=params['output_conn'],
+    username=username,
+    password=output_password,
+    ca_file=params['rhv_cafile'],
+    log=logging.getLogger(),
+    insecure=params['insecure'],
 )
 
 system_service = connection.system_service()
@@ -74,9 +74,9 @@ vm = vms_service.add(
     types.Vm(
         cluster=cluster,
         initialization=types.Initialization(
-            configuration = types.Configuration(
-                type = types.ConfigurationType.OVA,
-                data = ovf,
+            configuration=types.Configuration(
+                type=types.ConfigurationType.OVA,
+                data=ovf,
             )
         )
     )
diff --git a/v2v/rhv-upload-deletedisks.py b/v2v/rhv-upload-deletedisks.py
index bdd570b4..3c970801 100644
--- a/v2v/rhv-upload-deletedisks.py
+++ b/v2v/rhv-upload-deletedisks.py
@@ -50,12 +50,12 @@ username = parsed.username or "admin at internal"
 
 # Connect to the server.
 connection = sdk.Connection(
-    url = params['output_conn'],
-    username = username,
-    password = output_password,
-    ca_file = params['rhv_cafile'],
-    log = logging.getLogger(),
-    insecure = params['insecure'],
+    url=params['output_conn'],
+    username=username,
+    password=output_password,
+    ca_file=params['rhv_cafile'],
+    log=logging.getLogger(),
+    insecure=params['insecure'],
 )
 
 system_service = connection.system_service()
diff --git a/v2v/rhv-upload-plugin.py b/v2v/rhv-upload-plugin.py
index 3942ec72..ab14bc2d 100644
--- a/v2v/rhv-upload-plugin.py
+++ b/v2v/rhv-upload-plugin.py
@@ -34,7 +34,7 @@ import ovirtsdk4.types as types
 
 # Timeout to wait for oVirt disks to change status, or the transfer
 # object to finish initializing [seconds].
-timeout = 5*60
+timeout = 5 * 60
 
 # Parameters are passed in via a JSON doc from the OCaml code.
 # Because this Python code ships embedded inside virt-v2v there
@@ -93,12 +93,12 @@ def failing(func):
 
 def open(readonly):
     connection = sdk.Connection(
-        url = params['output_conn'],
-        username = parse_username(),
-        password = read_password(),
-        ca_file = params['rhv_cafile'],
-        log = logging.getLogger(),
-        insecure = params['insecure'],
+        url=params['output_conn'],
+        username=parse_username(),
+        password=read_password(),
+        ca_file=params['rhv_cafile'],
+        log=logging.getLogger(),
+        insecure=params['insecure'],
     )
 
     # Use the local host is possible.
@@ -175,7 +175,7 @@ def pread(h, count, offset):
     http = h['http']
     transfer = h['transfer']
 
-    headers = {"Range": "bytes=%d-%d" % (offset, offset+count-1)}
+    headers = {"Range": "bytes=%d-%d" % (offset, offset + count - 1)}
     if h['needs_auth']:
         headers["Authorization"] = transfer.signed_ticket
 
@@ -196,14 +196,14 @@ def pwrite(h, buf, offset):
     transfer = h['transfer']
 
     count = len(buf)
-    h['highestwrite'] = max(h['highestwrite'], offset+count)
+    h['highestwrite'] = max(h['highestwrite'], offset + count)
 
     http.putrequest("PUT", h['path'] + "?flush=n")
     if h['needs_auth']:
         http.putheader("Authorization", transfer.signed_ticket)
     # The oVirt server only uses the first part of the range, and the
     # content-length.
-    http.putheader("Content-Range", "bytes %d-%d/*" % (offset, offset+count-1))
+    http.putheader("Content-Range", "bytes %d-%d/*" % (offset, offset + count - 1))
     http.putheader("Content-Length", str(count))
     http.endheaders()
 
@@ -258,17 +258,17 @@ def emulate_zero(h, count, offset):
     # Since we've just created a new disk it's safe to ignore these
     # requests as long as they are smaller than the highest write seen.
     # After that we must emulate them with writes.
-    if offset+count < h['highestwrite']:
+    if offset + count < h['highestwrite']:
         http.putrequest("PUT", h['path'])
         if h['needs_auth']:
             http.putheader("Authorization", transfer.signed_ticket)
         http.putheader("Content-Range",
-                       "bytes %d-%d/*" % (offset, offset+count-1))
+                       "bytes %d-%d/*" % (offset, offset + count - 1))
         http.putheader("Content-Length", str(count))
         http.endheaders()
 
         try:
-            buf = bytearray(128*1024)
+            buf = bytearray(128 * 1024)
             while count > len(buf):
                 http.send(buf)
                 count -= len(buf)
@@ -426,7 +426,7 @@ def find_host(connection):
     host = hosts[0]
     debug("host.id = %r" % host.id)
 
-    return types.Host(id = host.id)
+    return types.Host(id=host.id)
 
 def create_disk(connection):
     """
@@ -443,23 +443,23 @@ def create_disk(connection):
         disk_format = types.DiskFormat.COW
 
     disk = disks_service.add(
-        disk = types.Disk(
+        disk=types.Disk(
             # The ID is optional.
-            id = params.get('rhv_disk_uuid'),
-            name = params['disk_name'],
-            description = "Uploaded by virt-v2v",
-            format = disk_format,
+            id=params.get('rhv_disk_uuid'),
+            name=params['disk_name'],
+            description="Uploaded by virt-v2v",
+            format=disk_format,
             # XXX For qcow2 disk on block storage, we should use the estimated
             # size, based on qemu-img measure of the overlay.
-            initial_size = params['disk_size'],
-            provisioned_size = params['disk_size'],
+            initial_size=params['disk_size'],
+            provisioned_size=params['disk_size'],
             # XXX Ignores params['output_sparse'].
             # Handling this properly will be complex, see:
             # https://www.redhat.com/archives/libguestfs/2018-March/msg00177.html
-            sparse = True,
-            storage_domains = [
+            sparse=True,
+            storage_domains=[
                 types.StorageDomain(
-                    name = params['output_storage'],
+                    name=params['output_storage'],
                 )
             ],
         )
@@ -498,9 +498,9 @@ def create_transfer(connection, disk, host):
 
     transfer = transfers_service.add(
         types.ImageTransfer(
-            disk = types.Disk(id = disk.id),
-            host = host,
-            inactivity_timeout = 3600,
+            disk=types.Disk(id=disk.id),
+            host=host,
+            inactivity_timeout=3600,
             **extra,
         )
     )
@@ -559,8 +559,8 @@ def cancel_transfer(connection, transfer):
     """
     debug("canceling transfer %s" % transfer.id)
     transfer_service = (connection.system_service()
-                            .image_transfers_service()
-                            .image_transfer_service(transfer.id))
+                        .image_transfers_service()
+                        .image_transfer_service(transfer.id))
     transfer_service.cancel()
 
 def finalize_transfer(connection, transfer, disk_id):
@@ -585,16 +585,16 @@ def finalize_transfer(connection, transfer, disk_id):
     """
     debug("finalizing transfer %s" % transfer.id)
     transfer_service = (connection.system_service()
-                            .image_transfers_service()
-                            .image_transfer_service(transfer.id))
+                        .image_transfers_service()
+                        .image_transfer_service(transfer.id))
 
     start = time.time()
 
     transfer_service.finalize()
 
     disk_service = (connection.system_service()
-                        .disks_service()
-                        .disk_service(disk_id))
+                    .disks_service()
+                    .disk_service(disk_id))
 
     while True:
         time.sleep(1)
@@ -656,13 +656,13 @@ def create_http(url):
     """
     if url.scheme == "https":
         context = \
-            ssl.create_default_context(purpose = ssl.Purpose.SERVER_AUTH,
-                                       cafile = params['rhv_cafile'])
+            ssl.create_default_context(purpose=ssl.Purpose.SERVER_AUTH,
+                                       cafile=params['rhv_cafile'])
         if params['insecure']:
             context.check_hostname = False
             context.verify_mode = ssl.CERT_NONE
 
-        return HTTPSConnection(url.hostname, url.port, context = context)
+        return HTTPSConnection(url.hostname, url.port, context=context)
     elif url.scheme == "http":
         return HTTPConnection(url.hostname, url.port)
     else:
diff --git a/v2v/rhv-upload-precheck.py b/v2v/rhv-upload-precheck.py
index 1b344ba2..e8be90c5 100644
--- a/v2v/rhv-upload-precheck.py
+++ b/v2v/rhv-upload-precheck.py
@@ -50,12 +50,12 @@ username = parsed.username or "admin at internal"
 
 # Connect to the server.
 connection = sdk.Connection(
-    url = params['output_conn'],
-    username = username,
-    password = output_password,
-    ca_file = params['rhv_cafile'],
-    log = logging.getLogger(),
-    insecure = params['insecure'],
+    url=params['output_conn'],
+    username=username,
+    password=output_password,
+    ca_file=params['rhv_cafile'],
+    log=logging.getLogger(),
+    insecure=params['insecure'],
 )
 
 system_service = connection.system_service()
@@ -97,8 +97,8 @@ cluster = clusters[0]
 
 # Otherwise everything is OK, print a JSON with the results.
 results = {
-  "rhv_storagedomain_uuid": storage_domain.id,
-  "rhv_cluster_uuid": cluster.id,
+    "rhv_storagedomain_uuid": storage_domain.id,
+    "rhv_cluster_uuid": cluster.id,
 }
 
 json.dump(results, sys.stdout)
diff --git a/v2v/rhv-upload-vmcheck.py b/v2v/rhv-upload-vmcheck.py
index fbb884b9..89ead726 100644
--- a/v2v/rhv-upload-vmcheck.py
+++ b/v2v/rhv-upload-vmcheck.py
@@ -50,12 +50,12 @@ username = parsed.username or "admin at internal"
 
 # Connect to the server.
 connection = sdk.Connection(
-    url = params['output_conn'],
-    username = username,
-    password = output_password,
-    ca_file = params['rhv_cafile'],
-    log = logging.getLogger(),
-    insecure = params['insecure'],
+    url=params['output_conn'],
+    username=username,
+    password=output_password,
+    ca_file=params['rhv_cafile'],
+    log=logging.getLogger(),
+    insecure=params['insecure'],
 )
 
 system_service = connection.system_service()
@@ -63,7 +63,7 @@ system_service = connection.system_service()
 # Find if a virtual machine already exists with that name.
 vms_service = system_service.vms_service()
 vms = vms_service.list(
-    search = ("name=%s" % params['output_name']),
+    search=("name=%s" % params['output_name']),
 )
 if len(vms) > 0:
     vm = vms[0]
-- 
2.24.1




More information about the Libguestfs mailing list