Esempio n. 1
0
    def _initialize(self, resilient_dir):
        """
        Initialize the history module.
        """
        opts = self.opts

        # Calculate the location of the history file.
        if opts.history_file:
            histfn = opts.history_file
        else:
            histfn = join(resilient_dir, 'history')

        # Clear the history if requested.
        if opts.clear_history and exists(histfn):
            os.unlink(histfn)

        # Prepare and create a history file if one does not already exist.
        if not opts.history:
            return
        if not exists(histfn):
            makedirs(dirname(histfn), False)
            self.histf = open(histfn, 'w')

        # Otherwise read the history file contents.
        else:
            f = open(histfn, 'r')
            self.history.extend(x.strip() for x in f.readlines() if x)
            f.close()
            self.histf = open(histfn, 'a')
Esempio n. 2
0
    def _initialize(self, resilient_dir):
        """
        Initialize the history module.
        """
        opts = self.opts
        
        # Calculate the location of the history file.
        if opts.history_file:
            histfn = opts.history_file
        else:
            histfn = join(resilient_dir, 'history')

        # Clear the history if requested.
        if opts.clear_history and exists(histfn):
            os.unlink(histfn)

        # Prepare and create a history file if one does not already exist.
        if not opts.history:
            return
        if not exists(histfn):
            makedirs(dirname(histfn), False)
            self.histf = open(histfn, 'w')

        # Otherwise read the history file contents.
        else:
            f = open(histfn, 'r')
            self.history.extend(x.strip() for x  in f.readlines() if x)
            f.close()
            self.histf = open(histfn, 'a')
Esempio n. 3
0
def svndiff_main():
    """
    Main program for svn-diff script.
    """
    opts, args = parse_options()

    # Compute the location of the resilient directory for the comments and
    # history files (and maybe more stuff later on).
    resildir = xxdiff.resilient.resilient_for_paths(args)
    hist = xxdiff.history.History(opts, resildir)

    # Compute a list of files to ignore (e.g. if the comments or history file is
    # located in the checkout, we want to ignore them and then associated
    # swap/temp files).
    ignofiles = []
    if opts.commit and opts.comments_file:
        comfn = abspath(opts.comments_file)
        ignofiles.extend([comfn, '%s.swp' % comfn])
    if opts.history and opts.history_file:
        histfn = abspath(opts.history_file)
        ignofiles.extend([histfn, '%s.swp' % histfn])

    if opts.foreign:
        # Consider the unregistered files.
        if query_unregistered_svn_files(args,
                                        opts,
                                        sys.stdout,
                                        ignore=ignofiles) is not True:
            # The user has quit, don't continue.
            sys.exit(0)
        print()
        print()

    # Get the status of the working copy.
    statii = subversion.status(args)

    # Ignore the comments file from the svn status output.
    statii = [s for s in statii if abspath(s.filename) not in ignofiles]

    if not statii:
        print('(Nothing to do, exiting.)')
        hist.delete()
        return

    # First print out the status to a string.
    renstatus = os.linesep.join(x.parsed_line for x in statii)

    if opts.commit:
        # File to delete after a successful commit.
        if opts.comments_file:
            comfn = abspath(opts.comments_file)
        else:
            # Select a comments file and make sure that it exists.
            comfn = join(resildir, 'comments')

            makedirs(resildir, False)
            if not exists(comfn):
                open(comfn, 'w')

    # Spawn an editor if requested before starting the review.
    if opts.commit:
        m = {'date': datetime.datetime.now()}
        comments = None  # renstatus
        edit_waiter = xxdiff.editor.spawn_editor(comments, filename=comfn)

    # First print out the status to the user.
    print('Status Of Files To Be Diffed')
    print('----------------------------')
    print(renstatus)

    # Then we start printing each file and the associated decision.
    msgfmt = '  %-10s | %-10s | %s'
    print()
    print(msgfmt % ('Type', 'Action', 'Status'))
    print(msgfmt % ('-' * 10, '-' * 10, '-' * 40))

    # Main loop for graphical diffs, over each of the files reported by status.
    for s in statii:
        kind, action = 'unknown', 'exception'  # Initialize for in case of an
        # exception.
        try:
            # Skip directories.
            if isdir(s.filename):
                kind, action = 'directory', 'skip'
                continue
            elif islink(s.filename):
                kind, action = 'symlink', 'skip'
                continue

            # Compute unique string for history recorder.  We use the size, last
            # modification time, and status info to hash on this.
            if exists(s.filename):
                fstat = os.lstat(s.filename)
                sz, mtime = fstat.st_size, fstat.st_mtime
            else:
                # Deal with files that have been deleted.
                sz, mtime = 0, 0
            histitem = ' '.join((str(sz), str(mtime), s.parsed_line))

            # If the file has already been reviewed in the history, skip it.
            if hist.check(histitem):
                kind, action = 'seen', 'skip'
                continue

            # Review the file.
            (kind, action), waiter = review_file(s, opts)
        finally:
            print(msgfmt % (kind, action, s.parsed_line))

        if waiter is not None:
            waiter()

        # We have succesfully finished viewing the file, add it to the history.
        hist.append(histitem)

    # Commit the files if requested.
    if opts.commit:
        print("\nWaiting for editor '%s' to complete..." % edit_waiter.command,
              end='')
        sys.stdout.flush()
        comments = edit_waiter()
        print('Done.\n')
        print('Recorded Merge Comments: ', end='')
        if comments == '':
            print('(None)')
            comments = None
        else:
            print()
            print('-' * 70)
            print(comments)
            print('-' * 70)

        subversion.commit(args, comments=comments)

        # Delete temporary comments flie if we created it.
        if not opts.comments_file:
            xxdiff.resilient.resilient_remove(comfn)

    # The entire list of files has been reviewed (and possibly committed), clear
    # the history file.
    if opts.history:
        print()
        print('(Review complete, history cleared)')
        hist.delete()
