def edit(self, rep_filename=None): """ Edit report. :param rep_filename: Report template filename. """ # Set *.xls filename xls_filename = os.path.abspath( os.path.splitext(rep_filename)[0] + XLS_FILENAME_EXT) if sys_func.isLinuxPlatform(): cmd = '%s \"%s\"&' % (report_gen_system.UNIX_OFFICE_OPEN, xls_filename) log_func.info('Execute command <%s>' % cmd) os.system(cmd) return True elif sys_func.isWindowsPlatform(): win_office_open = iq.KERNEL.settings.THIS.SETTINGS.win_libreoffice_run.get( ) cmd = '%s \"%s\"&' % (win_office_open if win_office_open else report_gen_system.WIN_OFFICE_OPEN, xls_filename) log_func.info(u'Execute command <%s>' % cmd) os.system(cmd) return True else: log_func.warning(u'Unsupported platform <%s>' % sys_func.getPlatform()) return False
def openOffice(self, xls_filename): """ Open XLS report in Office. :param xls_filename: Report XLS filename. """ if xls_filename and os.path.exists(xls_filename): if sys_func.isLinuxPlatform(): cmd = '%s %s&' % (report_gen_system.UNIX_OFFICE_OPEN, xls_filename) log_func.info('Execute command <%s>' % cmd) os.system(cmd) return True elif sys_func.isWindowsPlatform(): win_office_open = iq.KERNEL.settings.THIS.SETTINGS.win_libreoffice_run.get( ) cmd = '%s %s&' % (win_office_open if win_office_open else report_gen_system.WIN_OFFICE_OPEN, xls_filename) log_func.info(u'Execute command <%s>' % cmd) os.system(cmd) return True else: log_func.warning(u'Unsupported platform <%s>' % sys_func.getPlatform()) else: log_func.warning(u'Open. Report file <%s> not exists' % xls_filename) return False
def previewOffice(self, xls_filename): """ Open preview in Office. :param xls_filename: Report XLS filename. """ if not os.path.exists(xls_filename): log_func.warning(u'Preview. Report file <%s> not exists' % xls_filename) return False pdf_filename = os.path.splitext(xls_filename)[0] + PDF_FILENAME_EXT if os.path.exists(pdf_filename): try: os.remove(pdf_filename) except: log_func.fatal(u'Error delete file <%s>' % pdf_filename) if sys_func.isLinuxPlatform(): cmd = report_gen_system.UNIX_CONV_TO_PDF_FMT % xls_filename log_func.info(u'Convert to PDF. Execute command <%s>' % cmd) os.system(cmd) if os.path.exists(pdf_filename): cmd = report_gen_system.UNIX_OPEN_PDF_FMT % pdf_filename log_func.info(u'Open PDF. Execute command <%s>' % cmd) os.system(cmd) return True else: log_func.warning(u'Open PDF. PDF file <%s> not found' % pdf_filename) elif sys_func.isWindowsPlatform(): win_conv_to_pdf_fmt = iq.KERNEL.settings.THIS.SETTINGS.win_conv_to_pdf_fmt.get( ) if not win_conv_to_pdf_fmt: win_conv_to_pdf_fmt = report_gen_system.WIN_CONV_TO_PDF_FMT cmd = win_conv_to_pdf_fmt % (xls_filename, os.path.dirname(xls_filename)) log_func.info(u'Convert to PDF. Execute command <%s>' % cmd) os.system(cmd) if os.path.exists(pdf_filename): win_open_pdf_fmt = iq.KERNEL.settings.THIS.SETTINGS.win_open_pdf_fmt.get( ) if not win_open_pdf_fmt: win_open_pdf_fmt = report_gen_system.WIN_OPEN_PDF_FMT cmd = win_open_pdf_fmt % pdf_filename log_func.info(u'Open PDF. Execute command <%s>' % cmd) os.system(cmd) return True else: log_func.warning(u'Open PDF. PDF file <%s> not found' % pdf_filename) else: log_func.warning(u'Unsupported <%s> platform' % sys_func.getPlatform()) return False
def getRunCommand(self): """ Get the resulting command to start the generation. :return: The resulting command to generate the chart file. """ commands = COMMAND_DELIMETER.join(self.commands) if sys_func.isLinuxPlatform(): return GNUPLOT_COMMAND_FMT % (UNIX_GNUPLOT_RUN, commands) elif sys_func.isWindowsPlatform(): win_gnuplot_run = iq.KERNEL.settings.THIS.SETTINGS.win_gnuplot_run.get() return GNUPLOT_COMMAND_FMT % (win_gnuplot_run if win_gnuplot_run else WIN_GNUPLOT_RUN, commands) else: log_func.warning(u'Unsupported <%s> platform' % sys_func.getPlatform()) return None