Example #1
0
def cmp(f1, f2, shallow=1):
    """Compare two files, use the cache if possible.
    May raise os.error if a stat or open of either fails.
    Return 1 for identical files, 0 for different.
    Raise exceptions if either file could not be statted, read, etc."""
    s1, s2 = sig(statcache.stat(f1)), sig(statcache.stat(f2))
    if not S_ISREG(s1[0]) or not S_ISREG(s2[0]):
        # Either is a not a plain file -- always report as different
        return 0
    if shallow and s1 == s2:
        # type, size & mtime match -- report same
        return 1
    if s1[:2] != s2[:2]: # Types or sizes differ, don't bother
        # types or sizes differ -- report different
        return 0
    # same type and size -- look in the cache
    key = f1 + ' ' + f2
    if cache.has_key(key):
        cs1, cs2, outcome = cache[key]
        # cache hit
        if s1 == cs1 and s2 == cs2:
            # cached signatures match
            return outcome
        # stale cached signature(s)
    # really compare
    outcome = do_cmp(f1, f2)
    cache[key] = s1, s2, outcome
    return outcome
Example #2
0
def cmp(f1, f2, shallow=1):
    """Compare two files, use the cache if possible.
    May raise os.error if a stat or open of either fails.
    Return 1 for identical files, 0 for different.
    Raise exceptions if either file could not be statted, read, etc."""
    s1, s2 = sig(statcache.stat(f1)), sig(statcache.stat(f2))
    if not S_ISREG(s1[0]) or not S_ISREG(s2[0]):
        # Either is a not a plain file -- always report as different
        return 0
    if shallow and s1 == s2:
        # type, size & mtime match -- report same
        return 1
    if s1[:2] != s2[:2]:  # Types or sizes differ, don't bother
        # types or sizes differ -- report different
        return 0
    # same type and size -- look in the cache
    key = f1 + ' ' + f2
    if cache.has_key(key):
        cs1, cs2, outcome = cache[key]
        # cache hit
        if s1 == cs1 and s2 == cs2:
            # cached signatures match
            return outcome
        # stale cached signature(s)
    # really compare
    outcome = do_cmp(f1, f2)
    cache[key] = s1, s2, outcome
    return outcome
Example #3
0
    def parseFile(self, filePath, oPath='', noCache=1, reload=0, allTags=0):
        
	if noCache:
                f = open(filePath)
                self.parse(f.read(), reload, allTags)
	else:
		ttime = stat(filePath)[ST_MTIME]
		if oPath:
		    path, file = split(filePath)
		    ofilePath= join(oPath, file)
		else:
		    idx = filePath.rindex('.')
		    if idx > -1:
			ofilePath= filePath[:idx] + '.pso'
		    else:
			ofilePath = filePath+'.pso'
		    try:
			
			otime = stat(ofilePath)[ST_MTIME]
			if otime < ttime:
			    raise 'do parse'
			tagsAccepted, tagsRejected, self.tokenTree = load(open(ofilePath))
			self.sTagsAccepted.update(tagsAccepted)
			self.sTagsRejected.update(tagsRejected)
		    except:
                        if not silent:
                            import traceback
                            traceback.print_exc()
			f = open(filePath)
			self.parse(f.read(), reload, allTags)
			if not noCache:
			    dump((self.sTagsAccepted, self.sTagsRejected, self.tokenTree), open(ofilePath,'wb'))
			forget(ofilePath)
		    forget(filePath)
        return self.tokenTree
Example #4
0
def cmp(f1, f2):
       # Return 1 for identical files, 0 for different.
       # Raise exceptions if either file could not be statted, read, etc.
       s1, s2 = sig(statcache.stat(f1)), sig(statcache.stat(f2))
       if not S_ISREG(s1[0]) or not S_ISREG(s2[0]):
               # Either is a not a plain file -- always report as different
               return 0
       if s1 = s2:
               # type, size & mtime match -- report same
               return 1
Example #5
0
    def phase2(self):  # Distinguish files, directories, funnies
        self.common_dirs = []
        self.common_files = []
        self.common_funny = []

        for x in self.common:
            a_path = os.path.join(self.left, x)
            b_path = os.path.join(self.right, x)

            ok = 1
            try:
                a_stat = statcache.stat(a_path)
            except os.error, why:
                # print 'Can\'t stat', a_path, ':', why[1]
                ok = 0
            try:
                b_stat = statcache.stat(b_path)
            except os.error, why:
                # print 'Can\'t stat', b_path, ':', why[1]
                ok = 0
