Check-in [2cc90f6c24]
Not logged in
Overview
Comment:Added stop --hard, written some usb-related code
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 2cc90f6c24cfbee55771cf402742988ab30a8128
User & Date: vitus on 2015-12-11 21:21:22
Other Links: manifest | tags
Context
2015-12-12
07:26
Hopefilly fixed problem with hangs of monitor operation. Implemented screenshot, record and stoprecord commands. Incorporated start.template inside script, improved error diagnostic on create check-in: a090f477b4 user: vitus tags: trunk
2015-12-11
21:21
Added stop --hard, written some usb-related code check-in: 2cc90f6c24 user: vitus tags: trunk
20:50
Improved help messages check-in: 4eed41b225 user: vitus tags: trunk
Changes

Modified vws from [c892d664ab] to [910684f88e].

88
89
90
91
92
93
94



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114


115
116
117
118
119
120
121
        options.sock = connect_vm(options.dir)
    if options.gui:
        uri = spiceurl(options)
        os.system("remote-viewer %s &" % uri)
    elif not options.stopped:
        print >>sys.stderr,"VM already running"
def cmd_stop(options):



    print send_command(options.sock,'system_powerdown')
def cmd_monitor(options):
    try:
        print "(qemu) ",
        sys.stdout.flush()
        while True:
            r,w,x=select.select([sys.stdin,options.sock],[],[])
            if sys.stdin in r:
                cmd = sys.stdin.readline().rstrip()
                answer=send_command(options.sock,cmd)
                n=answer.index('\n')
                print answer[n+1:],
                sys.stdout.flush()
            elif options.sock in r:
                print "UNSOLICITED MESSAGE %"+options.sock.readline().rstrip()
    except KeyboardInterrupt:
        print "Keyboard interrupt"
        sys.exit()
def cmd_reset(options):
    print send_command(options.sock,'system_reset')


def cmd_cdrom(options):
    if options.id  is None:
        # Search for devices which could be interpreted as CDROM
        devlist=send_command(options.sock,"info block")
        for dev in  re.findall("([-\\w]+): [^\n]+\n    Removable device:",devlist):
            if re.search("cd",dev):
                options.id=dev







>
>
>
|



















>
>







88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
        options.sock = connect_vm(options.dir)
    if options.gui:
        uri = spiceurl(options)
        os.system("remote-viewer %s &" % uri)
    elif not options.stopped:
        print >>sys.stderr,"VM already running"
def cmd_stop(options):
    if options.hard:
        print send_command(options.sock,'quit')
    else:
        print send_command(options.sock,'system_powerdown')
def cmd_monitor(options):
    try:
        print "(qemu) ",
        sys.stdout.flush()
        while True:
            r,w,x=select.select([sys.stdin,options.sock],[],[])
            if sys.stdin in r:
                cmd = sys.stdin.readline().rstrip()
                answer=send_command(options.sock,cmd)
                n=answer.index('\n')
                print answer[n+1:],
                sys.stdout.flush()
            elif options.sock in r:
                print "UNSOLICITED MESSAGE %"+options.sock.readline().rstrip()
    except KeyboardInterrupt:
        print "Keyboard interrupt"
        sys.exit()
def cmd_reset(options):
    print send_command(options.sock,'system_reset')
def cmd_save(options):
    print send_command(options.sock,'savevm')
def cmd_cdrom(options):
    if options.id  is None:
        # Search for devices which could be interpreted as CDROM
        devlist=send_command(options.sock,"info block")
        for dev in  re.findall("([-\\w]+): [^\n]+\n    Removable device:",devlist):
            if re.search("cd",dev):
                options.id=dev
130
131
132
133
134
135
136



137
138
139
140
141
142

















143
144
145
146
147
148
149
150
151
152
153
154
155

156
157
158
159
160
161
162
        answer=send_command(options.sock,"eject "+options.id)
    else:
        answer=send_command(options.sock, "change %s %s" % (options.id, 
                            options.file))
    print answer
def find_usb(options,devices):
    if hasattr("pattern",options):



        pass 
    elif not hasattr("address",options):
        print >>sys.stderr,"Addess or search pattern for device is not specified"
        sys.exit(1)
    else:
        return options.address

















def cmd_usb_insert(options):
    address=find_usb(options)
    answer=send_command(options.sock,"usb_add host:%s" % address)
    print answer
def cmd_usb_list(options):
    os.system("lsusb")
def cmd_usb_remove(options):
    address=find_usb(options)
    answer=send_command(options.sock,"usb_del %s" % address)
    print answer
    
def cmd_usb_attached(options):
    answer=send_command(options.sock,"info usb")

    print answer
def cmd_list(options):
    count = 0
    search_path=[os.environ['HOME']+"/VWs",
        config.get("directories","SharedVMs"),
        config.get("directories","AutostartVMs")]
    for dirname in search_path:







>
>
>
|





>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

|





|




|
>







135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
        answer=send_command(options.sock,"eject "+options.id)
    else:
        answer=send_command(options.sock, "change %s %s" % (options.id, 
                            options.file))
    print answer
def find_usb(options,devices):
    if hasattr("pattern",options):
        for dev in devies:
            if re.search(options.pattern,dev[1]):
                options.address=dev[0]
                break
    elif not hasattr("address",options):
        print >>sys.stderr,"Addess or search pattern for device is not specified"
        sys.exit(1)
    else:
        return options.address
def get_host_devices():
    f=os.popen("lsusb","r")
    l=[]
    for dev in f:
        m=re.match('Bus (\d+) Device (\d+): (.*)$',dev)
        if m:
            l.append((m.group(1)+"."+m.group(2),m.group(3)))
    f.close()
    return l
def get_vm_devices(sock):
    answer=send_command(sock,"info usb")
    l=[]
    for dev in answer.split("\n"):
        m=re.match('Device (\d+\.\d), .*?, Product (.*)$',dev)
        if m:
            l.append((m.group(1),m.group(2)))
    return l
def cmd_usb_insert(options):
    address=find_usb(options,get_host_devices())
    answer=send_command(options.sock,"usb_add host:%s" % address)
    print answer
def cmd_usb_list(options):
    os.system("lsusb")
def cmd_usb_remove(options):
    address=find_usb(options,get_vm_devices(options.sock))
    answer=send_command(options.sock,"usb_del %s" % address)
    print answer
    
def cmd_usb_attached(options):
    for t in get_host_devices(options.sock):
        print "Address %s : %s"%(t[0],t[1])
    print answer
def cmd_list(options):
    count = 0
    search_path=[os.environ['HOME']+"/VWs",
        config.get("directories","SharedVMs"),
        config.get("directories","AutostartVMs")]
    for dirname in search_path: