#!/usr/bin/env python3
import getopt
import sys
import platform
import subprocess
import os

curos = platform.system() 
pth = os.path.abspath(__file__)
wd = os.path.dirname(pth)
try:
    opts, args = getopt.getopt(sys.argv[1:], "h:", ["command=", "help", "output="])
except getopt.GetoptError as err:
    # print help information and exit:
    print(str(err))  # will print something like "option -a not recognized"
    #usage()
    sys.exit(2)
output = None
# QJ : getopts

for o, a in opts:
    if o == "-h":
        _ACTION = True
    elif o in ("-m", "--publish"):
        _MESSAGE = a
    else:
        _WIZZARD = True

print(wd)

if curos == "Windows":
    cmnd = ["scp.exe mqtt_srv.py root@192.168.77.1:/root/", "copy mqtt_srv.py mqtt_srv.pyw", "python.exe -m PyInstaller --onefile mqtt_srv.pyw --distpath .\dist", "Rmdir /Q /S  .\\__pycache__", "Rmdir /Q /S  .\\build"]
            #out = subprocess.Popen(cmnd.split())       
else:           
    cmnd = ["cp mqtt_srv.py mqtt_srv.pyw", "python -m pyinstaller --onefile mqtt_srv.pyw --distpath ./dist", "rm -rf ./__pycache__", "rm -rf ./build"]

for c in cmnd:
    status, output = subprocess.getstatusoutput(c)
    print(output)


if curos == "Windows":
    cmnd = ["copy .\\dist\\mqtt_srv.exe ..\\MyApp\\source\\"]

for c in cmnd:
    status, output = subprocess.getstatusoutput(c)
    print(output)




