Пример #1
0
    def setUp(self):
        """Prepare the test fixture for the Matrix class."""
        self.Configuration = Configuration()

        self.Configuration.RAMSTK_BACKEND = 'sqlite'
        self.Configuration.RAMSTK_PROG_INFO = {
            'host': 'localhost',
            'socket': 3306,
            'database': '/tmp/TestDB.ramstk',
            'user': '',
            'password': ''
        }

        self.Configuration.DEBUG_LOG = \
            Utilities.create_logger("RAMSTK.debug", 'DEBUG', '/tmp/RAMSTK_debug.log')
        self.Configuration.USER_LOG = \
            Utilities.create_logger("RAMSTK.user", 'INFO', '/tmp/RAMSTK_user.log')

        # Create a data access object and connect to a test database.
        self.dao = DAO()
        _database = self.Configuration.RAMSTK_BACKEND + ':///' + \
            self.Configuration.RAMSTK_PROG_INFO['database']
        self.dao.db_connect(_database)

        self.dao.RAMSTK_SESSION.configure(bind=self.dao.engine,
                                          autoflush=False,
                                          expire_on_commit=False)
        self.session = scoped_session(self.dao.RAMSTK_SESSION)

        self.DUT = RAMSTKDataMatrix(self.dao, RAMSTKFunction, RAMSTKHardware)
Пример #2
0
    def set_site_variables(self):
        """
        Set the site configuration variables.

        :return: False if successful or True if an error is encountered.
        :rtype: bool
        """
        # Prefer user-specific directories in their $HOME directory over the
        # system-wide directories.
        if Utilities.dir_exists(self.RAMSTK_HOME_DIR + '/.config/RAMSTK'):
            self.RAMSTK_CONF_DIR = self.RAMSTK_HOME_DIR + '/.config/RAMSTK'
        else:
            self.RAMSTK_CONF_DIR = self.RAMSTK_SITE_DIR

        if Utilities.dir_exists(self.RAMSTK_HOME_DIR + '/.config/RAMSTK/data'):
            self.RAMSTK_DATA_DIR = self.RAMSTK_HOME_DIR + \
            '/.config/RAMSTK/data'

        if Utilities.dir_exists(self.RAMSTK_HOME_DIR +
                                '/.config/RAMSTK/icons'):
            self.RAMSTK_ICON_DIR = self.RAMSTK_HOME_DIR + \
            '/.config/RAMSTK/icons'

        if Utilities.dir_exists(self.RAMSTK_HOME_DIR + '/.config/RAMSTK/logs'):
            self.RAMSTK_LOG_DIR = self.RAMSTK_HOME_DIR + '/.config/RAMSTK/logs'

        self.RAMSTK_SITE_CONF = self.RAMSTK_CONF_DIR + '/Site.conf'

        if not Utilities.file_exists(self.RAMSTK_SITE_CONF):
            self._set_site_configuration()

        self.get_site_configuration()

        return False
Пример #3
0
    def set_user_configuration(self):
        """
        Write changes to the user's configuration file.

        :return: False if successful or True if an error is encountered.
        :rtype: bool
        """
        _return = False

        if Utilities.file_exists(self.RAMSTK_PROG_CONF):
            _config = ConfigParser.ConfigParser()
            _config.add_section('General')
            _config.set('General', 'reportsize', self.RAMSTK_REPORT_SIZE)
            _config.set('General', 'parallelcalcs', 'False')
            _config.set('General', 'frmultiplier', self.RAMSTK_HR_MULTIPLIER)
            _config.set('General', 'calcreltime', self.RAMSTK_MTIME)
            _config.set('General', 'autoaddlistitems', 'False')
            _config.set('General', 'decimal', self.RAMSTK_DEC_PLACES)
            _config.set('General', 'modesource', self.RAMSTK_MODE_SOURCE)
            _config.set('General', 'moduletabpos',
                        self.RAMSTK_TABPOS['modulebook'])
            _config.set('General', 'listtabpos',
                        self.RAMSTK_TABPOS['listbook'])
            _config.set('General', 'worktabpos',
                        self.RAMSTK_TABPOS['workbook'])

            _config.add_section('Backend')
            _config.set('Backend', 'type', self.RAMSTK_BACKEND)
            _config.set('Backend', 'host', self.RAMSTK_PROG_INFO['host'])
            _config.set('Backend', 'socket',
                        int(self.RAMSTK_PROG_INFO['socket']))
            _config.set('Backend', 'database',
                        self.RAMSTK_PROG_INFO['database'])
            _config.set('Backend', 'user', self.RAMSTK_PROG_INFO['user'])
            _config.set('Backend', 'password',
                        self.RAMSTK_PROG_INFO['password'])

            _config.add_section('Directories')
            _config.set('Directories', 'datadir', self.RAMSTK_DATA_DIR)
            _config.set('Directories', 'icondir', self.RAMSTK_ICON_DIR)
            _config.set('Directories', 'logdir', self.RAMSTK_LOG_DIR)
            _config.set('Directories', 'progdir', self.RAMSTK_PROG_DIR)

            _config.add_section('Files')
            for _file in self._lst_format_files:
                _config.set('Files', _file,
                            path.basename(self.RAMSTK_FORMAT_FILE[_file]))

            _config.add_section('Colors')
            for _color in self._lst_colors:
                _config.set('Colors', _color, self.RAMSTK_COLORS[_color])

            try:
                _parser = open(self.RAMSTK_PROG_CONF, 'w')
                _config.write(_parser)
                _parser.close()
            except EnvironmentError:
                _return = True

        return _return
Пример #4
0
    def get_site_configuration(self):
        """
        Read the site configuration file.

        :return: False of successful or True if an error is encountered.
        :rtype: bool
        """
        _return = False

        # Try to read the user's configuration file.  If it doesn't exist,
        # create a new one.  If those options fail, read the system-wide
        # configuration file and keep going.
        if Utilities.file_exists(self.RAMSTK_SITE_CONF):
            _config = ConfigParser.ConfigParser()
            _config.read(self.RAMSTK_SITE_CONF)

            self.RAMSTK_COM_BACKEND = _config.get('Backend', 'type')
            self.RAMSTK_COM_INFO['host'] = _config.get('Backend', 'host')
            self.RAMSTK_COM_INFO['socket'] = _config.get('Backend', 'socket')
            self.RAMSTK_COM_INFO['database'] = _config.get(
                'Backend', 'database')
            self.RAMSTK_COM_INFO['user'] = _config.get('Backend', 'user')
            self.RAMSTK_COM_INFO['password'] = _config.get(
                'Backend', 'password')
            self.RAMSTK_COM_INFO['path'] = _config.get('Backend', 'password')

        return _return
