Example #1
0
def run_and_verify_checkout(URL,
                            wc_dir_name,
                            output_tree,
                            disk_tree,
                            singleton_handler_a=None,
                            a_baton=None,
                            singleton_handler_b=None,
                            b_baton=None):
    """Checkout the URL into a new directory WC_DIR_NAME.

  The subcommand output will be verified against OUTPUT_TREE,
  and the working copy itself will be verified against DISK_TREE.
  SINGLETON_HANDLER_A and SINGLETON_HANDLER_B will be passed to
  tree.compare_trees - see that function's doc string for more details.
  Returns if successful and raise on failure."""

    if isinstance(output_tree, wc.State):
        output_tree = output_tree.old_tree()
    if isinstance(disk_tree, wc.State):
        disk_tree = disk_tree.old_tree()

    # Remove dir if it's already there.
    main.safe_rmtree(wc_dir_name)

    # Checkout and make a tree of the output, using l:foo/p:bar
    ### todo: svn should not be prompting for auth info when using
    ### repositories with no auth/auth requirements
    output, errput = main.run_svn(None, 'co', '--username', main.wc_author,
                                  '--password', main.wc_passwd, URL,
                                  wc_dir_name)
    mytree = tree.build_tree_from_checkout(output)

    # Verify actual output against expected output.
    tree.compare_trees(mytree, output_tree)

    # Create a tree by scanning the working copy
    mytree = tree.build_tree_from_wc(wc_dir_name)

    # Verify expected disk against actual disk.
    tree.compare_trees(mytree, disk_tree, singleton_handler_a, a_baton,
                       singleton_handler_b, b_baton)
Example #2
0
def run_and_verify_checkout(URL, wc_dir_name, output_tree, disk_tree,
                            singleton_handler_a = None,
                            a_baton = None,
                            singleton_handler_b = None,
                            b_baton = None):
  """Checkout the URL into a new directory WC_DIR_NAME.

  The subcommand output will be verified against OUTPUT_TREE,
  and the working copy itself will be verified against DISK_TREE.
  SINGLETON_HANDLER_A and SINGLETON_HANDLER_B will be passed to
  tree.compare_trees - see that function's doc string for more details.
  Returns if successful and raise on failure."""

  if isinstance(output_tree, wc.State):
    output_tree = output_tree.old_tree()
  if isinstance(disk_tree, wc.State):
    disk_tree = disk_tree.old_tree()

  # Remove dir if it's already there.
  main.safe_rmtree(wc_dir_name)

  # Checkout and make a tree of the output, using l:foo/p:bar
  ### todo: svn should not be prompting for auth info when using
  ### repositories with no auth/auth requirements
  output, errput = main.run_svn (None, 'co',
                                 '--username', main.wc_author,
                                 '--password', main.wc_passwd,
                                 URL, wc_dir_name)
  mytree = tree.build_tree_from_checkout (output)

  # Verify actual output against expected output.
  tree.compare_trees (mytree, output_tree)

  # Create a tree by scanning the working copy
  mytree = tree.build_tree_from_wc (wc_dir_name)

  # Verify expected disk against actual disk.
  tree.compare_trees (mytree, disk_tree,
                      singleton_handler_a, a_baton,
                      singleton_handler_b, b_baton)
Example #3
0
def duplicate_dir(wc_name, wc_copy_name):
    """Copy the working copy WC_NAME to WC_COPY_NAME.  Overwrite any
  existing tree at that location."""

    main.safe_rmtree(wc_copy_name)
    shutil.copytree(wc_name, wc_copy_name)
