volumes have names

This commit is contained in:
j 2010-08-09 15:42:02 +02:00
parent c6e8ae8a37
commit 3a57ac389f
5 changed files with 78 additions and 73 deletions

View file

@ -301,11 +301,12 @@ class Database(object):
'''CREATE TABLE IF NOT EXISTS volume (
site varchar(1024),
user varchar(1024),
name varchar(1024),
path varchar(1024),
updated INT,
created INT,
updating INT,
UNIQUE(site, user, path))''',
UNIQUE(site, user, name))''',
'''CREATE TABLE IF NOT EXISTS derivative (
oshash varchar(16),
name varchar(1024),
@ -358,7 +359,7 @@ class Database(object):
def files(self, site, user, volume, since=None):
conn, c = self.conn()
c.execute('SELECT path from volume where site=? AND user=? AND path=?', (site, user, volume))
c.execute('SELECT path from volume where site=? AND user=? AND name=?', (site, user, volume))
prefix = None
for row in c:
prefix = row[0]
@ -512,27 +513,45 @@ class Database(object):
c.execute('UPDATE file SET deleted=? WHERE path=?', (deleted, f))
conn.commit()
def add_volume(self, site, user, path):
def set_location(self, site, user, name, path):
conn, c = self.conn()
path = os.path.normpath(path)
created = time.mktime(time.localtime())
t = (site, user, path, created, created)
#FIXME: check if site/name exists or deal with error here
c.execute(u'INSERT INTO volume values (?, ?, ?, ?, ?, 0)', t)
if name in self.volumes(site, user):
t = (path, site, user, name)
c.execute(u'UPDATE volume SET path=? WHERE site=? AND user=? and name=?', t)
else:
created = time.mktime(time.localtime())
t = (site, user, name, path, created, created)
#FIXME: check if site/name exists or deal with error here
c.execute(u'INSERT INTO volume values (?, ?, ?, ?, ?, ?, 0)', t)
conn.commit()
def remove_volume(self, site, user, name):
conn, c = self.conn()
c.execute('DELETE FROM volume WHERE site=? AND user=? AND name=?', [site, user, name])
conn.commit()
#fixme, files could be still used by sub volumes
#c.execute('DELETE FROM file WHERE path LIKE ?', ["%s%%"%path])
def rename_volume(self, site, user, name, new_name):
conn, c = self.conn()
t = (new_name, site, user, name)
c.execute(u'UPDATE volume SET name=? WHERE site=? AND user=? and name=?', t)
conn.commit()
def volumes(self, site, user):
conn, c = self.conn()
sql = 'SELECT path FROM volume WHERE site=? AND user=? ORDER BY path';
sql = 'SELECT name, path FROM volume WHERE site=? AND user=? ORDER BY name';
c.execute(sql, [site, user])
volumes = {}
for row in c:
path = row[0]
volumes[path] = {}
name = row[0]
path = row[1]
volumes[name] = {}
if os.path.exists(path):
volumes[path]['available'] = True
volumes[name]['available'] = True
else:
volumes[path]['available'] = False
volumes[name]['available'] = False
return volumes
def update_volumes(self, site, user):
@ -556,13 +575,6 @@ class Database(object):
(updated, site, user, '%s%%'%path))
conn.commit()
def remove_volume(self, site, user, name):
conn, c = self.conn()
c.execute('DELETE FROM volume WHERE site=? AND user=? AND name=?', [site, user, name])
conn.commit()
#fixme, files could be still used by sub volumes
#c.execute('DELETE FROM file WHERE path LIKE ?', ["%s%%"%path])
#web
def json_response(request, data):
request.headers['Content-Type'] = 'text/javascript'
@ -606,17 +618,32 @@ class OxControl(Resource):
return args
if request.path == '/add_volume':
args = required_args('site', 'user', 'path')
args = required_args('site', 'user', 'name', 'path')
self.db.add_volume(**args)
response = {'status': 'ok'}
return json_response(request, response)
if request.path == '/set_location':
args = required_args('site', 'user', 'name', 'path')
self.db.set_location(**args)
response = {'status': 'ok'}
return json_response(request, response)
if request.path == '/remove_volume':
args = required_args('site', 'user', 'path')
args = required_args('site', 'user', 'name')
self.db.remove_volume(**args)
response = {'status': 'ok'}
return json_response(request, response)
if request.path == '/rename_volume':
args = required_args('site', 'user', 'name', 'new_name')
if args['name'] in self.db.volumes(args['site'], args['user']):
self.db.rename_volume(**args)
response = {'status': 'ok'}
else:
response = {'status': '404'}
return json_response(request, response)
if request.path == '/volumes':
args = required_args('site', 'user')
response = self.db.volumes(**args)

