Changeset 21640 in vbox
- Timestamp:
- Jul 16, 2009 11:21:47 AM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 50172
- Location:
- trunk/src/VBox
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxShell/vboxshell.py
r21584 r21640 258 258 print session.QueryErrorObject(rc) 259 259 260 def getMachines(ctx): 261 return ctx['global'].getArray(ctx['vb'], 'machines') 260 def getMachines(ctx, invalidate = False): 261 if ctx['vb'] is not None: 262 if ctx['_machlist'] is None or invalidate: 263 ctx['_machlist'] = ctx['global'].getArray(ctx['vb'], 'machines') 264 return ctx['_machlist'] 265 else: 266 return [] 262 267 263 268 def asState(var): … … 389 394 390 395 def listCmd(ctx, args): 391 for m in getMachines(ctx ):396 for m in getMachines(ctx, True): 392 397 print "Machine '%s' [%s], state=%s" %(m.name,m.id,m.sessionState) 393 398 return 0 … … 420 425 os = ctx['vb'].getGuestOSType(mach.OSTypeId) 421 426 print " One can use setvar <mach> <var> <value> to change variable, using name in []." 422 print " Name [name]: " + mach.name423 print " ID [n/a]: " + mach.id424 print " OS Type [n/a]: " + os.description427 print " Name [name]: %s" %(mach.name) 428 print " ID [n/a]: %s" %(mach.id) 429 print " OS Type [n/a]: %s" %(os.description) 425 430 print 426 431 print " CPUs [CPUCount]: %d" %(mach.CPUCount) … … 435 440 print " ACPI [BIOSSettings.ACPIEnabled]: %s" %(asState(bios.ACPIEnabled)) 436 441 print " APIC [BIOSSettings.IOAPICEnabled]: %s" %(asState(bios.IOAPICEnabled)) 437 print " PAE [PAEEnabled]: %s" %(asState( mach.PAEEnabled))442 print " PAE [PAEEnabled]: %s" %(asState(int(mach.PAEEnabled))) 438 443 print " Hardware virtualization [HWVirtExEnabled]: " + asState(mach.HWVirtExEnabled) 439 444 print " VPID support [HWVirtExVPIDEnabled]: " + asState(mach.HWVirtExVPIDEnabled) … … 457 462 print " Controller: %s port: %d device: %d:" % (disk.controller, disk.port, disk.device) 458 463 hd = disk.hardDisk 459 print " id: " + hd.id460 print " location: " + hd.location461 print " name: " + hd.name462 print " format: " + hd.format464 print " id: %s" %(hd.id) 465 print " location: %s" %(hd.location) 466 print " name: %s" %(hd.name) 467 print " format: %s" %(hd.format) 463 468 print 464 469 465 470 dvd = mach.DVDDrive 466 if dvd.getHostDrive() is not None:471 if dvd.getHostDrive(): 467 472 hdvd = dvd.getHostDrive() 468 473 print " DVD:" 469 print " Host disk: ",hdvd.name474 print " Host disk: %s" %(hdvd.name) 470 475 print 471 476 472 if dvd.getImage() is not None:477 if dvd.getImage(): 473 478 vdvd = dvd.getImage() 474 479 print " DVD:" 475 print " Image at: ",vdvd.location476 print " Size: ",vdvd.size480 print " Image at: %s" %(vdvd.location) 481 print " Size: %s" %(vdvd.size) 477 482 print 478 483 479 484 floppy = mach.floppyDrive 480 if floppy.getHostDrive() is not None:485 if floppy.getHostDrive(): 481 486 hfloppy = floppy.getHostDrive() 482 487 print " Floppy:" 483 print " Host disk: ",hfloppy.name488 print " Host disk: %s" %(hfloppy.name) 484 489 print 485 490 486 if floppy.getImage() is not None:491 if floppy.getImage(): 487 492 vfloppy = floppy.getImage() 488 493 print " Floppy:" 489 print " Image at: ",vfloppy.location490 print " Size: ",vfloppy.size494 print " Image at: %s" %(vfloppy.location) 495 print " Size: %s" %(vfloppy.size) 491 496 print 492 497 … … 769 774 770 775 time.sleep(float(args[1])) 776 return 0 777 778 779 def connectCmd(ctx, args): 780 if (len(args) > 4): 781 print "usage: connect [url] [username] [passwd]" 782 return 0 783 784 if ctx['vb'] is not None: 785 print "Already connected, disconnect first..." 786 return 0 787 788 if (len(args) > 1): 789 url = args[1] 790 else: 791 url = None 792 793 if (len(args) > 2): 794 user = args[1] 795 else: 796 user = "" 797 798 if (len(args) > 3): 799 passwd = args[2] 800 else: 801 passwd = "" 802 803 vbox = ctx['global'].platform.connect(url, user, passwd) 804 ctx['vb'] = vbox 805 print "Running VirtualBox version %s" %(vbox.version) 806 ctx['perf'] = ctx['global'].getPerfCollector(ctx['vb']) 807 return 0 808 809 def disconnectCmd(ctx, args): 810 if (len(args) != 1): 811 print "usage: disconnect" 812 return 0 813 814 if ctx['vb'] is None: 815 print "Not connected yet." 816 return 0 817 818 try: 819 ctx['global'].platform.disconnect() 820 except: 821 ctx['vb'] = None 822 raise 823 824 ctx['vb'] = None 825 return 0 771 826 772 827 aliases = {'s':'start', … … 852 907 traceback.print_exc() 853 908 854 def interpret(ctx): 909 def interpret(ctx): 910 if ctx['remote']: 911 commands['connect'] = ["Connect to remote VBox instance", connectCmd, 0] 912 commands['disconnect'] = ["Disconnect from remote VBox instance", disconnectCmd, 0] 913 855 914 vbox = ctx['vb'] 856 print "Running VirtualBox version %s" %(vbox.version) 857 ctx['perf'] = ctx['global'].getPerfCollector(ctx['vb']) 858 859 checkUserExtensions(ctx, commands, vbox.homeFolder) 915 916 if vbox is not None: 917 print "Running VirtualBox version %s" %(vbox.version) 918 ctx['perf'] = ctx['global'].getPerfCollector(ctx['vb']) 919 home = vbox.homeFolder 920 else: 921 ctx['perf'] = None 922 home = os.path.join(os.path.expanduser("~"), ".VirtualBox") 923 924 print "h", home 925 checkUserExtensions(ctx, commands, home) 860 926 861 927 autoCompletion(commands, ctx) … … 923 989 'remote':g_virtualBoxManager.remote, 924 990 'type':g_virtualBoxManager.type, 925 'run':runCommandCb 991 'run':runCommandCb, 992 '_machlist':None 926 993 } 927 994 interpret(ctx) -
trunk/src/VBox/Main/glue/vboxapi.py
r21384 r21640 379 379 def __init__(self, params): 380 380 sys.path.append(VboxSdkDir+'/bindings/webservice/python/lib') 381 # not really needed, but just fail early if misconfigured 381 382 import VirtualBox_services 382 383 import VirtualBox_wrappers … … 390 391 self.password = "" 391 392 self.url = None 393 self.vbox = None 394 395 def getSessionObject(self, vbox): 396 return self.wsmgr.getSessionObject(vbox) 397 398 def getVirtualBox(self): 399 return connect(self.url, self.user, self.password) 400 401 def connect(self, url, user, passwd): 402 if self.vbox is not None: 403 disconnect() 404 from VirtualBox_wrappers import IWebsessionManager2 405 self.url = url 406 if user is None: 407 user = "" 408 self.user = user 409 if passwd is None: 410 passwd = "" 411 self.password = passwd 392 412 self.wsmgr = IWebsessionManager2(self.url) 393 394 def getSessionObject(self, vbox):395 return self.wsmgr.getSessionObject(vbox)396 397 def getVirtualBox(self):398 413 self.vbox = self.wsmgr.logon(self.user, self.password) 399 414 return self.vbox 415 416 def disconnect(self): 417 if self.vbox is not None and self.wsmgr is not None: 418 self.wsmgr.logoff(self.vbox) 419 self.vbox = None 420 self.wsmgr = None 400 421 401 422 def getConstants(self): … … 426 447 def deinit(self): 427 448 try: 428 if self.vbox is not None: 429 self.wsmg.logoff(self.vbox) 430 self.vbox = None 449 disconnect() 431 450 except: 432 451 pass 433 452 434 453 def getPerfCollector(self, vbox): … … 451 470 try: 452 471 exec "self.platform = Platform"+style+"(platparams)" 453 self.vbox = self.platform.getVirtualBox() 454 self.mgr = SessionManager(self) 472 455 473 self.constants = VirtualBoxReflectionInfo() 456 474 self.type = self.platform.getType() 457 475 self.remote = self.platform.getRemote() 458 476 self.style = style 477 478 self.mgr = SessionManager(self) 479 self.vbox = self.platform.getVirtualBox() 459 480 except Exception,e: 460 481 print "init exception: ",e 461 482 traceback.print_exc() 462 raise e 483 if self.remote: 484 self.vbox = None 485 else: 486 raise e 463 487 464 488 def getArray(self, obj, field): -
trunk/src/VBox/Main/webservice/websrv-python.xsl
r20036 r21640 55 55 <xsl:when test="$type='uuid'">UUID</xsl:when> 56 56 <xsl:when test="$type='$unknown'">IUnknown</xsl:when> 57 <xsl:when test="$type='$dispatched'">IUnknown</xsl:when> 57 58 <xsl:otherwise><xsl:value-of select="$type" /></xsl:otherwise> 58 59 </xsl:choose> … … 139 140 </xsl:template> 140 141 142 143 <xsl:template name="computeExtends"> 144 <xsl:param name="base" /> 145 146 <xsl:choose> 147 <xsl:when test="($base = '$unknown') or ($base = '$dispatched')"> 148 <xsl:value-of select="'IUnknown'"/> 149 </xsl:when> 150 <xsl:otherwise> 151 <xsl:value-of select="$base"/> 152 </xsl:otherwise> 153 </xsl:choose> 154 </xsl:template> 155 141 156 <xsl:template name="interface"> 157 <xsl:variable name="base"> 158 <xsl:call-template name="computeExtends"> 159 <xsl:with-param name="base" select="@extends" /> 160 </xsl:call-template> 161 </xsl:variable> 142 162 <xsl:variable name="ifname"><xsl:value-of select="@name" /></xsl:variable> 143 class <xsl:value-of select="$ifname"/>: 163 164 class <xsl:value-of select="$ifname"/>(<xsl:value-of select="$base" />): 144 165 def __init__(self, mgr, handle, isarray = False): 145 166 self.mgr = mgr 146 if handle is None or handle == "":167 if handle is None: 147 168 raise Exception("bad handle: "+str(handle)) 148 169 self.handle = handle … … 191 212 def __getattr__(self,name): 192 213 hndl = <xsl:value-of select="$ifname" />._Attrs_.get(name, None) 193 if (hndl != None and hndl[0] != None): 194 return hndl[0](self) 214 if hndl != None: 215 if hndl[0] != None: 216 return hndl[0](self) 217 else: 218 raise AttributeError 195 219 else: 196 r aise AttributeError220 return <xsl:value-of select="$base" />.__getattr__(self, name) 197 221 198 222 def __setattr__(self, name, val): … … 272 296 <xsl:variable name="ifname"><xsl:value-of select="@name" /></xsl:variable> 273 297 class <xsl:value-of select="$ifname"/>: 274 def __init__(self, mgr, handle):<xsl:for-each select="attribute"> 275 self.mgr = mgr 276 self.<xsl:value-of select="@name"/> = handle._<xsl:value-of select="@name"/> 298 def __init__(self, mgr, handle, isarray = False): 299 self.mgr = mgr 300 self.isarray = isarray 301 if isarray: 302 self.handle = handle 303 else: 304 <xsl:for-each select="attribute"> 305 self.<xsl:value-of select="@name"/> = <xsl:call-template name="emitConvertedType"> 306 <xsl:with-param name="ifname" select="$ifname" /> 307 <xsl:with-param name="methodname" select="''" /> 308 <xsl:with-param name="type" select="@type" /> 309 </xsl:call-template>(self.mgr, handle._<xsl:value-of select="@name"/>) 277 310 </xsl:for-each> 311 pass 278 312 279 313 <!-- also do getters/setters --> … … 285 319 raise Error, 'setters not supported' 286 320 </xsl:for-each> 321 322 def __next(self): 323 if self.isarray: 324 return self.handle.__next() 325 raise TypeError, "iteration over non-sequence" 326 327 def __size(self): 328 if self.isarray: 329 return self.handle.__size() 330 raise TypeError, "iteration over non-sequence" 331 332 def __len__(self): 333 if self.isarray: 334 return self.handle.__len__() 335 raise TypeError, "iteration over non-sequence" 336 337 def __getitem__(self, index): 338 if self.isarray: 339 return <xsl:value-of select="$ifname" />(self.mgr, self.handle[index]) 340 raise TypeError, "iteration over non-sequence" 341 287 342 </xsl:template> 288 343 … … 435 490 def __init__(self, mgr, handle, isarray = False): 436 491 self.handle = handle 492 self.mgr = mgr 437 493 self.isarray = isarray 438 494 … … 454 510 def __getitem__(self, index): 455 511 if self.isarray: 456 return String(self. handle[index])512 return String(self.mgr, self.handle[index]) 457 513 raise TypeError, "iteration over non-sequence" 458 514 459 515 def __str__(self): 460 return s elf.handle516 return str(self.handle) 461 517 462 518 def __eq__(self,other): … … 478 534 return True 479 535 536 def __add__(self,other): 537 return str(self.handle)+str(other) 538 480 539 481 540 class UUID: 482 541 def __init__(self, mgr, handle, isarray = False): 483 542 self.handle = handle 543 self.mgr = mgr 484 544 self.isarray = isarray 485 545 … … 501 561 def __getitem__(self, index): 502 562 if self.isarray: 503 return UUID(self. handle[index])563 return UUID(self.mgr, self.handle[index]) 504 564 raise TypeError, "iteration over non-sequence" 505 565 … … 526 586 527 587 class Boolean: 528 def __init__(self, mgr, handle, isarray = False): 529 self.handle = handle 588 def __init__(self, mgr, handle, isarray = False): 589 self.handle = handle 590 if self.handle == "false": 591 self.handle = None 592 self.mgr = mgr 530 593 self.isarray = isarray 531 594 … … 547 610 return True 548 611 612 def __int__(self): 613 return 1 if self.handle else 0 614 615 def __long__(self): 616 return 1 if self.handle else 0 617 618 def __nonzero__(self): 619 return True if self.handle else False 620 621 def __next(self): 622 if self.isarray: 623 return self.handle.__next() 624 raise TypeError, "iteration over non-sequence" 625 626 def __size(self): 627 if self.isarray: 628 return self.handle.__size() 629 raise TypeError, "iteration over non-sequence" 630 631 def __len__(self): 632 if self.isarray: 633 return self.handle.__len__() 634 raise TypeError, "iteration over non-sequence" 635 636 def __getitem__(self, index): 637 if self.isarray: 638 return Boolean(self.mgr, self.handle[index]) 639 raise TypeError, "iteration over non-sequence" 640 549 641 class UnsignedInt: 550 642 def __init__(self, mgr, handle, isarray = False): 551 643 self.handle = handle 644 self.mgr = mgr 552 645 self.isarray = isarray 553 646 … … 558 651 return int(self.handle) 559 652 560 def __next(self): 561 if self.isarray: 562 return self.handle.__next() 563 raise TypeError, "iteration over non-sequence" 564 565 def __size(self): 566 if self.isarray: 567 return self.handle.__size() 568 raise TypeError, "iteration over non-sequence" 569 570 def __len__(self): 571 if self.isarray: 572 return self.handle.__len__() 573 raise TypeError, "iteration over non-sequence" 574 575 def __getitem__(self, index): 576 if self.isarray: 577 return UnsignedInt(self.handle[index]) 653 def __long__(self): 654 return long(self.handle) 655 656 def __next(self): 657 if self.isarray: 658 return self.handle.__next() 659 raise TypeError, "iteration over non-sequence" 660 661 def __size(self): 662 if self.isarray: 663 return self.handle.__size() 664 raise TypeError, "iteration over non-sequence" 665 666 def __len__(self): 667 if self.isarray: 668 return self.handle.__len__() 669 raise TypeError, "iteration over non-sequence" 670 671 def __getitem__(self, index): 672 if self.isarray: 673 return UnsignedInt(self.mgr, self.handle[index]) 578 674 raise TypeError, "iteration over non-sequence" 579 675 … … 582 678 def __init__(self, mgr, handle, isarray = False): 583 679 self.handle = handle 584 self.isarray = isarray 585 586 def __next(self): 587 if self.isarray: 588 return self.handle.__next() 589 raise TypeError, "iteration over non-sequence" 590 591 def __size(self): 592 if self.isarray: 593 return self.handle.__size() 594 raise TypeError, "iteration over non-sequence" 595 596 def __len__(self): 597 if self.isarray: 598 return self.handle.__len__() 599 raise TypeError, "iteration over non-sequence" 600 601 def __getitem__(self, index): 602 if self.isarray: 603 return Int(self.handle[index]) 680 self.mgr = mgr 681 self.isarray = isarray 682 683 def __next(self): 684 if self.isarray: 685 return self.handle.__next() 686 raise TypeError, "iteration over non-sequence" 687 688 def __size(self): 689 if self.isarray: 690 return self.handle.__size() 691 raise TypeError, "iteration over non-sequence" 692 693 def __len__(self): 694 if self.isarray: 695 return self.handle.__len__() 696 raise TypeError, "iteration over non-sequence" 697 698 def __getitem__(self, index): 699 if self.isarray: 700 return Int(self.mgr, self.handle[index]) 604 701 raise TypeError, "iteration over non-sequence" 605 702 … … 610 707 return int(self.handle) 611 708 709 def __long__(self): 710 return long(self.handle) 711 612 712 class UnsignedShort: 613 713 def __init__(self, mgr, handle, isarray = False): 614 714 self.handle = handle 715 self.mgr = mgr 615 716 self.isarray = isarray 616 717 … … 621 722 return int(self.handle) 622 723 724 def __long__(self): 725 return long(self.handle) 726 727 def __next(self): 728 if self.isarray: 729 return self.handle.__next() 730 raise TypeError, "iteration over non-sequence" 731 732 def __size(self): 733 if self.isarray: 734 return self.handle.__size() 735 raise TypeError, "iteration over non-sequence" 736 737 def __len__(self): 738 if self.isarray: 739 return self.handle.__len__() 740 raise TypeError, "iteration over non-sequence" 741 742 def __getitem__(self, index): 743 if self.isarray: 744 return UnsignedShort(self.mgr, self.handle[index]) 745 raise TypeError, "iteration over non-sequence" 746 623 747 class Short: 624 748 def __init__(self, mgr, handle, isarray = False): 625 749 self.handle = handle 750 self.mgr = mgr 751 self.isarray = isarray 626 752 627 753 def __str__(self): … … 631 757 return int(self.handle) 632 758 759 def __long__(self): 760 return long(self.handle) 761 762 def __next(self): 763 if self.isarray: 764 return self.handle.__next() 765 raise TypeError, "iteration over non-sequence" 766 767 def __size(self): 768 if self.isarray: 769 return self.handle.__size() 770 raise TypeError, "iteration over non-sequence" 771 772 def __len__(self): 773 if self.isarray: 774 return self.handle.__len__() 775 raise TypeError, "iteration over non-sequence" 776 777 def __getitem__(self, index): 778 if self.isarray: 779 return Short(self.mgr, self.handle[index]) 780 raise TypeError, "iteration over non-sequence" 781 633 782 class UnsignedLong: 634 783 def __init__(self, mgr, handle, isarray = False): 635 784 self.handle = handle 785 self.mgr = mgr 786 self.isarray = isarray 636 787 637 788 def __str__(self): … … 641 792 return int(self.handle) 642 793 794 def __long__(self): 795 return long(self.handle) 796 797 def __next(self): 798 if self.isarray: 799 return self.handle.__next() 800 raise TypeError, "iteration over non-sequence" 801 802 def __size(self): 803 if self.isarray: 804 return self.handle.__size() 805 raise TypeError, "iteration over non-sequence" 806 807 def __len__(self): 808 if self.isarray: 809 return self.handle.__len__() 810 raise TypeError, "iteration over non-sequence" 811 812 def __getitem__(self, index): 813 if self.isarray: 814 return UnsignedLong(self.mgr, self.handle[index]) 815 raise TypeError, "iteration over non-sequence" 816 643 817 class Long: 644 818 def __init__(self, mgr, handle, isarray = False): 645 819 self.handle = handle 646 820 self.mgr = mgr 821 self.isarray = isarray 822 647 823 def __str__(self): 648 824 return str(self.handle) … … 651 827 return int(self.handle) 652 828 829 def __long__(self): 830 return int(self.handle) 831 832 def __next(self): 833 if self.isarray: 834 return self.handle.__next() 835 raise TypeError, "iteration over non-sequence" 836 837 def __size(self): 838 if self.isarray: 839 return self.handle.__size() 840 raise TypeError, "iteration over non-sequence" 841 842 def __len__(self): 843 if self.isarray: 844 return self.handle.__len__() 845 raise TypeError, "iteration over non-sequence" 846 847 def __getitem__(self, index): 848 if self.isarray: 849 return Long(self.mgr, self.handle[index]) 850 raise TypeError, "iteration over non-sequence" 851 653 852 class Double: 654 853 def __init__(self, mgr, handle, isarray = False): 655 854 self.handle = handle 855 self.mgr = mgr 856 self.isarray = isarray 656 857 657 858 def __str__(self): … … 661 862 return int(self.handle) 662 863 864 def __float__(self): 865 return float(self.handle) 866 867 def __next(self): 868 if self.isarray: 869 return self.handle.__next() 870 raise TypeError, "iteration over non-sequence" 871 872 def __size(self): 873 if self.isarray: 874 return self.handle.__size() 875 raise TypeError, "iteration over non-sequence" 876 877 def __len__(self): 878 if self.isarray: 879 return self.handle.__len__() 880 raise TypeError, "iteration over non-sequence" 881 882 def __getitem__(self, index): 883 if self.isarray: 884 return Double(self.mgr, self.handle[index]) 885 raise TypeError, "iteration over non-sequence" 886 663 887 class Float: 664 888 def __init__(self, mgr, handle, isarray = False): 665 889 self.handle = handle 666 890 self.mgr = mgr 891 self.isarray = isarray 892 667 893 def __str__(self): 668 894 return str(self.handle) … … 671 897 return int(self.handle) 672 898 899 def __float__(self): 900 return float(self.handle) 901 902 def __next(self): 903 if self.isarray: 904 return self.handle.__next() 905 raise TypeError, "iteration over non-sequence" 906 907 def __size(self): 908 if self.isarray: 909 return self.handle.__size() 910 raise TypeError, "iteration over non-sequence" 911 912 def __len__(self): 913 if self.isarray: 914 return self.handle.__len__() 915 raise TypeError, "iteration over non-sequence" 916 917 def __getitem__(self, index): 918 if self.isarray: 919 return Float(self.mgr, self.handle[index]) 920 raise TypeError, "iteration over non-sequence" 673 921 674 922 class IUnknown: … … 677 925 self.mgr = mgr 678 926 self.isarray = isarray 927 928 def __nonzero__(self): 929 return True if self.handle != "" else False 679 930 680 931 def __next(self): … … 700 951 def __str__(self): 701 952 return str(self.handle) 953 954 def __getattr__(self,attr): 955 if self.__class__.__dict__.get(attr) != None: 956 return self.__class__.__dict__.get(attr) 957 if self.__dict__.get(attr) != None: 958 return self.__dict__.get(attr) 959 raise AttributeError 702 960 703 961 </xsl:text>
Note:
See TracChangeset
for help on using the changeset viewer.