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

isIntra = (sys.argv[1] == 'intra')
mode = sys.argv[3]
env = sys.argv[2]

module = ''
hostfile = 'hosts-op.txt'
if env in ['pre', 'mspre', 'rypre']:
    module = 'www/order-print-pre'

if env in ['real']:
    env += ',ry-real,ms-real,tbk-real,df-real'
    module = 'www/order-print'

filePath = os.path.dirname(sys.argv[0]) + '/' + hostfile
ipsMap = CliTool.getIpsMap(filePath, isIntra, 3389, defaultModule=module)

envList = CliTool.getEnvList(env, ipsMap, isIntra)

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



argvNum = len(sys.argv)
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/order-print/'
else:
    localSrc = CliTool.workspace() + 'order-print.git/'

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)


