<s> """<STR_LIT>""" <EOL> import getpass <EOL> import hashlib <EOL> from hyde . _compat import basestring , input <EOL> from hyde . publisher import Publisher <EOL> from commando . util import getLoggerWithNullHandler <EOL> logger = getLoggerWithNullHandler ( '<STR_LIT>' ) <EOL> try : <EOL> from fs . osfs import OSFS <EOL> from fs . path import pathjoin <EOL> from fs . opener import fsopendir <EOL> except ImportError : <EOL> logger . error ( "<STR_LIT>" ) <EOL> logger . error ( "<STR_LIT>" ) <EOL> raise <EOL> class PyFS ( Publisher ) : <EOL> def initialize ( self , settings ) : <EOL> self . settings = settings <EOL> self . url = settings . url <EOL> self . check_mtime = getattr ( settings , "<STR_LIT>" , False ) <EOL> self . check_etag = getattr ( settings , "<STR_LIT>" , False ) <EOL> if self . check_etag and not isinstance ( self . check_etag , basestring ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> self . prompt_for_credentials ( ) <EOL> self . fs = fsopendir ( self . url ) <EOL> def prompt_for_credentials ( self ) : <EOL> credentials = { } <EOL> if "<STR_LIT>" in self . url : <EOL> print ( "<STR_LIT>" , ) <EOL> credentials [ "<STR_LIT:username>" ] = input ( ) . strip ( ) <EOL> if "<STR_LIT>" in self . url : <EOL> credentials [ "<STR_LIT:password>" ] = getpass . getpass ( "<STR_LIT>" ) <EOL> if credentials : <EOL> self . url = self . url % credentials <EOL> def publish ( self ) : <EOL> super ( PyFS , self ) . publish ( ) <EOL> deploy_fs = OSFS ( self . site . config . deploy_root_path . path ) <EOL> for ( dirnm , local_filenms ) in deploy_fs . walk ( ) : <EOL> logger . info ( "<STR_LIT>" , dirnm ) <EOL> self . fs . makedir ( dirnm , allow_recreate = True ) <EOL> remote_fileinfos = self . fs . listdirinfo ( dirnm , files_only = True ) <EOL> for filenm in local_filenms : <EOL> filepath = pathjoin ( dirnm , filenm ) <EOL> for ( nm , info ) in remote_fileinfos : <EOL> if nm == filenm : <EOL> break <EOL> else : <EOL> info = { } <EOL> if self . check_etag and "<STR_LIT>" in info : <EOL> with deploy_fs . open ( filepath , "<STR_LIT:rb>" ) as f : <EOL> local_etag = self . _calculate_etag ( f ) <EOL> if info [ "<STR_LIT>" ] == local_etag : <EOL> logger . info ( "<STR_LIT>" , filepath ) <EOL> continue <EOL> if self . check_mtime and "<STR_LIT>" in info : <EOL> local_mtime = deploy_fs . getinfo ( filepath ) [ "<STR_LIT>" ] <EOL> if info [ "<STR_LIT>" ] > local_mtime : <EOL> logger . info ( "<STR_LIT>" , filepath ) <EOL> continue <EOL> logger . info ( "<STR_LIT>" , filepath ) <EOL> with deploy_fs . open ( filepath , "<STR_LIT:rb>" ) as f : <EOL> self . fs . setcontents ( filepath , f ) <EOL> for ( filenm , info ) in remote_fileinfos : <EOL> filepath = pathjoin ( dirnm , filenm ) <EOL> if filenm not in local_filenms : <EOL> logger . info ( "<STR_LIT>" , filepath ) <EOL> self . fs . remove ( filepath ) <EOL> def _calculate_etag ( self , f ) : <EOL> hasher = getattr ( hashlib , self . check_etag . lower ( ) ) ( ) <EOL> data = f . read ( <NUM_LIT> * <NUM_LIT:64> ) <EOL> while data : <EOL> hasher . update ( data ) <EOL> data = f . read ( <NUM_LIT> * <NUM_LIT:64> ) <EOL> return hasher . hexdigest ( ) </s>
