def run(self, config_filename):
        """
        The "main" of the wrapper generator. Returns 0 on success, 1 if one or more errors occurred.
        :param str config_filename: The name of the configuration file.
        :return: The exit code.
        :rtype: int
        """
        self._read_configuration_file(config_filename)

        routines = self._read_routine_metadata()

        self._write_class_header()

        if routines:
            for routine_name in sorted(routines):
                if routines[routine_name]['designation'] != 'hidden':
                    self._write_routine_function(routines[routine_name])
        else:
            print("No files with stored routines found.")

        self._write_class_trailer()

        Util.write_two_phases(self._wrapper_filename, self._code)

        return 0
Ejemplo n.º 2
0
    def _write_columns(self):
        """
        Writes table and column names, the width of the column, and the constant name (if assigned) to
        constants_filename.
        """
        content = ''
        for table_name, table in sorted(self._columns.items()):
            width1 = 0
            width2 = 0

            key_map = {}
            for column_name, column in table.items():
                key_map[column['ordinal_position']] = column_name
                width1 = max(len(str(column['column_name'])), width1)
                width2 = max(len(str(column['length'])), width2)

            for ord_position, column_name in sorted(key_map.items()):
                if table[column_name]['length'] is not None:
                    if 'constant_name' in table[column_name]:
                        line_format = "%%s.%%-%ds %%%dd %%s\n" % (int(width1), int(width2))
                        content += line_format % (table[column_name]['table_name'],
                                                  table[column_name]['column_name'],
                                                  table[column_name]['length'],
                                                  table[column_name]['constant_name'])
                    else:
                        line_format = "%%s.%%-%ds %%%dd\n" % (int(width1), int(width2))
                        content += line_format % (table[column_name]['table_name'],
                                                  table[column_name]['column_name'],
                                                  table[column_name]['length'])

            content += "\n"

        # Save the columns, width and constants to the filesystem.
        Util.write_two_phases(self._constants_filename, content)
Ejemplo n.º 3
0
    def _write_columns(self):
        """
        Writes table and column names, the width of the column, and the constant name (if assigned) to
        constants_filename.
        """
        content = ''
        for table_name, table in sorted(self._columns.items()):
            width1 = 0
            width2 = 0

            key_map = {}
            for column_name, column in table.items():
                key_map[column['ordinal_position']] = column_name
                width1 = max(len(str(column['column_name'])), width1)
                width2 = max(len(str(column['length'])), width2)

            for ord_position, column_name in sorted(key_map.items()):
                if table[column_name]['length'] is not None:
                    if 'constant_name' in table[column_name]:
                        line_format = "%%s.%%-%ds %%%dd %%s\n" % (int(width1), int(width2))
                        content += line_format % (table[column_name]['table_name'],
                                                  table[column_name]['column_name'],
                                                  table[column_name]['length'],
                                                  table[column_name]['constant_name'])
                    else:
                        line_format = "%%s.%%-%ds %%%dd\n" % (int(width1), int(width2))
                        content += line_format % (table[column_name]['table_name'],
                                                  table[column_name]['column_name'],
                                                  table[column_name]['length'])

            content += "\n"

        # Save the columns, width and constants to the filesystem.
        Util.write_two_phases(self._constants_filename, content)
Ejemplo n.º 4
0
    def __write_constant_class(self):
        """
        Inserts new and replaces old (if any) constant declaration statements in the class that acts like a namespace
        for constants.
        """
        helper = ConstantClass(self._class_name, self._io)

        content = helper.source_with_constants(self._constants)

        Util.write_two_phases(helper.file_name(), content, self._io)
Ejemplo n.º 5
0
    def _write_target_config_file(self):
        """
        Creates a python configuration file with constants.
        """
        content = ''
        for constant, value in sorted(self._constants.items()):
            content += "{0!s} = {1!s}\n".format(str(constant), str(value))

            # Save the configuration file.
        Util.write_two_phases(self._config_filename, content, self._io)
Ejemplo n.º 6
0
    def _write_target_config_file(self):
        """
        Creates a python configuration file with constants.
        :return:
        """
        content = ''
        for constant, value in sorted(self._constants.items()):
            content += "%s = %s\n" % (str(constant), str(value))

            # Save the configuration file.
        Util.write_two_phases(self._config_filename, content)
Ejemplo n.º 7
0
    def _write_target_config_file(self):
        """
        Creates a python configuration file with constants.
        :return:
        """
        content = ''
        for constant, value in sorted(self._constants.items()):
            content += "%s = %s\n" % (str(constant), str(value))

            # Save the configuration file.
        Util.write_two_phases(self._config_filename, content)
    def __generate_wrapper_class(self):
        """
        Generates the wrapper class.
        """
        routines = self._read_routine_metadata()

        self._write_class_header()

        if routines:
            for routine_name in sorted(routines):
                if routines[routine_name]['designation'] != 'hidden':
                    self._write_routine_function(routines[routine_name])
        else:
            self._io.error('No files with stored routines found')

        self._write_class_trailer()

        Util.write_two_phases(self._wrapper_filename, self._code, self._io)
Ejemplo n.º 9
0
    def _write_columns(self):
        """
        Writes table and column names, the width of the column, and the constant name (if assigned) to
        constants_filename.
        """
        content = ''

        for schema_name, schema in sorted(self._columns.items()):
            for table_name, table in sorted(schema.items()):
                width1 = 0
                width2 = 0

                key_map = {}
                for column_name, column in table.items():
                    key_map[column['column_id']] = column_name
                    width1 = max(len(str(column['column_name'])), width1)
                    width2 = max(len(str(column['length'])), width2)

                for col_id, column_name in sorted(key_map.items()):
                    if table[column_name]['length'] is not None:
                        if 'constant_name' in table[column_name]:
                            line_format = "%s.%s.%-{0:d}s %{1:d}d %s\n".format(int(width1), int(width2))
                            content += line_format % (schema_name,
                                                      table[column_name]['table_name'],
                                                      table[column_name]['column_name'],
                                                      table[column_name]['length'],
                                                      table[column_name]['constant_name'])
                        else:
                            line_format = "%s.%s.%-{0:d}s %{1:d}d\n".format(int(width1), int(width2))
                            content += line_format % (schema_name,
                                                      table[column_name]['table_name'],
                                                      table[column_name]['column_name'],
                                                      table[column_name]['length'])

                content += "\n"""

        # Save the columns, width, and constants to the filesystem.
        Util.write_two_phases(self._constants_filename, content, self._io)