From 3a57ac389f1dc383536058f8159af1ede631f2c9 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Mon, 9 Aug 2010 15:42:02 +0200 Subject: [PATCH] volumes have names --- OxFF/bin/oxd.py | 69 +++++++++++++++++++++++++----------- OxFF/components/OxFF.js | 59 +++++++----------------------- OxFF/components/nsIOxFF.xpt | Bin 425 -> 481 bytes OxFF/modules/oxff.jsm | 11 ++++++ src/nsIOxFF.idl | 12 ++++--- 5 files changed, 78 insertions(+), 73 deletions(-) diff --git a/OxFF/bin/oxd.py b/OxFF/bin/oxd.py index 4d3db1b..e099d04 100755 --- a/OxFF/bin/oxd.py +++ b/OxFF/bin/oxd.py @@ -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) diff --git a/OxFF/components/OxFF.js b/OxFF/components/OxFF.js index 445d548..909e456 100644 --- a/OxFF/components/OxFF.js +++ b/OxFF/components/OxFF.js @@ -120,7 +120,7 @@ OxFF.prototype = { return "NoAccess"; }, debug: function() { - var msg = "OxFF: "; + var msg = this.extensionID + ": "; for(var i=0;it&Q+YT*KzQx7zgQJ$$`5(6{T zSVlDn4`Lys9>`!MSrZnJMaUu+7$Odg5VIP}Qj3Z+^Ya*T^3yZ(7>ZJJ^UG4h@^eaa vQ-Pek#N5;{K?tunwZtbsIk5z&c(OBNh)@b+!%mPx4IOEER5+U{c3}C=0omcD`Tv||&UsO`e0A%}DxVbSfFf#Bo0OfZuCQM*p z11UVf)UY#w3&K9e2xDD<%U=h{b3o)DFtu>OR6J*Dn8d&g#9r!%mRZ2a*$Wa*`60vl#%qB{f_C diff --git a/OxFF/modules/oxff.jsm b/OxFF/modules/oxff.jsm index 18adc37..24c8065 100644 --- a/OxFF/modules/oxff.jsm +++ b/OxFF/modules/oxff.jsm @@ -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(); + }, }; diff --git a/src/nsIOxFF.idl b/src/nsIOxFF.idl index f612702..ef65e96 100644 --- a/src/nsIOxFF.idl +++ b/src/nsIOxFF.idl @@ -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(); };