Exemple #1
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)
Exemple #2
0
def run_and_verify_commit(wc_dir_name,
                          output_tree,
                          status_output_tree,
                          error_re_string=None,
                          singleton_handler_a=None,
                          a_baton=None,
                          singleton_handler_b=None,
                          b_baton=None,
                          *args):
    """Commit and verify results within working copy WC_DIR_NAME,
  sending ARGS to the commit subcommand.

  The subcommand output will be verified against OUTPUT_TREE.  If
  optional STATUS_OUTPUT_TREE is given, then 'svn status' output will
  be compared.  (This is a good way to check that revision numbers
  were bumped.)

  If ERROR_RE_STRING is None, the commit must not exit with error.  If
  ERROR_RE_STRING is a string, the commit must exit with error, and
  the error message must match regular expression ERROR_RE_STRING.

  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, raises on failure."""

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

    # Commit.
    output, errput = main.run_svn(error_re_string, 'ci', '--username',
                                  main.wc_author, '--password', main.wc_passwd,
                                  '-m', 'log msg', *args)

    if (error_re_string):
        rm = re.compile(error_re_string)
        for line in errput:
            match = rm.search(line)
            if match:
                return
        raise main.SVNUnmatchedError

    # Else not expecting error:

    # Remove the final output line, and verify that the commit succeeded.
    lastline = ""
    if len(output):
        lastline = string.strip(output.pop())

        cm = re.compile("(Committed|Imported) revision [0-9]+.")
        match = cm.search(lastline)
        if not match:
            print "ERROR:  commit did not succeed."
            print "The final line from 'svn ci' was:"
            print lastline
            raise main.SVNCommitFailure

    # The new 'final' line in the output is either a regular line that
    # mentions {Adding, Deleting, Sending, ...}, or it could be a line
    # that says "Transmitting file data ...".  If the latter case, we
    # want to remove the line from the output; it should be ignored when
    # building a tree.
    if len(output):
        lastline = output.pop()

        tm = re.compile("Transmitting file data.+")
        match = tm.search(lastline)
        if not match:
            # whoops, it was important output, put it back.
            output.append(lastline)

    # Convert the output into a tree.
    mytree = tree.build_tree_from_commit(output)

    # Verify actual output against expected output.
    try:
        tree.compare_trees(mytree, output_tree)
    except tree.SVNTreeError:
        display_trees("Output of commit is unexpected.", "OUTPUT TREE",
                      output_tree, mytree)
        raise

    # Verify via 'status' command too, if possible.
    if status_output_tree:
        run_and_verify_status(wc_dir_name, status_output_tree)
Exemple #3
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)
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.write_tree(main.greek_dump_dir,
                    [[x[0], x[1]] for x in main.greek_tree])

    # build a URL for doing an import.
    url = main.test_area_url + '/' + main.pristine_dir

    # 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.',
                                  url, main.greek_dump_dir)

    # check for any errors from the import
    if len(errput):
      print "Errors during initial 'svn import':"
      print 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)

    output_list = []
    path_list = [x[0] for x in main.greek_tree]
    for apath in path_list:
      item = [ os.path.join(".", apath), None, {}, {'verb' : 'Adding'}]
      output_list.append(item)
    expected_output_tree = tree.build_generic_tree(output_list)
      
    if tree.compare_trees(output_tree, expected_output_tree):
      print "ERROR:  output of import command is unexpected."
      sys.exit(1)

  # Now that the pristine repos exists, copy it to PATH.
  if os.path.exists(path):
    shutil.rmtree(path)
  if not os.path.exists(os.path.dirname(path)):
    os.makedirs(os.path.dirname(path))
  shutil.copytree(main.pristine_dir, path)
  if os.path.exists(main.current_repo_dir):
    os.unlink(main.current_repo_dir)                              
  os.symlink(os.path.basename(path), main.current_repo_dir)
Exemple #5
0
def run_and_verify_commit(wc_dir_name, output_tree, status_output_tree,
                          error_re_string = None,
                          singleton_handler_a = None,
                          a_baton = None,
                          singleton_handler_b = None,
                          b_baton = None,
                          *args):
  """Commit and verify results within working copy WC_DIR_NAME,
  sending ARGS to the commit subcommand.

  The subcommand output will be verified against OUTPUT_TREE.  If
  optional STATUS_OUTPUT_TREE is given, then 'svn status' output will
  be compared.  (This is a good way to check that revision numbers
  were bumped.)

  If ERROR_RE_STRING is None, the commit must not exit with error.  If
  ERROR_RE_STRING is a string, the commit must exit with error, and
  the error message must match regular expression ERROR_RE_STRING.

  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, raises on failure."""

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

  # Commit.
  output, errput = main.run_svn(error_re_string, 'ci', '-m', 'log msg', *args)

  if (error_re_string):
    rm = re.compile(error_re_string)
    for line in errput:
      match = rm.search(line)
      if match:
        return
    raise main.SVNUnmatchedError

  # Else not expecting error:

  # Remove the final output line, and verify that the commit succeeded.
  lastline = ""
  if len(output):
    lastline = string.strip(output.pop())
    
    cm = re.compile("(Committed|Imported) revision [0-9]+.")
    match = cm.search(lastline)
    if not match:
      print "ERROR:  commit did not succeed."
      print "The final line from 'svn ci' was:"
      print lastline
      raise main.SVNCommitFailure

  # The new 'final' line in the output is either a regular line that
  # mentions {Adding, Deleting, Sending, ...}, or it could be a line
  # that says "Transmitting file data ...".  If the latter case, we
  # want to remove the line from the output; it should be ignored when
  # building a tree.
  if len(output):
    lastline = output.pop()

    tm = re.compile("Transmitting file data.+")
    match = tm.search(lastline)
    if not match:
      # whoops, it was important output, put it back.
      output.append(lastline)
    
  # Convert the output into a tree.
  mytree = tree.build_tree_from_commit (output)
    
  # Verify actual output against expected output.
  try:
    tree.compare_trees (mytree, output_tree)
  except tree.SVNTreeError:
      display_trees("Output of commit is unexpected.",
                    "OUTPUT TREE", output_tree, mytree)
      raise
    
  # Verify via 'status' command too, if possible.
  if status_output_tree:
    run_and_verify_status(wc_dir_name, status_output_tree)