示例#1
0
文件: spm.py 项目: EBRL/Nibble
 def jpg2pdf(self, orig_file, pdf_file):
     """Convert jpg file to pdf file"""
     try:
         from PIL import Image
         jpg_im = Image.open(orig_file)
         jpg_im.save(pdf_file, 'PDF')
     except ImportError, IOError:
         print("Falling back to ImageMagick to convert...")
         return_val = util.run_cmdline("convert %s %s" % (orig_file, pdf_file))
示例#2
0
文件: spm.py 项目: EBRL/Nibble
 def run(self):
     """Execute each piece"""
     if not self.skip:
         for piece in self.pieces:
             finish_file = self.batch_path(piece['name'], 'finish')
             if not os.path.isfile(finish_file):
                 cmdline = '%s -nosplash < %s >& %s'
                 piece_mfile = self.piece_path(piece)
                 piece_log = self.log_path(piece)
                 strf = '%Y%m%d %H:%M:%S'
                 beg_time = time.strftime(strf)
                 print('%s:%s:%s: begin %s' % (self.par_name, self.id, piece['name'], beg_time))
                 return_val = util.run_cmdline(cmdline % (self.mlab_path, piece_mfile, piece_log))
                 end_time = time.strftime(strf)
                 print('%s:%s:%s: end %s' % (self.par_name, self.id, piece['name'], end_time))
                 v = 'Piece:%s\nBegan: %s\nEnded: %s\n' 
                 email_text = v % (piece['name'], beg_time, end_time)
                 orig_file = self.piece_orig_path(piece)
                 pdf_file = self.piece_pdf_path(piece)
                 if return_val == 0:
                     email_text += "Success\n"
                     if os.path.isfile(orig_file):
                         _, ext = os.path.splitext(orig_file)
                         if ext == '.jpg':
                             self.jpg2pdf(orig_file, pdf_file)
                         if ext == '.ps':
                             self.ps2pdf(orig_file, pdf_file)
                 if return_val == 1:
                     email_text += "Success, no .ps file was created\n"
                 if return_val == 2:
                     email_text += "Success, couldn't copy .ps file"
                 if return_val == 3:
                     email_text += "Error(s)\n"
                     #TODO rescue ps
                 if return_val in [0, 1, 2]:
                     self.touch(finish_file)
                 if os.path.isfile(piece_log):
                     with open(piece_log, 'r') as f:                        
                         email_text += f.read()
                 else:
                     email_text += "Couldn't open log file.\n"
                 if self.email:
                     subject_line = '%s:%s %s' % (self.project['name'], 
                                     self.par_name, self.id)
                     util.email(self.email['address'], 
                                 self.email['to'], 
                                 subject_line, 
                                 self.email['server'], 
                                 self.email['pw'], 
                                 email_text, pdf_file)
             else:
                 print("%s:%s:%s: skipping" % (self.par_name, self.id, piece['name']))
示例#3
0
文件: spm.py 项目: EBRL/Nibble
 def ps2pdf(self, ps_name, pdf_name):
     """Full paths for each filename given, does what it says"""
     return util.run_cmdline('pstopdf %s %s' % (ps_name, pdf_name))