Index: vws ================================================================== --- vws +++ vws @@ -20,10 +20,11 @@ import grp VERSION = "0.8.1" config = ConfigParser(interpolation=None) # pylint: disable=invalid-name + def find_vm(name): """Search and return VM directory""" search_path = [ os.path.join(pwd.getpwuid(os.getuid()).pw_dir, "VWs"), @@ -91,17 +92,18 @@ for line in output.split("\n"): if url is not None: continue idx = line.find("address:") if idx != -1: - url = line[idx + 9 :] + url = line[idx + 9:] if url.startswith("*:"): url = socket.getfqdn() + url[1:] if url is None: if output.rstrip().endswith("(qemu)"): return spiceurl(sock) - print("ERROR parsing 'info spice' output:«%s»" % output, file=sys.stderr) + print("ERROR parsing 'info spice' output:«%s»" % output, + file=sys.stderr) return None return "spice://" + url.rstrip("\r") def list_bridges(): @@ -218,11 +220,11 @@ if idx0 != -1: idx = data.find("=", idx0) idx += 1 idx2 = data.find(" ", idx) bridgename = data[idx:idx2] - if not bridgename in list_bridges(): + if bridgename not in list_bridges(): net = config.get("create options", "net") if net == "user": data = data[:idx0] + "-net user" + data[idx2:] else: data = data[:idx] + net + data[idx2:] @@ -273,11 +275,11 @@ return "" def cmd_start(options): """vws start""" - if not "DISPLAY" in os.environ: + if "DISPLAY" not in os.environ: # If cannot start GUI just don't do it. options.gui = False if options.stopped: arg = make_start_cmdline(options) cwd = os.getcwd() @@ -340,19 +342,20 @@ eol = False try: print("(qemu) ", end="") sys.stdout.flush() while True: - readfd, dummy_w, dummy_x = select.select([sys.stdin, options.sock], [], []) + readfd, dummy_w, dummy_x = select.select([sys.stdin, options.sock], + [], []) if sys.stdin in readfd: cmd = sys.stdin.readline() # Check for eof if cmd == "": break answer = send_command(options.sock, cmd.rstrip()) idx = answer.index("\n") - print(answer[idx + 1 :], end="") + print(answer[idx + 1:], end="") eol = answer.endswith("\n") sys.stdout.flush() elif options.sock in readfd: print( "UNSOLICITED MESSAGE %" @@ -389,11 +392,11 @@ if options.id is None: # Search for devices which could be interpreted as CDROM devlist = send_command(options.sock, "info block") idx = devlist.find("info block") if idx != -1: - devlist = devlist[devlist.find("\n", idx) + 1 :] + devlist = devlist[devlist.find("\n", idx) + 1:] for dev in devlist.split("\r\n\r\n"): if dev.find("\n Removable device: ") == -1: continue if dev.startswith("floppy"): continue @@ -411,11 +414,12 @@ return 1 if options.file is None: answer = send_command(options.sock, "eject " + options.id) else: answer = send_command( - options.sock, "change %s %s" % (options.id, os.path.abspath(options.file)) + options.sock, "change %s %s" % (options.id, + os.path.abspath(options.file)) ) print(answer) return 0 @@ -508,11 +512,11 @@ uri = spiceurl(sock) if uri is None: f.update({"state": "problem ", "uri": "None", "ip": "-"}) f.update(read_netinfo(os.path.join(dirname, "start"))) else: - f["uri"] = uri[uri.rindex(":") + 1 :] + f["uri"] = uri[uri.rindex(":") + 1:] f.update(get_netinfo(sock)) sock.shutdown(socket.SHUT_RDWR) sock.close() f["state"] = "running " return f @@ -526,11 +530,11 @@ bridges.add(vminfo["iface"]) arp_data = {} for bridge in bridges: arp_data.update(parse_arp(bridge)) for vminfo in listing: - if "mac" in vminfo and not "ip" in vminfo: + if "mac" in vminfo and "ip" not in vminfo: if vminfo["mac"] in arp_data: vminfo["ip"] = arp_data[vminfo["mac"]] else: vminfo["ip"] = "-" @@ -837,13 +841,13 @@ else SPICE_AUTH="disable-ticketing,addr=127.0.0.1" fi SPICE_PORT=$(find_free_port 5900) if [ "$1" = '-cdrom' ]; then - shift - CDROM=",file=$1" - shift + shift + CDROM=",file=$1" + shift fi #set umask to make machine group-accessable umask 002 {qemubinary} -name $NAME {accel} \\ -m {memory} \\ @@ -903,11 +907,11 @@ pwd.getpwuid(os.getuid()).pw_dir, "VWs", parsed_args.machine ) dirmode = 0o775 if parsed_args.net != "user": bridges = list_bridges() - if not parsed_args.net in bridges: + if parsed_args.net not in bridges: raise ValueError( "No such bridge %s. Available ones %s" % (parsed_args.net, ", ".join(bridges)) ) options["net"] = "-net nic,macaddr=%s -net bridge,br=%s" % ( @@ -916,11 +920,11 @@ ) else: options["net"] = "-net nic,macaddr=%s -net user" % (macaddr,) options["qemubinary"] = "qemu-system-" + parsed_args.arch options["vga"] = parsed_args.vga - if not parsed_args.arch in ("i386", "x86_64"): + if parsed_args.arch not in ("i386", "x86_64"): print(NOACCEL + "target architecture", file=sys.stderr) options.accel = "" elif not os.access("/dev/kvm", os.W_OK): print(NOACCEL + "unavailability on the host system", file=sys.stderr) options.accel = "" @@ -1015,14 +1019,10 @@ # # prepare defaults for config # - - - - def config_defaults(conf): """Set default values for config options""" arch = os.uname()[4] if re.match("i[3-9]86", arch): arch = "i386" @@ -1074,11 +1074,11 @@ def main(): """Parse an arguments and execute everything""" # pylint: disable=too-many-branches, too-many-statements - global config # pylint: disable=invalid-name, global-variable-not-assigned + global config # pylint: disable=invalid-name, global-variable-not-assigned config_defaults(config) read_config(config) # Parse argument args = ArgumentParser(description="Manage Virtual Workstations") cmds = args.add_subparsers(dest="command", help="sub-command help") @@ -1396,11 +1396,11 @@ stopped_vm_commands = ["start", "snapshot", "revert", "commit", "snapshots"] if hasattr(parsed_args, "machine"): parsed_args.dir = find_vm(parsed_args.machine) parsed_args.sock = connect_vm(parsed_args.dir) if parsed_args.sock is None: - if not parsed_args.command in stopped_vm_commands: + if parsed_args.command not in stopped_vm_commands: print( "Virtual machine %s is not running." % parsed_args.machine, file=sys.stderr, ) sys.exit(1)