all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Max Carrara <m.carrara@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH v1 pve-esxi-import-tools 5/5] listvms: run formatter
Date: Tue, 19 Mar 2024 16:32:50 +0100	[thread overview]
Message-ID: <20240319153250.629369-6-m.carrara@proxmox.com> (raw)
In-Reply-To: <20240319153250.629369-1-m.carrara@proxmox.com>

This commit formats the script using `black -l 80` [0], even though we
don't have an official style guide for Python.

[0]: https://github.com/psf/black

Signed-off-by: Max Carrara <m.carrara@proxmox.com>
---
 listvms.py | 30 +++++++++++++++++++++++-------
 1 file changed, 23 insertions(+), 7 deletions(-)

diff --git a/listvms.py b/listvms.py
index 9f85bf9..a3cb35c 100755
--- a/listvms.py
+++ b/listvms.py
@@ -169,22 +169,29 @@ def list_vms(service_instance: vim.ServiceInstance) -> list[vim.VirtualMachine]:
     vm_view.Destroy()
     return vms
 
+
 def parse_file_path(path) -> tuple[str, Path]:
     """Parse a path of the form '[datastore] file/path'"""
-    datastore_name, relative_path = path.split('] ', 1)
-    datastore_name = datastore_name.strip('[')
+    datastore_name, relative_path = path.split("] ", 1)
+    datastore_name = datastore_name.strip("[")
     return (datastore_name, Path(relative_path))
 
+
 def get_vm_vmx_info(vm: vim.VirtualMachine) -> VmVmxInfo:
     """Extract VMX file path and checksum from a VM object."""
-    datastore_name, relative_vmx_path = parse_file_path(vm.config.files.vmPathName)
+    datastore_name, relative_vmx_path = parse_file_path(
+        vm.config.files.vmPathName
+    )
 
     return VmVmxInfo(
         datastore=datastore_name,
         path=relative_vmx_path,
-        checksum=vm.config.vmxConfigChecksum.hex() if vm.config.vmxConfigChecksum else 'N/A'
+        checksum=vm.config.vmxConfigChecksum.hex()
+        if vm.config.vmxConfigChecksum
+        else "N/A",
     )
 
+
 def get_vm_disk_info(vm: vim.VirtualMachine) -> list[VmDiskInfo]:
     disks = []
     for device in vm.config.hardware.device:
@@ -195,13 +202,22 @@ def get_vm_disk_info(vm: vim.VirtualMachine) -> list[VmDiskInfo]:
                 disks.append(VmDiskInfo(datastore, path, capacity))
             except Exception as err:
                 # if we can't figure out the disk stuff that's fine...
-                print("failed to get disk information for esxi vm: ", err, file=sys.stderr)
+                print(
+                    "failed to get disk information for esxi vm: ",
+                    err,
+                    file=sys.stderr,
+                )
     return disks
 
-def get_all_datacenters(service_instance: vim.ServiceInstance) -> list[vim.Datacenter]:
+
+def get_all_datacenters(
+    service_instance: vim.ServiceInstance,
+) -> list[vim.Datacenter]:
     """Retrieve all datacenters from the ESXi/vCenter server."""
     content = service_instance.content
-    dc_view = content.viewManager.CreateContainerView(content.rootFolder, [vim.Datacenter], True)
+    dc_view = content.viewManager.CreateContainerView(
+        content.rootFolder, [vim.Datacenter], True
+    )
     datacenters = dc_view.view
     dc_view.Destroy()
     return datacenters
-- 
2.39.2





  parent reply	other threads:[~2024-03-19 15:33 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-19 15:32 [pve-devel] [PATCH v1 pve-esxi-import-tools 0/5] Improve listvms.py Max Carrara
2024-03-19 15:32 ` [pve-devel] [PATCH v1 pve-esxi-import-tools 1/5] listvms: remove unused import and variable Max Carrara
2024-03-19 15:32 ` [pve-devel] [PATCH v1 pve-esxi-import-tools 2/5] listvms: reorder imports Max Carrara
2024-03-19 15:32 ` [pve-devel] [PATCH v1 pve-esxi-import-tools 3/5] listvms: improve typing and add dataclasses to represent dicts Max Carrara
2024-03-20  9:38   ` Lukas Wagner
2024-03-20 10:08     ` Max Carrara
2024-03-19 15:32 ` [pve-devel] [PATCH v1 pve-esxi-import-tools 4/5] listvms: add arg parser, context manager for connections, fetch helper Max Carrara
2024-03-20  9:39   ` Lukas Wagner
2024-03-20 10:08     ` Max Carrara
2024-03-20 12:45   ` Wolfgang Bumiller
2024-03-20 17:00     ` Max Carrara
2024-03-19 15:32 ` Max Carrara [this message]
2024-03-20  9:42 ` [pve-devel] [PATCH v1 pve-esxi-import-tools 0/5] Improve listvms.py Lukas Wagner
2024-03-20 10:08   ` Max Carrara

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240319153250.629369-6-m.carrara@proxmox.com \
    --to=m.carrara@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal