#!/usr/bin/env python
# coding=utf-8

from __future__ import print_function

import os
import sys
import time
import subprocess

def get_mac_app(p):
    while p and p != '/':
        d = os.path.dirname(p)
        if d[-4:] == '.app':
            return d
        p = d
    return ''

app = get_mac_app(os.path.abspath(__file__))
if not app:
    print("重启失败...", file=sys.stderr)
    sys.exit(1)

print("重启中，请稍后...")
sys.stdout.flush()

args = sys.argv[1:]
if args:
    pid = args[0]
    subprocess.call('kill ' + pid, shell=True)

time.sleep(2)
subprocess.call('open ' + app, shell=True)


