Exemplo n.º 1
0
 def __init__(self):
     tk.Tk.__init__(self)
     if not config.get_db_path():
         config.set_db_path()
     if not config.get_backup_path():
         config.set_backup_path()
     if not config.get_session_path():
         config.set_session_path()
     db_type = config.get_db_type()
     if db_type == 'standard':
         db = Databases.StandardDatabase()
     else:
         db = Databases.TranslationDatabase(config.get_lang1(),
                                            config.get_lang2())
     config.active_objects['db'] = db
     config.active_objects[
         'root'] = self  #Allows access outside creation module
     backup.backup()
     self.option_add('*Font',
                     'TkDefaultFont')  #All widgets use default font
     if db_type == 'standard':
         self.main_frame = StandardMainFrame(self)
     else:
         self.main_frame = TranslationMainFrame(self)
     self.menu_bar = MenuBar(self)
     self['menu'] = self.menu_bar
     self.title(config.get_language_dict()['title'])  #Application name
     icon = Image.open('icons/30101621.png')
     icon = ImageTk.PhotoImage(icon)
     self.iconphoto(True, icon)
     self.set_geometry()
     self.bind_events()
Exemplo n.º 2
0
    def __init__(self, options):
        make_dirs = [
            os.path.dirname(os.path.abspath(options.access_log)),
            os.path.dirname(os.path.abspath(options.error_log)),
            os.path.dirname(os.path.abspath(config.get_object_store())),
            os.path.abspath(config.get_screenshot_path()),
            os.path.abspath(config.get_session_path()),
            os.path.abspath(config.get_distros_store())
        ]
        for directory in make_dirs:
            if not os.path.isdir(directory):
                os.makedirs(directory)

        cherrypy.tools.nocache = cherrypy.Tool('on_end_resource', set_no_cache)
        cherrypy.tools.kimchiauth = cherrypy.Tool('before_handler',
                                                  auth.kimchiauth)
        cherrypy.server.socket_host = options.host
        cherrypy.server.socket_port = options.port

        # SSL Server
        try:
            if options.ssl_port and options.ssl_port > 0:
                self._init_ssl(options)
        except AttributeError, e:
            pass
Exemplo n.º 3
0
def generate_redo_filepath():
    """ Generate filepath for redo file | None -> Path """
    session_path = config.get_session_path()
    name = 'redo_' + str(len(redo_db_list)) + '.pickle'
    filepath = session_path / name
    return filepath
Exemplo n.º 4
0
class Server(object):
    # expires is one year.
    CACHEEXPIRES = 31536000
    CONFIG = {
        '/': {
            'tools.trailing_slash.on': False,
            'tools.staticdir.root': config.get_prefix(),
            'request.methods_with_bodies': ('POST', 'PUT'),
            'tools.nocache.on': True,
            'tools.sessions.on': True,
            'tools.sessions.name': 'kimchi',
            'tools.sessions.httponly': True,
            'tools.sessions.storage_type': 'file',
            'tools.sessions.storage_path': config.get_session_path(),
            'tools.kimchiauth.on': False
        },
        '/vms': {
            'tools.kimchiauth.on': True
        },
        '/templates': {
            'tools.kimchiauth.on': True
        },
        '/storagepools': {
            'tools.kimchiauth.on': True
        },
        '/tasks': {
            'tools.kimchiauth.on': True
        },
        '/css': {
            'tools.staticdir.on': True,
            'tools.staticdir.dir': 'ui/css',
            'tools.expires.on': True,
            'tools.expires.secs': CACHEEXPIRES,
            'tools.nocache.on': False
        },
        '/js': {
            'tools.staticdir.on': True,
            'tools.staticdir.dir': 'ui/js',
            'tools.expires.on': True,
            'tools.expires.secs': CACHEEXPIRES,
            'tools.nocache.on': False
        },
        '/libs': {
            'tools.staticdir.on': True,
            'tools.staticdir.dir': 'ui/libs',
            'tools.expires.on': True,
            'tools.expires.secs': CACHEEXPIRES,
            'tools.nocache.on': False,
        },
        '/images': {
            'tools.staticdir.on': True,
            'tools.staticdir.dir': 'ui/images',
            'tools.nocache.on': False
        },
        '/data/screenshots': {
            'tools.staticdir.on': True,
            'tools.staticdir.dir': 'data/screenshots',
            'tools.nocache.on': False
        }
    }

    def __init__(self, options):
        make_dirs = [
            os.path.dirname(os.path.abspath(options.access_log)),
            os.path.dirname(os.path.abspath(options.error_log)),
            os.path.dirname(os.path.abspath(config.get_object_store())),
            os.path.abspath(config.get_screenshot_path()),
            os.path.abspath(config.get_session_path()),
            os.path.abspath(config.get_distros_store())
        ]
        for directory in make_dirs:
            if not os.path.isdir(directory):
                os.makedirs(directory)

        cherrypy.tools.nocache = cherrypy.Tool('on_end_resource', set_no_cache)
        cherrypy.tools.kimchiauth = cherrypy.Tool('before_handler',
                                                  auth.kimchiauth)
        cherrypy.server.socket_host = options.host
        cherrypy.server.socket_port = options.port

        # SSL Server
        try:
            if options.ssl_port and options.ssl_port > 0:
                self._init_ssl(options)
        except AttributeError, e:
            pass

        cherrypy.log.screen = True
        cherrypy.log.access_file = options.access_log
        cherrypy.log.error_file = options.error_log

        logLevel = LOGGING_LEVEL.get(options.log_level, logging.DEBUG)
        dev_env = options.environment != 'production'

        # Create handler to rotate access log file
        h = logging.handlers.RotatingFileHandler(options.access_log, 'a',
                                                 10000000, 1000)
        h.setLevel(logLevel)
        h.setFormatter(cherrypy._cplogging.logfmt)

        # Add access log file to cherrypy configuration
        cherrypy.log.access_log.addHandler(h)

        # Create handler to rotate error log file
        h = logging.handlers.RotatingFileHandler(options.error_log, 'a',
                                                 10000000, 1000)
        h.setLevel(logLevel)
        h.setFormatter(cherrypy._cplogging.logfmt)

        # Add rotating log file to cherrypy configuration
        cherrypy.log.error_log.addHandler(h)

        # Handling running mode
        if not dev_env:
            cherrypy.config.update({'environment': 'production'})

        if hasattr(options, 'model'):
            model_instance = options.model
        elif options.test:
            model_instance = mockmodel.get_mock_environment()
        else:
            model_instance = model.Model()

        self.app = cherrypy.tree.mount(Root(model_instance, dev_env),
                                       config=self.CONFIG)
        cherrypy.lib.sessions.init()