list2form : gestion des erreurs et des petits fichiers (merci cgi.py…)
[progfou.git] / nautilus-scripts / Compression de PDF
CommitLineData
8b2df3bb
P
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# Copyright © 2016 AUF
4# Licence: GPL-2
5# Author: Progfou <jean-christophe.andre@auf.org>
6# Created: 2016-01-21
7# Debian-Depends: python (>= 2.6), ghostscript
8import sys
9import os
10from subprocess import Popen, PIPE
11
12for filename in os.getenv("NAUTILUS_SCRIPT_SELECTED_FILE_PATHS", "").split("\n"):
13 newdir = os.path.dirname(filename)
14 if newdir:
15 olddir = os.getcwd()
16 os.chdir(newdir)
17 filename = os.path.basename(filename)
18 root, ext = os.path.splitext(filename)
19 # FIXME: vérifier plutôt le type MIME
20 if ext.lower() != ".pdf":
21 continue
22 # première version
23 out_filename = root + "-opt1.pdf"
24 p = Popen(["/usr/bin/gs", "-dBATCH", "-dNOPAUSE", "-sDEVICE=pdfwrite",
25 "-q",
26 "-sOutputFile=" + out_filename, filename], stdout=PIPE)
27 # deuxième version
28 out_filename = root + "-opt2.pdf"
29 p = Popen(["/usr/bin/gs", "-dBATCH", "-dNOPAUSE", "-sDEVICE=pdfwrite",
30 "-dQUIET", "-dPDFSETTINGS=/ebook", "-dCompatibilityLevel=1.4",
31 "-sOutputFile=" + out_filename, filename], stdout=PIPE)
32 # retour au contexte initial
33 if newdir:
34 os.chdir(olddir)
35
36sys.exit(0)