Пример #5
0
    def get_user_configuration(self):
        """
        Read the RAMSTK configuration file.

        :return: False if successful or True if an error is encountered.
        :rtype: bool
        """
        _return = False

        # Try to read the user's configuration file.  If it doesn't exist,
        # create a new one.  If those options fail, read the system-wide
        # configuration file and keep going.
        if Utilities.file_exists(self.RAMSTK_PROG_CONF):
            _config = ConfigParser.ConfigParser()
            _config.read(self.RAMSTK_PROG_CONF)

            for _color in self._lst_colors:
                self.RAMSTK_COLORS[_color] = _config.get('Colors', _color)

            for _file in self._lst_format_files:
                self.RAMSTK_FORMAT_FILE[_file] = _config.get('Files', _file)

            self.RAMSTK_BACKEND = _config.get('Backend', 'type')
            self.RAMSTK_PROG_INFO['host'] = _config.get('Backend', 'host')
            self.RAMSTK_PROG_INFO['socket'] = _config.get('Backend', 'socket')
            self.RAMSTK_PROG_INFO['database'] = _config.get(
                'Backend', 'database')
            self.RAMSTK_PROG_INFO['user'] = _config.get('Backend', 'user')
            self.RAMSTK_PROG_INFO['password'] = _config.get(
                'Backend', 'password')

            self.RAMSTK_DATA_DIR = _config.get('Directories', 'datadir')
            self.RAMSTK_ICON_DIR = _config.get('Directories', 'icondir')
            self.RAMSTK_LOG_DIR = _config.get('Directories', 'logdir')
            self.RAMSTK_PROG_DIR = _config.get('Directories', 'progdir')

            self.RAMSTK_REPORT_SIZE = _config.get('General', 'reportsize')
            self.RAMSTK_HR_MULTIPLIER = _config.get('General', 'frmultiplier')
            self.RAMSTK_DEC_PLACES = _config.get('General', 'decimal')
            self.RAMSTK_MTIME = _config.get('General', 'calcreltime')
            self.RAMSTK_MODE_SOURCE = _config.get('General', 'modesource')
            self.RAMSTK_TABPOS['listbook'] = _config.get(
                'General', 'listtabpos')
            self.RAMSTK_TABPOS['modulebook'] = _config.get(
                'General', 'moduletabpos')
            self.RAMSTK_TABPOS['workbook'] = _config.get(
                'General', 'worktabpos')
        else:
            _return = True

        return _return
Пример #6
0
    def _request_create_sqlite3_project(self):
        """Create a RAMSTK Project database using SQLite3."""
        _dialog = gtk.FileChooserDialog(
            title=_(u"Create a RAMSTK Program Database"),
            action=gtk.FILE_CHOOSER_ACTION_SAVE,
            buttons=(gtk.STOCK_NEW, gtk.RESPONSE_ACCEPT, gtk.STOCK_CANCEL,
                     gtk.RESPONSE_REJECT))
        _dialog.set_current_folder(
            self._mdcRAMSTK.RAMSTK_CONFIGURATION.RAMSTK_PROG_DIR)

        if _dialog.run() == gtk.RESPONSE_ACCEPT:
            _new_program = _dialog.get_filename()
            _new_program = _new_program + '.ramstk'

            if Utilities.file_exists(_new_program):
                _dlgConfirm = ramstk.RAMSTKDialog(
                    _(u"RAMSTK - Confirm Overwrite"),
                    dlgbuttons=(gtk.STOCK_YES, gtk.RESPONSE_YES, gtk.STOCK_NO,
                                gtk.RESPONSE_NO))

                _label = ramstk.RTLabel(_(
                    u"RAMSTK Program database already exists. "
                    u"\n\n{0:s}\n\nOverwrite?").format(_new_program),
                                        width=-1,
                                        height=-1,
                                        bold=False,
                                        wrap=True)
                _dlgConfirm.vbox.pack_start(_label)
                _label.show()

                if _dlgConfirm.run() == gtk.RESPONSE_YES:
                    _dlgConfirm.destroy()
                    remove(_new_program)
                else:
                    _dlgConfirm.destroy()
                    _dialog.destroy()
                    return True

            self._mdcRAMSTK.RAMSTK_CONFIGURATION.RAMSTK_PROG_INFO['database'] = \
                _new_program

        _dialog.destroy()

        self._mdcRAMSTK.request_do_create_program()

        return False
Пример #7
0
    def set_user_variables(self, first_run=True):
        """
        Set the user-specific configuration variables.

        :return: False if successful or True if an error is encountered.
        :rtype: bool
        """
        _return = False

        # Prefer user-specific directories in their $HOME directory over the
        # system-wide directories.
        if Utilities.dir_exists(self.RAMSTK_HOME_DIR + '/.config/RAMSTK'):
            self.RAMSTK_CONF_DIR = self.RAMSTK_HOME_DIR + '/.config/RAMSTK'
        else:
            self.RAMSTK_CONF_DIR = self.RAMSTK_SITE_DIR
            _return = first_run

        self.RAMSTK_PROG_CONF = self.RAMSTK_CONF_DIR + '/RAMSTK.conf'

        return _return
