def makeClient(self,
                   ip,
                   ratelimit=2,
                   direct_reply=3,
                   self_reply=False,
                   require_email=False,
                   require_author=False):

        conf = config.load(os.path.join(dist.location, "share", "isso.conf"))
        conf.set("general", "dbpath", self.path)
        conf.set("hash", "algorithm", "none")
        conf.set("guard", "enabled", "true")
        conf.set("guard", "ratelimit", str(ratelimit))
        conf.set("guard", "direct-reply", str(direct_reply))
        conf.set("guard", "reply-to-self", "1" if self_reply else "0")
        conf.set("guard", "require-email", "1" if require_email else "0")
        conf.set("guard", "require-author", "1" if require_author else "0")

        class App(Isso, core.Mixin):
            pass

        app = App(conf)

        app.wsgi_app = FakeIP(app.wsgi_app, ip)

        return Client(app, Response)
Example #2
0
    def makeClient(self,
                   ip,
                   ratelimit=2,
                   direct_reply=3,
                   self_reply=False,
                   require_email=False,
                   require_author=False):

        conf = config.load(
            pkg_resources.resource_filename('isso', 'defaults.ini'))
        conf.set("general", "dbpath", self.path)
        conf.set("hash", "algorithm", "none")
        conf.set("guard", "enabled", "true")
        conf.set("guard", "ratelimit", str(ratelimit))
        conf.set("guard", "direct-reply", str(direct_reply))
        conf.set("guard", "reply-to-self", "1" if self_reply else "0")
        conf.set("guard", "require-email", "1" if require_email else "0")
        conf.set("guard", "require-author", "1" if require_author else "0")

        class App(Isso, core.Mixin):
            pass

        app = App(conf)

        app.wsgi_app = FakeIP(app.wsgi_app, ip)

        return Client(app, Response)
Example #3
0
File: __init__.py Project: GSI/isso
def main():

    parser = ArgumentParser(description="a blog comment hosting service")
    subparser = parser.add_subparsers(help="commands", dest="command")

    parser.add_argument('--version', action='version', version='%(prog)s ' + dist.version)
    parser.add_argument("-c", dest="conf", default="/etc/isso.conf",
            metavar="/etc/isso.conf", help="set configuration file")

    imprt = subparser.add_parser('import', help="import Disqus XML export")
    imprt.add_argument("dump", metavar="FILE")
    imprt.add_argument("-n", "--dry-run", dest="dryrun", action="store_true",
                       help="perform a trial run with no changes made")
    imprt.add_argument("-t", "--type", dest="type", default=None,
                       choices=["disqus", "wordpress"], help="export type")

    serve = subparser.add_parser("run", help="run server")

    args = parser.parse_args()
    conf = config.load(join(dist.location, "share", "isso.conf"), args.conf)

    if args.command == "import":
        conf.set("guard", "enabled", "off")

        if args.dryrun:
            xxx = tempfile.NamedTemporaryFile()
            dbpath = xxx.name
        else:
            dbpath = conf.get("general", "dbpath")

        mydb = db.SQLite3(dbpath, conf)
        migrate.dispatch(args.type, mydb, args.dump)

        sys.exit(0)

    if not any(conf.getiter("general", "host")):
        logger.error("No website(s) configured, Isso won't work.")
        sys.exit(1)

    if conf.get("server", "listen").startswith("http://"):
        host, port, _ = urlsplit(conf.get("server", "listen"))
        try:
            from gevent.pywsgi import WSGIServer
            WSGIServer((host, port), make_app(conf)).serve_forever()
        except ImportError:
            run_simple(host, port, make_app(conf), threaded=True,
                       use_reloader=conf.getboolean('server', 'reload'))
    else:
        sock = conf.get("server", "listen").partition("unix://")[2]
        try:
            os.unlink(sock)
        except OSError as ex:
            if ex.errno != errno.ENOENT:
                raise
        wsgi.SocketHTTPServer(sock, make_app(conf)).serve_forever()
Example #4
0
    def setUp(self):
        fd, self.path = tempfile.mkstemp()
        conf = config.load(config.default_file())
        conf.set("general", "dbpath", self.path)
        self.conf = conf

        class App(Isso, core.Mixin):
            pass

        self.app = App(conf)

        self.client = JSONClient(self.app, Response)
        self.post = self.client.post
