def spool_job(self, filename, type, printer, skip_lpr=False, logfile=None, lpr_user='******', def_lpr_cmd=None): """Spools the job. The spool command is executed in the directory where filename resides.""" if logfile is None: logfile = Utils.make_temp_file(only_name=True) self.logfile = logfile old_dir = os.getcwd() if os.path.dirname(filename): os.chdir(os.path.dirname(filename)) base_filename = filename[:filename.rindex('.')] try: if cereconf.PRINT_DVIPS_CMD: format_sys_cmd = "%s -f < %s.dvi > %s.ps 2>> %s" % (cereconf.PRINT_DVIPS_CMD, base_filename, base_filename, logfile) base_filename += ".ps" elif cereconf.PRINT_DVIPDF_CMD: format_sys_cmd = "%s %s.dvi %s.pdf 2>> %s" % (cereconf.PRINT_DVIPDF_CMD, base_filename, base_filename, logfile) base_filename += ".pdf" else: raise IOError("Error spooling job, see %s for details" % logfile) if type == 'tex': status = (os.system("%s --interaction nonstopmode %s >> %s 2>&1" % ( cereconf.PRINT_LATEX_CMD, filename, logfile)) or os.system("%s" % (format_sys_cmd))) if status: raise IOError("Error spooling job, see %s for details" % logfile) if not skip_lpr: if printer is not None and re.search(r'[^a-z0-9\-_]', printer): raise IOError("Bad printer name") if def_lpr_cmd: lpr_cmd = string.Template(def_lpr_cmd) else: lpr_cmd = string.Template(cereconf.PRINT_LPR_CMD) # Assemble parameters that might be of use for further # handling of the job. Contents of def_lpr_cmd/ # cereconf.PRINT_LPR_CMD determine what is actually used and for # what purpose lpr_params = {'filename': base_filename, 'uname': lpr_user, 'printer': printer, 'hostname': os.uname()[1]} status = os.system("%s >> %s 2>&1" % (lpr_cmd.substitute(lpr_params), logfile)) if status: raise IOError("Error spooling job, see %s for details (tail: %s)" % (logfile, self._tail(logfile, num=1))) finally: os.chdir(old_dir)
def _get_print_log(): u""" Lazy instantiation of __print_log. """ global __print_log if __print_log is None or not os.path.isfile(__print_log): __print_log = Utils.make_temp_file(only_name=True) return __print_log
def spool_job(self, filename, type, printer, skip_lpr=False, logfile=None, lpr_user='******', def_lpr_cmd=None): """Spools the job. The spool command is executed in the directory where filename resides.""" if logfile is None: logfile = Utils.make_temp_file(only_name=True) self.logfile = logfile old_dir = os.getcwd() if os.path.dirname(filename): os.chdir(os.path.dirname(filename)) base_filename = filename[:filename.rindex('.')] try: if cereconf.PRINT_DVIPS_CMD: format_sys_cmd = "%s -f < %s.dvi > %s.ps 2>> %s" % ( cereconf.PRINT_DVIPS_CMD, base_filename, base_filename, logfile) base_filename += ".ps" elif cereconf.PRINT_DVIPDF_CMD: format_sys_cmd = "%s %s.dvi %s.pdf 2>> %s" % ( cereconf.PRINT_DVIPDF_CMD, base_filename, base_filename, logfile) base_filename += ".pdf" else: raise IOError("Error spooling job, see %s for details" % logfile) if type == 'tex': status = (os.system( "%s --interaction nonstopmode %s >> %s 2>&1" % (cereconf.PRINT_LATEX_CMD, filename, logfile)) or os.system("%s" % (format_sys_cmd))) if status: raise IOError("Error spooling job, see %s for details" % logfile) if not skip_lpr: if printer is not None and re.search(r'[^a-z0-9\-_]', printer): raise IOError("Bad printer name") if def_lpr_cmd: lpr_cmd = string.Template(def_lpr_cmd) else: lpr_cmd = string.Template(cereconf.PRINT_LPR_CMD) # Assemble parameters that might be of use for further # handling of the job. Contents of def_lpr_cmd/ # cereconf.PRINT_LPR_CMD determine what is actually used and for # what purpose lpr_params = { 'filename': base_filename, 'uname': lpr_user, 'printer': printer, 'hostname': os.uname()[1] } status = os.system("%s >> %s 2>&1" % (lpr_cmd.substitute(lpr_params), logfile)) if status: raise IOError( "Error spooling job, see %s for details (tail: %s)" % (logfile, self._tail(logfile, num=1))) finally: os.chdir(old_dir)