VirtualBox

Changeset 29809 in vbox for trunk/src/VBox


Ignore:
Timestamp:
May 26, 2010 10:41:56 AM (15 years ago)
Author:
vboxsync
Message:

vboxshell: ask uid/passwd, minor tweaks to filename completion

File:
1 edited

Legend:

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

    r29802 r29809  
    178178            return rlcompleter.Completer.complete(self,text,state)
    179179
     180    def canBePath(self, phrase,word):
     181        return word.startswith('/')
     182
    180183    def canBeCommand(self, phrase, word):
    181184        spaceIdx = phrase.find(" ")
     
    188191        return False
    189192
    190     def canBePath(self,phrase,word):
    191         return word.startswith('/')
    192 
    193193    def canBeMachine(self,phrase,word):
    194194        return not self.canBePath(phrase,word) and not self.canBeCommand(phrase, word)
    195 
    196     def canBePath(self,phrase,word):
    197         return word.startswith('/')
    198195
    199196    def global_matches(self, text):
     
    208205
    209206        try:
     207            if self.canBePath(phrase,text):
     208                (dir,rest) = os.path.split(text)
     209                n = len(rest)
     210                for word in os.listdir(dir):
     211                    if n == 0 or word[:n] == rest:
     212                        matches.append(os.path.join(dir,word))
     213
    210214            if self.canBeCommand(phrase,text):
    211215                n = len(text)
     
    227231                        matches.append(word)
    228232
    229             if self.canBePath(phrase,text):
    230                 (dir,rest) = os.path.split(text)
    231                 n = len(rest)
    232                 for word in os.listdir(dir):
    233                     if n == 0 or word[:n] == rest:
    234                         matches.append(os.path.join(dir,word))
    235 
    236233        except Exception,e:
    237234            printErr(e)
     
    251248  readline.set_completer(completer.complete)
    252249  delims = readline.get_completer_delims()
    253   readline.set_completer_delims(re.sub("[\\.]", "", delims)) # remove some of the delimiters
     250  readline.set_completer_delims(re.sub("[\\./-]", "", delims)) # remove some of the delimiters
    254251  readline.parse_and_bind("set editing-mode emacs")
    255252  # OSX need it
     
    853850    return 0
    854851
    855 def execInGuest(ctx,console,args,env):
     852def execInGuest(ctx,console,args,env,user,passwd,tmo):
    856853    if len(args) < 1:
    857854        print "exec in guest needs at least program name"
    858855        return
    859     user = ""
    860     passwd = ""
    861     tmo = 0
    862856    guest = console.guest
    863857    # shall contain program name as argv[0]
    864858    gargs = args
    865     print "executing %s with args %s" %(args[0], gargs)
     859    print "executing %s with args %s as %s" %(args[0], gargs, user)
    866860    (progress, pid) = guest.executeProcess(args[0], 0, gargs, env, user, passwd, tmo)
    867861    print "executed with pid %d" %(pid)
     
    882876            if progress.cancelable:
    883877                progress.cancel()
     878        (reason, code, flags) = guest.getProcessStatus(pid)
     879        print "Exit code: %d" %(code)
    884880        return 0
    885881    else:
    886882        reportError(ctx, progress)
     883
     884def nh_raw_input(prompt=""):
     885    stream = sys.stdout
     886    prompt = str(prompt)
     887    if prompt:
     888        stream.write(prompt)
     889    line = sys.stdin.readline()
     890    if not line:
     891        raise EOFError
     892    if line[-1] == '\n':
     893        line = line[:-1]
     894    return line
     895
     896
     897def getCred(ctx):
     898    import getpass
     899    user = getpass.getuser()
     900    user_inp = raw_input("User (%s): " %(user))
     901    if len (user_inp) > 0:
     902        user = user_inp
     903    passwd = getpass.getpass()
     904
     905    return (user,passwd)
    887906
    888907def gexecCmd(ctx,args):
     
    895914    gargs = args[2:]
    896915    env = [] # ["DISPLAY=:0"]
    897     gargs.insert(0, lambda ctx,mach,console,args: execInGuest(ctx,console,args,env))
     916    (user,passwd) = getCred(ctx)
     917    gargs.insert(0, lambda ctx,mach,console,args: execInGuest(ctx,console,args,env,user,passwd,1000))
    898918    cmdExistingVm(ctx, mach, 'guestlambda', gargs)
    899919    return 0
     
    908928    gargs = args[2:]
    909929    env = []
    910     gargs.insert(0, lambda ctx,mach,console,args: execInGuest(ctx,console,args,env))
     930    (user,passwd) = getCred(ctx)
     931    gargs.insert(0, lambda ctx,mach,console,args: execInGuest(ctx,console,args,env, user, passwd, 0))
    911932    cmdExistingVm(ctx, mach, 'guestlambda', gargs)
    912933    return 0
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