Пример #1
0
    def test_065_main(self):
        """main (unknown project)
        """

        # no env
        x = os.popen4(
            (launcher +
             " LbConfiguration.SetupProject --shell=%s DummyProject") % _shell)
        s = x[1].read().strip()
        self.assert_(proj_not_found(s))

        env = SetupProject.TemporaryEnvironment()
        tmp_dir = mkdtemp()
        try:
            if "CMTPROJECTPATH" not in env:
                env['CMTPROJECTPATH'] = env['LHCBPROJECTPATH']
            env['CMTPROJECTPATH'] = tmp_dir + os.pathsep + env['CMTPROJECTPATH']
            os.mkdir(os.path.join(tmp_dir, 'DUMMYPROJECT'))
            x = os.popen4(
                (launcher +
                 " LbConfiguration.SetupProject --shell=%s DummyProject") %
                _shell)
            s = x[1].read().strip()
            self.assert_(proj_not_found(s))
        finally:
            SetupProject.removeall(tmp_dir)
Пример #2
0
    def test_205_main(self):
        """main (Brunel in user release area, ignored)
        """
        l = get_all_versions("Brunel")
        v = l[-1]

        env = SetupProject.TemporaryEnvironment()
        tmp_dir = mkdtemp()
        try:
            # prepare fake user release area
            os.mkdir(os.path.join(tmp_dir, 'Brunel_%s' % v))
            os.mkdir(os.path.join(tmp_dir, 'Brunel_%s' % v, "cmt"))
            open(os.path.join(tmp_dir,'Brunel_%s'%v,"cmt","project.cmt"),"w").\
                write("project Brunel_%s\n\nuse BRUNEL BRUNEL_%s\n"%(v,v))

            env['User_release_area'] = tmp_dir
            x = os.popen4((
                launcher +
                " LbConfiguration.SetupProject --shell=%s --no-auto-override --no-user-area Brunel %s"
            ) % (_shell, v))
            s = x[1].read().strip()

            self._check_env(s, "Brunel", v)

            if os.environ["CMTCONFIG"][0:3] != "win":
                m = re.compile('LIBRARY_PATH=(.*)').search(s)
            else:
                m = re.compile('set PATH=(.*)').search(s)
            self.assert_(m is not None)
            # Check that the user area is not in the path
            self.assert_(
                m.group(1).split(os.pathsep)[0].find(
                    os.path.join(tmp_dir, 'Brunel_%s' % v, "InstallArea")) < 0)
        finally:
            SetupProject.removeall(tmp_dir)
Пример #3
0
    def test_310_main(self):
        """main (Build-time environment, no version/ask)
        """
        l = get_all_versions("Brunel")
        v = l[-1]

        env = SetupProject.TemporaryEnvironment()
        tmp_dir = mkdtemp()
        env["User_release_area"] = tmp_dir
        try:
            x = os.popen3((
                launcher +
                " LbConfiguration.SetupProject --shell=%s --ignore-missing --build-env Brunel"
            ) % _shell)
            self.assertEquals("Please enter", x[2].read(12))

            # read up to the prompt
            while x[2].read(1) != ':':
                pass
            x[2].read(1)

            x[0].write("\n")
            x[0].flush()

            s = x[1].read()
            proj_cmt = os.path.join(tmp_dir, "Brunel_%s" % v, "cmt",
                                    "project.cmt")
            self.assert_(os.path.isfile(proj_cmt))
            self.assert_(
                re.search(r"use\s+BRUNEL\s+BRUNEL_%s" % v,
                          open(proj_cmt).read()) is not None)
        finally:
            SetupProject.removeall(tmp_dir)
Пример #4
0
    def test_410_main(self):
        """main (no-version project, ask version)
        """

        env = SetupProject.TemporaryEnvironment()
        tmp_dir = self._createFakeProject()
        self._createFakeProject(version="v1r0", tmp_dir=tmp_dir)
        env["CMTPROJECTPATH"] = env["User_release_area"] = tmp_dir

        try:
            x = os.popen3((
                launcher +
                " LbConfiguration.SetupProject --shell=%s --no-auto-override --disable-CASTOR TestProject --ask"
            ) % _shell)

            self.assertEquals("Please enter", x[2].read(12))

            # read up to the prompt
            while x[2].read(1) != ':':
                pass
            x[2].read(1)  # eat the space char

            # quit
            x[0].write("None\n")
            x[0].flush()

            s = x[1].read()
            self.assert_(project_configured(s, "TestProject", None))
        finally:
            SetupProject.removeall(tmp_dir)
