<s> from grow . pods . storage import base_storage <EOL> import errno <EOL> import jinja2 <EOL> import os <EOL> import shutil <EOL> class FileStorage ( base_storage . BaseStorage ) : <EOL> @ staticmethod <EOL> def open ( filename , mode = None ) : <EOL> if mode is None : <EOL> mode = '<STR_LIT:r>' <EOL> return open ( filename , mode = mode ) <EOL> @ staticmethod <EOL> def read ( filename ) : <EOL> fp = open ( filename ) <EOL> content = fp . read ( ) <EOL> fp . close ( ) <EOL> return content <EOL> @ staticmethod <EOL> def modified ( filename ) : <EOL> return os . stat ( filename ) . st_mtime <EOL> @ staticmethod <EOL> def size ( filename ) : <EOL> return os . path . getsize ( filename ) <EOL> @ staticmethod <EOL> def stat ( filename ) : <EOL> return os . stat ( filename ) <EOL> @ staticmethod <EOL> def listdir ( dirpath ) : <EOL> paths = [ ] <EOL> for root , dirs , files in os . walk ( dirpath , followlinks = True ) : <EOL> for filename in files : <EOL> path = os . path . join ( root , filename ) [ len ( dirpath ) : ] <EOL> paths . append ( path ) <EOL> return paths <EOL> @ staticmethod <EOL> def JinjaLoader ( path ) : <EOL> return jinja2 . FileSystemLoader ( path ) <EOL> @ classmethod <EOL> def write ( cls , path , content ) : <EOL> dirname = os . path . dirname ( path ) <EOL> try : <EOL> os . makedirs ( dirname ) <EOL> except OSError as e : <EOL> if e . errno == errno . EEXIST and os . path . isdir ( dirname ) : <EOL> pass <EOL> else : <EOL> raise <EOL> fp = cls . open ( path , mode = '<STR_LIT:w>' ) <EOL> fp . write ( content ) <EOL> fp . close ( ) <EOL> return fp <EOL> @ staticmethod <EOL> def exists ( filename ) : <EOL> return os . path . exists ( filename ) <EOL> @ staticmethod <EOL> def delete ( filename ) : <EOL> return os . remove ( filename ) <EOL> @ staticmethod <EOL> def delete_dir ( dirpath ) : <EOL> shutil . rmtree ( dirpath ) <EOL> @ staticmethod <EOL> def copy_to ( paths , target_paths ) : <EOL> for i , path in enumerate ( paths ) : <EOL> target_path = target_paths [ i ] <EOL> shutil . copyfile ( path , target_path ) <EOL> shutil . copystat ( path , target_path ) <EOL> @ staticmethod <EOL> def move_to ( path , target_path ) : <EOL> os . rename ( path , target_path ) </s>
