Author: poeml Date: Tue Apr 17 00:32:38 2012 New Revision: 8277 URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain?rev=8277&view=rev Log: mb db vacuum: - allow -q options to silence its output (issue #99) Modified: trunk/mb/mb.py trunk/mb/mb/dbmaint.py Modified: trunk/mb/mb.py URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain/trunk/mb/mb.py?rev=8277&r1=8276&r2=8277&view=diff ============================================================================== --- trunk/mb/mb.py (original) +++ trunk/mb/mb.py Tue Apr 17 00:32:38 2012 _at_@ -1229,6 +1229,9 @@ _at_cmdln.option('-n', '--dry-run', action='store_true', help='don\'t delete, but only show statistics.') + _at_cmdln.option('-q', '--quiet', dest='quietness', action='count', default=0, + help='Produce less output. ' + 'Can be given multiple times.') def do_db(self, subcmd, opts, *args): """${cmd_name}: perform database maintenance _at_@ -1253,9 +1256,9 @@ usage: - mb vacuum [-n] - mb sizes - mb shell + mb db vacuum [-q] [-n] + mb db sizes + mb db shell ${cmd_option_list} """ _at_@ -1264,8 +1267,8 @@ # this subcommand was renamed from "mb vacuum" to "mb db <action>" # let's keep the old way working if subcmd == 'vacuum': - mb.dbmaint.stale(self.conn) - mb.dbmaint.vacuum(self.conn) + mb.dbmaint.stale(self.conn, opts.quietness) + mb.dbmaint.vacuum(self.conn, opts.quietness) sys.exit(0) if len(args) < 1: _at_@ -1276,10 +1279,10 @@ mb.dbmaint.stats(self.conn) elif action == 'vacuum': if not opts.dry_run: - mb.dbmaint.stale(self.conn) - mb.dbmaint.vacuum(self.conn) + mb.dbmaint.stale(self.conn, opts.quietness) + mb.dbmaint.vacuum(self.conn, opts.quietness) else: - mb.dbmaint.stale(self.conn) + mb.dbmaint.stale(self.conn, opts.quietness) elif action == 'shell': mb.dbmaint.shell(self.config.dbconfig) Modified: trunk/mb/mb/dbmaint.py URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain/trunk/mb/mb/dbmaint.py?rev=8277&r1=8276&r2=8277&view=diff ============================================================================== --- trunk/mb/mb/dbmaint.py (original) +++ trunk/mb/mb/dbmaint.py Tue Apr 17 00:32:38 2012 _at_@ -1,5 +1,5 @@ -def stale(conn): +def stale(conn, quietness): """show statistics about stale files in the database""" n_file_total = conn.Filearr.select().count() _at_@ -10,14 +10,16 @@ n_file_stale = conn.Filearr._connection.queryAll(query)[0] - print 'Total files: %10d' % n_file_total - print 'Stale files (not on any mirror): %10d' % n_file_stale + if quietness < 1: + print 'Total files: %10d' % n_file_total + print 'Stale files (not on any mirror): %10d' % n_file_stale -def vacuum(conn): +def vacuum(conn, quietness): """delete stale file entries from the database""" - print 'Deleting stale files...' + if quietness < 1: + print 'Deleting stale files...' query = """DELETE FROM filearr WHERE id IN ( SELECT filearr.id FROM filearr _at_@ -26,7 +28,8 @@ )""" conn.Filearr._connection.query(query) - print 'Done.' + if quietness < 1: + print 'Done.' def stats(conn): _______________________________________________ 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.orgReceived on Mon Apr 16 2012 - 22:32:38 GMT
This archive was generated by hypermail 2.3.0 : Mon Apr 16 2012 - 22:47:03 GMT