mirror of
https://github.com/Kilian/Trimage.git
synced 2026-01-26 10:08:40 -05:00
add quiet and verbose modes to commandline
This commit is contained in:
parent
17fae20713
commit
24557b580f
1 changed files with 19 additions and 7 deletions
26
trimage.py
26
trimage.py
|
|
@ -17,8 +17,9 @@ DEBUG = True
|
||||||
#init imagelist
|
#init imagelist
|
||||||
imagelist = []
|
imagelist = []
|
||||||
|
|
||||||
# show application on load (or not if there are command line options)
|
# defaults
|
||||||
showapp = True
|
showapp = True
|
||||||
|
verbose = True
|
||||||
|
|
||||||
|
|
||||||
class StartQT4(QMainWindow):
|
class StartQT4(QMainWindow):
|
||||||
|
|
@ -62,11 +63,19 @@ class StartQT4(QMainWindow):
|
||||||
parser = OptionParser(version="%prog " + VERSION,
|
parser = OptionParser(version="%prog " + VERSION,
|
||||||
description="GUI front-end to compress png and jpg images via "
|
description="GUI front-end to compress png and jpg images via "
|
||||||
"optipng, advpng and jpegoptim")
|
"optipng, advpng and jpegoptim")
|
||||||
|
|
||||||
|
parser.set_defaults(verbose=True)
|
||||||
|
parser.add_option("-v", "--verbose", action="store_true",
|
||||||
|
dest="verbose", help="Verbose mode (default)")
|
||||||
|
parser.add_option("-q", "--quiet", action="store_false",
|
||||||
|
dest="verbose", help="Quiet mode")
|
||||||
|
|
||||||
parser.add_option("-f", "--file", action="store", type="string",
|
parser.add_option("-f", "--file", action="store", type="string",
|
||||||
dest="filename", help="compresses image and exit")
|
dest="filename", help="compresses image and exit")
|
||||||
parser.add_option("-d", "--directory", action="store", type="string",
|
parser.add_option("-d", "--directory", action="store", type="string",
|
||||||
dest="directory", help="compresses images in directory and exit", )
|
dest="directory", help="compresses images in directory and exit", )
|
||||||
|
|
||||||
|
|
||||||
options, args = parser.parse_args()
|
options, args = parser.parse_args()
|
||||||
|
|
||||||
# send to correct function
|
# send to correct function
|
||||||
|
|
@ -75,6 +84,9 @@ class StartQT4(QMainWindow):
|
||||||
if options.directory:
|
if options.directory:
|
||||||
self.dir_from_cmd(options.directory)
|
self.dir_from_cmd(options.directory)
|
||||||
|
|
||||||
|
global verbose
|
||||||
|
verbose = options.verbose
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Input functions
|
Input functions
|
||||||
"""
|
"""
|
||||||
|
|
@ -141,7 +153,7 @@ class StartQT4(QMainWindow):
|
||||||
imagelist.append(("Compressing...", "", "", "", image,
|
imagelist.append(("Compressing...", "", "", "", image,
|
||||||
QIcon(QPixmap("compressing.gif"))))
|
QIcon(QPixmap("compressing.gif"))))
|
||||||
else:
|
else:
|
||||||
print("[error] " + image + " not an image file")
|
print('[error] %s not an image file' % filename)
|
||||||
self.thread.compress_file(delegatorlist)
|
self.thread.compress_file(delegatorlist)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
@ -249,6 +261,7 @@ class Worker(QThread):
|
||||||
"""Compress the given file, get data from it and call update_table."""
|
"""Compress the given file, get data from it and call update_table."""
|
||||||
global showapp
|
global showapp
|
||||||
global imagelist
|
global imagelist
|
||||||
|
global verbose
|
||||||
for image in self.images:
|
for image in self.images:
|
||||||
#gather old file data
|
#gather old file data
|
||||||
filename = str(image[0])
|
filename = str(image[0])
|
||||||
|
|
@ -268,8 +281,7 @@ class Worker(QThread):
|
||||||
runString = '''optipng -force -o7 "%(file)s";
|
runString = '''optipng -force -o7 "%(file)s";
|
||||||
advpng -z4 "%(file)s"'''
|
advpng -z4 "%(file)s"'''
|
||||||
else:
|
else:
|
||||||
raise Exception('File %s does not have the appropriate'
|
print('[error] %s not an image file' % filename)
|
||||||
'extention' % filename)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
retcode = call(runString % {'file': filename}, shell=True,
|
retcode = call(runString % {'file': filename}, shell=True,
|
||||||
|
|
@ -298,16 +310,16 @@ class Worker(QThread):
|
||||||
|
|
||||||
self.emit(SIGNAL("updateUi"))
|
self.emit(SIGNAL("updateUi"))
|
||||||
|
|
||||||
if not showapp:
|
if not showapp and verbose:
|
||||||
# we work via the commandline
|
# we work via the commandline
|
||||||
print("File:" + filename + ", Old Size:" + oldfilesizestr +
|
print("File:" + filename + ", Old Size:" + oldfilesizestr +
|
||||||
", New Size:" + newfilesizestr + ", Ratio:" +
|
", New Size:" + newfilesizestr + ", Ratio:" +
|
||||||
ratiostr)
|
ratiostr)
|
||||||
else:
|
else:
|
||||||
# TODO nice error recovery
|
print('[error] %s' % runfile)
|
||||||
raise Exception('[error] %s' % runfile)
|
|
||||||
|
|
||||||
if not showapp:
|
if not showapp:
|
||||||
|
#make sure the app quits after all images are done
|
||||||
quit()
|
quit()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue