Permalink
Browse files

Add lic/load_path option to make all lic/petals:load commands load re…

…lative to that path
  • Loading branch information...
devyn committed Mar 28, 2012
1 parent fc91498 commit 471f1f470bd53684758bdb87c01ec3d00ccd3411
Showing with 27 additions and 7 deletions.
  1. +25 −7 hub/Hub.js
  2. +2 −0 hub/HubConfig.js
View
@@ -5,6 +5,7 @@ var Server = require ("./Server.js");
var EventManager = require ("./EventManager.js");
var CommandManager = require ("./CommandManager.js");
var LocalLink = require ("./LocalLink.js");
+var FileUtils = require ("./FileUtils.js");
var Hub = function () {
this.petals = {};
@@ -101,16 +102,33 @@ Hub.prototype.disconnect_petal = function (petal_name, callback) {
};
Hub.prototype.load_petal = function (path, success, error) {
- try {
- var link = new LocalLink (this);
+ var def = require ("path").join (FileUtils.home (), ".lic/petals")

This comment has been minimized.

Show comment Hide comment
@dsamarin

dsamarin Mar 28, 2012

Member

Convention is to add var path = require ("path"); at the top of the file and reference path.

@dsamarin

dsamarin Mar 28, 2012

Member

Convention is to add var path = require ("path"); at the top of the file and reference path.

+ , self = this
+ ;
- if (success) link.once ("connect", success);
+ function load (path) {
+ try {
+ var link = new LocalLink (self);
- link.petal = new (require (path)) (link, {});
- } catch (e) {
- console.error ("[WARN] failed to load " + path + ": " + e);
- if (error) error (e);
+ if (success) link.once ("connect", success);
+
+ link.petal = new (require (path)) (link, {});
+ } catch (e) {
+ console.error ("[WARN] failed to load " + path + ": " + e);
+ if (error) error (e);
+ }
}
+
+ this.config.get ("lic/load_path", function (value) {
+ if (value) {
+ load (require ("path").resolve (value, path));
+ } else {
+ load (require ("path").resolve (def, path));
+ }
+ }, function () {
+ self.config.set ("lic/load_path", def);
+ load (require ("path").resolve (def, path));
+ });
};
Hub.prototype.shutdown = function () {
View
@@ -17,6 +17,8 @@ var HubConfig = function (event_manager) {
this.data.lic = {};
this.data.lic.interfaces = ["unix:/tmp/lic.sock"]; // List of network interfaces to accept connections on.
// Acceptable values: unix:<path>, tcp:<host>:<port>, tcp-ssl:<host>:<port>
+ this.data.lic.load_path = path.join (FileUtils.home (), "lic/petals");
+ // Directory where loadable petal-scripts can be found.
this.data.lic.password = ""; // If non-empty, out-of-process petals need to authenticate with the
// specified password to register.
this.data.lic.routes = {}; // The lic petal routing tree as "parent":["child1",...] pairs.

0 comments on commit 471f1f4

Please sign in to comment.