use same db in extension and python, start and stop oxd.py as needed
This commit is contained in:
parent
34f9b07d46
commit
9520b7bc7b
3 changed files with 27 additions and 14 deletions
|
@ -718,6 +718,7 @@ class OxControl(Resource):
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
db = 'dev.sqlite'
|
db = 'dev.sqlite'
|
||||||
|
db = sys.argv[1]
|
||||||
port = 2620
|
port = 2620
|
||||||
username = 'fix'
|
username = 'fix'
|
||||||
password = 'me'
|
password = 'me'
|
||||||
|
|
|
@ -9,7 +9,9 @@
|
||||||
const Cc = Components.classes;
|
const Cc = Components.classes;
|
||||||
const Ci = Components.interfaces;
|
const Ci = Components.interfaces;
|
||||||
|
|
||||||
|
Components.utils.import("resource://gre/modules/AddonManager.jsm");
|
||||||
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||||
|
|
||||||
Components.utils.import("resource://ox/utils.jsm");
|
Components.utils.import("resource://ox/utils.jsm");
|
||||||
|
|
||||||
var OxFFFactory =
|
var OxFFFactory =
|
||||||
|
@ -35,6 +37,8 @@ function OxFF() {
|
||||||
this._site = 'localhost';
|
this._site = 'localhost';
|
||||||
}
|
}
|
||||||
this.access();
|
this.access();
|
||||||
|
|
||||||
|
this._window.addEventListener("unload", function() { _this.logout() }, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
OxFF.prototype = {
|
OxFF.prototype = {
|
||||||
|
@ -148,6 +152,7 @@ OxFF.prototype = {
|
||||||
return this._access;
|
return this._access;
|
||||||
},
|
},
|
||||||
api: function(action, data, callback) {
|
api: function(action, data, callback) {
|
||||||
|
var _this = this;
|
||||||
if (typeof(data) == 'function') {
|
if (typeof(data) == 'function') {
|
||||||
callback = data;
|
callback = data;
|
||||||
data = {};
|
data = {};
|
||||||
|
@ -169,9 +174,7 @@ OxFF.prototype = {
|
||||||
.createInstance(Ci.nsIXMLHttpRequest);
|
.createInstance(Ci.nsIXMLHttpRequest);
|
||||||
|
|
||||||
req.addEventListener("error", function(e) {
|
req.addEventListener("error", function(e) {
|
||||||
//should check that it was infact not able to connect to server
|
|
||||||
_this.startDaemon();
|
_this.startDaemon();
|
||||||
//does this need a timeout?
|
|
||||||
ox.setTimeout(function() { _this.api(action, data, callback); }, 500);
|
ox.setTimeout(function() { _this.api(action, data, callback); }, 500);
|
||||||
}, false);
|
}, false);
|
||||||
req.addEventListener("load", function(e) {
|
req.addEventListener("load", function(e) {
|
||||||
|
@ -213,7 +216,7 @@ OxFF.prototype = {
|
||||||
},
|
},
|
||||||
logout: function(user) {
|
logout: function(user) {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
this.api('shutdown', function() {
|
this.api('stop', function() {
|
||||||
_this._user = null;
|
_this._user = null;
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
|
@ -223,14 +226,13 @@ OxFF.prototype = {
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|
||||||
addVolume: function(archive) {
|
addVolume: function() {
|
||||||
if(!this._access) {
|
if(!this._access) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//var volumes = this.getVolumes(domain);
|
|
||||||
const nsIFilePicker = Ci.nsIFilePicker;
|
const nsIFilePicker = Ci.nsIFilePicker;
|
||||||
var fp = Cc["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
|
var fp = Cc["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
|
||||||
fp.init(this._window, "Choose location of " + archive, nsIFilePicker.modeGetFolder);
|
fp.init(this._window, "Add Volume to " + this._site, nsIFilePicker.modeGetFolder);
|
||||||
fp.appendFilters(nsIFilePicker.filterAll);
|
fp.appendFilters(nsIFilePicker.filterAll);
|
||||||
var rv = fp.show();
|
var rv = fp.show();
|
||||||
if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) {
|
if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) {
|
||||||
|
@ -284,6 +286,12 @@ OxFF.prototype = {
|
||||||
q.executeStep();
|
q.executeStep();
|
||||||
},
|
},
|
||||||
startDaemon: function() {
|
startDaemon: function() {
|
||||||
|
var _this = this;
|
||||||
|
//if daemon is already running to not start it again
|
||||||
|
if(this._daemon && this._daemon.isRunning) {
|
||||||
|
this.debug('daemon is still starting up, not starting again');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
var osString = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime).OS;
|
var osString = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime).OS;
|
||||||
var daemon = "";
|
var daemon = "";
|
||||||
if (osString == "WINNT")
|
if (osString == "WINNT")
|
||||||
|
@ -295,16 +303,16 @@ OxFF.prototype = {
|
||||||
try {
|
try {
|
||||||
file.permissions = 0755;
|
file.permissions = 0755;
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
var process = Cc["@mozilla.org/process/util;1"].createInstance(Ci.nsIProcess);
|
_this._daemon = Cc["@mozilla.org/process/util;1"].createInstance(Ci.nsIProcess);
|
||||||
process.init(file);
|
_this._daemon.init(file);
|
||||||
var args = [];
|
var args = [ox.getDBFile().path];
|
||||||
process.run(false, args, args.length);
|
_this._daemon.runw(false, args, args.length);
|
||||||
}
|
}
|
||||||
Components.utils.import("resource://gre/modules/AddonManager.jsm");
|
|
||||||
AddonManager.getAddonByID(this.extensionID, function(addon) {
|
AddonManager.getAddonByID(this.extensionID, function(addon) {
|
||||||
if (addon.hasResource(daemon)) {
|
if (addon.hasResource('bin')) {
|
||||||
var resource = addon.getResourceURI(daemon);
|
var resource = addon.getResourceURI('bin');
|
||||||
var file = resource.QueryInterface(Ci.nsIFileURL).file.QueryInterface(Ci.nsILocalFile);
|
var file = resource.QueryInterface(Ci.nsIFileURL).file.QueryInterface(Ci.nsILocalFile);
|
||||||
|
file.append(daemon);
|
||||||
runDaemon(file);
|
runDaemon(file);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -7,10 +7,14 @@ const Cc = Components.classes;
|
||||||
const Ci = Components.interfaces;
|
const Ci = Components.interfaces;
|
||||||
|
|
||||||
let ox = {
|
let ox = {
|
||||||
getDB: function() {
|
getDBFile: function() {
|
||||||
var file = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties)
|
var file = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties)
|
||||||
.get("ProfD", Ci.nsIFile);
|
.get("ProfD", Ci.nsIFile);
|
||||||
file.append("OxFF.sqlite");
|
file.append("OxFF.sqlite");
|
||||||
|
return file;
|
||||||
|
},
|
||||||
|
getDB: function() {
|
||||||
|
var file = this.getDBFile();
|
||||||
var storageService = Cc["@mozilla.org/storage/service;1"].getService(Ci.mozIStorageService);
|
var storageService = Cc["@mozilla.org/storage/service;1"].getService(Ci.mozIStorageService);
|
||||||
var conn = storageService.openDatabase(file);
|
var conn = storageService.openDatabase(file);
|
||||||
conn.executeSimpleSQL("CREATE TABLE IF NOT EXISTS site (site varchar(1024) unique, access INT)");
|
conn.executeSimpleSQL("CREATE TABLE IF NOT EXISTS site (site varchar(1024) unique, access INT)");
|
||||||
|
|
Loading…
Reference in a new issue