Exemplo n.º 1
0
def main(options):
    tool = options.tool
    bunzip2 = local['bunzip2']
    bzip2 = local['bzip2']
    tar = local['tar']

    for project, v in iter_versions(options.restrict_project, options.restrict_version, old=True, minimum=True):
        tarname = get_name_of_tar(tool, project)
        with tarfile.open(str(tarname), "r") as t:

            def mapping(inv, v=v):
                assert inv == v
                _, _, result = d4()('match-commits', '-p', project, '-v', '{0}f'.format(inv),  '-c', 'fse-commit-dbs').rstrip().partition('-> ')
                return int(result)


            for source, dest in get_extract_list(tool, project, v, mapping=mapping):
                alt_source = source[:-len('.bak')]
                try:
                    extract(t, source, OUT_DIR / dest)
                    # check for broken files
                    fixed_file = t.extractfile(alt_source)
                    with tarfile.open(fileobj=fixed_file) as t_fixed:
                        broken_files = [name[:-len('.broken')] for name in t_fixed.getnames() if name.endswith('.broken')]
                    fixed_file.close()

                    # now we have to remove the broken files from the archive
                    if broken_files:
                        plain_name = str(OUT_DIR / dest)[:-len('.bz2')]
                        bunzip2(str(OUT_DIR / dest))

                        # get number of .java currently in archive
                        with tarfile.open(plain_name) as t_current:
                            java_files = [name for name in t_current.getnames()
                                if name.endswith('.java') and not name.endswith('_scaffolding.java')]

                        if len(broken_files) == len(java_files):
                            # we are going to remove them all.
                            rm(plain_name)
                            touch(plain_name[:-len('.tar')] + '.empty')

                        else:
                            for broken_file in broken_files:
                                tar('--delete', '-f', plain_name, './' + broken_file)
                            bzip2(plain_name)

                        print "+ {source} -> {dest} ({broken} / {total} broken)".format(
                                source=source, dest=dest, broken=len(broken_files), total=len(java_files)
                            )
                    else:
                        print "+ {source} -> {dest} (none broken)".format(source=source, dest=dest)

                except KeyError:
                    try:
                        # no .bak file was ever created, so we are good.
                        extract(t, alt_source, OUT_DIR / dest)
                        print "* {source} -> {dest} (as is)".format(source=alt_source, dest=dest)
                    except KeyError:
                        print "- {source} -> missing".format(source=alt_source)
                        touch(str(OUT_DIR / dest)[:-len('.tar.bz2')] + '.missing')
Exemplo n.º 2
0
def un_block():
	local.cwd.chdir(home)
	local.cwd.chdir("../../private/etc/")
	touch("hosts")
	rm("hosts")
	touch("hosts")
	f = open("hosts", "r+")
	f.write(hosts_default)
	killall["-HUP", "mDNSResponder"]
Exemplo n.º 3
0
def test_md5_hasher(builddir):
    with local.cwd(builddir):
        sh.touch('testfile')
        sh.mkdir('testdir')
        sh.touch('testdir/testfile')
        sh.ln('-s', 'testdir', 'testdirlink')
        sh.ln('-s', 'testfile', 'testlink')
        sh.ln('-s', 'nofile', 'testlink_nofile')
        assert md5_hasher('nofile') == None
        assert md5_hasher('testfile') == EMPY_FILE_MD5
        assert md5_hasher('testdir') == md5func('testdir').hexdigest()
        assert md5_hasher('testlink') == EMPY_FILE_MD5
        assert md5_hasher('testdirlink') == md5func('testdir').hexdigest()
        assert md5_hasher('testlink_nofile') == md5func('nofile').hexdigest()
Exemplo n.º 4
0
    def test_copy_move_delete(self):
        from plumbum.cmd import touch

        with local.tempdir() as dir:
            (dir / "orog").mkdir()
            (dir / "orog" / "rec").mkdir()
            for i in range(20):
                touch(dir / "orog" / ("f%d.txt" % (i, )))
            for i in range(20, 40):
                touch(dir / "orog" / "rec" / ("f%d.txt" % (i, )))

            move(dir / "orog", dir / "orig")

            s1 = sorted(f.basename for f in (dir / "orig").walk())

            copy(dir / "orig", dir / "dup")
            s2 = sorted(f.basename for f in (dir / "dup").walk())
            self.assertEqual(s1, s2)

            with SshMachine("localhost") as rem:
                with rem.tempdir() as dir2:
                    copy(dir / "orig", dir2)
                    s3 = sorted(f.basename for f in (dir2 / "orig").walk())
                    self.assertEqual(s1, s3)

                    copy(dir2 / "orig", dir2 / "dup")
                    s4 = sorted(f.basename for f in (dir2 / "dup").walk())
                    self.assertEqual(s1, s4)

                    copy(dir2 / "dup", dir / "dup2")
                    s5 = sorted(f.basename for f in (dir / "dup2").walk())
                    self.assertEqual(s1, s5)

                    with SshMachine("localhost") as rem2:
                        with rem2.tempdir() as dir3:
                            copy(dir2 / "dup", dir3)
                            s6 = sorted(f.basename
                                        for f in (dir3 / "dup").walk())
                            self.assertEqual(s1, s6)

                            move(dir3 / "dup", dir / "superdup")
                            self.assertFalse((dir3 / "dup").exists())

                            s7 = sorted(f.basename
                                        for f in (dir / "superdup").walk())
                            self.assertEqual(s1, s7)

                            # test rm
                            delete(dir)
Exemplo n.º 5
0
def test_rename(builddir, runner):
    # prepare needed files
    with local.cwd(builddir):
        sh.touch('originalfile')

    builder = BuildFile(build_dir=builddir, runner=runner)

    ###### First build ##########
    builder.main(command_line=['-D', 'build'])

    expected_json = {
        ".deps_version": 2,
        "mv originalfile testfile": {
            "originalfile": "input-d41d8cd98f00b204e9800998ecf8427e",
            "testfile": "output-d41d8cd98f00b204e9800998ecf8427e"
        }
    }

    # assertions
    with local.cwd(builddir):
        assert_json_equality('.deps', expected_json)
        assert os.path.isfile('testfile')
        sys.exit.assert_called_once_with(0)

        # update original file to check the rebuild
        (sh.echo["newline"] > "originalfile")()

    ###### Second build ##########
    builder.main(command_line=['-D', 'build'])

    expected_json = {
        ".deps_version": 2,
        "mv originalfile testfile": {
            "originalfile": "input-321060ae067e2a25091be3372719e053",
            "testfile": "output-321060ae067e2a25091be3372719e053"
        }
    }

    with local.cwd(builddir):
        assert_json_equality('.deps', expected_json)
        assert "newline" in sh.cat('testfile')

    ###### Cleaning ##########
    builder.main(command_line=['-D', 'clean'])

    with local.cwd(builddir):
        assert not os.isfile('testfile')
        assert os.isfile('originalfile')
Exemplo n.º 6
0
    def test_copy_move_delete(self):
        from plumbum.cmd import touch

        with local.tempdir() as dir:
            (dir / "orog").mkdir()
            (dir / "orog" / "rec").mkdir()
            for i in range(20):
                touch(dir / "orog" / ("f%d.txt" % (i, )))
            for i in range(20, 40):
                touch(dir / "orog" / "rec" / ("f%d.txt" % (i, )))

            move(dir / "orog", dir / "orig")

            s1 = sorted(f.name for f in (dir / "orig").walk())

            copy(dir / "orig", dir / "dup")
            s2 = sorted(f.name for f in (dir / "dup").walk())
            assert s1 == s2

            with SshMachine("localhost") as rem:
                with rem.tempdir() as dir2:
                    copy(dir / "orig", dir2)
                    s3 = sorted(f.name for f in (dir2 / "orig").walk())
                    assert s1 == s3

                    copy(dir2 / "orig", dir2 / "dup")
                    s4 = sorted(f.name for f in (dir2 / "dup").walk())
                    assert s1 == s4

                    copy(dir2 / "dup", dir / "dup2")
                    s5 = sorted(f.name for f in (dir / "dup2").walk())
                    assert s1 == s5

                    with SshMachine("localhost") as rem2:
                        with rem2.tempdir() as dir3:
                            copy(dir2 / "dup", dir3)
                            s6 = sorted(f.name for f in (dir3 / "dup").walk())
                            assert s1 == s6

                            move(dir3 / "dup", dir / "superdup")
                            assert not (dir3 / "dup").exists()

                            s7 = sorted(f.name
                                        for f in (dir / "superdup").walk())
                            assert s1 == s7

                            # test rm
                            delete(dir)
Exemplo n.º 7
0
    def test_copy_move_delete(self):
        from plumbum.cmd import touch
        
        with local.tempdir() as dir:
            (dir / "orog").mkdir()
            (dir / "orog" / "rec").mkdir()
            for i in range(20):
                touch(dir / "orog" / ("f%d.txt" % (i,)))
            for i in range(20,40):
                touch(dir / "orog" / "rec" / ("f%d.txt" % (i,)))

            move(dir / "orog", dir / "orig")

            s1 = sorted(f.basename for f in (dir / "orig").walk())
            
            copy(dir / "orig", dir / "dup")
            s2 = sorted(f.basename for f in (dir / "dup").walk())
            self.assertEqual(s1, s2)
            
            with SshMachine("localhost") as rem:
                with rem.tempdir() as dir2:
                    copy(dir / "orig", dir2)
                    s3 = sorted(f.basename for f in (dir2 / "orig").walk())
                    self.assertEqual(s1, s3)

                    copy(dir2 / "orig", dir2 / "dup")
                    s4 = sorted(f.basename for f in (dir2 / "dup").walk())
                    self.assertEqual(s1, s4)

                    copy(dir2 / "dup", dir / "dup2")
                    s5 = sorted(f.basename for f in (dir / "dup2").walk())
                    self.assertEqual(s1, s5)
                
                    with SshMachine("localhost") as rem2:
                        with rem2.tempdir() as dir3:
                            copy(dir2 / "dup", dir3)
                            s6 = sorted(f.basename for f in (dir3 / "dup").walk())
                            self.assertEqual(s1, s6)
                            
                            move(dir3 / "dup", dir / "superdup")
                            self.assertFalse((dir3 / "dup").exists())
                            
                            s7 = sorted(f.basename for f in (dir / "superdup").walk())
                            self.assertEqual(s1, s7)
                            
                            # test rm
                            delete(dir)
Exemplo n.º 8
0
    def test_copy_move_delete(self):
        from plumbum.cmd import touch

        with local.tempdir() as dir:
            (dir / "orog").mkdir()
            (dir / "orog" / "rec").mkdir()
            for i in range(20):
                touch(dir / "orog" / ("f%d.txt" % (i,)))
            for i in range(20,40):
                touch(dir / "orog" / "rec" / ("f%d.txt" % (i,)))

            move(dir / "orog", dir / "orig")

            s1 = sorted(f.name for f in (dir / "orig").walk())

            copy(dir / "orig", dir / "dup")
            s2 = sorted(f.name for f in (dir / "dup").walk())
            assert s1 == s2

            with SshMachine("localhost") as rem:
                with rem.tempdir() as dir2:
                    copy(dir / "orig", dir2)
                    s3 = sorted(f.name for f in (dir2 / "orig").walk())
                    assert s1 == s3

                    copy(dir2 / "orig", dir2 / "dup")
                    s4 = sorted(f.name for f in (dir2 / "dup").walk())
                    assert s1 == s4

                    copy(dir2 / "dup", dir / "dup2")
                    s5 = sorted(f.name for f in (dir / "dup2").walk())
                    assert s1 == s5

                    with SshMachine("localhost") as rem2:
                        with rem2.tempdir() as dir3:
                            copy(dir2 / "dup", dir3)
                            s6 = sorted(f.name for f in (dir3 / "dup").walk())
                            assert s1 == s6

                            move(dir3 / "dup", dir / "superdup")
                            assert not (dir3 / "dup").exists()

                            s7 = sorted(f.name for f in (dir / "superdup").walk())
                            assert s1 == s7

                            # test rm
                            delete(dir)
Exemplo n.º 9
0
def mount_fs(volume):
    device = volume.attachments[0]['Device']
    container_device = '/host_root%s' % device
    fs_type = sh('-c', "file -sL %s" % container_device)
    if 'ext4' in fs_type:
        pass
    elif 'data' in fs_type:
        logger.info("Creating file system")
        sh('-c', 'mkfs.ext4 %s' % container_device)
        sh('-c', 'mkdir -p /tmp/mounted')
        mount(container_device, '/tmp/mounted')
        touch('/tmp/mounted/.mounted')
        umount('/tmp/mounted')

    if not device in mount():
        logger.info("Deferring mount via cron")
        mount_via_cron('%s' % device, volume.id)
Exemplo n.º 10
0
def mount_fs(volume):
    device = volume.attachments[0]['Device']
    container_device = '/host_root%s' % device
    fs_type = sh('-c', "file -sL %s" % container_device)
    if 'ext4' in fs_type:
        pass
    elif 'data' in fs_type:
        logger.info("Creating file system")
        sh('-c', 'mkfs.ext4 %s' % container_device)
        sh('-c', 'mkdir -p /tmp/mounted')
        mount(container_device, '/tmp/mounted')
        touch('/tmp/mounted/.mounted')
        umount('/tmp/mounted')

    if not device in mount():
        logger.info("Deferring mount via cron")
        mount_via_cron('%s' % device, volume.id)
Exemplo n.º 11
0
def test_symlink(builddir, runner):
    builder = BuildFile(build_dir=builddir, runner=runner)

    with local.cwd(builddir):
        sh.touch('testfile')
        sh.mkdir('testdir')

    ###### First build ##########
    builder.main(command_line=['-D', 'build'])

    expected_json = {
        ".deps_version": 2,
        "ln -s nofile testlink_nofile": {
            "testlink_nofile": "output-"
        },
        "ln -s testdir testlink_dir": {
            "testlink_dir": "output-"
        },
        "ln -s testfile testlink": {
            "testlink": "output-"
        }
    }

    # assertions
    with local.cwd(builddir):
        assert_same_json('.deps', expected_json)
        assert os.path.islink('testlink')
        assert os.path.realpath('testlink').endswith('/testfile')
        assert os.path.islink('testlink_dir')
        assert os.path.realpath('testlink_dir').endswith('/testdir')
        assert os.path.islink('testlink_nofile')
        assert not os.path.isfile('testlink_nofile')
        sys.exit.assert_called_once_with(0)

    ###### Cleaning ##########
    builder.main(command_line=['-D', 'clean'])

    with local.cwd(builddir):
        assert not os.path.isfile('.deps')
        assert not os.path.islink('testlink')
        assert not os.path.islink('testlink_dir')
        assert not os.path.islink('testlink_nofile')
Exemplo n.º 12
0
def build_server(settings):
    force = strtobool(settings.get('FORCE_CERT_REGEN', 'false'))
    with local.env(**settings):
        pkitool = local[os.path.join(local.env['EASY_RSA'], 'pkitool')]
        openssl = local['openssl']

        if force:
            print('FORCE_CERT_REGEN=true, regenerating {}'.format(
                local.env['KEY_DIR']))
            rm(['-rf', local.env['KEY_DIR']])

        if not local.path(local.env['KEY_DIR']).exists():
            print('KEY_DIR does not exist, creating')
            mkdir.run(['-p', local.env['KEY_DIR']], retcode=0)
            # see if this needs to be separate
            touch(os.path.join(local.env['KEY_DIR'], 'index.txt'), retcode=0)
            with open(os.path.join(local.env['KEY_DIR'], 'serial'),
                      'w') as serial:
                serial.write('01')

        ca_files = glob(os.path.join(local.env['KEY_DIR'], 'ca.*'))
        server_files = glob(os.path.join(local.env['KEY_DIR'], 'server.*'))

        if ca_files:
            print('Root CA exists, skipping')
        else:
            pkitool.run('--initca', retcode=0, stderr=sys.stdout)

        if server_files:
            print('Server cert exists, skipping')
        else:
            pkitool.run(['--server', 'server'], retcode=0, stderr=sys.stdout)

        dh_pem = os.path.join(local.env['KEY_DIR'],
                              'dh' + local.env['KEY_SIZE'] + '.pem')
        if local.path(dh_pem).exists():
            print('DH param exists, skipping')
        else:
            openssl.run(['dhparam', '-out', dh_pem, local.env['KEY_SIZE']],
                        stderr=sys.stdout)
Exemplo n.º 13
0
def build_server(settings):
    force = strtobool(settings.get('FORCE_CERT_REGEN', 'false'))
    with local.env(**settings):
        pkitool = local[os.path.join(local.env['EASY_RSA'], 'pkitool')]
        openssl = local['openssl']

        if force:
            print "FORCE_CERT_REGEN=true, regenerating {}".format(local.env['KEY_DIR'])
            rm(['-rf', local.env['KEY_DIR']])

        if not local.path(local.env['KEY_DIR']).exists():
            print "KEY_DIR does not exist, creating"
            mkdir.run(['-p', local.env['KEY_DIR']], retcode=0)
            # see if this needs to be separate
            touch(os.path.join(local.env['KEY_DIR'], 'index.txt'), retcode=0)
            with open(os.path.join(local.env['KEY_DIR'], 'serial'),
                      "w") as serial:
                serial.write("01")

        ca_files = glob(os.path.join(local.env['KEY_DIR'], 'ca.*'))
        server_files = glob(os.path.join(local.env['KEY_DIR'], 'server.*'))

        if ca_files:
            print 'Root CA exists, skipping'
        else:
            pkitool.run("--initca", retcode=0, stderr=sys.stdout)

        if server_files:
            print 'Server cert exists, skipping'
        else:
            pkitool.run(["--server", "server"], retcode=0, stderr=sys.stdout)

        dh_pem = os.path.join(local.env['KEY_DIR'],
                              'dh' + local.env['KEY_SIZE'] + '.pem')
        if local.path(dh_pem).exists():
            print 'DH param exists, skipping'
        else:
            openssl.run(["dhparam", "-out", dh_pem, local.env['KEY_SIZE']],
                        stderr=sys.stdout)
Exemplo n.º 14
0
def test_makeHTMLdir():
    HTMLdirName = '123'
    delete( HTMLdirName )
    
    fakeSSname = 'fakeSupportScripts'
    delete(fakeSSname)
    mkdir(fakeSSname)
    scriptNames=['xyz.test', 'xyz2.test']
    for scriptName in scriptNames:
        touch(f'{fakeSSname}/{scriptName}')

    
    makeHTMLdir( HTMLdirName , 
                 stacheDir = fakeSSname,
                 GLOWPATH='.', 
                 scriptNames= scriptNames) 
                 
    assert('supportScripts' in ls( HTMLdirName ).split() )
    
    assert( ls('123/supportScripts').split() == scriptNames )
    
    delete( HTMLdirName )
    delete(fakeSSname)
Exemplo n.º 15
0
def block_sites():
	print "works"
	local.cwd.chdir(home)
	local.cwd.chdir("Dropbox/Docs")
	blocked = []
	with open('blocked_sites.csv', 'rb') as csvfile:
		reader = csv.reader(csvfile, delimiter=',', quotechar='|')
		for row in reader:
			for r in row:
				blocked.append(r)
	print blocked
	local.cwd.chdir(home)
	local.cwd.chdir("../../private/etc/")
	rm("hosts")
	touch("hosts")
	with open("hosts", "r+") as hosts:
		hosts.write(hosts_default)
		# hosts.write("\n")
		for item in blocked:
			site = "127.0.0.1 " + item + "\n"
			site = "127.0.0.1 " + "www." + item + "\n"
			hosts.write(site)
	killall["-HUP", "mDNSResponder"]
Exemplo n.º 16
0
def test_webServer():
    """kill the server if it's alive
       then start it and point it to a randomly named directory.
       To prove its in the randomly named directory,
           put a randomly-named file in it it and see if it shows up in the server.
           """
    try:
        killServer(8081)
    except:
        pass

    import random
    randomDirName = str(random.randint(10000, 99999))
    mkdir(randomDirName)
    randomFileName = str(random.randint(10000, 99999))
    touch(f'{randomDirName}/{randomFileName}')  #create file in local directory

    webServer(randomDirName)
    sleep(1)
    assert randomFileName in requests.get(
        f'http://localhost:8081/{randomDirName}').text

    delete(randomDirName)
Exemplo n.º 17
0
def test_mkdir(builddir, runner):
    # prepare needed files
    with local.cwd(builddir):
        sh.mkdir('existingdir')
        sh.touch('existingdir/existingfile')

    builder = BuildFile(build_dir=builddir, runner=runner)
    builder.main(command_line=['-D', 'build']) #, parallel_ok=True)

    expected_json = {
        ".deps_version": 2,
        "mkdir -p existingdir/a": {
            "existingdir": "input-ae394c47b4ccf49007dc9ec847f657b9",
            "existingdir/a": "output-16873f5a4ba5199a8b51f812d159e37e"
        },
        "mkdir -p testdir/c/d": {
            "testdir": "input-3ca0a3620b59afb57cf5fd77cee6432c",
            "testdir/c": "input-54a9057bcd619534a49f669dd5ed3078",
            "testdir/c/d": "input-fdb1b8414eeab993acc5623371c43a71"
        },
        "mkdir -p testdir/c/g": {
            "testdir": "input-3ca0a3620b59afb57cf5fd77cee6432c",
            "testdir/c": "input-54a9057bcd619534a49f669dd5ed3078",
            "testdir/c/g": "output-c512be1476c9253326e479827c491f7f"
        },
        "mkdir testdir": {
            "testdir": "output-3ca0a3620b59afb57cf5fd77cee6432c"
        },
        "mkdir testdir/a": {
            "testdir/a": "output-832651e32363cb4b115b074240cd08b5"
        },
        "mkdir testdir/b": {
            "testdir/b": "output-0432d5c3dc41495725df46eeeedb1386"
        },
        "mkdir testdir/c": {
            "testdir/c": "output-54a9057bcd619534a49f669dd5ed3078"
        },
        "mkdir testdir/c/d": {
            "testdir/c/d": "output-fdb1b8414eeab993acc5623371c43a71"
        },
        "mkdir testdir/c/e": {
            "testdir/c/e": "output-eadea986453292aaa62ccde2312c3413"
        },
        "mkdir testdir/c/f": {
            "testdir/c/f": "output-5d7c7f98e6d795bbb252f6866c8d7850"
        },
        "touch testdir/b/f1": {
            "testdir/b/f1": "output-d41d8cd98f00b204e9800998ecf8427e"
        },
        "touch testdir/b/f2": {
            "testdir/b/f2": "output-d41d8cd98f00b204e9800998ecf8427e"
        },
        "touch testdir/c/d/f1": {
            "testdir/c/d/f1": "output-d41d8cd98f00b204e9800998ecf8427e"
        },
        "touch testdir/c/d/f2": {
            "testdir/c/d/f2": "output-d41d8cd98f00b204e9800998ecf8427e"
        },
        "touch testdir/f1": {
            "testdir/f1": "output-d41d8cd98f00b204e9800998ecf8427e"
        },
        "touch testdir/f2": {
            "testdir/f2": "output-d41d8cd98f00b204e9800998ecf8427e"
        }
    }

    # assertions
    with local.cwd(builddir):
        assert_json_equality('.deps', expected_json)
        assert os.path.isdir('testdir/c/g')
        assert os.path.isfile('testdir/c/d/f2')
        assert os.path.isdir('existingdir/a')
        sys.exit.assert_called_once_with(0)

    builder.main(command_line=['-D', 'clean']) 
    #parallel_ok=True,
    #jobs=4,

    with local.cwd(builddir):
        assert not os.path.isdir('testdir')
        assert os.path.isdir('existingdir')
        assert os.path.isfile('existingdir/existingfile')
        assert not os.path.isdir('existingdir/a')
Exemplo n.º 18
0
def test_mkdir(builddir, runner, end_fabricate):

    # build.py content >>>>>>>>>>>>>>>>>>>>>
    def fabricate_file():
        def build():
            # Make lots of directories to check ordered delete
            run('mkdir', 'testdir', group='testdir')
            run('mkdir', 'testdir/a', group='a', after='testdir')
            run('mkdir', 'testdir/b', group='b', after='testdir')
            run('mkdir', 'testdir/c', group='c', after='testdir')
            run('mkdir', 'testdir/c/f', group='f', after='c')
            run('mkdir', 'testdir/c/e', group='e', after='c')
            run('mkdir', 'testdir/c/d', group='d', after='c')

            # put some files in them to ensure content deleted before dir
            run('touch', 'testdir/f1', after='testdir')
            run('touch', 'testdir/f2', after='testdir')
            run('touch', 'testdir/b/f1', after='b')
            run('touch', 'testdir/b/f2', after='b')
            run('touch', 'testdir/c/d/f1', after='d')
            run('touch', 'testdir/c/d/f2', after='d')

            # make a dir that alreay exists
            run('mkdir', '-p', 'testdir/c/d', after='d')

            # make a dir that already partialy exists
            run('mkdir', '-p', 'testdir/c/g', after='c')

            # make a dir that already partialy exists but should not be deleted
            run('mkdir', '-p', 'existingdir/a')

        def clean():
            autoclean()

        return copy(locals())

    with local.cwd(builddir):
        sh.mkdir('existingdir')
        sh.touch('existingdir/existingfile')

    main(globals_dict=fabricate_file(),
         #parallel_ok=True,
         build_dir=builddir,
         runner=runner,
         command_line=['-D', 'build'])
    end_fabricate()

    expected_json = {
        ".deps_version": 2,
        "mkdir -p existingdir/a": {
            "existingdir": "input-ae394c47b4ccf49007dc9ec847f657b9",
            "existingdir/a": "output-16873f5a4ba5199a8b51f812d159e37e"
        },
        "mkdir -p testdir/c/d": {
            "testdir": "input-3ca0a3620b59afb57cf5fd77cee6432c",
            "testdir/c": "input-54a9057bcd619534a49f669dd5ed3078",
            "testdir/c/d": "input-fdb1b8414eeab993acc5623371c43a71"
        },
        "mkdir -p testdir/c/g": {
            "testdir": "input-3ca0a3620b59afb57cf5fd77cee6432c",
            "testdir/c": "input-54a9057bcd619534a49f669dd5ed3078",
            "testdir/c/g": "output-c512be1476c9253326e479827c491f7f"
        },
        "mkdir testdir": {
            "testdir": "output-3ca0a3620b59afb57cf5fd77cee6432c"
        },
        "mkdir testdir/a": {
            "testdir/a": "output-832651e32363cb4b115b074240cd08b5"
        },
        "mkdir testdir/b": {
            "testdir/b": "output-0432d5c3dc41495725df46eeeedb1386"
        },
        "mkdir testdir/c": {
            "testdir/c": "output-54a9057bcd619534a49f669dd5ed3078"
        },
        "mkdir testdir/c/d": {
            "testdir/c/d": "output-fdb1b8414eeab993acc5623371c43a71"
        },
        "mkdir testdir/c/e": {
            "testdir/c/e": "output-eadea986453292aaa62ccde2312c3413"
        },
        "mkdir testdir/c/f": {
            "testdir/c/f": "output-5d7c7f98e6d795bbb252f6866c8d7850"
        },
        "touch testdir/b/f1": {
            "testdir/b/f1": "output-d41d8cd98f00b204e9800998ecf8427e"
        },
        "touch testdir/b/f2": {
            "testdir/b/f2": "output-d41d8cd98f00b204e9800998ecf8427e"
        },
        "touch testdir/c/d/f1": {
            "testdir/c/d/f1": "output-d41d8cd98f00b204e9800998ecf8427e"
        },
        "touch testdir/c/d/f2": {
            "testdir/c/d/f2": "output-d41d8cd98f00b204e9800998ecf8427e"
        },
        "touch testdir/f1": {
            "testdir/f1": "output-d41d8cd98f00b204e9800998ecf8427e"
        },
        "touch testdir/f2": {
            "testdir/f2": "output-d41d8cd98f00b204e9800998ecf8427e"
        }
    }

    # assertions
    with local.cwd(builddir):
        assert_json_equality('.deps', expected_json)
        assert os.path.isdir('testdir/c/g')
        assert os.path.isfile('testdir/c/d/f2')
        assert os.path.isdir('existingdir/a')
        sys.exit.assert_called_once_with(0)

    main(globals_dict=fabricate_file(),
         #parallel_ok=True,
         #jobs=4,
         build_dir=builddir,
         runner=runner,
         command_line=['-D', 'clean'])
    end_fabricate()

    with local.cwd(builddir):
        assert not os.path.isdir('testdir')
        assert os.path.isdir('existingdir')
        assert os.path.isfile('existingdir/existingfile')
        assert not os.path.isdir('existingdir/a')