Example #5
0
    def __init__(self, *confs):

        self.isso = {}

        for i, conf in enumerate(map(config.load(Dispatcher.default, conf))):

            if not conf.get("general", "name"):
                logger.warn("unable to dispatch %r, no 'name' set", confs[i])
                continue

            self.isso["/" + conf.get("general", "name")] = make_app(conf)

        super(Dispatcher, self).__init__(self.default, mounts=self.isso)
Example #6
0
    def __init__(self, *confs):
        self.isso = {}

        default = os.path.join(dist.location, dist.project_name, "defaults.ini")
        for i, path in enumerate(confs):
            conf = config.load(default, path)

            if not conf.get("general", "name"):
                logger.warn("unable to dispatch %r, no 'name' set", confs[i])
                continue

            self.isso["/" + conf.get("general", "name")] = make_app(conf)

        super(Dispatcher, self).__init__(self.default, mounts=self.isso)
Example #7
0
    def makeClient(self, ip):

        conf = config.load(config.default_file())
        conf.set("general", "dbpath", self.path)
        conf.set("guard", "enabled", "off")
        conf.set("hash", "algorithm", "none")

        class App(Isso, core.Mixin):
            pass

        app = App(conf)
        app.wsgi_app = FakeIP(app.wsgi_app, ip)

        return JSONClient(app, Response)
Example #8
0
    def makeClient(self, ip):

        conf = config.load(os.path.join(dist.location, "share", "isso.conf"))
        conf.set("general", "dbpath", self.path)
        conf.set("guard", "enabled", "off")
        conf.set("hash", "algorithm", "none")

        class App(Isso, core.Mixin):
            pass

        app = App(conf)
        app.wsgi_app = FakeIP(app.wsgi_app, ip)

        return JSONClient(app, Response)
Example #9
0
    def setUp(self):
        fd, self.path = tempfile.mkstemp()
        conf = config.load(os.path.join(dist.location, "share", "isso.conf"))
        conf.set("general", "dbpath", self.path)
        conf.set("moderation", "enabled", "true")
        conf.set("guard", "enabled", "off")
        conf.set("hash", "algorithm", "none")

        class App(Isso, core.Mixin):
            pass

        self.app = App(conf)
        self.app.wsgi_app = FakeIP(self.app.wsgi_app, "192.168.1.1")
        self.client = JSONClient(self.app, Response)
Example #10
0
    def __init__(self, *confs):
        self.isso = {}

        default = pkg_resources.resource_filename('isso', 'defaults.ini')
        for i, path in enumerate(confs):
            conf = config.load(default, path)

            if not conf.get("general", "name"):
                logger.warn("unable to dispatch %r, no 'name' set", confs[i])
                continue

            self.isso["/" + conf.get("general", "name")] = make_app(conf)

        super(Dispatcher, self).__init__(self.default, mounts=self.isso)
Example #11
0
    def setUp(self):
        fd, self.path = tempfile.mkstemp()
        conf = config.load(os.path.join(dist.location, "share", "isso.conf"))
        conf.set("general", "dbpath", self.path)
        conf.set("moderation", "enabled", "true")
        conf.set("guard", "enabled", "off")
        conf.set("hash", "algorithm", "none")

        class App(Isso, core.Mixin):
            pass

        self.app = App(conf)
        self.app.wsgi_app = FakeIP(self.app.wsgi_app, "192.168.1.1")
        self.client = JSONClient(self.app, Response)
Example #12
0
    def setUp(self):
        fd, self.path = tempfile.mkstemp()
        conf = config.load(
            os.path.join(dist.location, dist.project_name, "defaults.ini"))
        conf.set("general", "dbpath", self.path)
        self.conf = conf

        class App(Isso, core.Mixin):
            pass

        self.app = App(conf)

        self.client = JSONClient(self.app, Response)
        self.post = self.client.post
Example #13
0
    def __init__(self, *confs):
        self.isso = {}

        default = os.path.join(dist.location, 'isso', "defaults.ini")
        for i, path in enumerate(confs):
            conf = config.load(default, path)

            if not conf.get("general", "name"):
                logger.warn("unable to dispatch %r, no 'name' set", confs[i])
                continue

            self.isso["/" + conf.get("general", "name")] = make_app(conf)

        super(Dispatcher, self).__init__(self.default, mounts=self.isso)
