...
 
Commits (2)
include bin/vispa
include bin/vispad
include conf/*.sample
recursive-include alembic *
recursive-exclude alembic *.pyc
recursive-include vispa *
recursive-exclude vispa *.pyc
include license.txt
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# imports
from argparse import ArgumentParser
from time import sleep
import logging.config
import os
import sys
import webbrowser
import cherrypy
import gtk
base = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
if os.path.isdir(base):
sys.path.insert(0, base)
from vispa import RELEASE_VERSION
logger = logging.getLogger(__name__)
class Browser(object):
def __init__(self):
if not self.create_webkit():
self.create_mozilla()
def create_window(self):
self.window = gtk.Window()
self.window.connect('destroy', self.on_destroy)
self.window.set_size_request(1280, 800)
self.scroller = gtk.ScrolledWindow()
self.window.add(self.scroller)
def on_destroy(self, widget):
logger.error("Destroy window")
gtk.main_quit()
def create_mozilla(self):
try:
import gtkmozembed
except:
return False
logger.error("Using MozEmbed")
self.create_window()
self.widget = gtkmozembed.MozEmbed()
self.scroller.add(self.widget)
return True
def create_webkit(self):
try:
import webkit
except:
return False
logger.error("Using Webkit")
self.create_window()
self.widget = webkit.WebView()
self.scroller.add(self.widget)
return True
def open(self, url):
if hasattr(self, "widget"):
if hasattr(self.widget, "load_url"):
self.widget.load_url(url)
elif hasattr(self.widget, "open"):
self.widget.open(url)
else:
logger.error("Open external Webbrowser...")
webbrowser.open(url)
def show(self):
if hasattr(self, "window"):
self.window.show_all()
gtk.mainloop()
def parse_commandline():
parser = ArgumentParser()
from vispa import RELEASE_VERSION
config_dir = "~/.vispa-%s/conf" % RELEASE_VERSION
parser.add_argument("--config-dir", "-c", dest="configdir",
default=os.path.expanduser(config_dir),
help="Directory containing config files (default: %s)" % config_dir)
parser.add_argument(
"--config-dir",
"-c",
dest="configdir",
default=os.path.expanduser(config_dir),
help="Directory containing config files (default: %s)" % config_dir,
)
data_dir = "~/.vispa-%s/var" % RELEASE_VERSION
parser.add_argument("--data-dir", "-d", dest="vardir",
default=os.path.expanduser(data_dir),
help="Directory containing data and cache files (default: %s)" % data_dir)
parser.add_argument(
"--data-dir",
"-d",
dest="vardir",
default=os.path.expanduser(data_dir),
help="Directory containing data and cache files (default: %s)" % data_dir,
)
parser.add_argument("--loglevel", "-l", dest="loglevel", default=None,
help="Enable debug messages")
parser.add_argument(
"--loglevel", "-l", dest="loglevel", default=None, help="Enable debug messages"
)
parser.add_argument("--port", "-p", default=None,
help="Which port the server shall listen on")
parser.add_argument(
"--port", "-p", default=None, help="Which port the server shall listen on"
)
parser.add_argument("--browser", "-b", action="store_true",
help="Start a browser.")
parser.add_argument("--browser", "-b", action="store_true", help="Start a browser.")
return parser.parse_args()
def setup_logging(args):
logging_conf = os.path.join(args.configdir, "logging.ini")
logformat = "%(asctime)s - %(levelname)-6s - %(name)-s - %(message)s"
datefmt = "%Y-%m-%d %H:%M"
loglevel = args.loglevel
if os.path.isfile(logging_conf):
logging.config.fileConfig(logging_conf,
defaults={"log_dir": args.vardir})
elif loglevel == "info":
logging.basicConfig(level=logging.INFO,
format=logformat,
datefmt=datefmt)
cherrypy.log.screen = False
cherrypy.log.access_file = os.path.join(args.vardir, "access.log")
elif loglevel == "debug":
logging.basicConfig(level=logging.DEBUG,
format=logformat,
datefmt=datefmt)
cherrypy.log.screen = False
cherrypy.log.access_file = os.path.join(args.vardir, "access.log")
logging.config.fileConfig(logging_conf, defaults={"log_dir": args.vardir})
else:
cherrypy.log('Using default logging.', 'SERVER')
cherrypy.log.access_file = os.path.join(args.vardir, "access.log")
loglevel = dict(info=logging.INFO, debug=logging.DEBUG,).get(loglevel, None)
if loglevel:
logformat = "%(asctime)s - %(levelname)-6s - %(name)-s - %(message)s"
datefmt = "%Y-%m-%d %H:%M"
logging.basicConfig(level=loglevel, format=logformat, datefmt=datefmt)
cherrypy.log.screen = False
cherrypy.log.access_file = os.path.join(args.vardir, "access.log")
def run():
......@@ -137,17 +70,22 @@ def run():
del server_args["browser"]
from vispa.server import Server
server = Server(**server_args)
if args.browser:
browser = Browser()
server = Server(**server_args)
server.start()
if args.browser:
port = int(args.port or 4282)
browser.open("http://localhost:%d" % port)
browser.show()
webbrowser.open(server.start_url(), new=2)
try:
while True:
sleep(9999)
except KeyboardInterrupt:
pass
server.stop()
if __name__ == "__main__":
run()
......@@ -2,60 +2,42 @@
# -*- coding: utf-8 -*-
from setuptools import setup
import os
ignore_extensions = [".py", ".pyc", ".pyo", ".orig"]
files = []
packages = []
srcdir = os.path.dirname(os.path.abspath(__file__))
for wroot, wdirs, wfiles in os.walk("vispa"):
for name in wfiles:
if name == "__init__.py":
packages.append(wroot.replace(os.sep, ".").strip(". \t\n\r"))
base, ext = os.path.splitext(name)
if ext not in ignore_extensions:
files.append(os.path.join(wroot[6:], name))
versions_path = os.path.join("vispa", "models", "alembic", "versions")
for wroot, wdirs, wfiles in os.walk(versions_path):
for name in wfiles:
if name.endswith(".py"):
files.append(os.path.join(wroot[6:], name))
from setuptools import setup, find_packages, findall
# http://stackoverflow.com/a/24517154
version_ns = {}
version_path = os.path.join(srcdir, 'vispa', 'version.py')
with open(version_path) as version_file:
exec(version_file.read(), version_ns)
metadata = {}
execfile("vispa/version.py", metadata)
setup(
name="vispa",
version=version_ns['__version__'],
version=metadata['__version__'],
description="VISPA - Integrated Development Environment for Physicists",
author="VISPA Project",
author_email="vispa@lists.rwth-aachen.de",
url="http://vispa.physik.rwth-aachen.de/",
license="GNU GPL v2",
packages=packages,
package_data={"vispa": files},
scripts=[os.path.join(srcdir, 'bin', 'vispa'), os.path.join(srcdir, 'bin', 'vispad'), os.path.join(srcdir, 'bin', 'vispa-ldap-export')],
packages=find_packages(),
package_data={
"vispa": [
path.split("/", 1)[-1]
for path in findall("vispa")
if "/static/" in path
or "/templates/" in path
or "/models/alembic/versions/" in path
]
},
scripts=findall("bin"),
install_requires=[
"sqlalchemy >= 0.9.0",
"mako",
"cherrypy<9.0.0", # cherrypy removed wsgiserver, see https://github.com/Lawouach/WebSocket-for-Python/issues/205
"cherrypy >= 10.1",
"paramiko",
"rpyc>3.3.0",
"rpyc >= 4",
"alembic >= 0.7.3", # for Operations.batch_alter_table
"passlib",
"ws4py",
"ldap3"
],
dependency_links=[
'https://github.com/geromueller/rpyc/archive/master.zip#egg=rpyc-3.4.0',
],
extras_require={"doc": ["sphinx", "sphinx-bootstrap-theme"]},
classifiers=[
"Development Status :: 5 - Production/Stable",
......
......@@ -146,8 +146,9 @@ class Server(object):
'server.request_queue_size': 10,
'server.thread_pool': 10,
'engine.autoreload.on': False,
'engine.timeout_monitor.on': False,
}
if hasattr(cherrypy, "TimeoutError"):
__default_server_config['engine.timeout_monitor.on'] = False
@property
def __default_mount_config(self):
......@@ -416,10 +417,20 @@ class Server(object):
cherrypy.engine.start()
vispa.setup_thread_dump()
def stop(self):
cherrypy.engine.exit()
def run(self):
self.start()
cherrypy.engine.block()
def start_url(self):
return urlparse("%s:%d%s" % (
cherrypy.config.get("server.socket_host"),
cherrypy.config.get("server.socket_port"),
vispa.url.dynamic('/')
), "http", False).geturl()
def _load_extensions(self):
self._extensions = {}
# loop through all extensions and import their files
......