Пример #5
0
    def test_030_removeall(self):
        """removeall
        """
        tmp_dir = mkdtemp()
        os.mkdir(os.path.join(tmp_dir, "test1"), 0700)
        open(os.path.join(tmp_dir, "test2"), "w")
        open(os.path.join(tmp_dir, "test1", "test2"), "w")

        SetupProject.removeall(tmp_dir)

        self.assert_(not os.path.exists(tmp_dir))
Пример #6
0
    def test_085_main(self):
        """main (Brunel with runtime project, Online)
        """

        v = SetupProject.makeProjectInfo("Brunel").version
        vo = SetupProject.makeProjectInfo("Online").version

        # --ignore-missing is needed to avoid problems with incompatible versions of Online ad Brunel
        x = os.popen4((
            launcher +
            " LbConfiguration.SetupProject --shell=%s Brunel --ignore-missing --runtime-project Online"
        ) % _shell)
        s = x[1].read()

        self._check_env(s, "Brunel", v)
        self._check_env(s, "Online", vo, withsys=False, main=False)
Пример #7
0
    def test_075_main(self):
        """main (Brunel w/o ext, w/o User_release_area)
        """

        env = SetupProject.TemporaryEnvironment()
        if 'User_release_area' in env:
            del env['User_release_area']

        v = SetupProject.makeProjectInfo("Brunel").version

        x = os.popen4(
            (launcher + " LbConfiguration.SetupProject --shell=%s Brunel") %
            _shell)
        s = x[1].read()

        self._check_env(s, "Brunel", v)
Пример #8
0
    def test_400_main(self):
        """main (no-version project, no explicit version)
        """

        env = SetupProject.TemporaryEnvironment()
        tmp_dir = self._createFakeProject()
        self._createFakeProject(version="v1r0", tmp_dir=tmp_dir)
        env["CMTPROJECTPATH"] = env["User_release_area"] = tmp_dir
        try:
            x = os.popen4((
                launcher +
                " LbConfiguration.SetupProject --shell=%s --no-auto-override --disable-CASTOR TestProject"
            ) % _shell)
            s = x[1].read()
            self.assert_(project_configured(s, "TestProject", None))
        finally:
            SetupProject.removeall(tmp_dir)
Пример #9
0
    def test_077_main(self):
        """main (Brunel w/o ext, w/o CMTPATH and CMTPROJECTPATH)
        """

        env = SetupProject.TemporaryEnvironment()
        for n in ['CMTPATH', 'CMTPROJECTPATH']:
            if n in env:
                del env[n]

        v = SetupProject.makeProjectInfo("Brunel").version

        x = os.popen4(
            (launcher + " LbConfiguration.SetupProject --shell=%s Brunel") %
            _shell)
        s = x[1].read()

        self._check_env(s, "Brunel", v)
Пример #10
0
 def test_020_mkstemp(self):
     """mkstemp
     """
     fd, name = SetupProject.mkstemp()
     self.assert_(os.path.exists(name))
     self.assert_(os.path.isfile(name))
     self.assert_(not os.path.islink(name))
     os.fdopen(fd, "w")
     os.remove(name)
Пример #11
0
    def test_320_main(self):
        """main (Build-time environment, bad version)
        """

        env = SetupProject.TemporaryEnvironment()
        tmp_dir = mkdtemp()
        env["User_release_area"] = tmp_dir
        try:
            x = os.popen4((
                launcher +
                " LbConfiguration.SetupProject --shell=%s --ignore-missing --build-env Brunel v999r999"
            ) % _shell)
            s = x[1].read()
            proj_cmt = os.path.join(tmp_dir, "Brunel_v999r999", "cmt",
                                    "project.cmt")
            self.assert_(not os.path.isfile(proj_cmt))
        finally:
            SetupProject.removeall(tmp_dir)