Example #14
0
    def makeClient(self, ip):

        conf = config.load(os.path.join(dist.location, "share", "isso.conf"))
        conf.set("general", "dbpath", self.path)
        conf.set("guard", "enabled", "off")
        conf.set("hash", "algorithm", "none")

        class App(Isso, core.Mixin):
            pass

        app = App(conf)
        app.wsgi_app = FakeIP(app.wsgi_app, ip)

        return JSONClient(app, Response)
Example #15
0
    def setUp(self):
        fd, self.path = tempfile.mkstemp()
        conf = config.load(
            pkg_resources.resource_filename('isso', 'defaults.ini'))
        conf.set("general", "dbpath", self.path)
        conf.set("moderation", "enabled", "true")
        conf.set("guard", "enabled", "off")
        conf.set("hash", "algorithm", "none")

        class App(Isso, core.Mixin):
            pass

        self.app = App(conf)
        self.app.wsgi_app = FakeIP(self.app.wsgi_app, "192.168.1.1")
        self.client = JSONClient(self.app, Response)
Example #16
0
    def makeClient(self, ip, ratelimit=2, direct_reply=3, self_reply=False):

        conf = config.load(os.path.join(dist.location, "share", "isso.conf"))
        conf.set("general", "dbpath", self.path)
        conf.set("hash", "algorithm", "none")
        conf.set("guard", "enabled", "true")
        conf.set("guard", "ratelimit", str(ratelimit))
        conf.set("guard", "direct-reply", str(direct_reply))
        conf.set("guard", "reply-to-self", "1" if self_reply else "0")

        class App(Isso, core.Mixin):
            pass

        app = App(conf)
        app.wsgi_app = FakeIP(app.wsgi_app, ip)

        return Client(app, Response)
Example #17
0
    def setUp(self):
        fd, self.path = tempfile.mkstemp()
        conf = config.load(config.default_file())
        conf.set("general", "dbpath", self.path)
        conf.set("moderation", "enabled", "true")
        conf.set("guard", "enabled", "off")
        conf.set("hash", "algorithm", "none")

        class App(Isso, core.Mixin):
            pass

        self.app = App(conf)
        self.app.wsgi_app = FakeIP(self.app.wsgi_app, "192.168.1.1")
        self.client = JSONClient(self.app, Response)

        # add default comment
        rv = self.client.post(
            '/new?uri=test', data=json.dumps({"text": "..."}))
        self.assertEqual(rv.status_code, 202)
Example #18
0
    def setUp(self):
        fd, self.path = tempfile.mkstemp()
        conf = config.load(config.default_file())
        conf.set("general", "dbpath", self.path)
        conf.set("guard", "enabled", "off")
        conf.set("hash", "algorithm", "none")
        conf.set("general", "latest-enabled", "true")
        self.conf = conf

        class App(Isso, core.Mixin):
            pass

        self.app = App(conf)
        self.app.wsgi_app = FakeIP(self.app.wsgi_app, "192.168.1.1")

        self.client = JSONClient(self.app, Response)
        self.get = self.client.get
        self.put = self.client.put
        self.post = self.client.post
        self.delete = self.client.delete
Example #19
0
# -*- encoding: utf-8 -*-

from __future__ import unicode_literals

import os

from isso import make_app
from isso import dist, config

application = make_app(config.load(
    os.path.join(dist.location, dist.project_name, "defaults.ini"),
    os.environ.get('ISSO_SETTINGS')),
                       multiprocessing=True)
