Ejemplo n.º 1
0
def start_server(args=None):
    if args is None:
        args = sys.argv[1:]

    if args:
        mode = args.pop(0)
    else:
        mode = "dev"

    print("Bespin mobwrite worker (mode=" + mode + ")")
    config.set_profile(mode)

    if args:
        config.load_pyconfig(args.pop(0))

    if mode == "dev":
        config.load_pyconfig("devconfig.py")

    config.activate_profile()

    app = WSGIMobWrite()
    app = db_middleware(app)

    serve(app,
          config.c.mobwrite_server_address,
          config.c.mobwrite_server_port,
          use_threadpool=True)
Ejemplo n.º 2
0
def _init_data():
    global macgyver, someone_else, murdoc
    config.activate_profile()
    
    fsroot = config.c.fsroot
    if fsroot.exists() and fsroot.basename() == "testfiles":
        fsroot.rmtree()
    fsroot.makedirs()
    
    app.reset()
    
    Base.metadata.drop_all(bind=config.c.dbengine)
    Base.metadata.create_all(bind=config.c.dbengine)
    s = config.c.session_factory()
    
    someone_else = User.create_user("SomeoneElse", "", "*****@*****.**")
    murdoc = User.create_user("Murdoc", "", "*****@*****.**")
    
    otherproject = get_project(someone_else, someone_else,
                                            "otherproject", create=True)
    otherproject.save_file('foo', 'Just a file to reserve a project')
    
    app.post("/register/new/MacGyver", 
        dict(password="******", email="*****@*****.**"))
        
    macgyver = User.find_user("MacGyver")
def create_db():
    """Creates the development database"""
    from bespin import config, database, db_versions
    from migrate.versioning.shell import main

    config.set_profile('dev')

    base_url = config.c.dburl

    config_file = options.server.config_file
    if config_file.exists():
        info("Loading config: %s", config_file)
        code = compile(config_file.bytes(), config_file, "exec")
        exec code in {}

    if config.c.dburl == base_url and path("devdata.db").exists():
        raise BuildFailure("Development database already exists")

    config.activate_profile()
    dry("Create database tables",
        database.Base.metadata.create_all,
        bind=config.c.dbengine)

    repository = str(path(db_versions.__file__).dirname())
    dburl = config.c.dburl
    result = sh("python bespin/db_versions/manage.py version", capture=True)
    dry("Turn on migrate versioning", main,
        ["version_control", "--version",
         result.rstrip(), dburl, repository])
Ejemplo n.º 4
0
def editbespin(options):
    """Use Bespin to edit Bespin. This will change the given
    user's file location to the directory above Bespin, allowing
    you to edit Bespin (and any other projects you have
    in that directory)."""
    
    if not 'editbespin' in options or not options.editbespin.user:
        raise BuildFailure("You must specify a user with -u for this task.")
        
    user = options.editbespin.user
    
    from bespin import config
    from bespin import database, filesystem
    from sqlalchemy.orm.exc import NoResultFound
    
    config.set_profile("dev")
    config.activate_profile()
    session = config.c.session_factory()
    try:
        user = session.query(database.User).filter_by(username=user).one()
    except NoResultFound:
        raise BuildFailure("I couldn't find %s in the database. Sorry!" % (user))
    
    location = path.getcwd().parent.abspath()
    user.file_location = location
    user.recompute_files()
    session.commit()
    bespinsettings_loc = location / "BespinSettings"
    if not bespinsettings_loc.exists():
        project = filesystem.get_project(user, user, "BespinSettings", create=True)
        project.install_template('usertemplate')
    info("User %s set up to access directory %s" % (user, location))
Ejemplo n.º 5
0
def test_register_and_verify_user():
    config.activate_profile()
    _clear_db()
    s = _get_session()
    app = controllers.make_app()
    app = BespinTestApp(app)
    resp = app.post('/register/new/BillBixby', dict(email="*****@*****.**",
                                                    password="******"))
    assert resp.content_type == "application/json"
    data = simplejson.loads(resp.body)
    assert data == {}
    assert resp.cookies_set['auth_tkt']
    assert app.cookies
    billbixby = User.find_user("BillBixby")
    sample_project = get_project(billbixby, billbixby, "SampleProject")
    files = [file.name for file in sample_project.list_files()]
    assert "readme.txt" in files
    
    # should be able to run again without an exception appearing
    resp = app.post('/register/new/BillBixby', dict(email="*****@*****.**",
                                                    password="******"),
                    status=409)
    
    # with the cookie set, we should be able to retrieve the 
    # logged in name
    resp = app.get('/register/userinfo/')
    assert resp.content_type == 'application/json'
    data = simplejson.loads(resp.body)
    assert data['username'] == 'BillBixby'
    assert 'quota' in data
    assert data['quota'] == 15728640
    assert 'amountUsed' in data
    
    resp = app.get("/file/at/BespinSettings/config")
    app.post("/file/close/BespinSettings/config")
