Beispiel #1
0
cfg = {}
for line in cfgdata:
    if line.startswith("#") or line.find("=") == -1:
        continue
    key, value = line.split("=")
    cfg[key]=value

sys.path.append(os.path.dirname(__file__))

from instanceconf import SCV_INSTANCE_SCOPE_ID
cfg["SCV_INSTANCE_SCOPE_ID"] = SCV_INSTANCE_SCOPE_ID

from skarphedcore.scv import Core
from skarphedcore.scv import OperationDaemon

core = Core(cfg)
configuration = core.get_configuration()
pidfile = configuration.get_entry("core.webpath")+"/opd.pid"
opd = OperationDaemon(core, pidfile)

# This script accepts a dummy argument (sys.argv[2])
# This argument is supposed to be the instance id, so
# one can distinguish the daemon-processes from each 
# other in e.g. htop

success = False
if len(sys.argv) == 2 or len(sys.argv) == 3:
    if sys.argv[1] == 'start':
        opd.start()
        success = True
    elif sys.argv[1] == 'stop':
Beispiel #2
0
def application(environ, start_response):
    response_body = []
    response_headers = []

    session_id = ""

    core = Core(cfg)

    if environ['PATH_INFO'].startswith("/static/"):
        path = environ['PATH_INFO'].replace("/static/","",1)

        binary_manager = core.get_binary_manager()
        binary = binary_manager.get_by_filename(path)
        data = binary.get_data()
        
        response_body=[data]
        response_headers.append(('Content-Type', bytes(binary.get_mime())))

    elif environ['PATH_INFO'].startswith("/rpc/"):
        ret = core.rpc_call(environ)
        response_body.extend(ret["body"])
        response_headers.extend(ret["header"])
        response_headers.append(('Content-Type', 'application/json'))

    elif environ['PATH_INFO'].startswith("/css/"):
        configuration = core.get_configuration()
        css_folder = configuration.get_entry("core.css_folder")
        wpath = configuration.get_entry("global.webpath")
        iid = configuration.get_entry("core.instance_id")
        css = open(wpath+str(iid)+css_folder+"/"+environ["PATH_INFO"].replace("/css/","",1)).read()
        response_body = [css]
        response_headers.append(('Content-Type', 'text/css'))

    elif environ['PATH_INFO'].startswith("/web/"):
        ret = core.web_call(environ)
        response_body.extend(ret["body"])
        response_headers.extend(ret["header"])
        response_headers.append(('Content-Type', 'text/html; charset=utf-8'))

    elif environ['PATH_INFO'].startswith("/ajax/"):
        ret = core.ajax_call(environ)
        response_body.extend(ret["body"])
        response_headers.append(('Content-Type', 'application/json'))

    elif environ['PATH_INFO'].startswith("/debug/"):
        response_body = ['%s: %s' % (key, value)
                    for key, value in sorted(environ.items())]
        response_body = ['\n'.join(response_body)]
        response_headers.append(('Content-Type', 'text/plain'))

    else: #call default view
        ret = core.web_call(environ)
        response_body.extend(ret["body"])
        response_headers.extend(ret["header"])
        response_headers.append(('Content-Type', 'text/html; charset=utf-8'))


    # So the content-lenght is the sum of all string's lengths
    content_length = 0
    for s in response_body:
        content_length += len(s)

    response_headers.append(('Content-Length', str(content_length)))

    status = '200 OK'

    start_response(status, response_headers)

    return response_body