Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature request: command option added #49

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions peepdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ def getPeepJSON(statsDict, version, revision):
help='Shows the document information in XML format.')
argsParser.add_option('-j', '--json', action='store_true', dest='jsonOutput', default=False,
help='Shows the document information in JSON format.')
argsParser.add_option('-C','--command',action='store',type='string', dest='commands',help='execute mentioned commands.')
(options, args) = argsParser.parse_args()

try:
Expand Down Expand Up @@ -548,6 +549,25 @@ def getPeepJSON(statsDict, version, revision):
scriptFileObject.close()
traceback.print_exc(file=open(errorsFile, 'a'))
raise Exception('PeepException', 'Send me an email ;)')
if options.commands != None:
from PDFConsole import PDFConsole
import tempfile

comm = options.commands.strip().split(',')
newfileobj = tempfile.TemporaryFile()
for c in comm:
newfileobj.write(c+'\n')

newfileobj.seek(0)
console = PDFConsole(pdf, VT_KEY, options.avoidColors, stdin=newfileobj)
try:
console.cmdloop()
except:
errorMessage = '*** Error: Exception not handled using the batch mode!!'
newfileobj.close()
traceback.print_exc(file=open(errorsFile, 'a'))
raise Exception('PeepException', 'Send me an email ;)')

else:
if statsDict != None:
if COLORIZED_OUTPUT and not options.avoidColors:
Expand Down