Ejemplo n.º 6
0
def _init_data():
    global macgyver, someone_else, murdoc
    config.activate_profile()

    fsroot = config.c.fsroot
    if fsroot.exists() and fsroot.basename() == "testfiles":
        fsroot.rmtree()
    fsroot.makedirs()

    app.reset()

    Base.metadata.drop_all(bind=config.c.dbengine)
    Base.metadata.create_all(bind=config.c.dbengine)
    s = config.c.session_factory()

    someone_else = User.create_user("SomeoneElse", "", "*****@*****.**")
    murdoc = User.create_user("Murdoc", "", "*****@*****.**")

    otherproject = get_project(someone_else,
                               someone_else,
                               "otherproject",
                               create=True)
    otherproject.save_file('foo', 'Just a file to reserve a project')

    app.post("/register/new/MacGyver",
             dict(password="******", email="*****@*****.**"))

    macgyver = User.find_user("MacGyver")
Ejemplo n.º 7
0
def create_db():
    """Creates the development database"""
    from bespin import config, database, db_versions
    from migrate.versioning.shell import main
    
    config.set_profile('dev')
    
    base_url = config.c.dburl
    
    config_file = options.server.config_file
    if config_file.exists():
        info("Loading config: %s", config_file)
        code = compile(config_file.bytes(), config_file, "exec")
        exec code in {}

    if config.c.dburl == base_url and path("devdata.db").exists():
        raise BuildFailure("Development database already exists")
    
    config.activate_profile()
    dry("Create database tables", database.Base.metadata.create_all, bind=config.c.dbengine)
    
    repository = str(path(db_versions.__file__).dirname())
    dburl = config.c.dburl
    result = sh("python bespin/db_versions/manage.py version", capture=True)
    dry("Turn on migrate versioning", main, ["version_control", "--version", result.rstrip(), dburl, repository])
Ejemplo n.º 8
0
def test_register_and_verify_user():
    config.activate_profile()
    _clear_db()
    s = _get_session()
    app = controllers.make_app()
    app = BespinTestApp(app)
    resp = app.post('/register/new/BillBixby',
                    dict(email="*****@*****.**", password="******"))
    assert resp.content_type == "application/json"
    data = simplejson.loads(resp.body)
    assert data == {}
    assert resp.cookies_set['auth_tkt']
    assert app.cookies
    billbixby = User.find_user("BillBixby")
    sample_project = get_project(billbixby, billbixby, "SampleProject")
    files = [file.name for file in sample_project.list_files()]
    assert "readme.txt" in files

    # should be able to run again without an exception appearing
    resp = app.post('/register/new/BillBixby',
                    dict(email="*****@*****.**", password="******"),
                    status=409)

    # with the cookie set, we should be able to retrieve the
    # logged in name
    resp = app.get('/register/userinfo/')
    assert resp.content_type == 'application/json'
    data = simplejson.loads(resp.body)
    assert data['username'] == 'BillBixby'
    assert 'quota' in data
    assert data['quota'] == 15728640
    assert 'amountUsed' in data

    resp = app.get("/file/at/BespinSettings/config")
    app.post("/file/close/BespinSettings/config")
Ejemplo n.º 9
0
def start():
    """Starts the BespinServer on localhost port 8080 for development.
    
    You can change the port and allow remote connections by setting
    server.port or server.address on the command line.
    
    paver server.address=your.ip.address server.port=8000 start
    
    will allow remote connections (assuming you don't have a firewall
    blocking the connection) and start the server on port 8000.
    """
    # automatically install Dojo if it's not there already
    if not (options.dojo.destination / "dojo").exists():
        dojo()
    
    from bespin import config, controllers
    from paste.httpserver import serve
    
    options.order('server')
    
    config.set_profile('dev')
    
    if options.server.try_build:
        config.c.static_dir = (options.build_dir / "frontend").abspath()
    
    if options.server.dburl:
        config.c.dburl = options.server.dburl
    
    if options.server.async:
        config.c.async_jobs = True
        config.c.queue_path = path.getcwd() / "queue.db"
    
    config.activate_profile()
    port = int(options.port)
    serve(controllers.make_app(), options.address, port, use_threadpool=True)
