Example #1
0
def win_subprocess_write_bat(cmd, arg, prefix, plan):
    assert sys.platform == 'win32'

    import json
    from conda.win_batlink import make_bat_link, make_bat_unlink

    dist_dir = join(config.pkgs_dir, arg)
    info_dir = join(dist_dir, 'info')

    if cmd == LINK:
        files = list(install.yield_lines(join(info_dir, 'files')))

        return make_bat_link(files, prefix, dist_dir)

    elif cmd == UNLINK:
        meta_path = join(prefix, 'conda-meta', arg + '.json')
        with open(meta_path) as fi:
            meta = json.load(fi)

        files = set([])
        directories1 = set([])
        for f in meta['files']:
            dst = abspath(join(prefix, f))
            files.add(dst)
            directories1.add(dirname(dst))
        files.add(meta_path)

        directories = set([])
        for path in directories1:
            while len(path) > len(prefix):
                directories.add(path)
                path = dirname(path)
        directories.add(join(prefix, 'conda-meta'))
        directories.add(prefix)

        directories = sorted(directories, key=len, reverse=True)

        return make_bat_unlink(files, directories, prefix, dist_dir)
    else:
        raise ValueError
Example #2
0
def win_subprocess_write_bat(cmd, arg, prefix, plan):
    assert sys.platform == 'win32'

    import json
    from conda.win_batlink import make_bat_link, make_bat_unlink

    dist_dir = join(config.pkgs_dir, arg)
    info_dir = join(dist_dir, 'info')

    if cmd == LINK:
        files = list(install.yield_lines(join(info_dir, 'files')))

        return make_bat_link(files, prefix, dist_dir)

    elif cmd == UNLINK:
        meta_path = join(prefix, 'conda-meta', arg + '.json')
        with open(meta_path) as fi:
            meta = json.load(fi)

        files = set([])
        directories1 = set([])
        for f in meta['files']:
            dst = abspath(join(prefix, f))
            files.add(dst)
            directories1.add(dirname(dst))
        files.add(meta_path)

        directories = set([])
        for path in directories1:
            while len(path) > len(prefix):
                directories.add(path)
                path = dirname(path)
        directories.add(join(prefix, 'conda-meta'))
        directories.add(prefix)

        directories = sorted(directories, key=len, reverse=True)

        return make_bat_unlink(files, directories, prefix, dist_dir)
    else:
        raise ValueError
Example #3
0
def test_win_subprocess(prefix):
    """
    Make sure the windows subprocess stuff will work before we try it.
    """
    import subprocess
    from conda.win_batlink import make_bat_link, make_bat_unlink
    from conda.builder.utils import rm_rf

    try:
        print("Testing if we can install certain packages")
        batfiles = ['ping 1.1.1.1 -n 1 -w 3000 > nul']
        dist_dir = join(config.pkgs_dir, 'battest_pkg', 'battest')

        # First create a file in the prefix.
        print("making file in the prefix")
        prefix_battest = join(prefix, 'battest')
        print("making directories")
        os.makedirs(join(prefix, 'battest'))
        print("making file")
        with open(join(prefix_battest, 'battest1'), 'w') as f:
            f.write('test1')
        print("testing file")
        with open(join(prefix_battest, 'battest1')) as f:
            assert f.read() == 'test1'

        # Now unlink it.
        print("making unlink command")
        batfiles.append(make_bat_unlink([join(prefix_battest, 'battest1')],
        [prefix_battest], prefix, dist_dir))

        # Now create a file in the pkgs dir
        print("making file in pkgs dir")
        print("making directories")
        os.makedirs(join(dist_dir, 'battest'))
        print("making file")
        with open(join(dist_dir, 'battest', 'battest2'), 'w') as f:
            f.write('test2')
        print("testing file")
        with open(join(dist_dir, 'battest', 'battest2')) as f:
            assert f.read() == 'test2'

        # And link it
        print("making link command")
        batfiles.append(make_bat_link([join('battest', 'battest2')],
                                      prefix, dist_dir))

        batfile = '\n'.join(batfiles)

        print("writing batlink_test.bat file")
        with open(join(prefix, 'batlink_test.bat'), 'w') as f:
            f.write(batfile)
        print("running batlink_test.bat file")
        subprocess.check_call([join(prefix, 'batlink_test.bat')])

        print("testing result")
        print("testing if old file does not exist")
        assert not os.path.exists(join(prefix_battest, 'battest1'))
        print("testing if new file does exist")
        assert os.path.exists(join(prefix_battest, 'battest2'))
        print("testing content of installed file")
        with open(join(prefix_battest, 'battest2')) as f:
            assert f.read() == 'test2'
        print("testing content of pkg file")
        with open(join(dist_dir, 'battest', 'battest2')) as f:
            assert f.read() == 'test2'

    finally:
        try:
            print("cleaning up")
            rm_rf(join(prefix, 'battest'))
            rm_rf(join(config.pkgs_dir, 'battest_pkg'))
            rm_rf(join(prefix, 'batlink_test.bat'))
        except Exception as e:
            print(e)