Пример #8
0
    def __init__(self):
        """Initialize the RAMSTK configuration parser."""
        # Initialize private dictionary attributes.

        # Initialize private list attributes.
        self._lst_colors = [
            'revisionfg', 'functionfg', 'requirementfg', 'hardwarefg',
            'validationfg', 'revisionbg', 'functionbg', 'requirementbg',
            'hardwarebg', 'validationbg', 'stakeholderbg', 'stakeholderfg'
        ]
        self._lst_format_files = [
            'allocation', 'dfmeca', 'failure_definition', 'ffmea', 'function',
            'hardware', 'hazops', 'pof', 'requirement', 'revision',
            'similaritem', 'stakeholder', 'validation'
        ]

        # Initialize private scalar attributes.
        self._INSTALL_PREFIX = Utilities.prefix()

        # Initialize public dictionary attributes.

        # Initialize public list attributes.

        # Initialize public scalar attributes.
        if sys.platform == 'linux2':
            self.RAMSTK_OS = 'Linux'
            self.RAMSTK_SITE_DIR = self._INSTALL_PREFIX + '/share/RAMSTK'
            self.RAMSTK_HOME_DIR = environ['HOME']
            self.RAMSTK_LOG_DIR = '/var/log/RAMSTK'

        elif sys.platform == 'win32':
            self.RAMSTK_OS = 'Windows'
            self.RAMSTK_SITE_DIR = environ['PYTHONPATH'] + '/RAMSTK'
            self.RAMSTK_HOME_DIR = environ['USERPROFILE']
            self.RAMSTK_LOG_DIR = self.RAMSTK_SITE_DIR + '/logs'

        self.RAMSTK_DATA_DIR = self.RAMSTK_SITE_DIR + '/layouts'
        self.RAMSTK_ICON_DIR = self.RAMSTK_SITE_DIR + '/icons'
        self.RAMSTK_PROG_DIR = self.RAMSTK_HOME_DIR + '/analyses/ramstk/'
        self.RAMSTK_CONF_DIR = self.RAMSTK_SITE_DIR