Ejemplo n.º 10
0
def setup_module(module):
    if queue_db.exists():
        print "Deleting old queue DB"
        queue_db.unlink()
    config.set_profile("test")
    config.c.async_jobs = True
    config.c.queue_path = queue_db
    config.activate_profile()
Ejemplo n.º 11
0
def try_upgrade():
    """Run SQLAlchemy-migrate test on your database."""
    from bespin import config, model, db_versions
    from migrate.versioning.shell import main
    config.set_profile('dev')
    config.activate_profile()
    repository = str(path(db_versions.__file__).dirname())
    dburl = config.c.dburl
    dry("Test the database upgrade", main, ["test", repository, dburl])
Ejemplo n.º 12
0
def upgrade():
    """Upgrade your database."""
    from bespin import config, model, db_versions
    from migrate.versioning.shell import main
    config.set_profile('dev')
    config.activate_profile()
    repository = str(path(db_versions.__file__).dirname())
    dburl = config.c.dburl
    dry("Run the database upgrade", main, ["upgrade", dburl, repository])
Ejemplo n.º 13
0
def upgrade():
    """Upgrade your database."""
    from bespin import config, model, db_versions
    from migrate.versioning.shell import main
    config.set_profile('dev')
    config.activate_profile()
    repository = str(path(db_versions.__file__).dirname())
    dburl = config.c.dburl
    dry("Run the database upgrade", main, ["upgrade", dburl, repository])
Ejemplo n.º 14
0
def try_upgrade():
    """Run SQLAlchemy-migrate test on your database."""
    from bespin import config, model, db_versions
    from migrate.versioning.shell import main
    config.set_profile('dev')
    config.activate_profile()
    repository = str(path(db_versions.__file__).dirname())
    dburl = config.c.dburl
    dry("Test the database upgrade", main, ["test", repository, dburl])
def setup_module():
    global app, app_murdoc
    config.set_profile('test')
    app = controllers.make_app()
    app = BespinTestApp(app)
    app_murdoc = controllers.make_app()
    app_murdoc = BespinTestApp(app_murdoc)
    
    _install_test_plugin_path()
    config.activate_profile()
Ejemplo n.º 16
0
def setup_module(module):
    global app, session
    config.set_profile('test')
    config.activate_profile()
    Base.metadata.drop_all(bind=config.c.dbengine)
    Base.metadata.create_all(bind=config.c.dbengine)
    session = config.c.session_factory()
    User.create_user("BillBixby", "", "*****@*****.**")
    app = controllers.make_app()
    app = BespinTestApp(app)
    app.post("/register/login/BillBixby", dict(password=""))
Ejemplo n.º 17
0
def setup_module(module):
    global user_manager, app, session
    config.set_profile('test')
    config.activate_profile()
    model.Base.metadata.drop_all(bind=config.c.dbengine)
    model.Base.metadata.create_all(bind=config.c.dbengine)
    session = config.c.sessionmaker(bind=config.c.dbengine)
    user_manager = model.UserManager(session)
    user_manager.create_user("BillBixby", "", "*****@*****.**")
    app = controllers.make_app()
    app = TestApp(app)
    app.post("/register/login/BillBixby", dict(password=""))
Ejemplo n.º 18
0
def test_password_change_bad_code():
    config.set_profile("test")
    config.activate_profile()
    _clear_db()

    app = controllers.make_app()
    app = BespinTestApp(app)
    resp = app.post('/register/new/BillBixby',
                    dict(email="*****@*****.**", password="******"))
    app.reset()

    resp = app.post('/register/password/BillBixby',
                    dict(code="42", newPassword="******"),
                    status=400)
Ejemplo n.º 19
0
def create_db():
    """Creates the development database"""
    from bespin import config, database, db_versions
    from migrate.versioning.shell import main
    
    if path("devdata.db").exists():
        raise BuildFailure("Development database already exists")
    config.set_profile('dev')
    config.activate_profile()
    dry("Create database tables", database.Base.metadata.create_all, bind=config.c.dbengine)
    
    repository = str(path(db_versions.__file__).dirname())
    dburl = config.c.dburl
    dry("Turn on migrate versioning", main, ["version_control", dburl, repository])
