#! /usr/bin/env python # # Copyright (C) 2022 by the Free Software Foundation, Inc. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, # USA. # """A default install of Mailman will include running Mailman's cron/nightly_gzip script to gzip the periodic *.txt mbox files to corresponding *.txt.gz files. This uses extra space for the *.txt.gz files and the .txt files must also be kept as they are the ones updated with new posts. Also, the gzipped files are only up to date as of the last nightly_gzip run. The only reason for gzipping these files is to save bandwidth when downloading, but these days, that is not significant, so I recommend not running nightly_gzip which will stop creating new gzipped files, and running this script once to remove any existing gzipped files. This script will go through each list's pipermail archive and everywhere there is a .txt.gz file with a corresponding .txt file, it removes the .txt.gz file, and if any are removed, rebuilds the index.html file. Save this script in Mailman's bin/ directory as remove_gzip and run it with bin/remove_gzip LIST1 LIST2 ... to do the named lists. If no list names are given, it does all lists. """ import os import sys import paths from Mailman.Archiver.HyperArch import HyperArchive from Mailman.Errors import MMUnknownListError from Mailman.MailList import MailList from Mailman.Utils import list_names if len(sys.argv) == 1: names = list_names() else: names = sys.argv[1:] if '-h' in names or '--help' in names: print __doc__ sys.exit() for list in names: try: mlist = MailList(list) except MMUnknownListError: print >> sys.stderr, 'No such list: ' + list continue arch = HyperArchive(mlist) dir = arch.basedir changed = False try: for name in os.listdir(dir): if name.endswith('.txt.gz'): txt_name = name[:-3] if os.path.isfile(os.path.join(dir, txt_name)): os.remove(os.path.join(dir, name)) changed = True if changed: arch.write_TOC() finally: mlist.Unlock()