Created
March 1, 2009 22:23
-
-
Save olleolleolle/72500 to your computer and use it in GitHub Desktop.
here is a weird idea added to Bespin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -r ff80ef4e11e9 backend/python/bespin/controllers.py | |
--- a/backend/python/bespin/controllers.py Sun Mar 01 19:42:53 2009 +0100 | |
+++ b/backend/python/bespin/controllers.py Sun Mar 01 23:22:44 2009 +0100 | |
@@ -191,6 +191,18 @@ | |
fm.close(user, project, path) | |
return response() | |
+ | |
+@expose(r'^/file/compile/(?P<path>.*)$', 'POST') | |
+def compilefile(request, response): | |
+ fm = request.file_manager | |
+ user = request.user | |
+ | |
+ project, path = _split_path(request) | |
+ project = fm.get_project(user, user, project) | |
+ | |
+ fm.compile(user, project, path) | |
+ return response() | |
+ | |
@expose(r'^/file/at/(?P<path>.*)$', 'DELETE') | |
def deletefile(request, response): | |
diff -r ff80ef4e11e9 backend/python/bespin/model.py | |
--- a/backend/python/bespin/model.py Sun Mar 01 19:42:53 2009 +0100 | |
+++ b/backend/python/bespin/model.py Sun Mar 01 23:22:44 2009 +0100 | |
@@ -738,6 +738,36 @@ | |
raise ConflictError("You already have a project with the name %s" % | |
new_name) | |
project.name = segments[0] | |
+ | |
+ def perform_compilation(self, user, project=None, path=None): | |
+ if not project or not path: | |
+ for fs in user.files[:]: | |
+ file_obj = fs.file | |
+ self.perform_compilation(user, file_obj.project, file_obj.name) | |
+ return | |
+ s = self.session | |
+ try: | |
+ file_obj = s.query(File).filter_by(name=path) \ | |
+ .filter_by(project=project).one() | |
+ except NoResultFound: | |
+ return | |
+ log.error("Hello from perform_compilation!") | |
+ | |
+ def compile(self, user, project, path): | |
+ """Compile the file for the given user""" | |
+ log.error("compiling using model.py compile!") | |
+ s = self.session | |
+ try: | |
+ file_obj = s.query(File).filter_by(name=path) \ | |
+ .filter_by(project=project).one() | |
+ except NoResultFound: | |
+ return | |
+ try: | |
+ fs = s.query(FileStatus).filter_by(user_id=user.id) \ | |
+ .filter_by(file_id=file_obj.id).one() | |
+ except NoResultFound: | |
+ return | |
+ self.perform_compilation(user, project, path) | |
def _find_common_base(member_names): | |
diff -r ff80ef4e11e9 frontend/js/bespin/client/server.js | |
--- a/frontend/js/bespin/client/server.js Sun Mar 01 19:42:53 2009 +0100 | |
+++ b/frontend/js/bespin/client/server.js Sun Mar 01 23:22:44 2009 +0100 | |
@@ -144,14 +144,14 @@ | |
// * {{{onSuccess}}} fires when the user is logged in | |
// * {{{notloggedin}}} fires when not logged in | |
// * {{{userconflict}}} fires when the username exists | |
- signup: function(user, pass, email, onSuccess, notloggedin, userconflict) { | |
+ signup: function(user, pass, email, onSuccess, notloggedin, userconflict) { | |
var url = "/register/new/" + user; | |
this.request('POST', url, | |
- "password=" + escape(pass) + "&email=" + escape(email), { | |
- call: onSuccess, on401: notloggedin, on409: userconflict, | |
- log: 'Login complete.' | |
- }); | |
- }, | |
+ "password=" + escape(pass) + "&email=" + escape(email), { | |
+ call: onSuccess, on401: notloggedin, on409: userconflict, | |
+ log: 'Login complete.' | |
+ }); | |
+ }, | |
// ** {{{ logout(callback) }}} | |
// | |
@@ -324,6 +324,20 @@ | |
var url = bespin.util.path.combine('/file/close', project, path); | |
this.request('POST', url, null, { call: callback }); | |
}, | |
+ | |
+ // ** {{{ compileFile(project, path, callback) }}} | |
+ // | |
+ // Compile the given file | |
+ // | |
+ // * {{{project}}} is the project to compile from | |
+ // * {{{path}}} is the path to compile at | |
+ // * {{{callback}}} fires after the file is compiled | |
+ compileFile: function(project, path, callback) { | |
+ console.debug("compileFile (server.js)", project, path, callback); | |
+ var path = path || ''; | |
+ var url = bespin.util.path.combine('/file/compile', project, path); | |
+ this.request('POST', url, null, { call: callback }); | |
+ }, | |
// == EDIT == | |
diff -r ff80ef4e11e9 frontend/js/bespin/editor/events.js | |
--- a/frontend/js/bespin/editor/events.js Sun Mar 01 19:42:53 2009 +0100 | |
+++ b/frontend/js/bespin/editor/events.js Sun Mar 01 23:22:44 2009 +0100 | |
@@ -144,3 +144,17 @@ | |
window.location.hash = "project=" + project + "&path=" + path; | |
}); | |
+// ** {{{ Event: bespin:editor:compile }}} ** | |
+// | |
+// Compiles current sketch file (Arduino) | |
+bespin.subscribe("bespin:editor:compile", function(event) { | |
+ //console.log("events.js: bespin:editor:compile", event); | |
+ var filename = event.filename || _editSession.path; // default to current page | |
+ var project = event.project || _editSession.project; | |
+ | |
+ _server.compileFile(project, filename, function() { | |
+ bespin.publish("bespin:editor:compiledfile", { filename: filename }); // unused | |
+ | |
+ bespin.publish("bespin:cmdline:showinfo", { msg: 'Compiled file: ' + filename }); | |
+ }); | |
+}); | |
diff -r ff80ef4e11e9 frontend/js/bespin/events.js | |
--- a/frontend/js/bespin/events.js Sun Mar 01 19:42:53 2009 +0100 | |
+++ b/frontend/js/bespin/events.js Sun Mar 01 23:22:44 2009 +0100 | |
@@ -253,6 +253,8 @@ | |
}); | |
}); | |
+ | |
+ | |
// ** {{{ Event: bespin:directory:create }}} ** | |
// | |
// Create a new directory |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment