#NEWLINE# def deploy( args ) : #NEWLINE# #INDENT# current_dir = os . path . dirname ( os . path . abspath ( __file__ ) ) #NEWLINE# parent_dir = os . path . abspath ( os . path . join ( current_dir , '..' ) ) #NEWLINE# public_dir = os . path . join ( current_dir , 'public' ) #NEWLINE# commit_msg = '' #NEWLINE# with ChDir ( current_dir ) : #NEWLINE# #INDENT# if os . path . exists ( public_dir ) : #NEWLINE# #INDENT# shutil . rmtree ( public_dir ) #NEWLINE# #UNINDENT# if ( args . type == 'auto' ) : #NEWLINE# #INDENT# subprocess . call ( 'git fetch origin' , shell = True ) #NEWLINE# subprocess . call ( 'git checkout master' , shell = True ) #NEWLINE# subprocess . call ( 'git reset --hard origin/master' , shell = True ) #NEWLINE# subprocess . call ( 'git clean -fdx' , shell = True ) #NEWLINE# subprocess . call ( 'git submodule init' , shell = True ) #NEWLINE# subprocess . call ( 'git submodule update' , shell = True ) #NEWLINE# subprocess . call ( 'git submodule foreach git pull --rebase origin master' , shell = True ) #NEWLINE# #UNINDENT# s = subprocess . Popen ( 'git log -1 --pretty=format:"%s"' , shell = True , stdout = subprocess . PIPE ) #NEWLINE# commit_msg = s . communicate ( ) [ 0 ] . decode ( 'utf-8' ) . encode ( locale . getpreferredencoding ( ) ) #NEWLINE# subprocess . call ( 'hugo -v --cacheDir="./cache"' , shell = True ) #NEWLINE# #UNINDENT# deploy_dir = os . path . join ( args , DEPLOY_DIR ) #NEWLINE# if ( not os . path . exists ( deploy_dir ) ) : #NEWLINE# #INDENT# os . makedirs ( deploy_dir ) #NEWLINE# with ChDir ( deploy_dir ) : #NEWLINE# #INDENT# subprocess . call ( 'git init' , shell = True ) #NEWLINE# for repo in GIT_REPO : #NEWLINE# #INDENT# subprocess . call ( 'git remote add {0} {1}' . format ( repo [ 0 ] , repo [ 2 ] ) , shell = True ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( args . type == 'first' ) : #NEWLINE# #INDENT# with ChDir ( deploy_dir ) : #NEWLINE# #INDENT# subprocess . call ( 'git init' , shell = True ) #NEWLINE# for repo in GIT_REPO : #NEWLINE# #INDENT# subprocess . call ( 'git remote add {0} {1}' . format ( repo [ 0 ] , repo [ 2 ] ) , shell = True ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# with ChDir ( deploy_dir ) : #NEWLINE# #INDENT# if ( len ( GIT_REPO ) > 0 ) : #NEWLINE# #INDENT# subprocess . call ( 'git fetch {0}' . format ( GIT_REPO [ 0 ] [ 0 ] ) , shell = True ) #NEWLINE# if ( args . type == 'first' ) : #NEWLINE# #INDENT# subprocess . call ( 'git checkout --orphan temp' , shell = True ) #NEWLINE# subprocess . call ( 'git rm --cached -r .' , shell = True ) #NEWLINE# subprocess . call ( 'git clean -fdx' , shell = True ) #NEWLINE# subprocess . call ( 'git branch -D {0}' . format ( GIT_REPO [ 0 ] [ 1 ] ) , shell = True ) #NEWLINE# subprocess . call ( 'git checkout -b {0}' . format ( GIT_REPO [ 0 ] [ 1 ] ) , shell = True ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# subprocess . call ( 'git checkout {0}' . format ( GIT_REPO [ 0 ] [ 1 ] ) , shell = True ) #NEWLINE# #UNINDENT# subprocess . call ( 'git reset --hard {0}/{1}' . format ( GIT_REPO [ 0 ] [ 0 ] , GIT_REPO [ 0 ] [ 1 ] ) , shell = True ) #NEWLINE# subprocess . call ( 'git clean -fdx' , shell = True ) #NEWLINE# #UNINDENT# for f in os . listdir ( '.' ) : #NEWLINE# #INDENT# if ( f != '.git' ) : #NEWLINE# #INDENT# if os . path . isfile ( f ) : #NEWLINE# #INDENT# os . remove ( f ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if os . path . isdir ( f ) : #NEWLINE# #INDENT# shutil . rmtree ( f ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# for f in os . listdir ( public_dir ) : #NEWLINE# #INDENT# file_path = os . path . join ( public_dir , f ) #NEWLINE# if os . path . isfile ( file_path ) : #NEWLINE# #INDENT# shutil . copy ( file_path , '.' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if os . path . isdir ( file_path ) : #NEWLINE# #INDENT# shutil . copytree ( file_path , f ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( len ( GIT_REPO ) > 0 ) : #NEWLINE# #INDENT# subprocess . call ( 'git add --all' , shell = True ) #NEWLINE# subprocess . call ( 'git commit -a -m "{0}"' . format ( commit_msg ) , shell = True ) #NEWLINE# for repo in GIT_REPO : #NEWLINE# #INDENT# if args . test : #NEWLINE# #INDENT# print ( 'git push {0} {1}:{2} -u' . format ( repo [ 0 ] , GIT_REPO [ 0 ] [ 1 ] , repo [ 1 ] ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# subprocess . call ( 'git push {0} {1}:{2} -u' . format ( repo [ 0 ] , GIT_REPO [ 0 ] [ 1 ] , repo [ 1 ] ) , shell = True )