# Path: vcontrol/rest/helpers/get_allowed.py
# def get_allowed():
#     rest_url = ""
#     if "ALLOW_ORIGIN" in os.environ:
#         allow_origin = os.environ["ALLOW_ORIGIN"]
#         host_port = allow_origin.split("//")[1]
#         host = host_port.split(":")[0]
#         port = str(int(host_port.split(":")[1])+1)
#         rest_url = host+":"+port
#     else:
#         allow_origin = ""
#     return allow_origin, rest_url
# 
# Path: vcontrol/rest/helpers/json_yield.py
# def json_yield_none(fn):
#     def _(self, key, *o, **k):
# def json_yield_one(fn):
#     def _(self, arg, key, *o, **k):
# def json_yield_two(fn):
#     def _(self, arg1, arg2, key, *o, **k):


from ..helpers import get_allowed
from ..helpers import json_yield
import subprocess
import uuid
import web
    <div id="status">Building, please wait...</div>
    </body>
    </html>
    """

    def GET(self, machine, o_type):
        web.header('Access-Control-Allow-Origin', self.allow_origin)

        # !! TODO handle data later
        # !! TODO test with swagger
        #if 'no_cache' in data:
        #    if not data['no_cache']:
        #        cmd += " --no-cache"

        client_session_id = uuid.uuid4().hex
        out = ""
        if o_type == 'a':
            out = self.INDEX_HTML%(machine, client_session_id) + \
                  self.INDEX_HTML_TYPE_A + \
                  self.INDEX_HTML_END
        elif o_type == 'b':
            out = self.INDEX_HTML%(machine, client_session_id) + \
                  self.INDEX_HTML_TYPE_B + \
                  self.INDEX_HTML_END
        return out

class BuildCommandOutputR:
    """
    This endpoint is for rendering the output of building Docker images on an machine.
    """

# Path: vcontrol/rest/helpers/get_allowed.py
# def get_allowed():
#     rest_url = ""
#     if "ALLOW_ORIGIN" in os.environ:
#         allow_origin = os.environ["ALLOW_ORIGIN"]
#         host_port = allow_origin.split("//")[1]
#         host = host_port.split(":")[0]
#         port = str(int(host_port.split(":")[1])+1)
#         rest_url = host+":"+port
#     else:
#         allow_origin = ""
#     return allow_origin, rest_url
# 
# Path: vcontrol/rest/helpers/json_yield.py
# def json_yield_none(fn):
#     def _(self, key, *o, **k):
# def json_yield_one(fn):
#     def _(self, arg, key, *o, **k):
# def json_yield_two(fn):
#     def _(self, arg1, arg2, key, *o, **k):


# Path: vcontrol/rest/commands/build.py
from ..helpers import get_allowed
from ..helpers import json_yield
import subprocess
import uuid
import web

    <div id="status">Building, please wait...</div>
    </body>
    </html>
    """

    def GET(self, machine, o_type):
        web.header('Access-Control-Allow-Origin', self.allow_origin)

        # !! TODO handle data later
        # !! TODO test with swagger
        #if 'no_cache' in data:
        #    if not data['no_cache']:
        #        cmd += " --no-cache"

        client_session_id = uuid.uuid4().hex
        out = ""
        if o_type == 'a':
            out = self.INDEX_HTML%(machine, client_session_id) + \
                  self.INDEX_HTML_TYPE_A + \
                  self.INDEX_HTML_END
        elif o_type == 'b':
            out = self.INDEX_HTML%(machine, client_session_id) + \
                  self.INDEX_HTML_TYPE_B + \
                  self.INDEX_HTML_END
        return out

class BuildCommandOutputR:
    """
    This endpoint is for rendering the output of building Docker images on an machine.
    """

    json_yield = json_yield.json_yield_one