Example #4
0
def guarantee_greek_repository(path):
    """Guarantee that a local svn repository exists at PATH, containing
  nothing but the greek-tree at revision 1."""

    if path == main.pristine_dir:
        print "ERROR:  attempt to overwrite the pristine repos!  Aborting."
        sys.exit(1)

    # If there's no pristine repos, create one.
    if not os.path.exists(main.pristine_dir):
        main.create_repos(main.pristine_dir)

        # dump the greek tree to disk.
        main.greek_state.write_to_disk(main.greek_dump_dir)

        # build a URL for doing an import.
        url = main.test_area_url + '/' + main.pristine_dir
        if main.windows == 1:
            url = string.replace(url, '\\', '/')

        # import the greek tree, using l:foo/p:bar
        ### todo: svn should not be prompting for auth info when using
        ### repositories with no auth/auth requirements
        output, errput = main.run_svn(None, 'import', '--username',
                                      main.wc_author, '--password',
                                      main.wc_passwd, '-m',
                                      'Log message for revision 1.',
                                      main.greek_dump_dir, url)

        # check for any errors from the import
        if len(errput):
            display_lines("Errors during initial 'svn import':", 'STDERR',
                          None, errput)
            sys.exit(1)

        # verify the printed output of 'svn import'.
        lastline = string.strip(output.pop())
        cm = re.compile("(Committed|Imported) revision [0-9]+.")
        match = cm.search(lastline)
        if not match:
            print "ERROR:  import did not succeed, while creating greek repos."
            print "The final line from 'svn import' was:"
            print lastline
            sys.exit(1)
        output_tree = tree.build_tree_from_commit(output)

        ### due to path normalization in the .old_tree() method, we cannot
        ### prepend the necessary '.' directory. thus, let's construct an old
        ### tree manually from the greek_state.
        output_list = []
        for greek_path in main.greek_state.desc.keys():
            output_list.append([
                os.path.join(main.greek_dump_dir, greek_path), None, {}, {
                    'verb': 'Adding'
                }
            ])
        expected_output_tree = tree.build_generic_tree(output_list)

        try:
            tree.compare_trees(output_tree, expected_output_tree)
        except tree.SVNTreeUnequal:
            display_trees("ERROR:  output of import command is unexpected.",
                          'OUTPUT TREE', expected_output_tree, output_tree)
            sys.exit(1)

    # Now that the pristine repos exists, copy it to PATH.
    main.safe_rmtree(path)
    if main.copy_repos(main.pristine_dir, path, 1):
        print "ERROR:  copying repository failed."
        sys.exit(1)

    # make the repos world-writeable, for mod_dav_svn's sake.
    main.chmod_tree(path, 0666, 0666)
Example #5
0
def duplicate_dir(wc_name, wc_copy_name):
  """Copy the working copy WC_NAME to WC_COPY_NAME.  Overwrite any
  existing tree at that location."""

  main.safe_rmtree(wc_copy_name)
  shutil.copytree(wc_name, wc_copy_name)
Example #6
0
def guarantee_greek_repository(path):
  """Guarantee that a local svn repository exists at PATH, containing
  nothing but the greek-tree at revision 1."""

  if path == main.pristine_dir:
    print "ERROR:  attempt to overwrite the pristine repos!  Aborting."
    sys.exit(1)

  # If there's no pristine repos, create one.
  if not os.path.exists(main.pristine_dir):
    main.create_repos(main.pristine_dir)
    
    # dump the greek tree to disk.
    main.greek_state.write_to_disk(main.greek_dump_dir)

    # build a URL for doing an import.
    url = main.test_area_url + '/' + main.pristine_dir
    if main.windows == 1:
      url = string.replace(url, '\\', '/')

    # import the greek tree, using l:foo/p:bar
    ### todo: svn should not be prompting for auth info when using
    ### repositories with no auth/auth requirements
    output, errput = main.run_svn(None, 'import',
                                  '--username', main.wc_author,
                                  '--password', main.wc_passwd,
                                  '-m', 'Log message for revision 1.',
                                  main.greek_dump_dir, url)

    # check for any errors from the import
    if len(errput):
      display_lines("Errors during initial 'svn import':",
                    'STDERR', None, errput)
      sys.exit(1)

    # verify the printed output of 'svn import'.
    lastline = string.strip(output.pop())
    cm = re.compile ("(Committed|Imported) revision [0-9]+.")
    match = cm.search (lastline)
    if not match:
      print "ERROR:  import did not succeed, while creating greek repos."
      print "The final line from 'svn import' was:"
      print lastline
      sys.exit(1)
    output_tree = tree.build_tree_from_commit(output)

    ### due to path normalization in the .old_tree() method, we cannot
    ### prepend the necessary '.' directory. thus, let's construct an old
    ### tree manually from the greek_state.
    output_list = []
    for greek_path in main.greek_state.desc.keys():
      output_list.append([ os.path.join(main.greek_dump_dir, greek_path),
                           None, {}, {'verb' : 'Adding'}])
    expected_output_tree = tree.build_generic_tree(output_list)

    try:
      tree.compare_trees(output_tree, expected_output_tree)
    except tree.SVNTreeUnequal:
      display_trees("ERROR:  output of import command is unexpected.",
                    'OUTPUT TREE', expected_output_tree, output_tree)
      sys.exit(1)

  # Now that the pristine repos exists, copy it to PATH.
  main.safe_rmtree(path)
  if main.copy_repos(main.pristine_dir, path, 1):
    print "ERROR:  copying repository failed."
    sys.exit(1)

  # make the repos world-writeable, for mod_dav_svn's sake.
  main.chmod_tree(path, 0666, 0666)