From mboxrd@z Thu Jan 1 00:00:00 1970 From: jmcbray@carcosa.net (Jason F. McBrayer) Subject: Updated agenda printer script Date: Sun, 03 Jun 2007 16:44:32 -0400 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HuwwG-0000mJ-33 for emacs-orgmode@gnu.org; Sun, 03 Jun 2007 16:44:36 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HuwwE-0000m7-Hd for emacs-orgmode@gnu.org; Sun, 03 Jun 2007 16:44:34 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HuwwE-0000m4-DA for emacs-orgmode@gnu.org; Sun, 03 Jun 2007 16:44:34 -0400 Received: from cdptpa-omtalb.mail.rr.com ([75.180.132.33]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1HuwwE-0003vF-0f for emacs-orgmode@gnu.org; Sun, 03 Jun 2007 16:44:34 -0400 Received: from bertrand.carcosa.net ([24.168.217.245]) by cdptpa-omta06.mail.rr.com with ESMTP id <20070603204433.FEM12228.cdptpa-omta06.mail.rr.com@bertrand.carcosa.net> for ; Sun, 3 Jun 2007 20:44:33 +0000 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode --=-=-= And, as promised, here's the updated version of the agenda printer script. This version has only bugfixes and compatibility fixes. There are some more fundamental changes (listed in the TODOs in the source comments) that need to be made, but I'm waiting on a round tuit for them. I hope people find this useful, and that it is more usable for them than the previous version. Changes: 1. Uses os.popen3 rather than the subprocess module; as a result, it should work with python versions earlier than 2.4. 2. Better quoting for characters in headlines that could cause problems in the LaTeX output. --=-=-= Content-Type: text/x-python Content-Disposition: attachment; filename=pyagenda Content-Description: Agenda printer script #!/usr/bin/python # # pyagenda -- export an org agenda to PDF # # (c) 2007, Jason F. McBrayer # Version: 1.1 # This file is a stand-alone program. # # Legalese: # pyagenda is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # # pyagenda is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # Documentation: # pyagenda is a short python program for taking a formatted agenda # from org-mode (via org-batch-agenda-csv) and producing a PDF-format # planner page that can be inserted in a planner binder. Run # 'pyagenda --help' for usage. # # Currently, this is only a crude 'worksforme' implementation, with # many things being hardcoded. It produces an output file named # cmdkey.pdf where 'cmdkey' is the key given to # org-agenda-custom-commands. Not all arbitrary searches will work. # Be aware that it may overwrite cmdkey.tex, cmdkey.log, cmdkey.aux, # etc. The output size is hardcoded to 5.5x8.0in, which is suitable # for a Circa or Rollabind junior sized planner. The output is not # suitable for daily/weekly agenda views, and does not present all the # information it could. If you want to change any of the output, edit # the TEX_* constants. # # TODO: # 1. Use safer tmpfile handling. # 2. Nicer command-line handling. # 3. Prettier output, including use of more of the information # passed by org-batch-agenda-csv. # import csv import sys import os #from subprocess import Popen, PIPE, call from os import popen3 import re EMACS = 'emacs' INIT_FILE = "~/.emacs.d/init.el" # Most people should use "~/.emacs" instead AGENDA_COMMAND = '(org-batch-agenda-csv "%s")' REMOVE_INTERMEDIATES = True # Remove generated latex & tex's log/aux files. TEX_HEADER = """ \\documentclass[twoside, american]{article} \\usepackage[T1]{fontenc} \\usepackage[latin1]{inputenc} \\usepackage{pslatex} \\usepackage{geometry} \\geometry{verbose,paperwidth=5.5in,paperheight=8in,tmargin=0.25in,bmargin=0.25in,lmargin=0.5in,rmargin=0.25in} \\pagestyle{empty} \\setlength{\\parskip}{\\medskipamount} \\setlength{\\parindent}{0pt} \\usepackage{calc} \\makeatletter \\newcommand{\\myline}[1]{ {#1 \\hrule width \\columnwidth } } \\usepackage{babel} \\makeatother \\begin{document} \\part*{\\textsf{Actions}\\hfill{}%% \\framebox{\\begin{minipage}[t][1em][t]{0.25\\paperwidth}%% \\textsf{%s} \\hfill{}%% \\end{minipage}}%% \\protect \\\\ } \\myline{\\normalsize} """ TEX_FOOTER = """ \\end{document} """ TEX_ITEM = """ %% \\framebox{\\begin{minipage}[c][0.5em][c]{0.5em}%% \\hfill{}%% \\end{minipage}}%% %% \\begin{minipage}[c][1em]{1em}%% \\hfill{}%% \\end{minipage}%% \\textsf{%s}\\\\ \\myline{\\normalsize} """ class AgendaItem(object): def __init__(self, data=None): if data: self.category = data[0] self.headline = data[1] self.type = data[2] self.todo = data[3] self.tags = data[4].split(':') self.date = data[5] self.time = data[6] self.extra = data[7] self.prio = data[8] self.fullprio = data[9] def get_agenda_items(cmdkey): #output = Popen([EMACS, "-batch", "-l", INIT_FILE, # "-eval", AGENDA_COMMAND % cmdkey ], # stdout=PIPE, stderr=PIPE) _, output, _ = popen3("'%s' -batch -l '%s' -eval '%s'" % (EMACS, INIT_FILE, AGENDA_COMMAND % cmdkey)) reader = csv.reader(output) items = [] for row in reader: items.append(AgendaItem(row)) return items def usage(): print "Usage: pyagenda 'cmd-key' [label]" print " cmd-key is an org agenda custom command key, or an " print " org-agenda tags/todo match string." print " label (optional) is a context label to be printed " print " at the top of your agenda page." def main(): try: search = sys.argv[1] except IndexError: usage() sys.exit(1) if search == "--help" or search == "-h": usage() sys.exit(0) try: label = sys.argv[2] except IndexError: label = "" texfile = file(search + ".tex", 'w') texfile.write(TEX_HEADER % label + "\n") for item in get_agenda_items(search): #texfile.write(TEX_ITEM % # item.headline.replace('&', r'\&') + "\n" ) texfile.write(TEX_ITEM % re.sub(r'([&_#])', r'\\\1', item.headline)) texfile.write(TEX_FOOTER) texfile.close() #call(['pdflatex', texfile.name], stdout=PIPE, stderr=PIPE) _, output, _ = popen3("pdflatex '%s'" % texfile.name) output.read() # pdflatex needs this in order to complete. if REMOVE_INTERMEDIATES: os.unlink(texfile.name) os.unlink(search + ".aux") os.unlink(search + ".log") if __name__ == '__main__': main() --=-=-= -- +-----------------------------------------------------------+ | Jason F. McBrayer jmcbray@carcosa.net | | If someone conquers a thousand times a thousand others in | | battle, and someone else conquers himself, the latter one | | is the greatest of all conquerors. --- The Dhammapada | --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-orgmode mailing list Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode --=-=-=--