Changeset 3333

Show
Ignore:
Timestamp:
01/05/10 18:42:35 (10 years ago)
Author:
justinc
Message:

This is the feature addition requested in #772.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • seattle/trunk/seash/seash.py

    r3141 r3333  
    739739show identities -- Display the known identities 
    740740show keys       -- Display the known keys 
    741 show log       -- Display the log from the vessel (*) 
     741show log [to file] -- Display the log from the vessel (*) 
    742742show files      -- Display a list of files in the vessel (*) 
    743743show resources  -- Display the resources / restrictions for the vessel (*) 
     
    946946 
    947947 
    948 # show log        -- Display the log from the node (*) 
     948# show log [to file] -- Display the log from the vessel (*) 
    949949        elif userinputlist[1] == 'log' or userinputlist[1] == 'logs': 
     950          if len(userinputlist) == 2: 
     951            writeoutputtofile = False 
     952          elif len(userinputlist) == 4 and (userinputlist[2] == 'to' or userinputlist[2] == 'TO' or userinputlist[2] == '>'): 
     953            writeoutputtofile = True 
     954            # handle '~' 
     955            fileandpath = os.path.expanduser(userinputlist[3]) 
     956            outputfileprefix = fileandpath 
     957          else: 
     958            raise UserError("Error, format is 'show log' or 'show log to filenameprefix'") 
     959             
    950960 
    951961          if not currenttarget: 
     
    960970            # True means it worked 
    961971            if retdict[longname][0]: 
    962               print "Log from '"+longname+"':" 
    963               print retdict[longname][1] 
     972              if writeoutputtofile: 
     973                # write to a file if requested. 
     974                outputfilename = outputfileprefix +'.'+ longname 
     975                outputfo = file(outputfilename,'w') 
     976                outputfo.write(retdict[longname][1]) 
     977                outputfo.close() 
     978                print "Wrote log as '"+outputfilename+"'." 
     979 
     980              else: 
     981                # else print it to the terminal 
     982                print "Log from '"+longname+"':" 
     983                print retdict[longname][1] 
     984 
     985              # regardless, this is a good node 
    964986              goodlist.append(longname) 
     987 
    965988            else: 
    966989              print "failure on '"+longname+"': ",retdict[longname][1]