Пример #12
0
    def test_210_main(self):
        """main (Brunel in LHCBDEV)
        """
        l = get_all_versions("Brunel")
        v = l[-1]

        env = SetupProject.TemporaryEnvironment()
        tmp_dir = mkdtemp()
        try:
            # prepare fake dev area
            dsys = os.path.join(tmp_dir, 'BRUNEL', 'BRUNEL_v999r999',
                                'BrunelSys', 'v999r999', 'cmt')
            os.makedirs(dsys)
            open(os.path.join(dsys, "requirements"), "w").write("""
package BrunelSys
version v999r999
""")
            os.mkdir(os.path.join(tmp_dir, 'BRUNEL', 'BRUNEL_v999r999', 'cmt'))
            os.makedirs(
                os.path.join(tmp_dir, 'BRUNEL', 'BRUNEL_v999r999',
                             'InstallArea', os.environ['CMTCONFIG']))
            open(
                os.path.join(tmp_dir, 'BRUNEL', 'BRUNEL_v999r999', 'cmt',
                             'project.cmt'), "w").write("project Brunel\n")

            env['LHCBDEV'] = tmp_dir
            # get it from LHCBDEV
            x = os.popen4((
                launcher +
                " LbConfiguration.SetupProject --debug --shell=%s --ignore-missing --dev Brunel"
            ) % _shell)
            s = x[1].read()
            #print s
            self.assert_(project_configured(s, "Brunel", "v999r999"))

            # get it from offical releases
            x = os.popen4(
                (launcher + " LbConfiguration.SetupProject --shell=%s Brunel")
                % _shell)
            s = x[1].read()
            self.assert_(project_configured(s, "Brunel", v))

        finally:
            SetupProject.removeall(tmp_dir)
Пример #13
0
    def test_200_main(self):
        """main (Brunel in user release area)
        """
        l = get_all_versions("Brunel")
        v = l[-1]

        env = SetupProject.TemporaryEnvironment()
        tmp_dir = mkdtemp()
        try:
            # prepare fake user release area
            os.makedirs(os.path.join(tmp_dir, 'Brunel_%s' % v, "cmt"))
            os.makedirs(
                os.path.join(tmp_dir, 'Brunel_%s' % v, "InstallArea",
                             env["CMTCONFIG"], "lib"))
            open(os.path.join(tmp_dir,'Brunel_%s'%v,"cmt","project.cmt"),"w").\
                write("project Brunel_%s\n\nuse BRUNEL BRUNEL_%s\n"%(v,v))
            open(os.path.join(tmp_dir,'Brunel_%s'%v,"InstallArea",env["CMTCONFIG"],"lib","do_not_strip"), "w").\
                write("nothing")
            env['User_release_area'] = tmp_dir
            x = os.popen4((
                launcher +
                " LbConfiguration.SetupProject --shell=%s --no-auto-override Brunel %s"
            ) % (_shell, v))
            s = x[1].read().strip()

            self._check_env(s, "Brunel", v)

            if "win" in os.environ["CMTCONFIG"]:
                pat = re.compile('set PATH=(.*)')
            elif "osx" in os.environ["CMTCONFIG"]:
                pat = re.compile('(?<!SAVED_)DYLD_LIBRARY_PATH=(.*)')
            else:  # Linux
                pat = re.compile('(?<!SAVED_)LD_LIBRARY_PATH=(.*)')
            m = pat.search(s)
            self.assert_(m is not None)
            # print m.groups()
            self.assert_(
                m.group(1).strip('"').split(os.pathsep)[0].find(
                    os.path.join(tmp_dir, 'Brunel_%s' %
                                 v, "InstallArea")) >= 0)
            #self.assert_(proj_not_found(s))
        finally:
            SetupProject.removeall(tmp_dir)
Пример #14
0
    def test_070_main(self):
        """main (Brunel w/o ext)
        """

        v = SetupProject.makeProjectInfo("Brunel").version

        x = os.popen4(
            (launcher + " LbConfiguration.SetupProject --shell=%s Brunel") %
            _shell)
        s = x[1].read()

        self._check_env(s, "Brunel", v)
Пример #15
0
    def test_067_main(self):
        """main (wrong case in project name)
        """
        v = SetupProject.makeProjectInfo("Brunel").version

        x = os.popen4(
            (launcher + " LbConfiguration.SetupProject --shell=%s BrUnEl") %
            _shell)
        s = x[1].read()
        ## wrong case is valid
        # self.assert_("Could not produce the environment, check the arguments" in s)
        self._check_env(s, "Brunel", v)
Пример #16
0
    def test_040_gen_script(self):
        """gen_script
        """
        env = {"A": "1", "B": "2", "C": None}
        # clean up the environment
        envguard = SetupProject.TemporaryEnvironment()
        for var in env:
            if var in envguard:
                del envguard[var]
        envguard["C"] = "test"

        expected = {}
        expected['csh'] = 'setenv A "1"\nsetenv B "2"\nunsetenv C\n'.split(
            '\n')
        expected['csh'].sort()

        expected['sh'] = 'export A="1"\nexport B="2"\nunset C\n'.split('\n')
        expected['sh'].sort()

        expected['bat'] = 'set A=1\nset B=2\nset C=\n'.split('\n')
        expected['bat'].sort()

        shells = ['csh', 'sh', 'bat']
        for sh in shells:
            newenv = SetupProject.TemporaryEnvironment()
            for var in env:
                if env[var]:
                    newenv[var] = env[var]
                else:
                    del newenv[var]
            res = newenv.gen_script(sh).split('\n')
            res.sort()
            self.assertEquals(expected[sh], res)
            del newenv

        self.assertRaises(RuntimeError,
                          SetupProject.TemporaryEnvironment().gen_script,
                          "abc")
