import subprocess
from time import ctime
import multiprocessing
from util.tools import get_appium_log_dir


def appium_auto_start(host, port):
    bp_port = str(port + 1)
    cmd = 'appium -a ' + host + ' -p ' + str(port) + ' -bp ' + str(bp_port)

    print('%s at %s' % (cmd, ctime()))
    subprocess.Popen(cmd, shell=True, stdout=open(get_appium_log_dir(str(port)), 'a'), stderr=subprocess.STDOUT)

appium_process =[]

for i in range(1):
    host = '127.0.0.1'
    port = 4723 + 2 * i
    appium = multiprocessing.Process(target=appium_auto_start, args=(host, port))
    appium_process.append(appium)


if __name__ == '__main__':
    # for process in appium_process:
    #     process.start()
    # for process in appium_process:
    #     process.join()

    host = '127.0.0.1'
    port = 4723
    appium_auto_start(host, port)

