[mirrorbrain-commits] [opensuse-svn] r6940 - in trunk/tools/download-redirector-v2/mirrordoctor: . mb

From: Novell Forge SVN <noreply_at_novell.com>
Date: Sun, 29 Mar 2009 16:55:20 -0600 (MDT)
Author: poeml
Date: 2009-03-29 16:55:18 -0600 (Sun, 29 Mar 2009)
New Revision: 6940

Modified:
   trunk/tools/download-redirector-v2/mirrordoctor/mb/files.py
   trunk/tools/download-redirector-v2/mirrordoctor/mirrordoctor.py
Log:
mb dirs:
- New subcommand for showing directories that the database contains.
  Useful to find out on which mirror certain directories were found, and
  thereby useful for tuning of scan exclude patterns.


Modified: trunk/tools/download-redirector-v2/mirrordoctor/mb/files.py
===================================================================
--- trunk/tools/download-redirector-v2/mirrordoctor/mb/files.py	2009-03-29 22:39:32 UTC (rev 6939)
+++ trunk/tools/download-redirector-v2/mirrordoctor/mb/files.py	2009-03-29 22:55:18 UTC (rev 6940)
@@ -92,3 +92,44 @@
     query = """SELECT mirr_del_byid(%d, (SELECT id FROM filearr WHERE path='%s'))""" \
                    % (mirror.id, path)
     conn.Server._connection.queryAll(query)
+
+
+def dir_ls(conn, segments = 1, mirror=None):
+    """Show distinct directory names, looking only on the first path components.
+
+    Manually, this could be done in the following way:
+    select distinct array_to_string((string_to_array(path, '/'))[0:2], '/') from filearr
+    """
+
+    query = """SELECT DISTINCT array_to_string(
+                                   (string_to_array(path, '/'))[0:%s],
+                                   '/') FROM filearr""" % segments
+
+    if mirror:
+        query += ' where %s = any(mirrors)' % mirror.id
+
+    result = conn.Server._connection.queryAll(query)
+    return result
+
+def dir_show_mirrors(conn, path):
+    """Show mirrors on which a certain directory path was found.
+    """
+
+    query = """select distinct(mirrors) from filearr where path like '%s%%'""" % path
+    result = conn.Server._connection.queryAll(query)
+
+    mirror_ids = []
+    for i in result:
+        i = i[0]
+        for mirror_id in i:
+            mirror_id = str(mirror_id)
+            if mirror_id not in mirror_ids:
+                mirror_ids.append(mirror_id)
+
+    if not mirror_ids:
+        return []
+    query = """select identifier from server where id in (%s)""" % ','.join(mirror_ids)
+    result = conn.Server._connection.queryAll(query)
+
+    return result
+

Modified: trunk/tools/download-redirector-v2/mirrordoctor/mirrordoctor.py
===================================================================
--- trunk/tools/download-redirector-v2/mirrordoctor/mirrordoctor.py	2009-03-29 22:39:32 UTC (rev 6939)
+++ trunk/tools/download-redirector-v2/mirrordoctor/mirrordoctor.py	2009-03-29 22:55:18 UTC (rev 6940)
@@ -792,6 +792,49 @@
             sys.exit('ACTION must be either ls, rm or add.')
 
 
+    @cmdln.option('-s', dest='segments', metavar='N', default=2,
+                  help='show up to N distinct path segments.')
+    @cmdln.option('-d', dest='dirpath', metavar='DIR',
+                  help='list mirrors on which DIR was found.')
+    def do_dirs(self, subcmd, opts, *args):
+        """${cmd_name}: show directories that are in the database
+
+        This subcommand is helpful when tuning scan excludes. You can
+        list the directories of all paths that have ended up in the database,
+        which is a good basis to define excludes, so the files can be eliminated
+        from the database.
+
+        Use -s N to show path components aggregated up to N segments.
+
+        Use -d PATH to show mirrors which host directories that match PATH*.
+
+        Examples for listing directories:
+          mb dirs 
+          mb dirs ftp.mirrorservice.org
+          mb dirs -s 3
+        Example for listing mirrors:
+          mb dirs -d distribution/11.1-
+
+        Usage:
+            mb dirs [OPTS] [MIRROR]
+        ${cmd_option_list}
+        """
+        
+        import mb.files
+
+        if args:
+            mirror = lookup_mirror(self, args[0])
+        else:
+            mirror = None
+
+        if opts.dirpath:
+            for i in mb.files.dir_show_mirrors(self.conn, opts.dirpath):
+                print i[0]
+        else:
+            for i in mb.files.dir_ls(self.conn, segments=opts.segments, mirror=mirror):
+                print i[0]
+
+
     @cmdln.option('-c', '--caption', metavar='STRING',
                   help='insert this string as table caption')
     @cmdln.option('-t', '--title', metavar='STRING',

_______________________________________________
Opensuse-svn mailing list
Opensuse-svn_at_forge.novell.com
http://forge.novell.com/mailman/listinfo/opensuse-svn


_______________________________________________
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 2009-03-29Z22:56:22

This archive was generated by hypermail 2.2.0 : 2009-07-10Z19:18:12 GMT