當前位置: 首頁>>代碼示例>>Python>>正文


Python Utils.make_temp_file方法代碼示例

本文整理匯總了Python中Cerebrum.Utils.make_temp_file方法的典型用法代碼示例。如果您正苦於以下問題:Python Utils.make_temp_file方法的具體用法?Python Utils.make_temp_file怎麽用?Python Utils.make_temp_file使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Cerebrum.Utils的用法示例。


在下文中一共展示了Utils.make_temp_file方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: spool_job

# 需要導入模塊: from Cerebrum import Utils [as 別名]
# 或者: from Cerebrum.Utils import make_temp_file [as 別名]
    def spool_job(self, filename, type, printer, skip_lpr=False, logfile=None,
                  lpr_user='unknown', 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)
開發者ID:,項目名稱:,代碼行數:56,代碼來源:

示例2: _get_print_log

# 需要導入模塊: from Cerebrum import Utils [as 別名]
# 或者: from Cerebrum.Utils import make_temp_file [as 別名]
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
開發者ID:,項目名稱:,代碼行數:8,代碼來源:


注:本文中的Cerebrum.Utils.make_temp_file方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。