Пример #1
0
def test_create_temporary_directory():
    from bloom.util import create_temporary_directory

    tmp_dir = create_temporary_directory()
    assert os.path.exists(tmp_dir)
    shutil.rmtree(tmp_dir)

    if os.path.exists('/tmp'):
        os.mkdir('/tmp/test-bloom-util')
        tmp_dir = create_temporary_directory('/tmp/test-bloom-util')
        assert os.path.exists(tmp_dir)
        shutil.rmtree('/tmp/test-bloom-util')
Пример #2
0
def main(sysargs=None):
    parser = get_argument_parser()
    parser = add_global_arguments(parser)
    args = parser.parse_args(sysargs)
    handle_global_arguments(args)

    # Check that the current directory is a serviceable git/bloom repo
    ret = ensure_clean_working_env()
    if ret != 0:
        parser.print_usage()
        return ret

    # Get the current git branch
    current_branch = get_current_branch()

    # Create a working temp directory
    tmp_dir = create_temporary_directory()

    cwd = os.getcwd()

    try:
        # Get off upstream branch
        if current_branch == 'upstream':
            checkout(get_commit_hash('upstream'), directory=cwd)

        retcode = import_upstream(cwd, tmp_dir, args)

        # Done!
        retcode = retcode if retcode is not None else 0
        if retcode == 0:
            info("I'm happy.  You should be too.")

        return retcode
    finally:
        # Change back to the original cwd
        os.chdir(cwd)
        # Clean up
        shutil.rmtree(tmp_dir)
        if current_branch and branch_exists(current_branch, True, cwd):
            checkout(current_branch, directory=cwd)