Ejemplo n.º 20
0
def seeddb():
    from bespin import config, filesystem
    from bespin.database import User, Connection
    config.set_profile("dev")
    config.activate_profile()

    def get_user(name):
        user = User.find_user(name)
        if user == None:
            user = User.create_user(name, name, name + "@foo.com")
            session.commit()
            info("Created user called '" + name + "'")
        try:
            filesystem.get_project(user, user, "BespinSettings")
        except:
            settings = filesystem.get_project(user,
                                              user,
                                              "BespinSettings",
                                              create=True)
            settings.install_template('usertemplate')
            info("Created BespinSettings project for '" + name + "'")
        return user

    # Seriously there is something wrong with my ego today ;-)
    bgalbraith = get_user("bgalbraith")
    kdangoor = get_user("kdangoor")
    dalmaer = get_user("d")
    mattb = get_user("mattb")
    zuck = get_user("zuck")
    tom = get_user("tom")
    ev = get_user("ev")
    j = get_user("j")

    bgalbraith.follow(j)
    kdangoor.follow(j)
    dalmaer.follow(j)
    mattb.follow(j)
    zuck.follow(j)
    tom.follow(j)
    ev.follow(j)

    jproject = filesystem.get_project(j, j, "SampleProject", create=True)

    j.add_sharing(jproject, bgalbraith, edit=True)
    j.add_sharing(jproject, kdangoor, edit=True)
    j.add_sharing(jproject, dalmaer, edit=True)
    j.add_sharing(jproject, mattb, edit=False)
    j.add_sharing(jproject, zuck, edit=False)
    j.add_sharing(jproject, tom, edit=False)
    j.add_sharing(jproject, ev, edit=False)
Ejemplo n.º 21
0
def test_password_change_bad_code():
    config.set_profile("test")
    config.activate_profile()
    _clear_db()
    
    app = controllers.make_app()
    app = BespinTestApp(app)
    resp = app.post('/register/new/BillBixby', dict(email="*****@*****.**",
                                                    password="******"))
    app.reset()
    
    resp = app.post('/register/password/BillBixby', dict( 
                                            code="42",
                                            newPassword="******"),
                    status=400)
    
Ejemplo n.º 22
0
def seeddb():
    from bespin import config, filesystem
    from bespin.database import User, Connection
    config.set_profile("dev")
    config.activate_profile()

    def get_user(name):
        user = User.find_user(name)
        if user == None:
            user = User.create_user(name, name, name + "@foo.com")
            session.commit()
            info("Created user called '" + name + "'")
        try:
            filesystem.get_project(user, user, "BespinSettings")
        except:
            settings = filesystem.get_project(user, user, "BespinSettings", create=True)
            settings.install_template('usertemplate')
            info("Created BespinSettings project for '" + name + "'")
        return user

    # Seriously there is something wrong with my ego today ;-)
    bgalbraith = get_user("bgalbraith")
    kdangoor = get_user("kdangoor")
    dalmaer = get_user("d")
    mattb = get_user("mattb")
    zuck = get_user("zuck")
    tom = get_user("tom")
    ev = get_user("ev")
    j = get_user("j")

    bgalbraith.follow(j)
    kdangoor.follow(j)
    dalmaer.follow(j)
    mattb.follow(j)
    zuck.follow(j)
    tom.follow(j)
    ev.follow(j)

    jproject = filesystem.get_project(j, j, "SampleProject", create=True)

    j.add_sharing(jproject, bgalbraith, edit=True)
    j.add_sharing(jproject, kdangoor, edit=True)
    j.add_sharing(jproject, dalmaer, edit=True)
    j.add_sharing(jproject, mattb, edit=False)
    j.add_sharing(jproject, zuck, edit=False)
    j.add_sharing(jproject, tom, edit=False)
    j.add_sharing(jproject, ev, edit=False)
Ejemplo n.º 23
0
def main():
  # Start up a thread that does timeouts and cleanup
  thread.start_new_thread(cleanup_thread, ())

  from bespin import config, controllers
  from bespin.mobwrite.mobwrite_daemon import MobwriteWorker
  config.set_profile('dev')    
  config.activate_profile()

  logging.info("Listening on port %d..." % LOCAL_PORT)
  s = SocketServer.ThreadingTCPServer(("", LOCAL_PORT), AutoPersisterEchoRequestHandler)
  try:
    s.serve_forever()
  except KeyboardInterrupt:
    logging.info("Shutting down.")
    logging.shutdown()
    s.socket.close()
