<s> """<STR_LIT>""" <EOL> import os <EOL> import re <EOL> import shutil <EOL> import sys <EOL> from os import chdir as cd <EOL> from os . path import join as pjoin <EOL> from subprocess import Popen , PIPE , CalledProcessError , check_call <EOL> pages_dir = '<STR_LIT>' <EOL> html_dir = '<STR_LIT>' <EOL> pdf_dir = '<STR_LIT>' <EOL> pages_repo = '<STR_LIT>' <EOL> def sh ( cmd ) : <EOL> """<STR_LIT>""" <EOL> return check_call ( cmd , shell = True ) <EOL> def sh2 ( cmd ) : <EOL> """<STR_LIT>""" <EOL> p = Popen ( cmd , stdout = PIPE , shell = True ) <EOL> out = p . communicate ( ) [ <NUM_LIT:0> ] <EOL> retcode = p . returncode <EOL> if retcode : <EOL> raise CalledProcessError ( retcode , cmd ) <EOL> else : <EOL> return out . rstrip ( ) <EOL> def sh3 ( cmd ) : <EOL> """<STR_LIT>""" <EOL> p = Popen ( cmd , stdout = PIPE , stderr = PIPE , shell = True ) <EOL> out , err = p . communicate ( ) <EOL> retcode = p . returncode <EOL> if retcode : <EOL> raise CalledProcessError ( retcode , cmd ) <EOL> else : <EOL> return out . rstrip ( ) , err . rstrip ( ) <EOL> def init_repo ( path ) : <EOL> """<STR_LIT>""" <EOL> sh ( "<STR_LIT>" % ( pages_repo , path ) ) <EOL> here = os . getcwd ( ) <EOL> cd ( path ) <EOL> sh ( '<STR_LIT>' ) <EOL> cd ( here ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> try : <EOL> tag = sys . argv [ <NUM_LIT:1> ] <EOL> except IndexError : <EOL> try : <EOL> tag = sh2 ( '<STR_LIT>' ) <EOL> except CalledProcessError : <EOL> tag = "<STR_LIT>" <EOL> startdir = os . getcwd ( ) <EOL> if not os . path . exists ( pages_dir ) : <EOL> init_repo ( pages_dir ) <EOL> else : <EOL> cd ( pages_dir ) <EOL> sh ( '<STR_LIT>' ) <EOL> sh ( '<STR_LIT>' ) <EOL> cd ( startdir ) <EOL> dest = pjoin ( pages_dir , tag ) <EOL> shutil . rmtree ( dest , ignore_errors = True ) <EOL> shutil . copytree ( html_dir , dest ) <EOL> shutil . copy ( pjoin ( pdf_dir , '<STR_LIT>' ) , pjoin ( dest , '<STR_LIT>' ) ) <EOL> try : <EOL> cd ( pages_dir ) <EOL> status = sh2 ( '<STR_LIT>' ) <EOL> branch = re . match ( '<STR_LIT>' , status ) . group ( <NUM_LIT:1> ) <EOL> if branch != '<STR_LIT>' : <EOL> e = '<STR_LIT>' % ( pages_dir , <EOL> branch ) <EOL> raise RuntimeError ( e ) <EOL> sh ( '<STR_LIT>' % tag ) <EOL> sh ( '<STR_LIT>' % tag ) <EOL> print ( ) <EOL> print ( '<STR_LIT>' ) <EOL> sys . stdout . flush ( ) <EOL> sh ( '<STR_LIT>' ) <EOL> finally : <EOL> cd ( startdir ) <EOL> print ( ) <EOL> print ( '<STR_LIT>' % dest ) <EOL> print ( "<STR_LIT>" ) </s>
