[primer mensaje] problema adaptando raccoonshow

Pablo Rodríguez oinos en web.de
Mie Feb 7 21:17:13 CET 2007


Hola a todos,

éste es mi primer mensaje a la lista. Soy un novato auténtico en Python
(y no sé programar) y he intentado adaptar raccoonshow para que genere
presentaciones en Flash como las que hace Lawrence Lessig (en concreto
quiero adaptar ésta: http://lessig.org/blog/archives/003696.shtml).

Bien, el problema es que el código (que está debajo), me da cuando lo
invoco "python mracconshow.py -p orphanworks-x -t linetime.txt -w
orphan.mp3", el siguiente error:

Traceback (most recent call last):
  File "mracconshow.py", line 203, in ?
    main(sys.argv[1:])
  File "mracconshow.py", line 201, in main
    back.run()
  File "mracconshow.py", line 152, in run
    self.convertPdf(pdfcheck)
NameError: global name 'pdfcheck' is not defined

Sinceramente, no sé qué falla. Desde mi ignorancia absoluta creo que ése
es el único fallo, fundamentalmente porque he ido cambiando teniendo al
lado el raccoonshow original.

Agradecería si alguien me pudiese decir dónde está el fallo y cuál sería
el código parcheado.

Muchas gracias y perdonad las molestias (me corre cierta prisa).

Saludos,


Pablo



#!/usr/bin/env python
# -*- coding: UTF8 -*-
#
# RaccoonShow
# Written by Jono Bacon (jono en jonobacon.org)
#
# Licensed under the GNU Public License v2
#
# This program is free software. See the included LICENSE file for details.

VERSION = "0.7"

import commands
import glob
import sys
import getopt

# deal with command line arguments

# a few defaults for the moment

class Backend:
	def __init__(self):
		self.wavfile = ""
		self.pdffile = ""
		self.timesfile = ""
		self.times = list()

	def setPdfFile(self, setting):
		self.pdffile = setting

	def setWavFile(self, setting):
		self.wavfile = setting

	def setTimesFile(self, setting):
		self.timesfile = setting

	def importTimesFile(self):
		print "\tReading in times.txt..."
		timesfile = open(self.timesfile,"r")
		self.times =  filter(lambda x: len(x.strip()) > 0, list(x.rstrip("\n")
for x in timesfile) )

	def inputFileCheck(self):
		if self.pdffile == "":
			print "Error: You have not specified a PDF file - use the -p or
--pdf-file options to do this"
			sys.exit(2)
		if self.wavfile == "":
			print "Error: You have not specified a WAV/MP3 file - use the -w or
--wav-file options to do this"
			sys.exit(2)
		if self.timesfile == "":
			print "Error: You have not specified a Times file - use the -t or
--times-file options to do this"
			sys.exit(2)

	def checkSWFExist(self):
		if glob.glob(self.pdffile + '.swf'):
			return True
		else:
			return False

	def convertPdf(self, pdfcheck):
		if pdfcheck == True:
			print "\tPDF already converted"
		else:
			print "\tConverting pdf to swf..."
			commands.getoutput("pdf2swf -z " + self.pdffile + " -o " + self.pdffile)

#	def checkAudioSwfExists(self):
#		try:
#			open("processed-audio.swf")
#			return True
#		except IOError:
#			return False

#	def convertWav(self, soundcheck):
#		if soundcheck == False:
#			print "Converting WAV to SWF..."
#			commands.getoutput("wav2swf -o processed-audio.swf -l 0 " +
self.wavfile)
#		else:
#			print "\tSound file already converted"

	def createScript(self):
		print "\tBuilding presentation file..."

		filebuffer = ["# Presentation script, generated by RaccoonShow"]

		filebuffer.append(".flash filename=\"pr-" + self.pdffile + "\"
version=6 fps=10")
		filebuffer.append(".flash filename=\"" + self.pdffile + ".swf\"")
		filebuffer.append(".put slides")
		filebuffer.append(".stop slides")
		filebuffer.append(".put slides")
		filebuffer.append(".sound audio \"" + self.wavfile + "\"")
		filebuffer.append(".play audio nomultiple")
		
		# append main images and times

#		imageslisting = commands.getoutput("ls *slide*")
#		images = imageslisting.split('\n')

#		num = 1
#		for im in images:
#			filebuffer.append(".jpeg s" + str(num) + " \"" + im  + "\"
quality=100%")
#			num = num + 1

		# add timings settings

		num = 1
		lastsecs = 0;

		for t in self.times:
			secs = (float(t))
			secint = secs - lastsecs
			lastsecs = secs

			filebuffer.append(".frame n+=" + str(int(secint * 10)) + " \#
duration: " + str(float(secint)) + "time: " + str(float(t)))
			num = num + 1
			filebuffer.append(".nextframe slides")


		filebuffer.append(".end");

		file = open(self.pdffile + ".sc","w")

		file.write("\n".join(filebuffer))

		file.close()

	def checkImagesSwfExists(self):
		try:
			open(self.pdffile + ".swf")
			return True
		except IOError:
			return False

	def processScript(self, imagesswfcheck):
		if imagesswfcheck == False:
			print "\tGenerating presentation to SWF..."
			commands.getoutput("swfc " + self.pdffile + ".sc")

#	def combineFiles(self):
#		print "\tCombining files..."
#		commands.getoutput("swfcombine -Tm processed-images.swf
processed-audio.swf -o Presentation.swf")

	def clean(self):
		print "Cleaning the project..."
		commands.getoutput("rm " + self.pdffile + ".swf")
		commands.getoutput("rm " + self.pdffile + ".sc")

	def run(self):
		print "RaccoonShow-" + VERSION + "\n"
		self.inputFileCheck()
		imgchk = self.checkSWFExist()
		self.convertPdf(pdfcheck)

		self.importTimesFile()		

#		wavchk = self.checkAudioSwfExists()
#		self.convertWav(wavchk)
		self.createScript()

		self.processScript()

		print "\nPresentation successfully created!"

def usage():
	print "RaccoonShow-" + VERSION
	print "Written by Jono Bacon raccoonshow AT jonobacon DOT org"
	print "\nUsage: raccoonshow [options]"
	print "\n-c, --clean\t\tRemove all generated files"
	print "-p, --pdf-file\t\tPDF file with the presentation slides"
	print "-t, --times-file\ta file containing a list of times"
	print "-w, --wav-file\t\tWAV/MP3 file with the recorded audio"
	print "-v, --version\t\tDisplay the RacconShow version number"

def main(argv):
	back = Backend()

	try:
		opts, args = getopt.getopt(argv, "hcp:w:t:v", ["help", "debug",
"pdf-file=", "wav-file=", "times-file="])
	except getopt.GetoptError:
		usage()
		sys.exit(2)

	for opt, arg in opts:
		if opt in ("-h", "--help"):
			usage()
			sys.exit()

		if opt in ("-c", "--clean"):
			back.clean()
			sys.exit()
		elif opt in ("-p", "--pdf-file"):
			back.setPdfFile(arg)
		elif opt in ("-w", "--wav-file"):
			back.setWavFile(arg)
		if opt in ("-t", "--times-file"):
			back.setTimesFile(arg)
		if opt in ("-v", "--version"):
			print "RaccoonShow v" + VERSION
			sys.exit()

	back.run()
if __name__ == "__main__":
	main(sys.argv[1:])




Más información sobre la lista de distribución Python-es