Ejemplo n.º 24
0
def test_lost_username(send_text_email):
    config.set_profile("test")
    config.activate_profile()
    _clear_db()
    
    app = controllers.make_app()
    app = BespinTestApp(app)
    resp = app.post('/register/new/BillBixby', dict(email="*****@*****.**",
                                                    password="******"))
    
    resp = app.post('/register/lost/', dict(email='*****@*****.**'))
    assert send_text_email.called
    args = send_text_email.call_args[0]
    assert args[0] == '*****@*****.**'
    assert args[1].startswith("Your username for ")
    assert "Your username is:" in args[2]
    assert "BillBixby" in args[2]
Ejemplo n.º 25
0
def test_lost_username(send_text_email):
    config.set_profile("test")
    config.activate_profile()
    _clear_db()

    app = controllers.make_app()
    app = BespinTestApp(app)
    resp = app.post('/register/new/BillBixby',
                    dict(email="*****@*****.**", password="******"))

    resp = app.post('/register/lost/', dict(email='*****@*****.**'))
    assert send_text_email.called
    args = send_text_email.call_args[0]
    assert args[0] == '*****@*****.**'
    assert args[1].startswith("Your username for ")
    assert "Your username is:" in args[2]
    assert "BillBixby" in args[2]
Ejemplo n.º 26
0
def create_db():
    """Creates the development database"""
    from bespin import config, database, db_versions
    from migrate.versioning.shell import main

    if path("devdata.db").exists():
        raise BuildFailure("Development database already exists")
    config.set_profile('dev')
    config.activate_profile()
    dry("Create database tables",
        database.Base.metadata.create_all,
        bind=config.c.dbengine)

    repository = str(path(db_versions.__file__).dirname())
    dburl = config.c.dburl
    dry("Turn on migrate versioning", main,
        ["version_control", dburl, repository])
Ejemplo n.º 27
0
def test_users_can_be_locked_out():
    config.set_profile("test")
    config.c.login_failure_tracking = "memory"
    config.c.login_attempts = "1"
    config.c.lockout_period = "1"
    config.activate_profile()
    app = controllers.make_app()
    app = BespinTestApp(app)
    _clear_db()
    
    resp = app.post('/register/new/BillBixby', dict(email="*****@*****.**",
                                                    password="******"))
    resp = app.post("/register/login/BillBixby",
        dict(password="******"), status=401)
    
    # fail with good password now, because we're locked out
    resp = app.post("/register/login/BillBixby",
        dict(password="******"), status=401)
Ejemplo n.º 28
0
def test_password_change_with_confirmation_code():
    config.set_profile("test")
    config.activate_profile()
    _clear_db()

    app = controllers.make_app()
    app = BespinTestApp(app)
    resp = app.post('/register/new/BillBixby',
                    dict(email="*****@*****.**", password="******"))
    app.reset()

    user = User.find_user("BillBixby")
    verify_code = controllers._get_password_verify_code(user)
    resp = app.post('/register/password/BillBixby',
                    dict(code=verify_code, newPassword="******"))

    user = User.find_user('BillBixby', 'hatetraffic')
    assert user
Ejemplo n.º 29
0
def test_password_change_with_confirmation_code():
    config.set_profile("test")
    config.activate_profile()
    _clear_db()
    
    app = controllers.make_app()
    app = BespinTestApp(app)
    resp = app.post('/register/new/BillBixby', dict(email="*****@*****.**",
                                                    password="******"))
    app.reset()
    
    user = User.find_user("BillBixby")
    verify_code = controllers._get_password_verify_code(user)
    resp = app.post('/register/password/BillBixby', dict( 
                                            code=verify_code,
                                            newPassword="******"))
    
    user = User.find_user('BillBixby', 'hatetraffic')
    assert user
Ejemplo n.º 30
0
def test_lost_password_request(send_text_email):
    config.set_profile("test")
    config.activate_profile()
    _clear_db()
    
    app = controllers.make_app()
    app = BespinTestApp(app)
    resp = app.post('/register/new/BillBixby', dict(email="*****@*****.**",
                                                    password="******"))
    
    app.reset()
    resp = app.post('/register/lost/', dict(username='******'))
    assert send_text_email.called
    args = send_text_email.call_args[0]
    assert args[0] == '*****@*****.**'
    assert args[1].startswith("Requested password change for ")
    user = User.find_user("BillBixby")
    verify_code = controllers._get_password_verify_code(user)
    assert verify_code in args[2]
Ejemplo n.º 31
0
def test_lost_password_request(send_text_email):
    config.set_profile("test")
    config.activate_profile()
    _clear_db()

    app = controllers.make_app()
    app = BespinTestApp(app)
    resp = app.post('/register/new/BillBixby',
                    dict(email="*****@*****.**", password="******"))

    app.reset()
    resp = app.post('/register/lost/', dict(username='******'))
    assert send_text_email.called
    args = send_text_email.call_args[0]
    assert args[0] == '*****@*****.**'
    assert args[1].startswith("Requested password change for ")
    user = User.find_user("BillBixby")
    verify_code = controllers._get_password_verify_code(user)
    assert verify_code in args[2]
Ejemplo n.º 32
0
def installkey(options):
    """Install an SSH key into your Bespin keychain. This will
    prompt you for your Bespin keychain password. You must
    give a Bespin username with -u. You must also specify
    a passwordless SSH private key file with -f."""

    if not 'installkey' in options or not options.installkey.user:
        raise BuildFailure("You must specify a user with -u for this task.")

    if not options.installkey.file:
        raise BuildFailure("You must specify a private key with with -f")

    private_key = path(options.installkey.file)
    public_key = private_key + ".pub"

    if not private_key.exists() or not public_key.exists():
        raise BuildFailure(
            "Either your private key file or public key file does not exist")

    user = options.installkey.user

    import getpass

    password = getpass.getpass("Enter your keychain password: "******"dev")
    config.activate_profile()
    session = config.c.session_factory()
    try:
        user = session.query(database.User).filter_by(username=user).one()
    except NoResultFound:
        raise BuildFailure("I couldn't find %s in the database. Sorry!" %
                           (user))

    keychain = vcs.KeyChain(user, password)
    public_key = public_key.bytes()
    private_key = private_key.bytes()
    keychain.set_ssh_key(private_key, public_key)
Ejemplo n.º 33
0
def installkey(options):
    """Install an SSH key into your Bespin keychain. This will
    prompt you for your Bespin keychain password. You must
    give a Bespin username with -u. You must also specify
    a passwordless SSH private key file with -f."""
    
    if not 'installkey' in options or not options.installkey.user:
        raise BuildFailure("You must specify a user with -u for this task.")
    
    if not options.installkey.file:
        raise BuildFailure("You must specify a private key with with -f")
    
    private_key = path(options.installkey.file)
    public_key = private_key + ".pub"
    
    if not private_key.exists() or not public_key.exists():
        raise BuildFailure("Either your private key file or public key file does not exist")
        
    
        
    user = options.installkey.user
    
    import getpass
    
    password = getpass.getpass("Enter your keychain password: "******"dev")
    config.activate_profile()
    session = config.c.session_factory()
    try:
        user = session.query(database.User).filter_by(username=user).one()
    except NoResultFound:
        raise BuildFailure("I couldn't find %s in the database. Sorry!" % (user))
    
    keychain = vcs.KeyChain(user, password)
    public_key = public_key.bytes()
    private_key = private_key.bytes()
    keychain.set_ssh_key(private_key, public_key)
Ejemplo n.º 34
0
def _init_data():
    global macgyver
    config.activate_profile()
    
    fsroot = config.c.fsroot
    if fsroot.exists() and fsroot.basename() == "testfiles":
        fsroot.rmtree()
    fsroot.makedirs()
    
    app.reset()
    
    Base.metadata.drop_all(bind=config.c.dbengine)
    Base.metadata.create_all(bind=config.c.dbengine)
    s = config.c.session_factory()
    
    app.post("/register/new/MacGyver", 
        dict(password="******", email="*****@*****.**"))
        
    macgyver = User.find_user("MacGyver")
    s.flush()
Ejemplo n.º 35
0
def process_mobwrite(args=None):
  if args is None:
    args = sys.argv[1:]

  if args:
    mode = args.pop(0)
  else:
    mode = "dev"

  print("Bespin mobwrite worker (mode=" + mode + ")")  
  config.set_profile(mode)

  if args:
    config.load_pyconfig(args.pop(0))

  config.activate_profile()

  mobwrite_core.logging.basicConfig()
  main()
  mobwrite_core.logging.shutdown()