Example #20
0
def main():

    parser = ArgumentParser(description="a blog comment hosting service")
    subparser = parser.add_subparsers(help="commands", dest="command")

    parser.add_argument('--version',
                        action='version',
                        version='%(prog)s ' + dist.version)
    parser.add_argument("-c",
                        dest="conf",
                        default="/etc/isso.conf",
                        metavar="/etc/isso.conf",
                        help="set configuration file")

    imprt = subparser.add_parser('import', help="import Disqus XML export")
    imprt.add_argument("dump", metavar="FILE")
    imprt.add_argument("-n",
                       "--dry-run",
                       dest="dryrun",
                       action="store_true",
                       help="perform a trial run with no changes made")
    imprt.add_argument("-t",
                       "--type",
                       dest="type",
                       default=None,
                       choices=["disqus", "wordpress"],
                       help="export type")
    imprt.add_argument("--empty-id",
                       dest="empty_id",
                       action="store_true",
                       help="workaround for weird Disqus XML exports, #135")

    serve = subparser.add_parser("run", help="run server")

    args = parser.parse_args()
    conf = config.load(join(dist.location, dist.project_name, "defaults.ini"),
                       args.conf)

    if args.command == "import":
        conf.set("guard", "enabled", "off")

        if args.dryrun:
            xxx = tempfile.NamedTemporaryFile()
            dbpath = xxx.name
        else:
            dbpath = conf.get("general", "dbpath")

        mydb = db.SQLite3(dbpath, conf)
        migrate.dispatch(args.type, mydb, args.dump, args.empty_id)

        sys.exit(0)

    if conf.get("general", "log-file"):
        handler = logging.FileHandler(conf.get("general", "log-file"))

        logger.addHandler(handler)
        logging.getLogger("werkzeug").addHandler(handler)

        logger.propagate = False
        logging.getLogger("werkzeug").propagate = False

    if not any(conf.getiter("general", "host")):
        logger.error("No website(s) configured, Isso won't work.")
        sys.exit(1)

    if conf.get("server", "listen").startswith("http://"):
        host, port, _ = urlsplit(conf.get("server", "listen"))
        try:
            from gevent.pywsgi import WSGIServer
            WSGIServer((host, port), make_app(conf)).serve_forever()
        except ImportError:
            run_simple(host,
                       port,
                       make_app(conf),
                       threaded=True,
                       use_reloader=conf.getboolean('server', 'reload'))
    else:
        sock = conf.get("server", "listen").partition("unix://")[2]
        try:
            os.unlink(sock)
        except OSError as ex:
            if ex.errno != errno.ENOENT:
                raise
        wsgi.SocketHTTPServer(sock, make_app(conf)).serve_forever()
Example #21
0
File: run.py Project: fliiiix/isso
# -*- encoding: utf-8 -*-

import os
import pkg_resources

from isso import config, make_app

application = make_app(config.load(
    pkg_resources.resource_filename('isso', 'defaults.ini'),
    os.environ.get('ISSO_SETTINGS')),
                       multiprocessing=True)
Example #22
0
#! python3

"""
    WSGI script to allow launch isso through Apache mod_wsgi.
"""

import site

site.addsitedir("./.venv")

import os
from pathlib import Path

from isso import config, dist, make_app

# globals
isso_conf_file = Path(__file__).parent / "isso-prod.cfg"

application = make_app(
    config.load(
        default=os.path.join(dist.location, dist.project_name, "defaults.ini"),
        user=str(isso_conf_file.resolve()),
    ),
    multiprocessing=True,
    threading=True,
)
Example #23
0
# -*- encoding: utf-8 -*-

from __future__ import unicode_literals

import os

from isso import make_app
from isso import dist, config

application = make_app(
    config.load(
        os.path.join(dist.location, "isso", "defaults.ini"),
        os.environ.get('ISSO_SETTINGS')),
    multiprocessing=True)
Example #24
0
# This portion of code is fork of gunicorn's example of running
# custom applications.
# Original link - http://gunicorn-docs.readthedocs.org/en/latest/custom.html
# 2009-2015 (c) Benoit Chesneau <*****@*****.**>
# 2009-2015 (c) Paul J. Davis <*****@*****.**>

import os
import sys
import multiprocessing

import gunicorn.app.base
from gunicorn.six import iteritems
from isso import make_app
from isso import config as isso_config

application = make_app(isso_config.load('production.cfg'))

virtenv = os.environ['OPENSHIFT_PYTHON_DIR'] + '/virtenv/'
virtualenv = os.path.join(virtenv, 'bin/activate_this.py')
try:
    execfile(virtualenv, dict(__file__=virtualenv))
except IOError:
    pass

ip = os.environ['OPENSHIFT_PYTHON_IP']
port = int(os.environ['OPENSHIFT_PYTHON_PORT'])


def number_of_workers():
    return (multiprocessing.cpu_count() * 2) + 1
Example #25
0
File: run.py Project: Batur24/isso
# -*- encoding: utf-8 -*-

from __future__ import unicode_literals

import os

from isso import make_app
from isso import dist, config

application = make_app(
    config.load(
        os.path.join(dist.location, dist.project_name, "defaults.ini"),
        os.environ.get('ISSO_SETTINGS')),
    multiprocessing=True)
