Beispiel #1
0
def vcs_error(qi, e):
    """Handles exceptions that come up during VCS operations.
    A message is added to the user's message queue."""
    log.debug("Handling VCS error: %s", e)
    s = database._get_session()
    user = qi.message['user']
    # if the user hadn't already been looked up, go ahead and pull
    # them out of the database
    if isinstance(user, basestring):
        user = User.find_user(user)
    else:
        s.add(user)

    # if we didn't find the user in the database, there's not much
    # we can do.
    if user:
        if isinstance(e, (FSException, main.UVCError)):
            # for exceptions that are our types, just display the
            # error message
            tb = str(e)
        else:
            # otherwise, it looks like a programming error and we
            # want more information
            tb = format_exc()
        message = dict(jobid=qi.id, output=tb, error=True)
        message['asyncDone'] = True
        retval = Message(user_id=user.id, message=simplejson.dumps(message))
        s.add(retval)
Beispiel #2
0
def vcs_error(qi, e):
    """Handles exceptions that come up during VCS operations.
    A message is added to the user's message queue."""
    log.debug("Handling VCS error: %s", e)
    s = database._get_session()
    user = qi.message['user']
    # if the user hadn't already been looked up, go ahead and pull
    # them out of the database
    if isinstance(user, basestring):
        user = User.find_user(user)
    else:
        s.add(user)
    
    # if we didn't find the user in the database, there's not much
    # we can do.
    if user:
        if isinstance(e, (FSException, main.UVCError)):
            # for exceptions that are our types, just display the
            # error message
            tb = str(e)
        else:
            # otherwise, it looks like a programming error and we
            # want more information
            tb = format_exc()
        message = dict(jobid=qi.id, output=tb, error=True)
        message['asyncDone'] = True
        retval = Message(user_id=user.id, message=simplejson.dumps(message))
        s.add(retval)
Beispiel #3
0
 def post_message(self):
     s = database._get_session()
     message_body = dict(jobid=self.qid, asyncDone=False, 
         output="%s %s" % (self.line_count, self.label))
     message = Message(user_id = self.user_id,
         message=simplejson.dumps(message_body))
     s.add(message)
     s.commit()
Beispiel #4
0
 def post_message(self):
     s = database._get_session()
     message_body = dict(jobid=self.qid,
                         asyncDone=False,
                         output="%s %s" % (self.line_count, self.label))
     message = Message(user_id=self.user_id,
                       message=simplejson.dumps(message_body))
     s.add(message)
     s.commit()
Beispiel #5
0
def clone_run(qi):
    """Runs the queued up clone job."""
    message = qi.message
    s = database._get_session()
    user = User.find_user(message['user'])
    message['user'] = user
    result = _clone_impl(**message)
    result.update(dict(jobid=qi.id, asyncDone=True))
    retvalue = Message(user_id=user.id, message=simplejson.dumps(result))
    s.add(retvalue)
    config.c.stats.incr('vcs_DATE')
Beispiel #6
0
def test_good_file_operations_from_web():
    _init_data()
    app.put("/file/at/bigmac/reqs", "Chewing gum wrapper")
    bigmac = get_project(macgyver, macgyver, "bigmac")
    fileobj = File(bigmac, "reqs")
    contents = str(fileobj.data)
    assert contents == "Chewing gum wrapper"

    s = _get_session()
    sel = EventLog.select().where(
        and_(EventLog.c.kind == 'filesave', EventLog.c.username == 'MacGyver'))
    result = s.connection().execute(sel).fetchall()
    assert len(result) == 1

    resp = app.get("/file/at/bigmac/reqs")
    assert resp.body == "Chewing gum wrapper"

    resp = app.get("/file/at/bigmac/reqs?mode=r")
    assert resp.body == "Chewing gum wrapper"

    resp = app.get("/file/list/bigmac/")
    data = simplejson.loads(resp.body)
    print data

    resp = app.get("/file/list/")
    data = simplejson.loads(resp.body)
    assert data == [{
        'name': 'BespinSettings/'
    }, {
        'name': 'SampleProject/'
    }, {
        'name': 'bigmac/'
    }]

    resp = app.get("/file/list/SampleProject/")
    data = simplejson.loads(resp.body)
    assert data[1]['name'] == 'index.html'

    resp = app.get("/file/list/bigmac/")
    assert resp.content_type == "application/json"
    data = simplejson.loads(resp.body)
    assert len(data) == 1
    data = data[0]
    assert data['name'] == 'reqs'
    assert data['size'] == 19
    assert data['created'].startswith("20")
    assert 'T' in data['created']
    assert data['modified'].startswith("20")
    assert 'T' in data['modified']

    app.delete("/file/at/bigmac/reqs")
    resp = app.get("/file/list/bigmac/")
    data = simplejson.loads(resp.body)
    assert data == []
def test_user_installed_plugins():
    _init_data()
    sfp = (path(__file__).dirname() / "plugindir").abspath() / "single_file_plugin1.js"
    sfp_content = sfp.text()
    response = app.put("/file/at/BespinSettings/plugins/MyPlugin.js", sfp_content)
    response = app.put("/file/at/BespinSettings/plugins/BiggerPlugin/package.json", "{}");
    response = app.put("/file/at/BespinSettings/plugins/BiggerPlugin/somedir/script.js", 
        "exports.foo = 1;\n")
    response = app.get("/plugin/register/user")
    assert response.content_type == "application/json"
    assert "MyPlugin" in response.body
    assert "BiggerPlugin" in response.body
    assert "file/at/BespinSettings/plugins/MyPlugin.js%3A" in response.body
    assert "EditablePlugin" not in response.body
    assert "file/at/BespinSettings/plugins/BiggerPlugin%3Asomedir/script.js" in response.body
    data = loads(response.body)
    md = data["metadata"]["BiggerPlugin"]
    assert md["resourceURL"] == "/server/file/at/BespinSettings/plugins/BiggerPlugin/resources/"
    
    response = app.put("/file/at/myplugins/EditablePlugin/package.json", "{}")
    response = app.put("/file/at/BespinSettings/pluginInfo.json", """{
"path": ["myplugins/"],
"ordering": ["EditablePlugin", "MyPlugin"],
"deactivated": { "EditablePlugin": true, "BiggerPlugin": true }
}""")

    response = app.get("/plugin/register/user")
    
    assert response.content_type == "application/json"
    assert "MyPlugin" in response.body
    assert "BiggerPlugin" in response.body
    assert "EditablePlugin" in response.body
        
    data = loads(response.body)
    assert len(data["metadata"]) == 3
    s = _get_session()
    sel = EventLog.select().where(EventLog.c.kind=='userplugin')
    result = s.connection().execute(sel).fetchall()
    assert len(result) == 2
    assert result[-1].details == '3'
    
    assert len(data["ordering"]) == 2
    assert data["ordering"] == ["EditablePlugin", "MyPlugin"]
    assert data["deactivated"] == dict(EditablePlugin=True, BiggerPlugin=True)
    
    response = app.get("/getscript/file/at/BespinSettings/plugins/MyPlugin.js%3A")
    assert response.content_type == "text/javascript"
    assert "someFunction" in response.body
    assert "tiki.module('MyPlugin:index', function" in response.body
    
    response = app.get("/getscript/file/at/BespinSettings/plugins/BiggerPlugin%3Asomedir/script.js")
    assert "tiki.module('BiggerPlugin:somedir/script', function" in response.body
    assert "tiki.script('BiggerPlugin:somedir/script.js')" in response.body
Beispiel #8
0
def rescan_project(qi):
    """Runs an asynchronous rescan of a project"""
    from bespin import database
    
    message = qi.message
    s = database._get_session()
    user = database.User.find_user(message['user'])
    project = get_project(user, user, message['project'])
    project.scan_files()
    retvalue = database.Message(user_id=user.id, message=simplejson.dumps(
            dict(asyncDone=True,
            jobid=qi.id, output="Rescan complete")))
    s.add(retvalue)
Beispiel #9
0
 def file_done(self):
     super(BespinOmniSync, self).file_done()
     if time.time() - self.last_display_time > 5:
         s = _get_session()
         message_body = dict(jobid=self.qid, asyncDone=False, 
             output="%s files and %s bytes copied" % (
                 self.file_counter, self.bytes_total))
         message = Message(user_id = self.user_id,
             message=dumps(message_body))
         s.add(message)
         s.commit()
         
         self.last_display_time = time.time()
Beispiel #10
0
def clone_run(qi):
    """Runs the queued up clone job."""
    message = qi.message
    s = database._get_session()
    user = User.find_user(message['user'])
    message['user'] = user
    
    # wrap the output in "output" in a new dictionary, because
    # the client will peel off one layer from this.
    result = dict(output=_clone_impl(qid=qi.id, **message))
    result.update(dict(jobid=qi.id, asyncDone=True))
    retvalue = Message(user_id=user.id, message=simplejson.dumps(result))
    s.add(retvalue)
    config.c.stats.incr('vcs_DATE')
