def hashfile(fn, lcache=None, logger=None):
 db = {}
 try:
  dbfile = os.path.join(lcache, 'link_cache.json')
  if os.path.exists(dbfile):
   db = simplejson.load(open(dbfile, 'r'))
 except:
  pass
 mtime = os.stat(fn).st_mtime
 if (fn in db):
  if (db[fn][0] >= mtime):
   return db[fn][1]
 if os.path.exists(fn):
  cmd = ('/usr/bin/sha1sum %s' % fn)
  key = subprocess_get(logger, cmd).split(' ')[0]
  if (lcache is not None):
   db[fn] = (mtime, key)
   simplejson.dump(db, open(dbfile, 'w'))
  return key
 else:
  return None

def hashfile ( fn , lcache = None , logger = None ) : db = { } try : dbfile = os . path . join ( lcache , 'link_cache.json' ) if os . path . exists ( dbfile ) : db = simplejson . load ( open ( dbfile , 'r' ) ) except : pass mtime = os . stat ( fn ) . st_mtime if ( fn in db ) : if ( db [ fn ] [ 0 ] >= mtime ) : return db [ fn ] [ 1 ] if os . path . exists ( fn ) : cmd = ( '/usr/bin/sha1sum %s' % fn ) key = subprocess_get ( logger , cmd ) . split ( ' ' ) [ 0 ] if ( lcache is not None ) : db [ fn ] = ( mtime , key ) simplejson . dump ( db , open ( dbfile , 'w' ) ) return key else : return None
returns the sha1sum of the file .