Пример #17
0
    def test_080_main(self):
        """main (Brunel with ext)
        """

        v = SetupProject.makeProjectInfo("Brunel").version

        x = os.popen4(
            (launcher +
             " LbConfiguration.SetupProject --shell=%s Brunel mysql") % _shell)
        s = x[1].read()

        self._check_env(s, "Brunel", v)

        self.assert_(s.find('MYSQLROOT') >= 0)
Пример #18
0
    def test_100_main(self):
        """main (Brunel with wrong ext ignored)
        """

        v = SetupProject.makeProjectInfo("Brunel").version

        x = os.popen4((
            launcher +
            " LbConfiguration.SetupProject --shell=%s --ignore-missing Brunel NoPack"
        ) % _shell)
        s = x[1].read()
        self.assert_(
            s.find("Warning: package NoPack v* LCG_Interfaces not found") >= 0)
        self.assert_(project_configured(s, "Brunel", v))
Пример #19
0
    def test_300_main(self):
        """main (Build-time environment expl. version)
        """
        l = get_all_versions("Brunel")
        v = l[-1]

        env = SetupProject.TemporaryEnvironment()
        tmp_dir = mkdtemp()
        env["User_release_area"] = tmp_dir
        try:
            x = os.popen3((
                launcher +
                " LbConfiguration.SetupProject --shell=%s --ignore-missing --build-env Brunel %s"
            ) % (_shell, v))
            s = x[1].read()
            proj_cmt = os.path.join(tmp_dir, "Brunel_%s" % v, "cmt",
                                    "project.cmt")
            self.assert_(os.path.isfile(proj_cmt))
            self.assert_(
                re.search(r"use\s+BRUNEL\s+BRUNEL_%s" % v,
                          open(proj_cmt).read()) is not None)
        finally:
            SetupProject.removeall(tmp_dir)
Пример #20
0
    def _test_190_main(self):
        """main (Brunel release area not in CMTPROJECTPATH)
        """
        env = SetupProject.TemporaryEnvironment()
        # override default PROJECTPATH
        env['LHCBPROJECTPATH'] = os.pathsep.join(
            [env['Gaudi_release_area'], env['LCG_release_area']])
        if 'CMTPROJECTPATH' in env:
            del env['CMTPROJECTPATH']

        l = get_all_versions("Brunel")
        if len(l) > 1:
            v = l[-2]
        else:
            v = l[0]
        x = os.popen4(
            (launcher + " LbConfiguration.SetupProject --shell=%s Brunel %s") %
            (_shell, v))
        s = x[1].read()

        self._check_env(s, "Brunel", v)