Beispiel #11
0
def test_good_file_operations_from_web():
    _init_data()
    app.put("/file/at/bigmac/reqs", "Chewing gum wrapper")
    bigmac = get_project(macgyver, macgyver, "bigmac")
    fileobj = File(bigmac, "reqs")
    contents = str(fileobj.data)
    assert contents == "Chewing gum wrapper"
    
    s = _get_session()
    sel = EventLog.select().where(and_(EventLog.c.kind=='filesave', 
        EventLog.c.username=='MacGyver'))
    result = s.connection().execute(sel).fetchall()
    assert len(result) == 1
    
    resp = app.get("/file/at/bigmac/reqs")
    assert resp.body == "Chewing gum wrapper"
    
    resp = app.get("/file/at/bigmac/reqs?mode=r")
    assert resp.body == "Chewing gum wrapper"
    
    resp = app.get("/file/list/bigmac/")
    data = simplejson.loads(resp.body)
    print data
    
    resp = app.get("/file/list/")
    data = simplejson.loads(resp.body)
    assert data == [{'name' : 'BespinSettings/'},
                    {'name' : 'SampleProject/'}, 
                    {'name' : 'bigmac/'}]
    
    resp = app.get("/file/list/SampleProject/")
    data = simplejson.loads(resp.body)
    assert data[1]['name'] == 'index.html'
    
    resp = app.get("/file/list/bigmac/")
    assert resp.content_type == "application/json"
    data = simplejson.loads(resp.body)
    assert len(data) == 1
    data = data[0]
    assert data['name'] == 'reqs'
    assert data['size'] == 19
    assert data['created'].startswith("20")
    assert 'T' in data['created']
    assert data['modified'].startswith("20")
    assert 'T' in data['modified']
    
    app.delete("/file/at/bigmac/reqs")
    resp = app.get("/file/list/bigmac/")
    data = simplejson.loads(resp.body)
    assert data == []
Beispiel #12
0
    def file_done(self):
        super(BespinOmniSync, self).file_done()
        if time.time() - self.last_display_time > 5:
            s = _get_session()
            message_body = dict(jobid=self.qid,
                                asyncDone=False,
                                output="%s files and %s bytes copied" %
                                (self.file_counter, self.bytes_total))
            message = Message(user_id=self.user_id,
                              message=dumps(message_body))
            s.add(message)
            s.commit()

            self.last_display_time = time.time()
Beispiel #13
0
def clone_run(qi):
    """Runs the queued up clone job."""
    message = qi.message
    s = database._get_session()
    user = User.find_user(message['user'])
    message['user'] = user

    # wrap the output in "output" in a new dictionary, because
    # the client will peel off one layer from this.
    result = dict(output=_clone_impl(qid=qi.id, **message))
    result.update(dict(jobid=qi.id, asyncDone=True))
    retvalue = Message(user_id=user.id, message=simplejson.dumps(result))
    s.add(retvalue)
    config.c.stats.incr('vcs_DATE')
Beispiel #14
0
def rescan_project(qi):
    """Runs an asynchronous rescan of a project"""
    from bespin import database

    message = qi.message
    s = database._get_session()
    user = database.User.find_user(message["user"])
    project = get_project(user, user, message["project"])
    print "Got project %s from user %s" % (project.name, user.username)
    project.scan_files()
    print "Scan done"
    retvalue = database.Message(
        user_id=user.id, message=simplejson.dumps(dict(asyncDone=True, jobid=qi.id, output="Rescan complete"))
    )
    s.add(retvalue)
Beispiel #15
0
def deploy_impl(qi):
    """Executed via the worker queue to actually deploy the
    project."""
    message = qi.message
    kcpass = message['kcpass']
    options = _OptionHolder(message['options'])

    s = _get_session()

    user = User.find_user(message['user'])
    project = get_project(user, user, message['project'])
    pdo = ProjectDeploymentOptions.get(project)
    keychain = DeploymentKeyChain(user, kcpass)
    credentials = keychain.get_credentials_for_project(project)
    cwd = os.getcwd()

    keyfile = None

    options.username = credentials['username']

    if credentials['type'] == 'ssh':
        keyfile = TempSSHKeyFile()
        keyfile.store(credentials['ssh_public_key'],
                      credentials['ssh_private_key'])
        options.sshkey = keyfile.filename
    else:
        options.password = credentials['password']

    desturl = "sftp://%s/%s" % (quote(pdo.remote_host,
                                      safe=""), quote(pdo.remote_directory))

    try:
        os.chdir(project.location)
        log.debug("Computed destination URL: %s", desturl)
        log.debug("Running with options: %r", options)
        error, output = _launch_sync(qi.id, user.id, desturl, options)

        # there's an extra layer around the output that is
        # expected by the client
        result = dict(output=dict(output=output, error=error))

        result.update(dict(jobid=qi.id, asyncDone=True))
        retvalue = Message(user_id=user.id, message=dumps(result))
        s.add(retvalue)
    finally:
        if keyfile:
            keyfile.delete()
        os.chdir(cwd)
Beispiel #16
0
def deploy_impl(qi):
    """Executed via the worker queue to actually deploy the
    project."""
    message = qi.message
    kcpass = message['kcpass']
    options = _OptionHolder(message['options'])
    
    s = _get_session()
    
    user = User.find_user(message['user'])
    project = get_project(user, user, message['project'])
    pdo = ProjectDeploymentOptions.get(project)
    keychain = DeploymentKeyChain(user, kcpass)
    credentials = keychain.get_credentials_for_project(project)
    cwd = os.getcwd()
    
    keyfile = None
    
    options.username = credentials['username']

    if credentials['type'] == 'ssh':
        keyfile = TempSSHKeyFile()
        keyfile.store(credentials['ssh_public_key'], 
                      credentials['ssh_private_key'])
        options.sshkey = keyfile.filename
    else:
        options.password = credentials['password']
        
    desturl = "sftp://%s/%s" % (quote(pdo.remote_host, safe=""),
        quote(pdo.remote_directory))
        
    try:
        os.chdir(project.location)
        log.debug("Computed destination URL: %s", desturl)
        log.debug("Running with options: %r", options)
        error, output = _launch_sync(qi.id, user.id, desturl, options)
        
        # there's an extra layer around the output that is
        # expected by the client
        result = dict(output=dict(output=output, error=error))

        result.update(dict(jobid=qi.id, asyncDone=True))
        retvalue = Message(user_id=user.id, message=dumps(result))
        s.add(retvalue)
    finally:
        if keyfile:
            keyfile.delete()
        os.chdir(cwd)
Beispiel #17
0
def run_command_run(qi):
    """Runs the queued up run_command job."""
    message = qi.message
    s = database._get_session()
    user = User.find_user(message['user'])
    message['user'] = user
    message['project'] = get_project(user, user, message['project'])
    
    result = _run_command_impl(**message)
    result.update(dict(eventName="vcs:response",
                        asyncDone=True))
                        
    retvalue = Message(user_id=user.id, 
        message=simplejson.dumps(result))
    s.add(retvalue)
    config.c.stats.incr('vcs_DATE')
Beispiel #18
0
def deploy_error(qi, e):
    """Handles errors that come up during deployment."""
    log.debug("Handling deploy error: %s", e)
    s = _get_session()
    user = qi.message['user']
    # if the user hadn't already been looked up, go ahead and pull
    # them out of the database
    if isinstance(user, basestring):
        user = User.find_user(user)
    else:
        s.add(user)

    # if we didn't find the user in the database, there's not much
    # we can do.
    if user:
        # it looks like a programming error and we
        # want more information
        tb = format_exc()
        print "E:", tb
        message = dict(jobid=qi.id, output=dict(output=tb, error=True))
        message['asyncDone'] = True
        retval = Message(user_id=user.id, message=dumps(message))
        s.add(retval)
Beispiel #19
0
def deploy_error(qi, e):
    """Handles errors that come up during deployment."""
    log.debug("Handling deploy error: %s", e)
    s = _get_session()
    user = qi.message['user']
    # if the user hadn't already been looked up, go ahead and pull
    # them out of the database
    if isinstance(user, basestring):
        user = User.find_user(user)
    else:
        s.add(user)
    
    # if we didn't find the user in the database, there's not much
    # we can do.
    if user:
        # it looks like a programming error and we
        # want more information
        tb = format_exc()
        print "E:", tb
        message = dict(jobid=qi.id, output=dict(output=tb, 
            error=True))
        message['asyncDone'] = True
        retval = Message(user_id=user.id, message=dumps(message))
        s.add(retval)