def __init__(self): """ Create a Builder object """ self.__data = Config.get_data() self.__page_args = {} for page, args in self.__data['pages'].iteritems(): i = InjectParse(args).inserts n_i = {} for key, value in i.iteritems(): n_key = key.replace('kwargs:', '').strip().split('=') n_i[n_key[0]] = [n_key[-1], value] self.__page_args[page] = n_i self.__jax = self.__data['jax'] if Config.get('mini'): self.__jax = Mini.js(self.__jax) self.__sync_path = '\n<script>\n%s\n</script>' % self.__data['sync_path'] self.__frame_scripts = ('\n'.join(self.__data['frame_js'].values())).strip() \ if len(self.__data['frame_js']) > 0 else '' if Config.get('mini'): self.__frame_scripts = Mini.js(self.__frame_scripts) self.__frame_scripts = '<script>\n%s\n</script>' % self.__frame_scripts if len(self.__frame_scripts) > 0 else '' self.__media = self.__data['media'] self.__images = self.__data['img'] self.__script = self.__data['js'] self.__style = self.__data['style'] self.__header = '\n<head>\n' + self.__data['head'] + self.__get_style_links() + \ ('\n<script>\n%s\n</script>\n' % self.__jax) + self.__frame_scripts + '\n</head>' self.__body = '\n<body>\n' + self.__data['nav'] + '\n' + self.__data['frame'] + self.__data['footer'] + \ self.__get_script_links() + '\n</body>'
def __init__(self, args): self.__running = False self.__args = args print 'service created' self.__menu = InterfaceFactory.menu(False, self.__args) print 'services started: %s:%s' % (Config.get_server()['address'], Config.get_server()['web_port']) signal.signal(signal.SIGINT, self.quit)
def header(self): items = [['message', Config.get_tmp('log_message')], ['error', Config.get_tmp('log_error')], ['disconnect', Config.get_tmp('log_socket_error')]] msg = [item[0] for item in items if item[1]] if len(msg) == 0: msg = ['off'] return "\t____%s____\n%s\nLogging: %s" % (self.__title, self.__url, ', '.join(msg))
def __init__(self): """ WebSocketServer object is used to host the SocketServer. No parameters are needed. """ Thread.__init__(self) self.daemon = True self.__ports = Config.get('server') self.__running = False self.__server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.__server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.__cert = Config.get('cert') self.__key = Config.get('key') if self.__key and self.__cert: self.__server = wrap_socket(self.__server, certfile=self.__cert, keyfile=self.__key, server_side=True) self.__listeners = [self.__server] self.__handlers = {} self.__name = 'Socket Server'
def __init__(self): Thread.__init__(self) self.daemon = True self.__running = False self.__port = Config.get_server()['socket_update_port'] self.__server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.__server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.__name = 'Update Server'
def __get_style_links(self): """ Return the html formatted stylesheet. :return: """ if Config.get('mini'): for key, value in self.__style.iteritems(): self.__style[key] = Mini.css(value) return '<style>\n%s\n</style>' % ('\n'.join(self.__style.values())).strip() if len(self.__style) > 0 else ''
def __get_script_links(self): """ Return the html formatted javascript. """ if Config.get('mini'): for key, value in self.__script.iteritems(): self.__script[key] = Mini.js(value) return '\n<script>\n%s\n</script>' % ('\n'.join(self.__script.values())).strip() \ if len(self.__script) > 0 else ''
def __init__(self): Thread.__init__(self) self.daemon = True self.__running = False self.__master = SqlMaster() self.__port = Config.get_server().get('sql_port') self.__server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.__server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.__name = 'Sql Server'
def __init__(self): _server = Config.get_server() self.__congress = [ Threaded(ghost=Ghost.SERVER, ip=_server['address'], port=_server['ghost_port']), Threaded(ghost=Ghost.UPDATE, port=_server['ghost_update_port']) ] self.__name = 'Ghost Server'
def __get_style_links(self): """ Return the html formatted stylesheet. :return: """ if Config.get('mini'): for key, value in self.__style.iteritems(): self.__style[key] = Mini.css(value) return '<style>\n%s\n</style>' % ('\n'.join( self.__style.values())).strip() if len(self.__style) > 0 else ''
def __init__(self): """ Create a Builder object """ self.__data = Config.get_data() self.__page_args = {} for page, args in self.__data['pages'].iteritems(): i = InjectParse(args).inserts n_i = {} for key, value in i.iteritems(): n_key = key.replace('kwargs:', '').strip().split('=') n_i[n_key[0]] = [n_key[-1], value] self.__page_args[page] = n_i self.__jax = self.__data['jax'] if Config.get('mini'): self.__jax = Mini.js(self.__jax) self.__sync_path = '\n<script>\n%s\n</script>' % self.__data[ 'sync_path'] self.__frame_scripts = ('\n'.join(self.__data['frame_js'].values())).strip() \ if len(self.__data['frame_js']) > 0 else '' if Config.get('mini'): self.__frame_scripts = Mini.js(self.__frame_scripts) self.__frame_scripts = '<script>\n%s\n</script>' % self.__frame_scripts if len( self.__frame_scripts) > 0 else '' self.__media = self.__data['media'] self.__images = self.__data['img'] self.__script = self.__data['js'] self.__style = self.__data['style'] self.__header = '\n<head>\n' + self.__data['head'] + self.__get_style_links() + \ ('\n<script>\n%s\n</script>\n' % self.__jax) + self.__frame_scripts + '\n</head>' self.__body = '\n<body>\n' + self.__data['nav'] + '\n' + self.__data['frame'] + self.__data['footer'] + \ self.__get_script_links() + '\n</body>'
def __init__(self, url): """ Server object is used to host the normal WebServer. No parameters are needed. """ Thread.__init__(self) self.daemon = True self.__url = url _server = Config.get_server() self.__server = WebServer((_server['address'], _server['web_port']), ClientHandler) self.__server.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.__server.allow_reuse_address = socket.SO_REUSEADDR cert = _server['cert'] key = _server['key'] if cert and key: self.__server.socket = ssl.wrap_socket(self.__server.socket, certfile=cert, keyfile=key, server_side=True) self.__name = 'Web Server'
def __init__(self, arguments): super(self.__class__, self).__init__(hide=['back', 'schedule_events'], prompt='Input: ') try: signal.signal(signal.SIGINT, self.quit) except ValueError: pass self.looping = False self.__c_switch = CallbackFlag.as_switch(begin=self.__callback_begin, pre=self.__callback_pre) self.__title = Config.get('title') self.__url = None self.__servers = None self.__sql = None self.__cli = arguments.no_cli Menu.schedule_events() self.__load_args(arguments)
def proceed_socket_error(): now = time.time() if (now - Log.last_socket_error) > Log.INTERVAL: Log.last_socket_error = now Log.do_proceed_socket_error = Config.get_tmp('log_socket_error') return Log.do_proceed_socket_error
import uuid import json import time import os from jax.core.modules.Settings import Config class Static(type): SESSIONS = {} SESSION = 'SESSION' CACHE = '%ssessions.json' % Config.CACHE_DIR TIMEOUT = Config.get('session_timeout') TIMEOUT = TIMEOUT if TIMEOUT else 1440 def save(): with open(CACHE, 'w') as o: json.dump(Static.SESSIONS, o) def resume(): try: with open(CACHE, 'r') as o: Static.SESSIONS = json.load(o) except Exception: save()
def __init__post(self): _server = Config.get_server() self.__url = 'https://' if Config.get('cert') and Config.get('key') else 'http://' self.__url += '%s:%s' % (_server['address'], _server['web_port']) self.__servers = InterfaceFactory.servers(self.__cli, self.__url) self.__sql = InterfaceFactory.sql(self.__cli)
def __load_args(self, args): set_title(self.__title) Session.resume() if args.localhost: Config.load_server(address=get_address_local()) self.__init__post() if not args.no_web: self.__servers.start('web') if args.socket: self.__servers.start('socket') if args.socket_update: self.__servers.start('socket_update') if args.sql: self.__servers.start('sql') if args.ghost: self.__servers.start('ghost') if args.log_all: Config.load_tmp(log_socket_error=True) Config.load_tmp(log_error=True) Config.load_tmp(log_message=True) else: if args.log_disconnect: Config.load_tmp(log_socket_error=True) if args.log_error: Config.load_tmp(log_error=True) if args.log_message: Config.load_tmp(log_message=True)
""" Created on Oct 1, 2014 @author: Sean Mead """ from jax.core.modules.BaseLinks import BaseLinks from jax.core.modules import Session, Stream from jax.core.modules.Settings import Config from jax.core.modules.Decorators import IsPost, IsValid from web.site import Users RES = Config.load_dir('web/html_part') CONFIG = Config.load_dir('web/html_part/config') FRAMEWORK = Config.load_dir('web/html_part/framework') ASSETS = Config.load_dir('web/html_part/assets') SITE = Config.load_dir('web/html_part/site') def current_user_path(handler): """ Return the full path to the User folder. :param handler: the self.__handler of the Links object. """ return Config.USER_DIR + Session.get_name(handler) + '/' class Links(BaseLinks): def __init__(self, handler):
def proceed_message(): now = time.time() if (now - Log.last_message) > Log.INTERVAL: Log.last_message = now Log.do_proceed_message = Config.get_tmp('log_message') return Log.do_proceed_message
Created on Jan 30, 2014 @author: Sean Mead """ import sqlite3 as sql import ast from os import path from jax.core.modules.Settings import Config from jax.core.server.SqlServer import SqlAccess DB_DEFAULT = 'database.db' DB_PATH = Config.DB_DIR DB_NAME = Config.get('database') if not DB_NAME: DB_NAME = DB_DEFAULT DB_ABS = path.join(DB_PATH, DB_NAME) HIDDEN = ['_'] class F(type): @staticmethod def hidden(item): for h in HIDDEN: if str(item).startswith(h): return True return False
class StaticSqlAccess(type): PORT = Config.get_server().get('sql_port') @staticmethod def set_port(port): StaticSqlAccess.PORT = port
""" Created on Oct 1, 2014 @author: Sean Mead """ from jax.core.modules.BaseLinks import BaseLinks from jax.core.modules import Session, Stream from jax.core.modules.Settings import Config from jax.core.modules.Decorators import IsPost, IsValid from web.site import Users RES = Config.load_dir('web/html_part') CONFIG = Config.load_dir('web/html_part/config') FRAMEWORK = Config.load_dir('web/html_part/framework') ASSETS = Config.load_dir('web/html_part/assets') SITE = Config.load_dir('web/html_part/site') def current_user_path(handler): """ Return the full path to the User folder. :param handler: the self.__handler of the Links object. """ return Config.USER_DIR + Session.get_name(handler) + '/' class Links(BaseLinks): def __init__(self, handler): BaseLinks.__init__(self, handler)
def toggle_error(arg=None): if Config.get_tmp('log_error'): Config.load_tmp(log_error=False) else: Config.load_tmp(log_error=True) Log.last_error = 0
def toggle_disconnect(arg=None): if Config.get_tmp('log_socket_error'): Config.load_tmp(log_socket_error=False) else: Config.load_tmp(log_socket_error=True) Log.last_socket_error = 0
def toggle_message(arg=None): if Config.get_tmp('log_message'): Config.load_tmp(log_message=False) else: Config.load_tmp(log_message=True) Log.last_message = 0
""" Created on Jan 30, 2014 @author: Sean Mead """ import sqlite3 as sql import ast from os import path from jax.core.modules.Settings import Config from jax.core.server.SqlServer import SqlAccess DB_DEFAULT = 'database.db' DB_PATH = Config.DB_DIR DB_NAME = Config.get('database') if not DB_NAME: DB_NAME = DB_DEFAULT DB_ABS = path.join(DB_PATH, DB_NAME) HIDDEN = ['_'] class F(type): @staticmethod def hidden(item): for h in HIDDEN: if str(item).startswith(h): return True return False
def __init__(self): _server = Config.get_server() self.__congress = [Threaded(ghost=Ghost.SERVER, ip=_server['address'], port=_server['ghost_port']), Threaded(ghost=Ghost.UPDATE, port=_server['ghost_update_port'])] self.__name = 'Ghost Server'