コード例 #1
0
ファイル: horse_server.py プロジェクト: wiz21b/koi
    def Initialize(self, configFileName):
        from Logging import mainlog, horse_dir, init_logging
        init_logging('web_server.log')
        mainlog.info("Horse dir : {}".format(horse_dir))

        try:
            from Configurator import load_configuration, configuration, resource_dir
            mainlog.info("Resource dir : {}".format(resource_dir))
            load_configuration("server.cfg", "server_config_check.cfg")
            mainlog.info("configuration loaded")

            from koi.http_handler import HorseHTTPHandler
            p = int(configuration.get("DownloadSite", "port"))
            mainlog.info("Listening on port {}".format(p))
            self.server = HTTPServer(('', p), HorseHTTPHandler)
        except Exception as ex:
            mainlog.exception(ex)
            raise ex
コード例 #2
0
from datetime import date
from sqlalchemy.sql import select,func,and_,or_

from Logging import mainlog,init_logging
from Configurator import init_i18n,load_configuration,configuration,resource_dir
init_logging()
init_i18n()
load_configuration()

from db_mapping import metadata
from datalayer.database_session import init_db_session

from datalayer.database_session import session
from db_mapping import FilterQuery


init_db_session(configuration.database_url, metadata, False or configuration.echo_query)

from dao import dao

def alter_structure():

    session().connection().execute("""CREATE TABLE horse.filter_queries (
        filter_query_id SERIAL NOT NULL,
        name VARCHAR NOT NULL,
        query VARCHAR NOT NULL,
        shared BOOLEAN NOT NULL,
        owner_id INTEGER NOT NULL,
        PRIMARY KEY (filter_query_id),
        CONSTRAINT fq_by_name UNIQUE (name, owner_id),
        FOREIGN KEY(owner_id) REFERENCES horse.employees (employee_id))""")
コード例 #3
0
import urllib.request, urllib.error, urllib.parse

from Logging import init_logging, mainlog, horse_dir, log_stacktrace
init_logging("file_server.log")
from Configurator import load_configuration, init_i18n, configuration, resource_dir
load_configuration("server.cfg", "server_config_check.cfg")

if __name__ == "__main__":

    base_url = "http://localhost:{}".format(
        configuration.get("DownloadSite", "port"))

    mainlog.info("Testing {}".format(base_url))

    response = urllib.request.urlopen(base_url)
    if "This is the Horse download site !" not in response.read():
        mainlog.error("Can't see homepage")
    else:
        mainlog.info("Homepage OK")

    response = urllib.request.urlopen(base_url + "/database")
    mainlog.info("Database = " + response.read())

    response = urllib.request.urlopen(base_url + "/version")
    mainlog.info("Version = " + response.read())

    response = urllib.request.urlopen(base_url + "/file")

    mainlog.info("Client file = {} ".format(
        response.info().headers[4].strip()))
    mainlog.info("Client file = {} bytes".format(len(response.read())))
コード例 #4
0
    def handle_request(self):

        path = re.sub("\\?.*","",self.path)
        params = urlparse.parse_qs( urlparse.urlparse(self.path).query)

        if path == '/version':
            self.send_response(200)
            self.send_header('Content-type',    'text/html')
            self.end_headers()
            self.wfile.write(configuration.get("DownloadSite","current_version"))
            return

        elif path == '/file':

            configure_zip_with_config(configuration.get("DownloadSite","client_path"), configuration)

            f = open( configuration.get("DownloadSite","client_path"), 'rb' )
            bytes = f.read()
            f.close()
            self.send_response(200)
            self.send_header('Content-type',    'application/octet-stream')
            self.send_header('Content-Length',    str(len(bytes)))
            self.send_header('Content-Disposition', 'attachment; filename={}'.format(os.path.split(configuration.get("DownloadSite","client_path"))[-1]))
            self.send_header('Content-Transfer-Encoding', 'binary')
            self.end_headers()
            self.wfile.write(bytes)
            mainlog.info("Served {} with {} bytes".format(configuration.get("DownloadSite","client_path"), len(bytes)))
            return

        elif path == '/database':
            self.send_response(200)
            self.send_header('Content-type',    'text/html')
            self.end_headers()
            self.wfile.write(configuration.get("Database","url"))
            return

        elif path == '/delivery_slips':
            f = open( configuration.get("DownloadSite","client_path"), 'rb' )
            bytes = f.read()
            f.close()
            self.send_response(200)
            self.send_header('Content-type',    'application/octet-stream')
            self.send_header('Content-Length',    str(len(bytes)))
            self.end_headers()
            self.wfile.write(bytes)
            return

        elif path == '/logo.png':
            f = open( os.path.join(resource_dir,"file_server_logo.png"), 'rb' )
            bytes = f.read()
            f.close()
            self.send_response(200)
            self.send_header('Content-type', 'image/png')
            self.send_header('Content-Length', str(len(bytes)))
            self.end_headers()
            self.wfile.write(bytes)
            return

        elif self.path.startswith('/upgrade'):

            if 'version' not in params:
                mainlog.error("Upgrade requested without version")

                self.send_response(500)
                self.send_header('Content-type',    'text/html')
                self.end_headers()
                self.wfile.write("Version parameter not supplied")
                return

            version = ''.join(params['version']).strip()
            mainlog.info("Upgrade requested to version {}".format(version))

            res = "No message"
            try:
                res = upgrade(version)
                self.send_response(200)
            except Exception as ex:
                mainlog.error("Upgrade failed because {}".format(str(ex)))
                res = str(ex)
                self.send_response(500)

            self.send_header('Content-type',    'text/html')
            self.end_headers()
            self.wfile.write(cgi.escape(res))

            return
        else:
            mainlog.error("Unsupported path {} from {}".format(self.path, self.client_address))

            load_configuration("server.cfg","server_config_check.cfg")

            bytes = """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html><head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"><style>
p,h2 {text-align:center; font-family:Verdana; }
table, th, td { border: 1px solid #2900af; border-collapse:collapse; padding:0; margin:0; }
img {background-color:white;}
</style></head>

<body>
   <br/>
   <p><img koi="logo.png"></p>
   <br/>
   <table width="100%" height="1"><tr><td></td><tr/></table><br/><br/>
   <h2>This is the Horse download site !</h2>
<p>The current version is <b>{version}</b>.</p>
<p>To download the latest delivery_slips, <a href='/file'>click here</a>.</p>
</body></html>
"""
            bytes = bytes.replace("{version}",configuration.get("DownloadSite","current_version"))

            self.send_response(200)
            self.send_header('Content-type',    'text/html')
            self.send_header('Content-Length', str(len(bytes)))
            self.end_headers()
            self.wfile.write(bytes)