Example #6
0
    def phase2(self): # Distinguish files, directories, funnies
        self.common_dirs = []
        self.common_files = []
        self.common_funny = []

        for x in self.common:
            a_path = os.path.join(self.left, x)
            b_path = os.path.join(self.right, x)

            ok = 1
            try:
                a_stat = statcache.stat(a_path)
            except os.error, why:
                # print 'Can\'t stat', a_path, ':', why[1]
                ok = 0
            try:
                b_stat = statcache.stat(b_path)
            except os.error, why:
                # print 'Can\'t stat', b_path, ':', why[1]
                ok = 0
Example #7
0
	def phase2(dd): # Distinguish files, directories, funnies
		dd.common_dirs = []
		dd.common_files = []
		dd.common_funny = []
		#
		for x in dd.common:
			a_path = path.cat(dd.a, x)
			b_path = path.cat(dd.b, x)
			#
			ok = 1
			try:
				a_stat = statcache.stat(a_path)
			except posix.error, why:
				# print 'Can\'t stat', a_path, ':', why[1]
				ok = 0
			try:
				b_stat = statcache.stat(b_path)
			except posix.error, why:
				# print 'Can\'t stat', b_path, ':', why[1]
				ok = 0
Example #8
0
 def phase2(dd): # Distinguish files, directories, funnies
         dd.common_dirs = []
         dd.common_files = []
         dd.common_funny = []
         #
         for x in dd.common:
                 a_path = path.cat(dd.a, x)
                 b_path = path.cat(dd.b, x)
                 #
                 ok = 1
                 try:
                         a_stat = statcache.stat(a_path)
                 except posix.error, why:
                         # print 'Can\'t stat', a_path, ':', why[1]
                         ok = 0
                 try:
                         b_stat = statcache.stat(b_path)
                 except posix.error, why:
                         # print 'Can\'t stat', b_path, ':', why[1]
                         ok = 0
Example #9
0
import statcache
import os, stat, time

now = time.time()
for i in range(1000):
    st = os.stat("samples/sample.txt")
print("os.stat", "=>", time.time() - now)

now = time.time()
for i in range(1000):
    st = statcache.stat("samples/sample.txt")
print("statcache.stat", "=>", time.time() - now)

print("mode", "=>", oct(stat.S_IMODE(st[stat.ST_MODE])))
print("size", "=>", st[stat.ST_SIZE])
print("last modified", "=>", time.ctime(st[stat.ST_MTIME]))

