Example #1
0
    def test_two_envs(self):
        """fails for two environment variables"""
        sat_path = os.path.abspath(os.path.join(MODEL_PATH, 'Satellite_V02'))
        os.environ['Satellite_V02_base'] = sat_path
        os.environ['Satellite_V02_bddm'] = os.path.join('BULK', 'MATERIAUX')
        #os.environ['Satellite_V02_INCLUDE'] = os.path.join(sat_path, 'INCLUDE')
        #os.environ['Satellite_V02_BULK'] = os.path.join(sat_path, 'BULK')

        pth = "INCLUDE 'Satellite_V02_base:Satellite_V02_bddm:Satellite_V02_Materiaux.blk'"
        with self.assertRaises(SyntaxError):
            pth2 = get_include_filename([pth], include_dir=r'C:\dir\dir2', is_windows=True)
        with self.assertRaises(SyntaxError):
            pth2 = get_include_filename([pth], include_dir=r'C:\dir\dir2', is_windows=False)
Example #2
0
    def test_paths_sat(self):
        """runs through the various satellite includes on windows and linux"""
        sat_path = os.path.abspath(os.path.join(MODEL_PATH, 'Satellite_V02'))
        os.environ['Satellite_V02_base'] = sat_path
        os.environ['Satellite_V02_bddm'] = os.path.join(
            sat_path, 'BULK', 'MATERIAUX')
        os.environ['Satellite_V02_BULK'] = os.path.join(sat_path, 'BULK')
        os.environ['Satellite_V02_INCLUDE'] = os.path.join(sat_path, 'INCLUDE')

        assert os.path.exists(sat_path), print_bad_path(sat_path)
        assert os.path.exists(os.path.join(sat_path, 'BULK')), print_bad_path(
            os.path.join(sat_path, 'BULK'))
        assert os.path.exists(os.path.join(
            sat_path, 'BULK', 'MATERIAUX')), print_bad_path(
                os.path.join(sat_path, 'BULK', 'MATERIAUX'))
        assert os.path.exists(os.path.join(
            sat_path,
            'INCLUDE')), print_bad_path(os.path.join(sat_path, 'INCLUDE'))

        pths = [
            "INCLUDE 'Satellite_V02_bddm:Satellite_V02_Materiaux.blk'",
            "INCLUDE 'Satellite_V02_BULK:CONM2/Satellite_V02_CONM2.blk'",
            "INCLUDE 'Satellite_V02_BULK:RBE2/Satellite_V02_RBE2.blk'",
            "INCLUDE 'Satellite_V02_BULK:TUBE/Satellite_V02_TubeCentral.blk'",
            "INCLUDE 'Satellite_V02_BULK:TUBE/Satellite_V02_Barre_TubeCentral.blk'",
            "INCLUDE 'Satellite_V02_INCLUDE:Satellite_V02_Panneau_Etoile.dat'",
            "INCLUDE 'Satellite_V02_BULK:ETOILE/Satellite_V02_Barre_Panneau_Etoile.blk'",
            "INCLUDE 'Satellite_V02_BULK:TOP/Satellite_V02_Panneau_PZ.blk'",
            "INCLUDE 'Satellite_V02_BULK:TOP/Satellite_V02_Barre_Panneau_PZ.blk'",
            "INCLUDE 'Satellite_V02_BULK:BOTTOM/Satellite_V02_Panneau_MZ.blk'",
            "INCLUDE 'Satellite_V02_INCLUDE:Satellite_V02_Tube_Cone.dat'",
            "INCLUDE 'Satellite_V02_BULK:COORDS/satellite_V02_Coord.blk'",
            "INCLUDE 'Satellite_V02_INCLUDE:Satellite_V02_Panneau_Externe.dat'",
        ]
        for pth in pths:
            pth2 = get_include_filename([pth], include_dir='', is_windows=True)
            #if not os.path.exists(pth2):
            #msg = 'Invalid Path\nold:  %r\nnew:  %r' % (pth, pth2)
            #msg += print_bad_path(pth2)
            #raise RuntimeError(msg)
            #print('pth1 =', pth2)

            pth2 = get_include_filename([pth],
                                        include_dir='',
                                        is_windows=False)
Example #3
0
    def test_dollar_envs(self):
        """tests sane environment variables"""
        sat_path = os.path.abspath(os.path.join(MODEL_PATH, 'Satellite_V02'))
        os.environ['Satellite_V02_base'] = sat_path
        os.environ['Satellite_V02_bddm'] = os.path.join('BULK', 'MATERIAUX')
        #os.environ['Satellite_V02_INCLUDE'] = os.path.join(sat_path, 'INCLUDE')
        #os.environ['Satellite_V02_BULK'] = os.path.join(sat_path, 'BULK')

        pth = "INCLUDE '%Satellite_V02_bddm%:Satellite_V02_Materiaux.blk'"
        pth2 = get_include_filename([pth], include_dir='', is_windows=True)
