Changeset 785


Ignore:
Timestamp:
Aug 27, 2009, 5:34:26 PM (15 years ago)
Author:
joergs
Message:

cleanup

File:
1 edited

Legend:

Unmodified
Added
Removed
  • baculafs/trunk/baculafs.py

    r784 r785  
    2828#BACULA_CMD = 'strace -f -o /tmp/bconsole.strace /usr/sbin/bconsole -n'
    2929BACULA_CMD = '/usr/sbin/bconsole -n'
    30 # .clients
    31 # 5: ting-fd
    32 BACULA_CLIENT='5'
    3330
    3431BCONSOLE_CMD_PROMPT='\*'
     
    3734
    3835
     36class BconsoleState:
     37    UNKNOWN = ''
     38    SELECT_PROMPT  = BCONSOLE_SELECT_PROMPT
     39    RESTORE_PROMPT = BCONSOLE_RESTORE_PROMPT
     40    ERROR          = "error"
     41
     42
    3943class Bconsole:
    4044
    41     def __init__(self, client=BACULA_CLIENT):
     45    def __init__(self):
    4246        #logging.debug('BC init')
    4347
    4448        self.cwd = "/"
     49        self.state = BconsoleState.UNKNOWN
    4550
    4651        self.bconsole = pexpect.spawn( BACULA_CMD, logfile=file(LOG_BCONSOLE_DUMP, 'w'), timeout=10 )
     
    5156        self.bconsole.sendline( "5" )
    5257        #self.bconsole.expect( BCONSOLE_SELECT_PROMPT )
    53 
    54 
    5558
    5659        #self.bconsole.sendline( BACULA_CLIENT )
     
    8184
    8285
    83     def cd(self,path):
    84         path = self._normalize_dir( path )
    85         logging.debug( "(" + path + ")" )
    86 
    87         if path = "":
    88             return True
     86
     87    def wait_for_prompt(self):
     88
     89        # set to error state.
     90        # Only set back to valid state,
     91        # if a valid prompt is received
     92        self.state=BconsoleState.ERROR
    8993
    9094        try:
     
    9296            if index == 0:
    9397                # SELECT_PROMPT
    94                 return self.cd_select( path )
     98                self.state=BconsoleState.SELECT_PROMPT
     99                return BCONSOLE_SELECT_PROMPT
    95100            elif index == 1:
    96101                # RESTORE_PROMPT
    97                 return self.cd_restore( path )
     102                self.state=BconsoleState.RESTORE_PROMPT
     103                return BCONSOLE_RESTORE_PROMPT
     104            else:
     105                logging.error( "unexpected result" )
    98106        except pexpect.EOF:
    99107            logging.error( "EOF bconsole" )
    100108        except pexpect.TIMEOUT:
    101109            logging.error( "TIMEOUT  bconsole" )
     110
     111        return self.state
     112
     113
     114    def cd(self,path):
     115        path = self._normalize_dir( path )
     116        logging.debug( "(" + path + ")" )
     117
     118        if not path:
     119            return True
     120
     121        state = self.wait_for_prompt()
     122        if state == BconsoleState.SELECT_PROMPT:
     123            return self.cd_select( path )
     124        elif state == BconsoleState.RESTORE_PROMPT:
     125            return self.cd_restore( path )
     126        # else error
     127        return False
    102128
    103129
Note: See TracChangeset for help on using the changeset viewer.