#!/usr/bin/env python3
# -*- coding:utf-8 -*-
from inc import CliTool
import sys, os

isIntra = (sys.argv[1] == 'intra')
isMcPre = (sys.argv[2] == 'mc-pre')
filePath = os.path.dirname(sys.argv[0]) + '/hosts-honor.txt'
ipsMap = CliTool.getIpsMap(filePath, isIntra, 8873)

envList = CliTool.getEnvList(sys.argv[2], ipsMap, isIntra)

ips = {}
for env in envList:
    ips = dict(ips, **ipsMap[env])

mode = sys.argv[3]

argvNum = len(sys.argv)
if argvNum >= 5:
    timeout = sys.argv[4]
else:
    timeout = 120
timeout = str(timeout)

if isIntra is True:
    localPwdFile = '/home/porsche/publish/tjds1.passwd'
else:
    localPwdFile = '/Users/tangjianhui/Documents/publish/tjds1.passwd'

if isIntra is True:
    localSrc = '/alidata/www/honor/'
    if isMcPre is True:
        localSrc = '/alidata/www/honor-pre/'
else:
    localSrc = CliTool.workspace() + 'honor.master/'

cmdTpl = 'rsync -%s --delay-updates --del --stats --port=%s --password-file=' + localPwdFile + ' --timeout=' + timeout + CliTool.excludeFile() + localSrc + ' www@%s::%s/'

sshCmdTpl = 'rsync -%s --delay-updates --del --stats [%s] -e ssh' + CliTool.excludeFile() + localSrc + ' www@%s:/alidata/%s/'

Ct = CliTool()

syntax_check = False if isIntra is True else True
Ct.publish(ips, mode, cmdTpl, isIntra, sshCmdTpl, php_syntax_check = syntax_check)