Example #26
0
# This portion of code is fork of gunicorn's example of running
# custom applications.
# Original link - http://gunicorn-docs.readthedocs.org/en/latest/custom.html
# 2009-2015 (c) Benoit Chesneau <*****@*****.**>
# 2009-2015 (c) Paul J. Davis <*****@*****.**>

import os
import sys
import multiprocessing

import gunicorn.app.base
from gunicorn.six import iteritems
from isso import make_app
from isso import config as isso_config

application = make_app(isso_config.load('production.cfg'))
"""
virtenv = os.environ['OPENSHIFT_PYTHON_DIR'] + '/virtenv/'
virtualenv = os.path.join(virtenv, 'bin/activate_this.py')
try:
    execfile(virtualenv, dict(__file__=virtualenv))
except IOError:
    pass

ip = os.environ['OPENSHIFT_PYTHON_IP']
port = int(os.environ['OPENSHIFT_PYTHON_PORT'])
"""


def number_of_workers():
    return (multiprocessing.cpu_count() * 2) + 1
Example #27
0
File: __init__.py Project: ix5/isso
def main():

    parser = ArgumentParser(description="a blog comment hosting service")
    subparser = parser.add_subparsers(help="commands", dest="command")

    parser.add_argument('--version', action='version',
                        version='%(prog)s ' + dist.version)
    parser.add_argument("-c", dest="conf", default="/etc/isso.cfg",
                        metavar="/etc/isso.cfg", help="set configuration file")

    imprt = subparser.add_parser('import', help="import Disqus XML export")
    imprt.add_argument("dump", metavar="FILE")
    imprt.add_argument("-n", "--dry-run", dest="dryrun", action="store_true",
                       help="perform a trial run with no changes made")
    imprt.add_argument("-t", "--type", dest="type", default=None,
                       choices=["disqus", "wordpress", "generic"], help="export type")
    imprt.add_argument("--empty-id", dest="empty_id", action="store_true",
                       help="workaround for weird Disqus XML exports, #135")

    # run Isso as stand-alone server
    subparser.add_parser("run", help="run server")

    args = parser.parse_args()

    # ISSO_SETTINGS env var takes precedence over `-c` flag
    conf_file = os.environ.get('ISSO_SETTINGS') or args.conf

    if not conf_file:
        logger.error("No configuration file specified! Exiting.")
        sys.exit(1)
    if exists(conf_file):
        logger.info("Using configuration file '%s'", abspath(conf_file))
    else:
        logger.error("Specified config '%s' does not exist! Exiting.",
                     abspath(conf_file))
        sys.exit(1)

    conf = config.load(config.default_file(), conf_file)

    if args.command == "import":
        conf.set("guard", "enabled", "off")

        if args.dryrun:
            xxx = tempfile.NamedTemporaryFile()
            dbpath = xxx.name
        else:
            dbpath = conf.get("general", "dbpath")

        mydb = db.SQLite3(dbpath, conf)
        migrate.dispatch(args.type, mydb, args.dump, args.empty_id)

        sys.exit(0)

    if conf.get("general", "log-file"):
        handler = logging.FileHandler(conf.get("general", "log-file"))

        logger.addHandler(handler)
        logging.getLogger("werkzeug").addHandler(handler)

        logger.propagate = False
        logging.getLogger("werkzeug").propagate = False

    if conf.get("server", "listen").startswith("http://"):
        host, port, _ = urlsplit(conf.get("server", "listen"))
        try:
            from gevent.pywsgi import WSGIServer
            WSGIServer((host, port), make_app(conf)).serve_forever()
        except ImportError:
            run_simple(host, port, make_app(conf), threaded=True,
                       use_reloader=conf.getboolean('server', 'reload'))
    else:
        sock = conf.get("server", "listen").partition("unix://")[2]
        try:
            os.unlink(sock)
        except OSError as ex:
            if ex.errno != errno.ENOENT:
                raise
        wsgi.SocketHTTPServer(sock, make_app(conf)).serve_forever()
Example #28
0
File: run.py Project: uche100/isso
# -*- encoding: utf-8 -*-

from __future__ import unicode_literals

import os

from isso import make_app
from isso import dist, config

application = make_app(config.load(
    os.path.join(dist.location, "share", "isso.conf"),
    os.environ.get('ISSO_SETTINGS')),
                       multiprocessing=True)