View file

@ -120,7 +120,7 @@ OxFF.prototype = {
return "NoAccess";
},
debug: function() {
var msg = "OxFF: ";
var msg = this.extensionID + ": ";
for(var i=0;i<arguments.length;i++) {
msg += arguments[i];
if(i+1<arguments.length)
@ -245,43 +245,39 @@ OxFF.prototype = {
this.api('update', callback.callback);
return true;
},
addVolume: function() {
setLocation: function(name) {
if(!this._access) {
return false;
}
const nsIFilePicker = Ci.nsIFilePicker;
var fp = Cc["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
fp.init(this._window, "Add Volume to " + this._site, nsIFilePicker.modeGetFolder);
fp.init(this._window, "Set Locatin of "+name+" for " + this._site, nsIFilePicker.modeGetFolder);
fp.appendFilters(nsIFilePicker.filterAll);
var rv = fp.show();
if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) {
var new_location = fp.file.path;
this.api('add_volume', {'path': new_location}, function(result) {});
this.api('set_location', {'name': name, 'path': new_location}, function(result) {});
return true;
}
return false;
},
removeVolume: function(name) {
return this.api('remove_volume', {'name': name});
},
renameVolume: function(name, new_name) {
return this.api('rename_volume', {'name': name, 'new_name': new_name});
},
volumes: function(callback) {
return this.api('volumes', callback.callback);
},
//private functions
permitAccess: function() {
this._access = true;
var conn = oxff.getDB();
var q = conn.createStatement("INSERT OR REPLACE INTO site values (:site, 1)");
q.params.site = this._site;
q.executeStep();
q.finalize();
oxff.access(this._site, this._access);
},
denyAccess: function() {
this._access = false;
var conn = oxff.getDB();
var q = conn.createStatement("INSERT OR REPLACE INTO site values (:site, 0)");
q.params.site = this._site;
q.executeStep();
q.finalize();
oxff.access(this._site, this._access);
},
startDaemon: function() {
var _this = this;
@ -315,37 +311,6 @@ OxFF.prototype = {
}
});
},
getFormatInfo: function(filename, callback) {
var that = this;
var get_json = function(data) {
var json = {"format": "unknown"};
try {
json = JSON.parse(data);
} catch(e) {
json = {"format": "unknown"};
}
var source_file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
source_file.initWithPath(filename);
// Try to determine the MIME type of the file
//json.contentType = that.getMimeType(source_file);
return json;
}
var info_callback = function(data) {
callback(get_json(data));
}
var options = [filename, '--info'];
if (callback) {
ox.subprocess(this.bin('ffmpeg2theora'), options, callback);
return;
}
data = ox.subprocess(this.bin('ffmpeg2theora'), options, false);
return get_json(data);
},
bin: function(cmd) {
this._cmd_name = '/usr/local/bin/_cmd_';
return this._cmd_name.replace('_cmd_', cmd);
},
}
//4.0 only
var NSGetFactory = XPCOMUtils.generateNSGetFactory([OxFF]);

Binary file not shown.

View file

@ -40,5 +40,16 @@ let oxff = {
q.executeStep();
q.finalize();
},
access: function(site, access) {
var conn = oxff.getDB();
var q = conn.createStatement("INSERT OR REPLACE INTO site values (:site, :access)");
q.params.site = site;
if (access)
q.params.access = 1;
else
q.params.access = 0;
q.executeStep();
q.finalize();
},
};

View file

@ -16,15 +16,17 @@ interface nsIOxFF : nsISupports
readonly attribute string version;
boolean login(in AString user);
boolean addVolume();
string import();
float progress(in AString oshash);
boolean access([optional] in boolean request);
boolean logout();
string volumes(in oxICallback callback);
boolean setLocation(in AString name);
boolean renameVolume(in AString name, in AString new_name);
boolean removeVolume(in AString name);
boolean update(in oxICallback callback);
string volumes(in oxICallback callback);
boolean files(in AString volume, in oxICallback callback);
boolean get(in AString oshash, in AString media, in oxICallback callback);
boolean extract(in AString oshash, in AString media, in oxICallback callback);
boolean logout();
};