Exemplo n.º 19
0
def test_symlink(builddir, runner, end_fabricate):

    # build.py content >>>>>>>>>>>>>>>>>>>>>
    def fabricate_file():
        def build():
            run('ln', '-s', 'testfile', 'testlink')
            run('ln', '-s', 'testdir', 'testlink_dir')
            run('ln', '-s', 'nofile', 'testlink_nofile')

        def clean():
            autoclean()

        return copy(locals())

    with local.cwd(builddir):
        sh.touch('testfile')
        sh.mkdir('testdir')

    ###### First build ##########
    main(globals_dict=fabricate_file(),
         #parallel_ok=True,
         build_dir=builddir,
         runner=runner,
         command_line=['-D', 'build'])
    end_fabricate()

    expected_json = {
        ".deps_version": 2,
        "ln -s nofile testlink_nofile": {
            "testlink_nofile": "output-"
        },
        "ln -s testdir testlink_dir": {
            "testlink_dir": "output-"
        },
        "ln -s testfile testlink": {
            "testlink": "output-"
        }
    }

    # assertions
    with local.cwd(builddir):
        assert_same_json('.deps', expected_json)
        assert os.path.islink('testlink')
        assert os.path.realpath('testlink').endswith('/testfile')
        assert os.path.islink('testlink_dir')
        assert os.path.realpath('testlink_dir').endswith('/testdir')
        assert os.path.islink('testlink_nofile')
        assert not os.path.isfile('testlink_nofile')
        sys.exit.assert_called_once_with(0)

    ###### Cleaning ##########
    main(globals_dict=fabricate_file(),
         #parallel_ok=True,
         #jobs=4,
         build_dir=builddir,
         runner=runner,
         command_line=['-D', 'clean'])
    end_fabricate()

    with local.cwd(builddir):
        assert not os.path.isfile('.deps')
        assert not os.path.islink('testlink')
        assert not os.path.islink('testlink_dir')
        assert not os.path.islink('testlink_nofile')
Exemplo n.º 20
0
def test_rename(builddir, runner, end_fabricate):

    # build.py content >>>>>>>>>>>>>>>>>>>>>
    def fabricate_file():
        def build():
            run('mv', 'originalfile', 'testfile')

        def clean():
            autoclean()
            # remake the original file
            shell('touch', 'originalfile')

        return copy(locals())

    with local.cwd(builddir):
        sh.touch('originalfile')

    ###### First build ##########
    main(globals_dict=fabricate_file(),
         #parallel_ok=True,
         build_dir=builddir,
         runner=runner,
         command_line=['-D', 'build'])
    end_fabricate()

    expected_json = {
            ".deps_version": 2,
            "mv originalfile testfile": {
                "originalfile": "input-d41d8cd98f00b204e9800998ecf8427e",
                "testfile": "output-d41d8cd98f00b204e9800998ecf8427e"
            }
        }

    # assertions
    with local.cwd(builddir):
        assert_json_equality('.deps', expected_json)
        assert os.path.isfile('testfile')
        sys.exit.assert_called_once_with(0)

        # update original file to check the rebuild
        (sh.echo["newline"] > "originalfile")()

    ###### Second build ##########
    main(globals_dict=fabricate_file(),
         #parallel_ok=True,
         #jobs=4,
         build_dir=builddir,
         runner=runner,
         command_line=['-D', 'build'])
    end_fabricate()

    expected_json = {
            ".deps_version": 2,
            "mv originalfile testfile": {
                "originalfile": "input-321060ae067e2a25091be3372719e053",
                "testfile": "output-321060ae067e2a25091be3372719e053"
            }
        }

    with local.cwd(builddir):
        assert_json_equality('.deps', expected_json)
        assert "newline" in sh.cat('testfile')


    ###### Cleaning ##########
    main(globals_dict=fabricate_file(),
         #parallel_ok=True,
         #jobs=4,
         build_dir=builddir,
         runner=runner,
         command_line=['-D', 'clean'])
    end_fabricate()

    with local.cwd(builddir):
        assert not os.isfile('testfile')
        assert os.isfile('originalfile')