Esempio n. 4
0
def svndiff_main():
    """
    Main program for svn-diff script.
    """
    opts, args = parse_options()

    # Compute the location of the resilient directory for the comments and
    # history files (and maybe more stuff later on).
    resildir = xxdiff.resilient.resilient_for_paths(args)
    hist = xxdiff.history.History(opts, resildir)

    # Compute a list of files to ignore (e.g. if the comments or history file is
    # located in the checkout, we want to ignore them and then associated
    # swap/temp files).
    ignofiles = []
    if opts.commit and opts.comments_file:
        comfn = abspath(opts.comments_file)
        ignofiles.extend([comfn, '%s.swp' % comfn])
    if opts.history and opts.history_file:
        histfn = abspath(opts.history_file)
        ignofiles.extend([histfn, '%s.swp' % histfn])

    if opts.foreign:
        # Consider the unregistered files.
        if query_unregistered_svn_files(
            args, opts, sys.stdout, ignore=ignofiles) is not True:
            # The user has quit, don't continue.
            sys.exit(0)
        print
        print

    # Get the status of the working copy.
    statii = subversion.status(args)

    # Ignore the comments file from the svn status output.
    statii = [s for s in statii if abspath(s.filename) not in ignofiles]

    if not statii:
        print '(Nothing to do, exiting.)'
        hist.delete()
        return

    # First print out the status to a string.
    renstatus = os.linesep.join(x.parsed_line for x in statii)

    if opts.commit:
        # File to delete after a successful commit.
        if opts.comments_file:
            comfn = abspath(opts.comments_file)
        else:
            # Select a comments file and make sure that it exists.
            comfn = join(resildir, 'comments')

            makedirs(resildir, False)
            if not exists(comfn):
                open(comfn, 'w')

    # Spawn an editor if requested before starting the review.
    if opts.commit:
        m = {'date': datetime.datetime.now()}
        comments = None # renstatus
        edit_waiter = xxdiff.editor.spawn_editor(comments, filename=comfn)

    # First print out the status to the user.
    print 'Status Of Files To Be Diffed'
    print '----------------------------'
    print renstatus

    # Then we start printing each file and the associated decision.
    msgfmt = '  %-10s | %-10s | %s'
    print
    print msgfmt % ('Type', 'Action', 'Status')
    print msgfmt % ('-'*10, '-'*10, '-'*40)

    # Main loop for graphical diffs, over each of the files reported by status.
    for s in statii:
        kind, action = 'unknown', 'exception' # Initialize for in case of an
                                              # exception.
        try:
            # Skip directories.
            if isdir(s.filename):
                kind, action = 'directory', 'skip'
                continue
            elif islink(s.filename):
                kind, action = 'symlink', 'skip'
                continue

            # Compute unique string for history recorder.  We use the size, last
            # modification time, and status info to hash on this.
            if exists(s.filename):
                fstat = os.lstat(s.filename)
                sz, mtime = fstat.st_size, fstat.st_mtime
            else:
                # Deal with files that have been deleted.
                sz, mtime = 0, 0
            histitem = ' '.join((str(sz), str(mtime), s.parsed_line))

            # If the file has already been reviewed in the history, skip it.
            if hist.check(histitem):
                kind, action = 'seen', 'skip'
                continue

            # Review the file.
            (kind, action), waiter = review_file(s, opts)
        finally:
            print msgfmt % (kind, action, s.parsed_line)

        if waiter is not None:
            waiter()

        # We have succesfully finished viewing the file, add it to the history.
        hist.append(histitem)

    # Commit the files if requested.
    if opts.commit:
        print "\nWaiting for editor '%s' to complete..." % edit_waiter.command,
        sys.stdout.flush()
        comments = edit_waiter()
        print 'Done.\n'
        print 'Recorded Merge Comments: ',
        if comments == '':
            print '(None)'
            comments = None
        else:
            print
            print '-' * 70
            print comments
            print '-' * 70

        subversion.commit(args, comments=comments)

        # Delete temporary comments flie if we created it.
        if not opts.comments_file:
            xxdiff.resilient.resilient_remove(comfn)

    # The entire list of files has been reviewed (and possibly committed), clear
    # the history file.
    if opts.history:
        print
        print '(Review complete, history cleared)'
        hist.delete()