VirtualBox

Changeset 30280 in vbox for trunk/src


Ignore:
Timestamp:
Jun 17, 2010 9:34:00 AM (15 years ago)
Author:
vboxsync
Message:

VBoxShell: foreach with simple XPath-like nodes addressing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxShell/vboxshell.py

    r30261 r30280  
    665665        return []
    666666    def matches(self,subexp):
    667 #        m = re.search(r"@(?P<a>\w+)=(?P<v>\w+)", subexp)
     667        if subexp == self.type:
     668            return True
     669        if not subexp.startswith(self.type):
     670            return False
     671        m = re.search(r"@(?P<a>\w+)=(?P<v>\w+)", subexp)
    668672        matches = False
    669 #        try:
    670 #        if m is not None:
    671 #        else:
    672 #            print "no match in ",subexp
    673 #       except:
    674 
     673        try:
     674            if m is not None:
     675                dict = m.groupdict()
     676                attr = dict['a']
     677                val  = dict['v']
     678                matches = (str(getattr(self.obj, attr)) == val)
     679        except:
     680            pass
    675681        return matches
    676682    def apply(self, cmd):
     
    710716    def __init__(self, parent, obj):
    711717        XPathNode.__init__(self, parent, obj, 'vm')
    712     def matches(self,subexp):
    713         return subexp=='vm'
     718    #def matches(self,subexp):
     719    #    return subexp=='vm'
    714720    def enum(self):
    715721        return [XPathNodeHolderNIC(self, self.obj),
     
    27932799def foreachCmd(ctx, args):
    27942800    if len(args) < 3:
    2795         print "foreach scope command"
     2801        print "usage: foreach scope command, where scope is XPath-like expression //vms/vm[@CPUCount='2']"
    27962802        return 0
    27972803
     
    28962902            'prompt' : ['Control prompt', promptCmd, 0],
    28972903            'foreachvm' : ['Perform command for each VM', foreachvmCmd, 0],
    2898             'foreach' : ['Generic "for each" construction, using XPath-like notation: foreach //vms/vm "print obj.name"', foreachCmd, 0],
     2904            'foreach' : ['Generic "for each" construction, using XPath-like notation: foreach //vms/vm[@OSTypeId=\'MacOS\'] "print obj.name"', foreachCmd, 0],
    28992905            }
    29002906
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette