Diff
Not logged in

Differences From Artifact [6ec55019ca]:

To Artifact [45822981f1]:


78
79
80
81
82
83
84














85
86
87
88
89
90
91
                continue
            name = line[:n]
            if name == "bridge name":
                continue
            lst.append(name)
    return lst

















#
# command implementation
#

def cmd_spiceuri(options):







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







78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
                continue
            name = line[:n]
            if name == "bridge name":
                continue
            lst.append(name)
    return lst

def validate_size(size):
    return re.match('\d+[KMG]',size) is not None

def get_drives(vm_dir):
    """ Return list of drive files in the VW directory """
    result=[]
    with open(vm_dir+"/start") as f:
        for line in f:
            if (re.match("\s*-drive .*",line) and
                line.find("media=disk")>-1):
                m=re.search("file=([^,\s]*)",line)
                if m:
                    result.append(m.group(1))
    return result


#
# command implementation
#

def cmd_spiceuri(options):
100
101
102
103
104
105
106















107
108
109
110


111
112
113
114
115
116
117
        if options.snapshot:
            arg=arg+" -snapshot"
        if options.args:
            arg=arg+" "+"".join(options.args)
        print arg
        cwd=os.getcwd()
        os.chdir(options.dir)















        os.system("./start%s" % arg)
        os.chdir(cwd)
        time.sleep(2)
        options.sock = connect_vm(options.dir)


    else:
        if options.snapshot or options.args:
            print >>sys.stderr, "Cannot change qemu options. VM is already running"
        if options.cdrom:
            options.file = options.cdrom[0]
            cmd_cdrom(options)    
    if options.gui:







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




>
>







114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
        if options.snapshot:
            arg=arg+" -snapshot"
        if options.args:
            arg=arg+" "+"".join(options.args)
        print arg
        cwd=os.getcwd()
        os.chdir(options.dir)
        # Check for snapshot
        next=0
        snapshot_id=None
        with os.popen("qemu-img info \"%s\"" % (get_drives(options.dir)[0]),"r") as f:
            for line in f:
                if line == 'Snapshot list:\n':
                    next=2
                elif next==2 and line.startswith('ID'):
                    next=1
                elif next==1:
                    next=0
                    snapshot_id = line[:line.index(' ')]
                    arg=arg+" -loadvm " + snapshot_id
                    break

        os.system("./start%s" % arg)
        os.chdir(cwd)
        time.sleep(2)
        options.sock = connect_vm(options.dir)
        if snapshot_id:
            send_command(options.sock,"delvm "+snapshot_id)
    else:
        if options.snapshot or options.args:
            print >>sys.stderr, "Cannot change qemu options. VM is already running"
        if options.cdrom:
            options.file = options.cdrom[0]
            cmd_cdrom(options)    
    if options.gui:
140
141
142
143
144
145
146
147






148
149
150
151
152
153
154
                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







|
>
>
>
>
>
>







171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
                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):
    answer=send_command(options.sock,'savevm')
    if re.search("Error",answer):
        print >>sys.stderr,answer
        sys.exit(1)
    else:
        send_command(options.sock,'quit')

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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
        print >>sys.stderr,"No sound recording in progress"
        sys.exit(1)
    else:
        print send_command(options.sock,"stopcapture "+m.group(1))
def cmd_version(options):
    print VERSION

def validate_size(size):
    return re.match('\d+[KMG]',size) is not None

def get_drives(vm_dir):
    """ Return list of drive files in the VW directory """
    result=[]
    with open(vm_dir+"/start") as f:
        for line in f:
            if (re.match("\s*-drive .*",line) and
                line.find("media=disk")>-1):
                m=re.search("file=([^,\s]*)",line)
                if m:
                    result.append(m.group(1))
    return result

def cmd_snapshot(options):
    import os.path
    if not options.stopped:
        print >>sys.stderr,"Cannot make snapshot of running VW"
        sys.exit(1)
    drives=get_drives(options.dir)







<
<
<
<
<
<
<
<
<
<
<
<
<
<







299
300
301
302
303
304
305














306
307
308
309
310
311
312
        print >>sys.stderr,"No sound recording in progress"
        sys.exit(1)
    else:
        print send_command(options.sock,"stopcapture "+m.group(1))
def cmd_version(options):
    print VERSION
















def cmd_snapshot(options):
    import os.path
    if not options.stopped:
        print >>sys.stderr,"Cannot make snapshot of running VW"
        sys.exit(1)
    drives=get_drives(options.dir)