[mirrorbrain-commits] r8036 - in /trunk/mirrordoctor: mb/conn.py mb/core.py mirrordoctor.py

From: <poeml_at_mirrorbrain.org>
Date: Mon, 19 Apr 2010 21:48:43 -0000
Author: poeml
Date: Mon Apr 19 23:48:41 2010
New Revision: 8036

URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain?rev=8036&view=rev
Log:
mb list:
- implement option -N/--number-of-files, which displays the number of files
  that a mirror is known to have
- using new stored procedure mirr_get_nfiles via mb.core.mirror_get_nfiles,
  and create it if migrating from < 2.13.0

Modified:
    trunk/mirrordoctor/mb/conn.py
    trunk/mirrordoctor/mb/core.py
    trunk/mirrordoctor/mirrordoctor.py

Modified: trunk/mirrordoctor/mb/conn.py
URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain/trunk/mirrordoctor/mb/conn.py?rev=8036&r1=8035&r2=8036&view=diff
==============================================================================
--- trunk/mirrordoctor/mb/conn.py (original)
+++ trunk/mirrordoctor/mb/conn.py Mon Apr 19 23:48:41 2010
_at_@ -175,6 +175,7 @@
             # XXX This feels like being totally the wrong place for a database migration.
             #     maybe a separate module with upgrade procedures to be run would be better.
             #     The main point is that this is a migration that we want to happen fully automatically.
+            # added 2.12.x -> 2.13.0
             print >>sys.stderr
             print >>sys.stderr, '>>> A database table for hashes does not exit. Creating...'
             query = """
_at_@ -214,6 +215,19 @@
               FROM hash;
             """
             Filearr._connection.query(query)
+            # XXX and another thing that should not happen here, but in an
+            # "upgrade" module (that can be called at will)
+            # added 2.12.x -> 2.13.0
+            query = """
+            CREATE OR REPLACE FUNCTION mirr_get_nfiles(integer) RETURNS bigint AS '
+                SELECT count(*) FROM filearr WHERE $1 = ANY(mirrors)
+            ' LANGUAGE 'SQL';
+
+            CREATE OR REPLACE FUNCTION mirr_get_nfiles(text) RETURNS bigint AS '
+                SELECT count(*) FROM filearr WHERE (SELECT id from server where identifier = $1) = ANY(mirrors)
+            ' LANGUAGE 'SQL';
+            """
+            Filearr._connection.query(query)
             print >>sys.stderr, '>>> Done.'
             print >>sys.stderr 
             # now try again

Modified: trunk/mirrordoctor/mb/core.py
URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain/trunk/mirrordoctor/mb/core.py?rev=8036&r1=8035&r2=8036&view=diff
==============================================================================
--- trunk/mirrordoctor/mb/core.py (original)
+++ trunk/mirrordoctor/mb/core.py Mon Apr 19 23:48:41 2010
_at_@ -11,6 +11,7 @@
 
 
 def delete_mirror(conn, mirror):
+    """delete a mirror by specifying its (exact) identifier string)"""
     try:
         m = conn.Server.select(conn.Server.q.identifier == mirror)[0]
     except IndexError:
_at_@ -22,3 +23,8 @@
 
     conn.Server.delete(m.id)
 
+
+def mirror_get_nfiles(conn, mirror):
+    query = """SELECT mirr_get_nfiles(%d)""" % (mirror.id)
+    return conn.Server._connection.queryAll(query)[0]
+

Modified: trunk/mirrordoctor/mirrordoctor.py
URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain/trunk/mirrordoctor/mirrordoctor.py?rev=8036&r1=8035&r2=8036&view=diff
==============================================================================
--- trunk/mirrordoctor/mirrordoctor.py (original)
+++ trunk/mirrordoctor/mirrordoctor.py Mon Apr 19 23:48:41 2010
_at_@ -212,6 +212,8 @@
             print s
 
 
+    _at_cmdln.option('--number-of-files', '-N', action='store_true',
+                        help='display number of files the mirror is known to have')
     _at_cmdln.option('--prefix-only', action='store_true',
                         help='display whether the mirror is configured to handle only its network prefix')
     _at_cmdln.option('--as-only', action='store_true',
_at_@ -295,6 +297,9 @@
                 s.append('as_only=%s' % mirror.asOnly)
             if opts.prefix_only:
                 s.append('prefix_only=%s' % mirror.prefixOnly)
+            if opts.number_of_files:
+                import mb.core
+                s.append('nfiles=%s' % mb.core.mirror_get_nfiles(self.conn, mirror))
             s = ' '.join(s)
 
             if opts.show_disabled:




_______________________________________________
mirrorbrain-commits mailing list
Archive: http://mirrorbrain.org/archive/mirrorbrain-commits/

Note: To remove yourself from this list, send a mail with the content
 	unsubscribe
to the address mirrorbrain-commits-request_at_mirrorbrain.org
Received on Mon Apr 19 2010 - 21:48:45 GMT

This archive was generated by hypermail 2.3.0 : Mon Feb 20 2012 - 23:47:04 GMT