<s> import time <EOL> import os <EOL> from stat import S_IFDIR <EOL> from errno import ENOENT <EOL> from fuse import FuseOSError <EOL> from gitfs . log import log <EOL> from gitfs . cache import lru_cache <EOL> from . read_only import ReadOnlyView <EOL> class HistoryView ( ReadOnlyView ) : <EOL> def getattr ( self , path , fh = None ) : <EOL> '''<STR_LIT>''' <EOL> if path not in self . repo . get_commit_dates ( ) and path != '<STR_LIT:/>' : <EOL> raise FuseOSError ( ENOENT ) <EOL> attrs = super ( HistoryView , self ) . getattr ( path , fh ) <EOL> attrs . update ( { <EOL> '<STR_LIT>' : S_IFDIR | <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT:2> , <EOL> '<STR_LIT>' : self . _get_first_commit_time ( ) , <EOL> '<STR_LIT>' : self . _get_last_commit_time ( ) , <EOL> } ) <EOL> return attrs <EOL> def access ( self , path , mode ) : <EOL> if getattr ( self , '<STR_LIT:date>' , None ) : <EOL> log . info ( '<STR_LIT>' , path ) <EOL> if path == '<STR_LIT:/>' : <EOL> available_dates = self . repo . get_commit_dates ( ) <EOL> if self . date not in available_dates : <EOL> raise FuseOSError ( ENOENT ) <EOL> else : <EOL> commits = self . repo . get_commits_by_date ( self . date ) <EOL> dirname = os . path . split ( path ) [ <NUM_LIT:1> ] <EOL> if dirname not in commits : <EOL> raise FuseOSError ( ENOENT ) <EOL> else : <EOL> if path != '<STR_LIT:/>' : <EOL> raise FuseOSError ( ENOENT ) <EOL> return <NUM_LIT:0> <EOL> def readdir ( self , path , fh ) : <EOL> if getattr ( self , '<STR_LIT:date>' , None ) : <EOL> additional_entries = self . repo . get_commits_by_date ( self . date ) <EOL> else : <EOL> additional_entries = self . repo . get_commit_dates ( ) <EOL> dir_entries = [ '<STR_LIT:.>' , '<STR_LIT:..>' ] + additional_entries <EOL> for entry in dir_entries : <EOL> yield entry <EOL> def _get_commit_time ( self , index ) : <EOL> date = getattr ( self , '<STR_LIT:date>' , None ) <EOL> if date and date in self . repo . commits : <EOL> return self . repo . commits [ date ] [ index ] . timestamp <EOL> return int ( time . time ( ) ) <EOL> def _get_last_commit_time ( self ) : <EOL> return self . _get_commit_time ( - <NUM_LIT:1> ) <EOL> def _get_first_commit_time ( self ) : <EOL> return self . _get_commit_time ( <NUM_LIT:0> ) </s>