Example #4
0
def test_win_subprocess(prefix):
    """
    Make sure the windows subprocess stuff will work before we try it.
    """
    import subprocess
    from conda.win_batlink import make_bat_link, make_bat_unlink
    from conda.builder.utils import rm_rf

    try:
        print("Testing if we can install certain packages")
        batfiles = ['ping 1.1.1.1 -n 1 -w 3000 > nul']
        dist_dir = join(config.pkgs_dir, 'battest_pkg', 'battest')

        # First create a file in the prefix.
        print("making file in the prefix")
        prefix_battest = join(prefix, 'battest')
        print("making directories")
        os.makedirs(join(prefix, 'battest'))
        print("making file")
        with open(join(prefix_battest, 'battest1'), 'w') as f:
            f.write('test1')
        print("testing file")
        with open(join(prefix_battest, 'battest1')) as f:
            assert f.read() == 'test1'

        # Now unlink it.
        print("making unlink command")
        batfiles.append(make_bat_unlink([join(prefix_battest, 'battest1')],
                                        [prefix_battest], prefix, dist_dir))

        # Now create a file in the pkgs dir
        print("making file in pkgs dir")
        print("making directories")
        os.makedirs(join(dist_dir, 'battest'))
        print("making file")
        with open(join(dist_dir, 'battest', 'battest2'), 'w') as f:
            f.write('test2')
        print("testing file")
        with open(join(dist_dir, 'battest', 'battest2')) as f:
            assert f.read() == 'test2'

        # And link it
        print("making link command")
        batfiles.append(make_bat_link([join('battest', 'battest2')],
                                      prefix, dist_dir))

        batfile = '\n'.join(batfiles)

        print("writing batlink_test.bat file")
        with open(join(prefix, 'batlink_test.bat'), 'w') as f:
            f.write(batfile)
        print("running batlink_test.bat file")
        subprocess.check_call([join(prefix, 'batlink_test.bat')])

        print("testing result")
        print("testing if old file does not exist")
        assert not os.path.exists(join(prefix_battest, 'battest1'))
        print("testing if new file does exist")
        assert os.path.exists(join(prefix_battest, 'battest2'))
        print("testing content of installed file")
        with open(join(prefix_battest, 'battest2')) as f:
            assert f.read() == 'test2'
        print("testing content of pkg file")
        with open(join(dist_dir, 'battest', 'battest2')) as f:
            assert f.read() == 'test2'

    finally:
        try:
            print("cleaning up")
            rm_rf(join(prefix, 'battest'))
            rm_rf(join(config.pkgs_dir, 'battest_pkg'))
            rm_rf(join(prefix, 'batlink_test.bat'))
        except Exception as e:
            print(e)