Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #91621
| Date | 2015-05-31 22:08 -0700 |
|---|---|
| From | Ethan Furman <ethan@stoneleaf.us> |
| Subject | Re: Using Python instead of Bash |
| References | <87h9qsnckl.fsf@Equus.decebal.nl> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.265.1433136649.5151.python-list@python.org> (permalink) |
Just for funsies, I did a slight rewrite using my scription[1] library:
--8<------------------------------------------------------------------------------
#!/usr/bin/python3
"""
Convert scanned images: contrast is increased, size is enlarged,
format is changed from jpeg to png.
"""
from __future__ import print_function # only needed if running in 2
from glob import glob
from scription import *
@Command(
threshold=Spec('cutoff value for white vs black', OPTION, type=int, default=66),
verify=Spec('confirm conversion by viewing on screen', FLAG),
)
def image_convert(verify, threshold):
for count, input in enumerate(sorted(glob('*.JPG')), start=1):
output = '{0:02d}.png'.format(count)
# only prints if --verbose on commandline
print('Going to convert {} to {}'.format(input, output))
while True:
# Execute automatically parses into a list
attempt = Execute(
'convert -threshold {}% {} {}'.format(threshold, input, output),
interactive='echo',
)
if attempt.returncode:
raise SystemExit(attempt.returncode)
if not verify:
break
attempt = Execute(
'display_the_png {}'.format(output),
interactive='echo',
)
if attempt.returncode:
raise SystemExit(attempt.returncode)
if get_response('Does the image look good?'):
break
threshold = get_response("New threshold value:", type=int)
# conversion looks good, or manual verification skipped
print('going to print {0}'.format(output))
attempt = Execute(
'lpr -o fit-to-page -o media=A4 {}'.format(output),
interactive='echo',
)
if attempt.returncode:
raise SystemExit(attempt.returncode)
Main()
--8<------------------------------------------------------------------------------
Opinions about the usability of the above script, both as the script writer and as the user, welcomed.
--
~Ethan~
[1] yes, everyone apparently writes their own command-line processor -- this one is mine. ;)
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Using Python instead of Bash Cecil Westerhof <Cecil@decebal.nl> - 2015-05-31 14:42 +0200
Re: Using Python instead of Bash Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid> - 2015-05-31 16:02 +0200
Re: Using Python instead of Bash Cecil Westerhof <Cecil@decebal.nl> - 2015-05-31 18:36 +0200
Re: Using Python instead of Bash Cem Karan <cfkaran2@gmail.com> - 2015-05-31 10:14 -0400
Re: Using Python instead of Bash Cecil Westerhof <Cecil@decebal.nl> - 2015-05-31 18:58 +0200
Re: Using Python instead of Bash Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-05-31 11:05 -0400
Re: Using Python instead of Bash Cecil Westerhof <Cecil@decebal.nl> - 2015-05-31 19:06 +0200
Re: Using Python instead of Bash Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-05-31 20:53 -0400
Re: Using Python instead of Bash Cecil Westerhof <Cecil@decebal.nl> - 2015-06-01 11:25 +0200
Re: Using Python instead of Bash Laura Creighton <lac@openend.se> - 2015-06-01 09:11 +0200
Re: Using Python instead of Bash Ethan Furman <ethan@stoneleaf.us> - 2015-05-31 22:08 -0700
Re: Using Python instead of Bash Larry Hudson <orgnut@yahoo.com> - 2015-06-01 00:56 -0700
Re: Using Python instead of Bash Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2015-06-01 11:06 +0300
Re: Using Python instead of Bash alister <alister.nospam.ware@ntlworld.com> - 2015-06-01 09:07 +0000
Re: Using Python instead of Bash Cecil Westerhof <Cecil@decebal.nl> - 2015-06-01 12:44 +0200
Re: Using Python instead of Bash Laura Creighton <lac@openend.se> - 2015-06-01 17:44 +0200
Re: Using Python instead of Bash Cecil Westerhof <Cecil@decebal.nl> - 2015-06-01 18:44 +0200
Re: Using Python instead of Bash Laura Creighton <lac@openend.se> - 2015-06-01 20:42 +0200
Re: Using Python instead of Bash Cecil Westerhof <Cecil@decebal.nl> - 2015-06-01 21:57 +0200
Re: Using Python instead of Bash Laura Creighton <lac@openend.se> - 2015-06-01 22:42 +0200
Re: Using Python instead of Bash Cecil Westerhof <Cecil@decebal.nl> - 2015-06-01 23:04 +0200
Re: Using Python instead of Bash Cecil Westerhof <Cecil@decebal.nl> - 2015-06-01 11:11 +0200
Re: Using Python instead of Bash Marko Rauhamaa <marko@pacujo.net> - 2015-06-01 12:38 +0300
Re: Using Python instead of Bash Grant Edwards <invalid@invalid.invalid> - 2015-06-01 14:51 +0000
csiph-web