<s> from __future__ import print_function <EOL> import fileinput <EOL> import glob <EOL> import os <EOL> import shutil <EOL> import sys <EOL> try : <EOL> WindowsError <EOL> except NameError : <EOL> WindowsError = None <EOL> def ignore_patterns ( * patterns ) : <EOL> """<STR_LIT>""" <EOL> import fnmatch <EOL> def _ignore_patterns ( path , names ) : <EOL> ignored_names = [ ] <EOL> for pattern in patterns : <EOL> ignored_names . extend ( fnmatch . filter ( names , pattern ) ) <EOL> return set ( ignored_names ) <EOL> return _ignore_patterns <EOL> def copytree ( src , dst , symlinks = False , ignore = None ) : <EOL> """<STR_LIT>""" <EOL> from shutil import copy2 , Error , copystat <EOL> names = os . listdir ( src ) <EOL> if ignore is not None : <EOL> ignored_names = ignore ( src , names ) <EOL> else : <EOL> ignored_names = set ( ) <EOL> os . makedirs ( dst ) <EOL> errors = [ ] <EOL> for name in names : <EOL> if name in ignored_names : <EOL> continue <EOL> srcname = os . path . join ( src , name ) <EOL> dstname = os . path . join ( dst , name ) <EOL> try : <EOL> if symlinks and os . path . islink ( srcname ) : <EOL> linkto = os . readlink ( srcname ) <EOL> os . symlink ( linkto , dstname ) <EOL> elif os . path . isdir ( srcname ) : <EOL> copytree ( srcname , dstname , symlinks , ignore ) <EOL> else : <EOL> copy2 ( srcname , dstname ) <EOL> except Error as err : <EOL> errors . extend ( err . args [ <NUM_LIT:0> ] ) <EOL> except EnvironmentError as why : <EOL> errors . append ( ( srcname , dstname , str ( why ) ) ) <EOL> try : <EOL> copystat ( src , dst ) <EOL> except OSError as why : <EOL> if WindowsError is not None and isinstance ( why , WindowsError ) : <EOL> pass <EOL> else : <EOL> errors . extend ( ( src , dst , str ( why ) ) ) <EOL> if errors : <EOL> raise Error ( errors ) <EOL> def copy_if_out_of_date ( original , derived ) : <EOL> if ( not os . path . exists ( derived ) or <EOL> os . stat ( derived ) . st_mtime < os . stat ( original ) . st_mtime ) : <EOL> try : <EOL> shutil . copyfile ( original , derived ) <EOL> except IOError : <EOL> if os . path . basename ( original ) == '<STR_LIT>' : <EOL> msg = "<STR_LIT>" % original + "<STR_LIT>" <EOL> raise IOError ( msg ) <EOL> else : <EOL> raise <EOL> def check_build ( ) : <EOL> build_dirs = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> for d in build_dirs : <EOL> try : <EOL> os . mkdir ( d ) <EOL> except OSError : <EOL> pass <EOL> def doctest ( ) : <EOL> os . system ( '<STR_LIT>' ) <EOL> def linkcheck ( ) : <EOL> os . system ( '<STR_LIT>' ) <EOL> def html ( ) : <EOL> check_build ( ) <EOL> if small_docs : <EOL> options = "<STR_LIT>" <EOL> else : <EOL> options = '<STR_LIT>' <EOL> if os . system ( '<STR_LIT>' % options ) : <EOL> raise SystemExit ( "<STR_LIT>" ) <EOL> figures_dest_path = '<STR_LIT>' <EOL> if os . path . exists ( figures_dest_path ) : <EOL> shutil . rmtree ( figures_dest_path ) <EOL> copytree ( <EOL> '<STR_LIT>' , figures_dest_path , <EOL> ignore = ignore_patterns ( "<STR_LIT>" ) ) <EOL> for filename in glob . glob ( '<STR_LIT>' ) : <EOL> os . remove ( filename ) <EOL> shutil . copy ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def latex ( ) : <EOL> check_build ( ) <EOL> if sys . platform != '<STR_LIT:win32>' : <EOL> if os . system ( '<STR_LIT>' ) : <EOL> raise SystemExit ( "<STR_LIT>" ) <EOL> os . chdir ( '<STR_LIT>' ) <EOL> if os . system ( '<STR_LIT>' ) : <EOL> raise SystemExit ( "<STR_LIT>" ) <EOL> os . chdir ( '<STR_LIT>' ) <EOL> else : <EOL> print ( '<STR_LIT>' ) <EOL> def texinfo ( ) : <EOL> check_build ( ) <EOL> if sys . platform != '<STR_LIT:win32>' : <EOL> if os . system ( <EOL> '<STR_LIT>' ) : <EOL> raise SystemExit ( "<STR_LIT>" ) <EOL> os . chdir ( '<STR_LIT>' ) <EOL> if os . system ( '<STR_LIT>' ) : <EOL> raise SystemExit ( "<STR_LIT>" ) <EOL> os . chdir ( '<STR_LIT>' ) <EOL> else : <EOL> print ( '<STR_LIT>' ) <EOL> def clean ( ) : <EOL> shutil . rmtree ( "<STR_LIT>" , ignore_errors = True ) <EOL> shutil . rmtree ( "<STR_LIT>" , ignore_errors = True ) <EOL> for pattern in [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] : <EOL> for filename in glob . glob ( pattern ) : <EOL> if os . path . exists ( filename ) : <EOL> os . remove ( filename ) <EOL> def all ( ) : <EOL> html ( ) <EOL> latex ( ) <EOL> funcd = { <EOL> '<STR_LIT:html>' : html , <EOL> '<STR_LIT>' : latex , <EOL> '<STR_LIT>' : texinfo , <EOL> '<STR_LIT>' : clean , <EOL> '<STR_LIT:all>' : all , <EOL> '<STR_LIT>' : doctest , <EOL> '<STR_LIT>' : linkcheck , <EOL> } <EOL> small_docs = False <EOL> current_dir = os . getcwd ( ) <EOL> filedir = os . path . dirname ( os . path . join ( current_dir , __file__ ) ) <EOL> os . chdir ( os . path . join ( filedir , '<STR_LIT:source>' ) ) <EOL> check_build ( ) <EOL> copy_if_out_of_date ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> required_symlinks = [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ] <EOL> for link , target in required_symlinks : <EOL> if not os . path . exists ( link ) : <EOL> try : <EOL> os . symlink ( target , link ) <EOL> except OSError : <EOL> shutil . copytree ( os . path . join ( link , '<STR_LIT:..>' , target ) , link ) <EOL> if len ( sys . argv ) > <NUM_LIT:1> : <EOL> if '<STR_LIT>' in sys . argv [ <NUM_LIT:1> : ] : <EOL> small_docs = True <EOL> sys . argv . remove ( '<STR_LIT>' ) <EOL> for arg in sys . argv [ <NUM_LIT:1> : ] : <EOL> func = funcd . get ( arg ) <EOL> if func is None : <EOL> raise SystemExit ( '<STR_LIT>' % ( <EOL> arg , funcd . keys ( ) ) ) <EOL> func ( ) <EOL> else : <EOL> small_docs = False <EOL> all ( ) <EOL> os . chdir ( current_dir ) </s>
