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;i