Пример #9
0
    def create_user_configuration(self):
        """
        Create the default user configuration file.

        :return: False if successful or True if an error is encountered.
        :rtype: bool
        """
        import glob
        from distutils import dir_util, file_util  # pylint: disable=no-name-in-module

        _return = False

        _config = ConfigParser.ConfigParser()

        # Create the directories needed for the user.  Always prefer the RAMSTK
        # directories in the user's $HOME over the system-wide directories.
        # Configuration directory.
        self.RAMSTK_CONF_DIR = self.RAMSTK_HOME_DIR + '/.config/RAMSTK'
        try:
            makedirs(self.RAMSTK_CONF_DIR)
            self.RAMSTK_PROG_CONF = self.RAMSTK_CONF_DIR + '/RAMSTK.conf'
        except OSError:
            pass

        # Data directory.
        self.RAMSTK_DATA_DIR = self.RAMSTK_CONF_DIR + '/layouts'
        if not Utilities.dir_exists(self.RAMSTK_DATA_DIR):
            try:
                makedirs(self.RAMSTK_DATA_DIR)
            except OSError:
                pass

        # Icon directory.
        self.RAMSTK_ICON_DIR = self.RAMSTK_CONF_DIR + '/icons'
        if not Utilities.dir_exists(self.RAMSTK_ICON_DIR):
            try:
                makedirs(self.RAMSTK_ICON_DIR)
            except OSError:
                pass

        # Log directory.
        self.RAMSTK_LOG_DIR = self.RAMSTK_CONF_DIR + '/logs'
        if not Utilities.dir_exists(self.RAMSTK_LOG_DIR):
            try:
                makedirs(self.RAMSTK_LOG_DIR)
            except OSError:
                pass

        # Program directory.
        if not Utilities.dir_exists(self.RAMSTK_PROG_DIR):
            try:
                makedirs(self.RAMSTK_PROG_DIR)
            except OSError:
                pass

        # Copy format files from RAMSTK_SITE_DIR (system) to the user's
        # RAMSTK_CONF_DIR.
        for _file in glob.glob(self.RAMSTK_SITE_DIR + '/layouts/*.xml'):
            file_util.copy_file(_file, self.RAMSTK_DATA_DIR)

        # Copy the icons from RAMSTK_SITE_DIR (system) to the user's
        # RAMSTK_ICON_DIR.
        try:
            dir_util.copy_tree(self.RAMSTK_SITE_DIR + '/icons/',
                               self.RAMSTK_ICON_DIR)
        except IOError:
            _return = True

        # Create the default RAMSTK user configuration file.
        _config.add_section('General')
        _config.set('General', 'firstrun', True)
        _config.set('General', 'reportsize', 'letter')
        _config.set('General', 'frmultiplier', 1000000.0)
        _config.set('General', 'calcreltime', 100.0)
        _config.set('General', 'autoaddlistitems', 'False')
        _config.set('General', 'decimal', 6)
        _config.set('General', 'modesource', 1)
        _config.set('General', 'parallelcalcs', 'False')
        _config.set('General', 'moduletabpos', 'top')
        _config.set('General', 'listtabpos', 'bottom')
        _config.set('General', 'worktabpos', 'bottom')

        _config.add_section('Backend')
        _config.set('Backend', 'type', 'sqlite')
        _config.set('Backend', 'host', 'localhost')
        _config.set('Backend', 'socket', 3306)
        _config.set('Backend', 'database', '')
        _config.set('Backend', 'user', '')
        _config.set('Backend', 'password', '')

        _config.add_section('Directories')
        _config.set('Directories', 'datadir', self.RAMSTK_DATA_DIR)
        _config.set('Directories', 'icondir', self.RAMSTK_ICON_DIR)
        _config.set('Directories', 'logdir', self.RAMSTK_LOG_DIR)
        _config.set('Directories', 'progdir', self.RAMSTK_PROG_DIR)

        _config.add_section('Files')
        _config.set('Files', 'allocation', 'Allocation.xml')
        _config.set('Files', 'dfmeca', 'DFMECA.xml')
        _config.set('Files', 'failure_definition', 'FailureDefinition.xml')
        _config.set('Files', 'ffmea', 'FFMEA.xml')
        _config.set('Files', 'function', 'Function.xml')
        _config.set('Files', 'hardware', 'Hardware.xml')
        _config.set('Files', 'hazops', 'HazOps.xml')
        _config.set('Files', 'pof', 'PoF.xml')
        _config.set('Files', 'requirement', 'Requirement.xml')
        _config.set('Files', 'revision', 'Revision.xml')
        _config.set('Files', 'similaritem', 'SimilarItem.xml')
        _config.set('Files', 'stakeholder', 'Stakeholder.xml')
        _config.set('Files', 'validation', 'Validation.xml')

        _config.add_section('Colors')
        _config.set('Colors', 'functionbg', '#FFFFFF')
        _config.set('Colors', 'functionfg', '#000000')
        _config.set('Colors', 'hardwarebg', '#FFFFFF')
        _config.set('Colors', 'hardwarefg', '#000000')
        _config.set('Colors', 'requirementbg', '#FFFFFF')
        _config.set('Colors', 'requirementfg', '#000000')
        _config.set('Colors', 'revisionbg', '#FFFFFF')
        _config.set('Colors', 'revisionfg', '#000000')
        _config.set('Colors', 'stakeholderbg', '#FFFFFF')
        _config.set('Colors', 'stakeholderfg', '#000000')
        _config.set('Colors', 'validationbg', '#FFFFFF')
        _config.set('Colors', 'validationfg', '#000000')

        try:
            _parser = open(self.RAMSTK_PROG_CONF, 'w')
            _config.write(_parser)
            _parser.close()
        except EnvironmentError:
            _return = True

        self._set_site_configuration()

        return _return
