diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-03-12 08:10:42 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-03-12 08:24:06 +0200 |
commit | 466fcd268e53743ca7414f1fe969a74cd0ac1ee1 (patch) | |
tree | 18056390e7f507c1f40b38edfaa4c218b840f0e7 /minimify | |
parent | 2a562fd5a7d935d3743f6746927236b40f891a5c (diff) | |
download | extrautils-466fcd268e53743ca7414f1fe969a74cd0ac1ee1.tar.gz |
drop old crap
Diffstat (limited to 'minimify')
-rwxr-xr-x | minimify | 71 |
1 files changed, 0 insertions, 71 deletions
diff --git a/minimify b/minimify deleted file mode 100755 index 36fc829..0000000 --- a/minimify +++ /dev/null @@ -1,71 +0,0 @@ -#!/usr/bin/python -# -# minimify -- compress file to smallest size -# Copyright (C) 2009 Lars Wirzenius -# -# 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 3 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, see <http://www.gnu.org/licenses/>. - - -import multiprocessing -import optparse -import os -import subprocess -import tempfile - - -COMPRESSORS = ( - ('gzip', '.gz'), - ('bzip2', '.bz2'), - ('xz', '.xz'), -) - - -def parse_args(): - parser = optparse.OptionParser() - options, filenames = parser.parse_args() - return options, filenames - - -def run_compressor(t): - compressor, filename, suffix, options = t - input_f = file(filename) - fd, name = tempfile.mkstemp(dir=os.path.dirname(filename)) - p = subprocess.Popen([compressor], stdin=input_f, stdout=fd) - p.communicate('') - os.close(fd) - if p.returncode: - raise Exception('Compression program %s failed' % p.returncode) - os.rename(name, filename + suffix) - return os.path.getsize(filename + suffix), filename + suffix - - -def compress(filename, options): - args = [(compressor, filename, suffix, options) - for compressor, suffix in COMPRESSORS] - pool = multiprocessing.Pool() - sizes = sorted(pool.map(run_compressor, args)) - for size, pathname in sizes[1:]: - os.remove(pathname) - return sizes[0] - - -def main(): - options, filenames = parse_args() - for filename in filenames: - size, name = compress(filename, options) - print size, name - - -if __name__ == "__main__": - main() |