Changeset 780 for baculafs


Ignore:
Timestamp:
Jul 25, 2009, 2:19:24 AM (15 years ago)
Author:
joergs
Message:

improved logging

File:
1 edited

Legend:

Unmodified
Added
Removed
  • baculafs/trunk/baculafs.py

    r779 r780  
    1616
    1717LOG_FILENAME        = '/tmp/baculafs.log'
    18 LOG_BCONSOLE        = '/tmp/bconsole.log'
     18#LOG_BCONSOLE        = '/tmp/bconsole.log'
    1919LOG_BCONSOLE_DUMP   = '/tmp/bconsole.out'
    2020
     
    3333class Bconsole:
    3434
    35     #bconsole = None
    36 
    3735    def __init__(self, client=BACULA_CLIENT):
    38         #logging.basicConfig(filename=LOG_BCONSOLE,level=logging.DEBUG,)
    39         logging.debug('BC init')
     36        #logging.debug('BC init')
    4037        self.bconsole = pexpect.spawn( BACULA_CMD, logfile=file(LOG_BCONSOLE_DUMP, 'w'), timeout=10 )
    4138        self.bconsole.setecho( False )
     
    4744        self.bconsole.sendline( BACULA_CLIENT )
    4845        self.bconsole.expect( BCONSOLE_RESTORE_PROMPT )
    49         logging.debug( "BC alive: " + str(self.bconsole.isalive()) )
    50         logging.debug('BC init done')
     46        #logging.debug( "BC alive: " + str(self.bconsole.isalive()) )
     47        #logging.debug('BC init done')
    5148
    5249
     
    5451
    5552        path = path + "/"
    56         logging.debug( "BC ls(" + path + ")" )
     53        logging.debug( "(" + path + ")" )
    5754
    5855        self.bconsole.sendline( 'cd ' + path )
     
    6158
    6259        index = self.bconsole.expect( ["cwd is: " + path + "[/]?", BCONSOLE_RESTORE_PROMPT, pexpect.EOF, pexpect.TIMEOUT ] )
    63         logging.debug( "BC ls: cd result: " + str(index) )
     60        logging.debug( "cd result: " + str(index) )
    6461
    6562        if index == 0:
     
    7976        self.bconsole.expect( BCONSOLE_RESTORE_PROMPT )
    8077        lines = self.bconsole.before.splitlines()
    81         logging.debug( "BC ls: " + str(lines) )
     78        #logging.debug( str(lines) )
    8279        return lines
    8380
     
    9390
    9491    def __init__(self, *args, **kw):
    95         logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG,)
    9692        logging.debug('init')
    9793        #self.console = Bconsole()
     
    10399        # TODO: may cause problems with filenames that ends with "/"
    104100        path = path.rstrip( '/' )
    105         logging.debug( "_getdir(" + path + ")" )
     101        logging.debug( '"' + path + '"' )
    106102
    107103        if (path in self.files):
    108             logging.debug( "  _getdir(" + path + ")=" + str(self.files[path]) )
     104            #logging.debug( "(" + path + ")=" + str(self.files[path]) )
    109105            if self.files[path]['type'] == self.TYPE_FILE:
    110                 logging.debug( "  type: file" )
     106                logging.debug( '"' + path + '"=file (cached)' )
    111107                return self.files[path]
    112108            elif ((self.files[path]['type'] == self.TYPE_DIR) and ('files' in self.files[path])):
    113                 logging.debug( "  type: dir (cached)" )
     109                logging.debug( '"' + path + '"=dir (cached)' )
    114110                return self.files[path]
    115111
    116112        try:
    117113            files = Bconsole().ls(path)
    118             logging.debug( "  files: " + str( files ) )
    119             self.files[path] = {}
    120             self.files[path]['type']  = self.TYPE_DIR
    121             self.files[path]['dirs']  = [ ".", ".." ]
    122             self.files[path]['files'] = []
     114            #logging.debug( "  files: " + str( files ) )
     115
     116            # setting initial empty directory. Add entires later in this function
     117            self.files[path] = { 'type': self.TYPE_DIR, 'dirs': [ ".", ".." ], 'files': [] }
    123118            for i in files:
    124119                if i.endswith('/'):
     
    133128                    self.files[path + "/" + i] = { 'type': self.TYPE_FILE }
    134129
    135         except:
    136             logging.debug( "Unexpected error:" + sys.exc_info()[0] )
     130        except Exception as e:
     131            logging.exception(e)
    137132            logging.error( "no access to path " + path )
    138133            self.files[path] = { 'type': TYPE_NONE }
    139         logging.debug( "  " + str( self.files[path] )  )
     134        logging.debug( '"' + path + '"=' + str( self.files[path] )  )
    140135        return self.files[path]
    141136
     
    144139    # TODO: only works after readdir for the directory (eg. ls)
    145140    def getattr(self, path):
    146         logging.debug( "getattr " + path )
    147141
     142        # TODO: may cause problems with filenames that ends with "/"
     143        path = path.rstrip( '/' )
     144        logging.debug( '"' + path + '"' )
     145
     146        file = self.files[path]
    148147        st = fuse.Stat()
    149148
    150149        #file = self._getdir( path )
    151 
    152         # TODO: may cause problems with filenames that ends with "/"
    153         path = path.rstrip( '/' )
    154         file = self.files[path]
    155150
    156151        if file['type'] == self.TYPE_FILE:
     
    171166
    172167    def readdir(self, path, offset):
    173         logging.debug( "readdir " + path + "(offset: " + str(offset) + ")" )
     168        logging.debug( '"' + path + '", offset=' + str(offset) + ')' )
    174169
    175170        dir = self._getdir( path )
     
    193188
    194189if __name__ == "__main__":
     190    # initialize logging
     191    logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG,format="%(asctime)s %(process)5d(%(threadName)s) %(levelname)-7s %(funcName)s( %(message)s )")
     192
    195193    fs = BaculaFS()
    196194    fs.parse()
Note: See TracChangeset for help on using the changeset viewer.