Example #4
0
    def _lines_to_deck_lines(self, lines):
        # type: (List[str]) -> List[str], int
        """
        Merges the includes into the main deck.

        Parameters
        ----------
        lines : List[str]
            the lines from the main BDF

        Returns
        -------
        active_lines : List[str]
            all the active lines in the deck
        """
        nlines = len(lines)

        i = 0
        while i < nlines:
            try:
                line = lines[i].rstrip('\r\n\t')
            except IndexError:
                break
            uline = line.upper()
            if uline.startswith('INCLUDE'):
                j, include_lines = self._get_include_lines(
                    lines, line, i, nlines)
                bdf_filename2 = get_include_filename(
                    include_lines, include_dir=self.include_dir)
                if self.read_includes:
                    try:
                        self._open_file_checks(bdf_filename2)
                    except IOError:
                        crash_name = 'pyNastran_crash.bdf'
                        self._dump_file(crash_name, lines, j)
                        msg = 'There was an invalid filename found while parsing.\n'
                        msg += 'Check the end of %r\n' % crash_name
                        msg += 'bdf_filename2 = %r\n' % bdf_filename2
                        msg += 'abs_filename2 = %r\n' % os.path.abspath(
                            bdf_filename2)
                        #msg += 'len(bdf_filename2) = %s' % len(bdf_filename2)
                        print(msg)
                        raise
                        #raise IOError(msg)

                    with self._open_file(bdf_filename2,
                                         basename=False) as bdf_file:
                        #print('bdf_file.name = %s' % bdf_file.name)
                        try:
                            lines2 = bdf_file.readlines()
                        except UnicodeDecodeError:
                            msg = 'Invalid Encoding: encoding=%r.  Fix it by:\n' % self.encoding
                            msg += '  1.  try a different encoding (e.g., latin1)\n'
                            msg += "  2.  call read_bdf(...) with `encoding`'\n"
                            msg += (
                                "  3.  Add '$ pyNastran : encoding=latin1"
                                ' (or other encoding) to the top of the main file\n'
                            )
                            raise RuntimeError(msg)

                    #print('lines2 = %s' % lines2)
                    nlines += len(lines2)

                    #line2 = lines[j].split('$')
                    #if not line2[0].isalpha():
                    #print('** %s' % line2)

                    include_comment = '\n$ INCLUDE processed:  %s\n' % bdf_filename2
                    #for line in lines2:
                    #print("  ?%s" % line.rstrip())
                    lines = lines[:i] + [include_comment] + lines2 + lines[j:]
                    #for line in lines:
                    #print("  *%s" % line.rstrip())
                else:
                    lines = lines[:i] + lines[j:]
                    self.reject_lines.append(include_lines)
                    #self.reject_lines.append(write_include(bdf_filename2))
            i += 1

        if self.dumplines:
            self._dump_file('pyNastran_dump.bdf', lines, i)
        return lines
Example #5
0
    def lines_to_deck_lines(self, lines, make_ilines=True):
        # type: (List[str]) -> List[str], int
        """
        Merges the includes into the main deck.

        Parameters
        ----------
        lines : List[str]
            the lines from the main BDF
        make_ilines : bool; default=True
            flag for ilines

        Returns
        -------
        active_lines : List[str]
            all the active lines in the deck
        ilines : (nlines, 2) int ndarray
            if make_ilines = True:
                the [ifile, iline] pair for each line in the file
            if make_ilines = False:
                 ilines = None
        """
        nlines = len(lines)

        ilines = None
        if make_ilines:
            ilines = _make_ilines(nlines, ifile=0)

        i = 0
        ifile = 1
        while i < nlines:
            try:
                line = lines[i].rstrip('\r\n\t')
            except IndexError:
                break
            uline = line.upper()
            if uline.startswith('INCLUDE'):
                j, include_lines = self._get_include_lines(
                    lines, line, i, nlines)
                bdf_filename2 = get_include_filename(
                    include_lines, include_dir=self.include_dir)
                self.include_lines[ifile - 1].append(
                    (include_lines, bdf_filename2))

                if self.read_includes:
                    lines, nlines, ilines = self._update_include(
                        lines,
                        nlines,
                        ilines,
                        include_lines,
                        bdf_filename2,
                        i,
                        j,
                        ifile,
                        make_ilines=make_ilines)
                    ifile += 1
                else:
                    lines = lines[:i] + lines[j:]
                    if make_ilines:
                        ilines = np.vstack([
                            ilines[:i, :],
                            ilines[j:, :],
                        ])
                        #assert len(ilines[:, 1]) == len(np.unique(ilines[:, 1]))
                    #self.include_lines[ifile].append(include_lines)
                    #self.reject_lines.append(write_include(bdf_filename2))
            i += 1

        if self.dumplines:
            self._dump_file('pyNastran_dump.bdf', lines, i)

        #if make_ilines:
        #nilines = ilines.shape[0]
        #assert nlines == ilines.shape[0], 'nlines=%s nilines=%s' % (nlines, nilines)
        return lines, ilines