Пример #10
0
def test_configuration():
    """Create configuration object to use for testing."""
    # Create the data directory if it doesn't exist.
    if not os.path.exists(DATA_DIR):
        os.makedirs(DATA_DIR)

    # Create the log directory if it doesn't exist.
    if not os.path.exists(LOG_DIR):
        os.makedirs(LOG_DIR)

    configuration = Configuration()

    configuration.RAMSTK_SITE_DIR = CONF_DIR
    configuration.RAMSTK_CONF_DIR = CONF_DIR
    configuration.RAMSTK_PROG_CONF = configuration.RAMSTK_CONF_DIR + '/RAMSTK.conf'

    configuration.RAMSTK_COM_BACKEND = 'sqlite'
    configuration.RAMSTK_COM_INFO['host'] = 'localhost'
    configuration.RAMSTK_COM_INFO['socket'] = 3306
    configuration.RAMSTK_COM_INFO['database'] = TEST_COMMON_DB_PATH
    configuration.RAMSTK_COM_INFO['user'] = '******'
    configuration.RAMSTK_COM_INFO['password'] = '******'

    configuration.RAMSTK_REPORT_SIZE = 'letter'
    configuration.RAMSTK_HR_MULTIPLIER = 1000000.0
    configuration.RAMSTK_MTIME = 100.0
    configuration.RAMSTK_DEC_PLACES = 6
    configuration.RAMSTK_MODE_SOURCE = 1
    configuration.RAMSTK_TABPOS = {
        'modulebook': 'top',
        'listbook': 'bottom',
        'workbook': 'bottom'
    }

    configuration.RAMSTK_BACKEND = 'sqlite'
    configuration.RAMSTK_PROG_INFO['host'] = 'localhost'
    configuration.RAMSTK_PROG_INFO['socket'] = 3306
    configuration.RAMSTK_PROG_INFO['database'] = TEST_PROGRAM_DB_PATH
    configuration.RAMSTK_PROG_INFO['user'] = '******'
    configuration.RAMSTK_PROG_INFO['password'] = '******'

    configuration.RAMSTK_DATA_DIR = DATA_DIR
    configuration.RAMSTK_ICON_DIR = ICON_DIR
    configuration.RAMSTK_LOG_DIR = LOG_DIR
    configuration.RAMSTK_PROG_DIR = TMP_DIR

    configuration.RAMSTK_FORMAT_FILE = {
        'allocation': 'Allocation.xml',
        'dfmeca': 'DFMECA.xml',
        'failure_definition': 'FailureDefinition.xml',
        'ffmea': 'FFMEA.xml',
        'function': 'Function.xml',
        'hardware': 'Hardware.xml',
        'hazops': 'HazOps.xml',
        'pof': 'PoF.xml',
        'requirement': 'Requirement.xml',
        'revision': 'Revision.xml',
        'similaritem': 'SimilarItem.xml',
        'stakeholder': 'Stakeholder.xml',
        'validation': 'Validation.xml'
    }
    configuration.RAMSTK_COLORS = {
        'functionbg': '#FFFFFF',
        'functionfg': '#000000',
        'hardwarebg': '#FFFFFF',
        'hardwarefg': '#000000',
        'requirementbg': '#FFFFFF',
        'requirementfg': '#000000',
        'revisionbg': '#FFFFFF',
        'revisionfg': '#000000',
        'stakeholderbg': '#FFFFFF',
        'stakeholderfg': '#000000',
        'validationbg': '#FFFFFF',
        'validationfg': '#000000'
    }

    configuration.set_user_configuration()

    configuration.RAMSTK_DEBUG_LOG = \
        Utilities.create_logger("RAMSTK.debug", 'DEBUG', DEBUG_LOG)
    configuration.RAMSTK_USER_LOG = \
        Utilities.create_logger("RAMSTK.user", 'INFO', USER_LOG)
    configuration.RAMSTK_IMPORT_LOG = \
        Utilities.create_logger("RAMSTK.user", 'INFO', IMPORT_LOG)

    yield configuration