def edit(self, rep_filename=None):
        """
        Edit report.

        :param rep_filename: Report template filename.
        """
        rprt_file_name = os.path.abspath(rep_filename)
        rep = res_func.loadResource(rprt_file_name)
        report_dir = os.path.abspath(self.getReportDir())
        rep_file = os.path.join(report_dir, rep['generator'])

        reportman_designer_key = utilfunc.getRegValue(
            'Software\\Classes\\Report Manager Designer\\shell\\open\\command',
            None)
        if reportman_designer_key:
            reportman_designer_run = reportman_designer_key.replace(
                '\'%1\'', '\'%s\'') % rep_file
            cmd = 'start %s' % reportman_designer_run
            log_func.debug(u'Execute command <%s>' % cmd)
            # Run Report Manager Designer
            os.system(cmd)
        else:
            msg = u'Not define Report Manager Designer <%s>' % reportman_designer_key
            log_func.warning(msg)
            dlg_func.openWarningBox(u'WARNING', msg)

        xml_file = os.path.normpath(
            os.path.abspath(os.path.splitext(rep_filename)[0] + '.xml'))
        cmd = 'start excel.exe \'%s\'' % xml_file
        log_func.debug(u'Execute command <%s>' % cmd)
        os.system(cmd)
Exemple #2
0
    def loadReportTemplate(self, report_filename=''):
        """
        Load report template data.

        :param report_filename: Report template filename.
        :return: Report template data or None if error.
        """
        return res_func.loadResource(report_filename)
Exemple #3
0
def doReport(parent_form=None,
             report_filename='',
             report_dir='',
             db_url='',
             sql='',
             command=None,
             stylelib_filename=None,
             variables=None):
    """
    The function starts the report generator.

    :param parent_form: The parent form, if not specified, creates a new application.
    :param report_filename: Report filename.
    :param report_dir: Directory where reports are stored.
    :param db_url: URL Connection string.
        For example:
        postgresql+psycopg2://postgres:[email protected]:5432/realization.
    :param sql: SQL query text.
    :param command: After generation command. print/preview/export.
    :param stylelib_filename: Style library filename.
    :param variables: A dictionary of variables to populate the report.
    :return: True/False.
    """
    try:
        if not report_filename:
            return openReportViewer(parent_form, report_dir)
        else:
            repgen_system = report_gen_func.getReportGeneratorSystem(
                report_filename, parent_form)
            stylelib = loadStyleLib(stylelib_filename)

            data = repgen_system.generate(
                res_func.loadResource(report_filename),
                db_url,
                sql,
                stylelib=stylelib,
                vars=variables)

            if command:
                command = command.lower()
                if command == DO_COMMAND_PRINT:
                    repgen_system.printResult(data)
                elif command == DO_COMMAND_PREVIEW:
                    repgen_system.previewResult(data)
                elif command == DO_COMMAND_EXPORT:
                    repgen_system.convertResult(data)
                elif command == DO_COMMAND_SELECT:
                    repgen_system.doSelectAction(data)
                else:
                    log_func.warning(u'Not processed start command <%s>' %
                                     command)
            else:
                repgen_system.save(data)
        return True
    except:
        log_func.fatal(u'Error starting report generator <%s>' %
                       report_filename)
    def renameReport(self, rep_filename, new_name):
        """
        Rename report.
        """
        old_name = os.path.splitext(os.path.split(rep_filename)[1])[0]
        old_rep_file_name = rep_filename
        old_rep_pkl_file_name = os.path.splitext(
            old_rep_file_name)[0] + res_func.PICKLE_RESOURCE_FILE_EXT
        old_xls_file_name = os.path.splitext(
            old_rep_file_name)[0] + XLS_FILENAME_EXT
        new_rep_file_name = os.path.join(
            os.path.split(old_rep_file_name)[0],
            new_name + REPORT_FILENAME_EXT)
        if os.path.isfile(old_rep_file_name):
            try:
                os.rename(old_rep_file_name, new_rep_file_name)
            except:
                log_func.fatal(u'Error rename file <%s>' % old_rep_file_name)

            if os.path.isfile(old_rep_pkl_file_name):
                os.remove(old_rep_pkl_file_name)

            report = res_func.loadResource(new_rep_file_name)
            report['name'] = new_name

            rep_file = None
            try:
                rep_file = open(new_rep_file_name, 'wt')
                rep_file.write(str(report))
                rep_file.close()
            except:
                rep_file.close()

        new_xls_file_name = os.path.join(
            os.path.split(old_rep_file_name)[0], new_name + XLS_FILENAME_EXT)
        if os.path.isfile(old_xls_file_name):
            os.rename(old_xls_file_name, new_xls_file_name)
            try:
                excel_app = win32com.client.Dispatch('Excel.Application')
                excel_app.Visible = 0
                rep_tmpl = new_xls_file_name.replace('./', os.getcwd() + '/')
                rep_tmpl_book = excel_app.Workbooks.Open(rep_tmpl)
                rep_tmpl_sheet = rep_tmpl_book.Worksheets(old_name)
                rep_tmpl_sheet.Name = new_name
                rep_tmpl_book.save()
                excel_app.Quit()
            except pythoncom.com_error:
                log_func.fatal(u'Error rename file')
Exemple #5
0
def selectReport(parent_form=None,
                 report_filename='',
                 report_dir='',
                 db_url=None,
                 sql=None,
                 command=None,
                 stylelib_filename=None,
                 variables=None):
    """
    The function starts the report generator with the subsequent choice of action.

    :param parent_form: The parent form, if not specified, creates a new application.
    :param report_filename: Report filename.
    :param report_dir: Directory where reports are stored.
    :param db_url: URL Connection string.
        For example:
        postgresql+psycopg2://postgres:[email protected]:5432/realization.
    :param sql: SQL query text.
    :param command: After generation command. print/preview/export.
    :param stylelib_filename: Style library filename.
    :param variables: A dictionary of variables to populate the report.
    :return: True/False.
    """
    report_filename = getReportResourceFilename(report_filename, report_dir)
    try:
        if not report_filename:
            return openReportViewer(parent_form, report_dir)
        else:
            stylelib = loadStyleLib(stylelib_filename)
            repgen_system = report_gen_func.getReportGeneratorSystem(
                report_filename, parent_form)
            log_func.info(u'Use report generate system <%s>' %
                          repgen_system.__class__.__name__)
            return repgen_system.selectAction(
                res_func.loadResource(report_filename),
                stylelib=stylelib,
                variables=variables)
    except:
        log_func.fatal(u'Error generating report with action selection <%s>' %
                       report_filename)
    return False