## os.stat => 0.371000051498
## statcache.stat => 0.0199999809265
## mode => 0666
## size => 305
## last modified => Sun Oct 10 18:39:37 1999
Example #10
0
"""Utilities for comparing files and directories.
Example #11
0
import statcache
import os, stat, time

now = time.time()
for i in range(1000):
    st = os.stat("samples/sample.txt")
print "os.stat", "=>", time.time() - now

now = time.time()
for i in range(1000):
    st = statcache.stat("samples/sample.txt")
print "statcache.stat", "=>", time.time() - now

print "mode", "=>", oct(stat.S_IMODE(st[stat.ST_MODE]))
print "size", "=>", st[stat.ST_SIZE]
print "last modified", "=>", time.ctime(st[stat.ST_MTIME])

## os.stat => 0.371000051498
## statcache.stat => 0.0199999809265
## mode => 0666
## size => 305
## last modified => Sun Oct 10 18:39:37 1999
Example #12
0
"""Efficiently compare files, boolean outcome only (equal / not equal).
Example #13
0
"""A class to build directory diff tools on."""
Example #14
0
"""A class to build directory diff tools on."""
Example #15
0
"""Utilities for comparing files and directories.
    def commit(self, t_fs, ctx):
        # commit this transaction
        print 'committing: %s, over %d seconds' % (time.ctime(
            self.t_min), self.t_max - self.t_min)

        # create a pool for the entire commit
        c_pool = util.svn_pool_create(ctx.pool)

        rev = fs.youngest_rev(t_fs, c_pool)
        txn = fs.begin_txn(t_fs, rev, c_pool)
        root = fs.txn_root(txn, c_pool)

        lastcommit = (None, None)

        # create a pool for each file; it will be cleared on each iteration
        f_pool = util.svn_pool_create(c_pool)

        for f, r in self.changes:
            # compute a repository path. ensure we have a leading "/" and drop
            # the ,v from the file name
            repos_path = '/' + relative_name(ctx.cvsroot, f[:-2])
            #print 'DEBUG:', repos_path

            print '    changing %s : %s' % (r, repos_path)

            ### hmm. need to clarify OS path separators vs FS path separators
            dirname = os.path.dirname(repos_path)
            if dirname != '/':
                # get the components of the path (skipping the leading '/')
                parts = string.split(dirname[1:], os.sep)
                for i in range(1, len(parts) + 1):
                    # reassemble the pieces, adding a leading slash
                    parent_dir = '/' + string.join(parts[:i], '/')
                    if fs.check_path(root, parent_dir,
                                     f_pool) == svn_node_none:
                        print '    making dir:', parent_dir
                        fs.make_dir(root, parent_dir, f_pool)

            if fs.check_path(root, repos_path, f_pool) == svn_node_none:
                created_file = 1
                fs.make_file(root, repos_path, f_pool)
            else:
                created_file = 0

            handler, baton = fs.apply_textdelta(root, repos_path, f_pool)

            # figure out the real file path for "co"
            try:
                statcache.stat(f)
            except os.error:
                dirname, fname = os.path.split(f)
                f = os.path.join(dirname, 'Attic', fname)
                statcache.stat(f)

            pipe = os.popen('co -q -p%s %s' % (r, f), 'r', 102400)

            # if we just made the file, we can send it in one big hunk, rather
            # than streaming it in.
            ### we should watch out for file sizes here; we don't want to yank
            ### in HUGE files...
            if created_file:
                _delta.svn_txdelta_send_string(pipe.read(), handler, baton,
                                               f_pool)
            else:
                # open an SVN stream onto the pipe
                stream2 = util.svn_stream_from_stdio(pipe, f_pool)

                # Get the current file contents from the repo, or, if we have
                # multiple CVS revisions to the same file being done in this
                # single commit, then get the contents of the previous
                # revision from co, or else the delta won't be correct because
                # the contents in the repo won't have changed yet.
                if repos_path == lastcommit[0]:
                    infile2 = os.popen("co -q -p%s %s" % (lastcommit[1], f),
                                       "r", 102400)
                    stream1 = util.svn_stream_from_stdio(infile2, f_pool)
                else:
                    stream1 = fs.file_contents(root, repos_path, f_pool)

                txstream = _delta.svn_txdelta(stream1, stream2, f_pool)
                _delta.svn_txdelta_send_txstream(txstream, handler, baton,
                                                 f_pool)

                # shut down the previous-rev pipe, if we opened it
                infile2 = None

            # shut down the current-rev pipe
            pipe.close()

            # wipe the pool. this will get rid of the pipe streams and the delta
            # stream, and anything the FS may have done.
            util.svn_pool_clear(f_pool)

            # remember what we just did, for the next iteration
            lastcommit = (repos_path, r)

        for f, r in self.deletes:
            # compute a repository path. ensure we have a leading "/" and drop
            # the ,v from the file name
            repos_path = '/' + relative_name(ctx.cvsroot, f[:-2])

            print '    deleting %s : %s' % (r, repos_path)

            # If the file was initially added on a branch, the first mainline
            # revision will be marked dead, and thus, attempts to delete it will
            # fail, since it doesn't really exist.
            if r != '1.1':
                ### need to discriminate between OS paths and FS paths
                fs.delete(root, repos_path, f_pool)

            # wipe the pool, in case the delete loads it up
            util.svn_pool_clear(f_pool)

        # get the metadata for this commit
        author, log, date = self.get_metadata(c_pool)
        fs.change_txn_prop(txn, 'svn:author', author, c_pool)
        fs.change_txn_prop(txn, 'svn:log', log, c_pool)

        conflicts, new_rev = fs.commit_txn(txn)

        # set the time to the proper (past) time
        fs.change_rev_prop(t_fs, new_rev, 'svn:date', date, c_pool)

        ### how come conflicts is a newline?
        if conflicts != '\n':
            print '    CONFLICTS:', ` conflicts `
        print '    new revision:', new_rev

        # done with the commit and file pools
        util.svn_pool_destroy(c_pool)