#! /usr/bin/python # -*- coding: iso-8859-1 -*- ### make-proceedings.py, versão 1.0 ### Copyright (C) 2004 Fabricio Chalub ### Antes de utilizar este programa, leia a documentação em ### http://www.ic.uff.br/~frosario/make-proceedings.html ## This program 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, version 2. ## This program 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. import re, os, sys, glob, shutil from sys import __stdout__ from string import * from textwrap import * ### Configure os seguintes valores (em milímetros) de acordo com as ### suas necessidades. Os valores aqui são dos valores default para ### papers gerados usando o estilo da SBC (sbc2003.sty) ### PAPER_WIDTH: largura da página dos papers dos autores ### PAPER_HEIGHT: altura da página dos papers dos autores ### TB, BB: bordas superior e inferior (top border / bottom border) ### LRB: bordas esquerda e direita (left right border) (PAPER_WIDTH, PAPER_HEIGHT) = (210, 297) (TOP_BORDER, BOTTOM_BORDER) = (035, 025) (LEFT_RIGHT_BORDER) = (030) ### Vamos dar uma folga de 5 mm FOLGA = 5 (TOP_BORDER, BOTTOM_BORDER) = (TOP_BORDER - FOLGA, BOTTOM_BORDER - FOLGA) (LEFT_RIGHT_BORDER) = (LEFT_RIGHT_BORDER - FOLGA) def mm2pt (x): "Converte de milímetros para pontos" return (x * 2.8452756) ### Iremos calcular a boundingbox final do EPS com as margens brancas ### cortadas. (LX, LY) = (mm2pt (LEFT_RIGHT_BORDER), mm2pt (BOTTOM_BORDER)) (UX, UY) = (mm2pt (PAPER_WIDTH - LEFT_RIGHT_BORDER), mm2pt (PAPER_HEIGHT - (TOP_BORDER + BOTTOM_BORDER))) print "make-proceedings.py versão 1.0, Copyright (C) 2004 Fabricio Chalub, frosario@ic.uff.br" print "make-proceedings.py comes with ABSOLUTELY NO WARRANTY and is free software." print "Antes de utilizar este programa, leia a documentação em:" print "http://www.ic.uff.br/~frosario/make-proceedings.html" print ### Antes de começar, verifica se a estrutura de diretórios está ### correta e se a estrutura artigos/ está completa em relação ao ### banco de dados de artigos e se cada subdiretório contem um único ### arquivo PDF. if not os.path.isdir ('tmp'): os.mkdir ("tmp") if not os.path.isdir ('papers'): os.mkdir ("papers") print fill ("Coloque no diretório papers/ os PDFs camera-ready, conforme as instruções.") sys.exit (1) if not os.path.isfile ('papers.text'): print fill ("Não encontrei o arquivo \"papers.text\". Crie este arquivo de acordo com as instruções.") sys.exit (1) try: os.rename ("all-papers.tex", "all-papers.bak") os.rename ("toc.tex", "toc.bak") except: pass os.system ("rm -f tmp/*") artigos = open ('papers.text') print "Processando artigos." for l in artigos.readlines(): artigo = split (strip (l), ';') (id, titulo, autores) = (artigo[0], artigo[1], artigo[2]) if not os.path.isdir ("papers/%s" % id): print fill ("Não encontrei o diretório \"%s\" relacionado ao artigo \ \"%s\". Por favor, remova este artigo do banco de \ dados e continue." % (id, titulo)) sys.exit (1) if len (glob.glob ("papers/%s/*.pdf" % (id))) == 0: print fill ("O diretório \"%s\" existe, mas não contém um PDF dentro dele.") sys.exit (1) if len (glob.glob ("papers/%s/*.pdf" % (id))) > 1: print fill ("O diretório \"%s\" existe, mas contém mais de um PDF dentro dele.") sys.exit (1) artigos.seek (0) allpapers = open ('all-papers.tex', 'w') toc = open ('toc.tex', 'w') t = 0 for l in artigos.readlines(): artigo = split (strip (l), ';') (id, titulo, autores) = (artigo[0], artigo[1], artigo[2]) toc.write ("\\paper{%s}{%s}{%s}" % (titulo, autores, id)) pdf = glob.glob ("papers/%s/*.pdf" % (id))[0] allpapers.write ("%%%%%%\n%%%%%% %s\n%%%%%% %s\n%%%%%%\n\\label{%s}%%\n" % (titulo, autores, id)) for autor in split (autores, ','): allpapers.write ("\\index{%s} " % autor) allpapers.write ("\n") shutil.copyfile (pdf, "tmp/%s.pdf" % id) os.chdir ("tmp/") os.system ("pdftk %s.pdf burst" % id) c = 0 for pagina in glob.glob ("pg_*.pdf"): c = c + 1 os.system ("pdftops -eps %s" % pagina) tmp = open ('tmp.eps', 'w') basename = os.path.splitext (pagina)[0] for linha in open ("%s.eps" % basename).readlines(): tmp.write (re.sub ("%%BoundingBox.*", "%%%%BoundingBox: %2.3f %2.3f %2.3f %2.3f" % (LX, LY, UX, UY), linha)) os.rename ("tmp.eps", "%s.%s.eps" % (id, basename)) allpapers.write ("\\pageimage{tmp/%s.%s.eps}\\newpage\n" % (id, basename)) os.unlink (pagina) os.unlink ("%s.eps" % basename) os.chdir ("..") plural='' if c > 1: plural = 's' t = t + c print "[%s (%d página%s)]" % (id, c, plural) os.unlink ("tmp/doc_data.txt") os.unlink ("tmp/%s.pdf" % id) allpapers.close() toc.close() print "Total de %d páginas." % t