Permalink
Browse files

Added default output file selection based on input file name

  • Loading branch information...
dswd committed Apr 19, 2012
1 parent f29ccef commit 78da49e59a49c85fdde59c88ef460a6f2356a83c
Showing with 13 additions and 2 deletions.
  1. +13 −2 bookmaker
View
@@ -32,8 +32,18 @@ def processargs():
if args.printer:
args.printfile = True
if not args.output and not args.printfile:
- print("Must either specify output file or print directive", file=sys.stderr)
- sys.exit(-1)
+ if args.input.lower().endswith(".pdf"):
+ base = os.path.splitext(args.input)[0]
+ else:
+ base = args.input
+ if os.path.exists("%s.book.pdf" % base):
+ num = 2
+ while os.path.exists("%s.book_%d.pdf" % (base, num)):
+ num += 1
+ args.output = "%s.book_%d.pdf" % (base, num)
+ else:
+ args.output = "%s.book.pdf" % base
+ assert not os.path.exists(args.output)
return args
@@ -139,6 +149,7 @@ def main():
os.chdir(wd)
if args.output:
+ print('Writing book to %s' % args.output)
shutil.move(intermediate_pdf, args.output)
# cleanup

0 comments on commit 78da49e

Please sign in to comment.