Ejemplo n.º 36
0
def _init_data():
    global macgyver
    config.activate_profile()
    
    fsroot = config.c.fsroot
    if fsroot.exists() and fsroot.basename() == "testfiles":
        fsroot.rmtree()
    fsroot.makedirs()
    
    app.reset()
    
    Base.metadata.drop_all(bind=config.c.dbengine)
    Base.metadata.create_all(bind=config.c.dbengine)
    s = config.c.session_factory()
    
    app.post("/register/new/MacGyver", 
        dict(password="******", email="*****@*****.**"))
        
    macgyver = User.find_user("MacGyver")
    s.flush()
Ejemplo n.º 37
0
def process_mobwrite(args=None):
    if args is None:
        args = sys.argv[1:]

    if args:
        mode = args.pop(0)
    else:
        mode = "dev"

    print("Bespin mobwrite worker (mode=" + mode + ")")
    config.set_profile(mode)

    if args:
        config.load_pyconfig(args.pop(0))

    config.activate_profile()

    mobwrite_core.logging.basicConfig()
    main()
    mobwrite_core.logging.shutdown()
Ejemplo n.º 38
0
def test_users_can_be_locked_out():
    config.set_profile("test")
    config.c.login_failure_tracking = "memory"
    config.c.login_attempts = "1"
    config.c.lockout_period = "1"
    config.activate_profile()
    app = controllers.make_app()
    app = BespinTestApp(app)
    _clear_db()

    resp = app.post('/register/new/BillBixby',
                    dict(email="*****@*****.**", password="******"))
    resp = app.post("/register/login/BillBixby",
                    dict(password="******"),
                    status=401)

    # fail with good password now, because we're locked out
    resp = app.post("/register/login/BillBixby",
                    dict(password="******"),
                    status=401)
Ejemplo n.º 39
0
def _init_data():
    global macgyver
    config.activate_profile()
    
    fsroot = config.c.fsroot
    if fsroot.exists() and fsroot.basename() == "testfiles":
        fsroot.rmtree()
    fsroot.makedirs()
    
    app.reset()
    
    model.Base.metadata.drop_all(bind=config.c.dbengine)
    model.Base.metadata.create_all(bind=config.c.dbengine)
    s = config.c.sessionmaker(bind=config.c.dbengine)
    user_manager = model.UserManager(s)
    
    app.post("/register/new/MacGyver", 
        dict(password="******", email="*****@*****.**"))
        
    macgyver = user_manager.get_user("MacGyver")
Ejemplo n.º 40
0
def start():
    """Starts the BespinServer on localhost port 8080 for development.
    
    You can change the port and allow remote connections by setting
    server.port or server.address on the command line.
    
    paver server.address=your.ip.address server.port=8000 start
    
    will allow remote connections (assuming you don't have a firewall
    blocking the connection) and start the server on port 8000.
    """
    # automatically install Dojo if it's not there already
    if not (options.dojo.destination / "dojo").exists():
        dojo()

    from bespin import config, controllers
    from paste.httpserver import serve

    options.order('server')

    config.set_profile('dev')

    if options.server.try_build:
        config.c.static_dir = (options.build_dir / "frontend").abspath()

    if options.server.dburl:
        config.c.dburl = options.server.dburl

    if options.server. async:
        config.c.async_jobs = True

    config_file = options.server.config_file
    if config_file.exists():
        info("Loading config: %s", config_file)
        code = compile(config_file.bytes(), config_file, "exec")
        exec code in {}

    config.activate_profile()
    port = int(options.port)
    serve(controllers.make_app(), options.address, port, use_threadpool=True)
def start():
    """Starts the BespinServer on localhost port 8080 for development.
    
    You can change the port and allow remote connections by setting
    server.port or server.address on the command line.
    
    paver server.address=your.ip.address server.port=8000 start
    
    will allow remote connections (assuming you don't have a firewall
    blocking the connection) and start the server on port 8000.
    """
    from bespin import config, controllers
    from paste.httpserver import serve

    options.order('server')

    config.set_profile('dev')

    if options.staticdir:
        config.c.static_dir = path(options.clientdir) / options.staticdir

    if options.server.dburl:
        config.c.dburl = options.server.dburl

    if options.server. async:
        config.c.async_jobs = True

    config.c.server_base_url = options.server_base_url

    config_file = options.server.config_file
    if config_file.exists():
        info("Loading config: %s", config_file)
        code = compile(config_file.bytes(), config_file, "exec")
        exec code in {}

    config.activate_profile()
    port = int(options.port)
    serve(controllers.make_app(), options.address, port, use_threadpool=True)
Ejemplo n.º 42
0
def start():
    """Starts the BespinServer on localhost port 8080 for development.
    
    You can change the port and allow remote connections by setting
    server.port or server.address on the command line.
    
    paver server.address=your.ip.address server.port=8000 start
    
    will allow remote connections (assuming you don't have a firewall
    blocking the connection) and start the server on port 8000.
    """
    from bespin import config, controllers
    from paste.httpserver import serve
    
    options.order('server')
    
    config.set_profile('dev')
    
    if options.staticdir:
        config.c.static_dir = path(options.clientdir) / options.staticdir
    
    if options.server.dburl:
        config.c.dburl = options.server.dburl
    
    if options.server.async:
        config.c.async_jobs = True
    
    config.c.server_base_url = options.server_base_url
    
    config_file = options.server.config_file
    if config_file.exists():
        info("Loading config: %s", config_file)
        code = compile(config_file.bytes(), config_file, "exec")
        exec code in {}
    
    config.activate_profile()
    port = int(options.port)
    serve(controllers.make_app(), options.address, port, use_threadpool=True)
def process_queue(args=None):
    log.info("Bespin queue worker")
    if args is None:
        args = sys.argv[1:]

    if args:
        config.set_profile(args.pop(0))
    else:
        config.set_profile("dev")
        config.c.async_jobs = True

    if args:
        config.load_pyconfig(args.pop(0))

    config.activate_profile()

    bq = config.c.queue
    log.debug("Queue: %s", bq)
    for qi in bq.read_queue("vcs"):
        log.info("Processing job %s", qi.id)
        log.debug("Message: %s", qi.message)
        qi.run()
        qi.done()
Ejemplo n.º 44
0
def process_queue(args=None):
    log.info("Bespin queue worker")
    if args is None:
        args = sys.argv[1:]

    if args:
        config.set_profile(args.pop(0))
    else:
        config.set_profile("dev")
        config.c.async_jobs=True

    if args:
        config.load_config(args.pop(0))

    config.activate_profile()

    bq = config.c.queue
    log.debug("Queue: %s", bq)
    for qi in bq.read_queue("vcs"):
        log.info("Processing job %s", qi.id)
        log.debug("Message: %s", qi.message)
        qi.run()
        qi.done()
Ejemplo n.º 45
0
def start_server(args=None):
    if args is None:
        args = sys.argv[1:]

    if args:
        mode = args.pop(0)
    else:
        mode = "dev"

    print("Bespin mobwrite worker (mode=" + mode + ")")  
    config.set_profile(mode)

    if args:
        config.load_pyconfig(args.pop(0))

    if mode == "dev":
        config.load_pyconfig("devconfig.py")

    config.activate_profile()

    app = WSGIMobWrite()
    app = db_middleware(app)

    serve(app, config.c.mobwrite_server_address, config.c.mobwrite_server_port, use_threadpool=True)
Ejemplo n.º 46
0
def editbespin(options):
    """Use Bespin to edit Bespin. This will change the given
    user's file location to the directory above Bespin, allowing
    you to edit Bespin (and any other projects you have
    in that directory)."""

    if not 'editbespin' in options or not options.editbespin.user:
        raise BuildFailure("You must specify a user with -u for this task.")

    user = options.editbespin.user

    from bespin import config
    from bespin import database, filesystem
    from sqlalchemy.orm.exc import NoResultFound

    config.set_profile("dev")
    config.activate_profile()
    session = config.c.session_factory()
    try:
        user = session.query(database.User).filter_by(username=user).one()
    except NoResultFound:
        raise BuildFailure("I couldn't find %s in the database. Sorry!" %
                           (user))

    location = path.getcwd().parent.abspath()
    user.file_location = location
    user.recompute_files()
    session.commit()
    bespinsettings_loc = location / "BespinSettings"
    if not bespinsettings_loc.exists():
        project = filesystem.get_project(user,
                                         user,
                                         "BespinSettings",
                                         create=True)
        project.install_template('usertemplate')
    info("User %s set up to access directory %s" % (user, location))
Ejemplo n.º 47
0
def setup_module(module):
    config.set_profile("test")
    config.activate_profile()
Ejemplo n.º 48
0
def setup_module(module):
    config.set_profile("test")
    config.activate_profile()