Author: poeml Date: 2009-03-01 14:26:07 -0700 (Sun, 01 Mar 2009) New Revision: 6637 Modified: trunk/tools/download-redirector-v2/mirrordoctor/mb/core.py trunk/tools/download-redirector-v2/mirrordoctor/mb/files.py trunk/tools/download-redirector-v2/mirrordoctor/mirrordoctor.py Log: mb tool: - adjust "mb file [ls|add|rm]" and "mb delete" to the array-based database scheme Modified: trunk/tools/download-redirector-v2/mirrordoctor/mb/core.py =================================================================== --- trunk/tools/download-redirector-v2/mirrordoctor/mb/core.py 2009-03-01 21:21:26 UTC (rev 6636) +++ trunk/tools/download-redirector-v2/mirrordoctor/mb/core.py 2009-03-01 21:26:07 UTC (rev 6637) @@ -7,3 +7,13 @@ #return '%s:\n%s' % (self.name, '\n'.join(self.files)) return '%-45s: %6s files' % (self.name, int(len(self.files))) + +def delete_mirror(conn, mirror): + m = conn.Server.select(conn.Server.q.identifier == mirror)[0] + + query = """SELECT mirr_del_byid(%d, id) FROM filearr WHERE %s = ANY(mirrors)""" \ + % (m.id, m.id) + conn.Server._connection.queryAll(query) + + #self.conn.Server.delete(m.id) + Modified: trunk/tools/download-redirector-v2/mirrordoctor/mb/files.py =================================================================== --- trunk/tools/download-redirector-v2/mirrordoctor/mb/files.py 2009-03-01 21:21:26 UTC (rev 6636) +++ trunk/tools/download-redirector-v2/mirrordoctor/mb/files.py 2009-03-01 21:26:07 UTC (rev 6637) @@ -1,5 +1,6 @@ from sqlobject.sqlbuilder import AND + def has_file(conn, path, mirror_id): """check if file 'path' exists on mirror 'mirror_id' by looking at the database. @@ -14,18 +15,10 @@ pattern = False oprtr = '=' - query = 'SELECT path \ - FROM file \ - LEFT JOIN file_server \ - ON file.id = file_server.fileid \ - WHERE file_server.serverid = %s \ - AND file.path %s \'%s\' \ - ORDER BY file.path' \ - % (mirror_id, oprtr, path) + query = 'SELECT mirr_hasfile_byname(%s, %s)' \ + % (mirror_id, path) + rows = conn.Server._connection.queryAll(query) - - rows = conn.FileServer._connection.queryAll(query) - return len(rows) > 0 @@ -48,7 +41,7 @@ return found_all -def ls(conn, path, mirror = None): +def ls(conn, path): if path.find('*') >= 0 or path.find('%') >= 0: pattern = True oprtr = 'like' @@ -57,34 +50,17 @@ pattern = False oprtr = '=' - if mirror: - query = 'SELECT server.identifier, server.country, server.region, \ - server.score, server.baseurl, server.enabled, \ - server.status_baseurl, file.path \ - FROM file \ - LEFT JOIN file_server \ - ON file.id = file_server.fileid \ - LEFT JOIN server \ - ON file_server.serverid = server.id \ - WHERE file.path %s \'%s\' \ - AND file_server.serverid = %s \ - ORDER BY server.region, server.country, server.score DESC' \ - % (oprtr, path, mirror.id) - else: - query = 'SELECT server.identifier, server.country, server.region, \ - server.score, server.baseurl, server.enabled, \ - server.status_baseurl, file.path \ - FROM file \ - LEFT JOIN file_server \ - ON file.id = file_server.fileid \ - LEFT JOIN server \ - ON file_server.serverid = server.id \ - WHERE file.path %s \'%s\' \ - ORDER BY server.region, server.country, server.score DESC' \ - % (oprtr, path) + query = 'SELECT server.identifier, server.country, server.region, \ + server.score, server.baseurl, server.enabled, \ + server.status_baseurl, filearr.path \ + FROM filearr \ + LEFT JOIN server \ + ON server.id = ANY(filearr.mirrors) \ + WHERE filearr.path %s \'%s\' \ + ORDER BY server.region, server.country, server.score DESC' \ + % (oprtr, path) + rows = conn.Server._connection.queryAll(query) - rows = conn.FileServer._connection.queryAll(query) - files = [] # ugly. Really need to let an ORM do this. for i in rows: @@ -107,39 +83,12 @@ def add(conn, path, mirror): - files = conn.File.select(conn.File.q.path==path) - if files.count() == 0: - f = conn.File(path = path) - fileid = f.id - else: - fileid = list(files)[0].id + query = """SELECT mirr_add_bypath(%d, '%s')""" \ + % (mirror.id, path) + conn.Server._connection.queryAll(query) - relations = conn.FileServer.select(AND(conn.FileServer.q.fileid == fileid, - conn.FileServer.q.serverid == mirror.id)) - if relations.count() == 0: - # this doesn't work because the table doesn't have a primary key 'id'... - # (our primary Key consists only of a number of columns) - #import datetime - #fs = conn.FileServer(fileid = f.id, - # serverid = mirror.id, - # pathMd5 = b64_md5(path), - # timestampScanner = datetime.datetime.now()) - #print fs - - query = """INSERT INTO file_server SET fileid=%d, serverid=%d""" \ - % (fileid, mirror.id) - conn.FileServer._connection.queryAll(query) - else: - print 'already exists' - - def rm(conn, path, mirror): - fileobj = conn.File.select(conn.File.q.path==path) - fileid = list(fileobj)[0].id - print fileid - query = """DELETE FROM file_server WHERE serverid=%s AND fileid=%s""" \ - % (mirror.id, fileid) - print query - print conn.FileServer._connection.queryAll(query) - + query = """SELECT mirr_del_byid(%d, (SELECT id FROM filearr WHERE path='%s'))""" \ + % (mirror.id, path) + conn.Server._connection.queryAll(query) Modified: trunk/tools/download-redirector-v2/mirrordoctor/mirrordoctor.py =================================================================== --- trunk/tools/download-redirector-v2/mirrordoctor/mirrordoctor.py 2009-03-01 21:21:26 UTC (rev 6636) +++ trunk/tools/download-redirector-v2/mirrordoctor/mirrordoctor.py 2009-03-01 21:26:07 UTC (rev 6637) @@ -503,9 +503,8 @@ if not identifier: sys.exit('need to specify identifier') - moribund = self.conn.Server.select(self.conn.Server.q.identifier == identifier)[0] - self.conn.FileServer.deleteBy(serverid = moribund.id) - self.conn.Server.delete(moribund.id) + import mb.core + mb.core.delete_mirror(self.conn, identifier) @cmdln.option('-C', '--comment', metavar='ARG', @@ -715,16 +714,17 @@ mirror = None if action == 'ls': - rows = mb.files.ls(self.conn, path, mirror = mirror) + rows = mb.files.ls(self.conn, path) for row in rows: - print '%s %s %4d %s %s %-30s %s%s' % \ - (row['region'].lower(), row['country'].lower(), - row['score'], - row['enabled'] == 1 and 'ok ' or 'disabled', - row['status_baseurl'] == 1 and 'ok ' or 'dead', - row['identifier'], - row['baseurl'], row['path']) + if not mirror or (str(mirror.identifier) == row['identifier']): + print '%s %s %4d %s %s %-30s %s%s' % \ + (row['region'].lower(), row['country'].lower(), + row['score'], + row['enabled'] == 1 and 'ok ' or 'disabled', + row['status_baseurl'] == 1 and 'ok ' or 'dead', + row['identifier'], + row['baseurl'], row['path']) elif action == 'add': mb.files.add(self.conn, path, mirror) _______________________________________________ Opensuse-svn mailing list Opensuse-svn_at_forge.novell.com http://forge.novell.com/mailman/listinfo/opensuse-svn _______________________________________________ mirrorbrain-commits mailing list Note: To remove yourself from this list, send a mail with the content unsubscribe to the address mirrorbrain-commits-request_at_mirrorbrain.orgReceived on 2009-03-01Z21:26:30
This archive was generated by hypermail 2.2.0 : 2009-07-10Z19:18:11 GMT