Пример #21
0
    def test_050_options(self):
        """option parsing
        """
        parse_opts = lambda opts: os.popen4(
            'python -c "from LbConfiguration import SetupProject; SetupProject.SetupProject().parser.parse_args(args=%s)"'
            % opts)[1].read()
        parse_opts_stdout = lambda opts: os.popen3(
            'python -c "from LbConfiguration import SetupProject; SetupProject.SetupProject().parser.parse_args(args=%s)"'
            % opts)[1].read()

        # This is different between Python 2.3 and Python 2.5
        exp23 = 'usage: -c [options] '
        exp25 = 'Usage: -c [options] '
        x = parse_opts(["-h"])
        self.assert_(x.startswith(exp23) or x.startswith(exp25))

        self.assert_(parse_opts_stdout(['-h']) == "")
        self.assert_(parse_opts_stdout(['--version']) == "")
        self.assert_(parse_opts_stdout(['--dummy']) == "")

        exp = "error: no such option: --dummy"
        x = parse_opts(["--dummy"]).strip()
        self.assert_(x.endswith(exp))

        sp = SetupProject.SetupProject()
        sp.parse_args(["--shell=csh"])
        self.assertEquals('csh', sp.shell)

        exp = "error: --mktemp cannot be used at the same time as --output or --append"
        x = parse_opts(["--mktemp", "--output", "xyz"]).strip()
        self.assert_(x.endswith(exp))

        ### All Options
        sp = SetupProject.SetupProject()
        # This is needed because the check of LHCBDEV is done during the parsing of the options
        tmpenv = SetupProject.TemporaryEnvironment()
        if "LHCBDEV" not in tmpenv:
            tmpenv["LHCBDEV"] = "dummy"
        sp.parse_args([
            '--shell=sh',
            '--output=/tmp',
            '--site=none',
            '--disable-CASTOR',
            '--tag_add=A1',
            '--tag_add=A2',
            '--use=abc v1',
            '--use=abc v2',
            '--verbose',
            '--force',
            '--ignore-context',
            '--list-versions',
            '--external-only',
            '--dev',
            '--ask',
            '--keep-CMTPROJECTPATH',
        ])
        self.assert_(sp.disable_CASTOR)
        self.assert_(sp.force)
        self.assert_(sp.ignore_context)
        self.assert_(sp.list_versions)
        self.assert_(sp.external_only)
        self.assert_(sp.dev_dirs)
        self.assert_(sp.ask)
        self.assertEquals(sp.loglevel, SetupProject.VERBOSE)
        self.assertEquals(sp.output, "/tmp")
        self.assertEquals(sp.site_externals, [])
        self.assertEquals(sp.use, ["abc v1", "abc v2"])
        self.assertEquals(sp.tag_add, ["A1", "A2"])
        self.assert_(sp.keep_CMTPROJECTPATH)

        sp = SetupProject.SetupProject()
        sp.parse_args([])
        self.assert_(not sp.disable_CASTOR)
        self.assert_(not sp.force)
        self.assert_(not sp.ignore_context)
        self.assert_(not sp.list_versions)
        self.assert_(not sp.external_only)
        self.assert_(not sp.dev_dirs)
        self.assert_(not sp.ask)
        self.assertEquals(sp.loglevel, SetupProject.WARNING)
        self.assert_(not sp.output)
        #self.assertEquals(sp.site_externals,[])
        self.assertEquals(sp.use, [])
        self.assertEquals(sp.tag_add, [])
        self.assert_(not sp.keep_CMTPROJECTPATH)

        sp = SetupProject.SetupProject()
        sp.parse_args(['--debug', "--mktemp", "--site=CERN"])
        self.assertEquals(sp.loglevel, SetupProject.DEBUG)
        self.assert_(sp.mktemp)
        self.assertEquals(sp.site_externals, [])  # ["CASTOR"]

        ### Ordering
        sp = SetupProject.SetupProject()
        sp.parse_args([
            'Project',
            '--shell=sh',
            '--verbose',
            'v123r456',
            'ROOT',
            '-v',
            '1.2.3.4',
        ])

        ### External version
        sp = SetupProject.SetupProject()
        sp.parse_args(['Project', 'ROOT', '-v', '1.2.3.4'])
        self.assertEquals(sp.ext_versions["ROOT"], '1.2.3.4')

        # --dev-dir implies --dev
        sp = SetupProject.SetupProject()
        sp.parse_args(['--dev-dir=MyDevDir'])
        self.assert_(sp.dev_dirs)

        days = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
        # --nightly implies --dev and append to dev_dirs
        sp = SetupProject.SetupProject()
        sp.parse_args(['--nightly', 'lhcb-patches'])
        self.assert_(
            len(sp.dev_dirs) >= 1
            and ("lhcb-patches/" + days[datetime.date.today().weekday()])
            in sp.dev_dirs[0])

        # --nightly implies --dev and append to dev_dirs
        sp = SetupProject.SetupProject()
        sp.parse_args(['--nightly', 'lhcb-patches', 'tUe'])
        self.assert_(
            len(sp.dev_dirs) >= 1 and "lhcb-patches/Tue" in sp.dev_dirs[0])

        # runtime dependencies on projects
        sp = SetupProject.SetupProject()
        sp.parse_args([
            '--runtime-project', 'Test', 'v1r1', '--runtime-project', 'Other',
            'v7r6p5', '--runtime-project', 'NoVers', 'argument'
        ])
        self.assertEquals(sp.opts.runtime_projects, [("Test", "v1r1"),
                                                     ('Other', 'v7r6p5'),
                                                     ('NoVers', None)])
Пример #22
0
def get_all_versions(project):
    versions = SetupProject.FindProjectVersions(
        project, SetupProject._defaultSearchPath())
    return SetupProject.SortVersions([v[1] for v in versions])