diff options
author | Steven Knight <knight@baldmt.com> | 2001-09-17 04:57:00 (GMT) |
---|---|---|
committer | Steven Knight <knight@baldmt.com> | 2001-09-17 04:57:00 (GMT) |
commit | 3c81bb2bd0e009c0ee81570e17b0f87ad8d034ab (patch) | |
tree | 1a08c189644909cdadc489cce0eaa487e2c6f578 /src/engine/SCons/Sig | |
parent | e2faf9c21bc7712fcdc547b7df0f12a6b2177601 (diff) | |
download | SCons-3c81bb2bd0e009c0ee81570e17b0f87ad8d034ab.zip SCons-3c81bb2bd0e009c0ee81570e17b0f87ad8d034ab.tar.gz SCons-3c81bb2bd0e009c0ee81570e17b0f87ad8d034ab.tar.bz2 |
Run setup.py on the unpacked .tar.gz for testing.
Diffstat (limited to 'src/engine/SCons/Sig')
-rw-r--r-- | src/engine/SCons/Sig/.aeignore | 4 | ||||
-rw-r--r-- | src/engine/SCons/Sig/MD5.py | 70 | ||||
-rw-r--r-- | src/engine/SCons/Sig/MD5Tests.py | 76 | ||||
-rw-r--r-- | src/engine/SCons/Sig/TimeStamp.py | 49 | ||||
-rw-r--r-- | src/engine/SCons/Sig/TimeStampTests.py | 74 | ||||
-rw-r--r-- | src/engine/SCons/Sig/__init__.py | 7 |
6 files changed, 280 insertions, 0 deletions
diff --git a/src/engine/SCons/Sig/.aeignore b/src/engine/SCons/Sig/.aeignore new file mode 100644 index 0000000..43fe851 --- /dev/null +++ b/src/engine/SCons/Sig/.aeignore @@ -0,0 +1,4 @@ +*,D +*.pyc +.*.swp +.consign diff --git a/src/engine/SCons/Sig/MD5.py b/src/engine/SCons/Sig/MD5.py new file mode 100644 index 0000000..9d461d9 --- /dev/null +++ b/src/engine/SCons/Sig/MD5.py @@ -0,0 +1,70 @@ +"""SCons.Sig.MD5 + +The MD5 signature package for the SCons software construction +utility. + +""" + +__revision__ = "Sig/MD5.py __REVISION__ __DATE__ __DEVELOPER__" + +import md5 +import string + + + +def hexdigest(s): + """Return a signature as a string of hex characters. + """ + # NOTE: This routine is a method in the Python 2.0 interface + # of the native md5 module, but we want SCons to operate all + # the way back to at least Python 1.5.2, which doesn't have it. + h = string.hexdigits + r = '' + for c in s: + i = ord(c) + r = r + h[(i >> 4) & 0xF] + h[i & 0xF] + return r + + + +def _init(): + pass # XXX + +def _end(): + pass # XXX + +def current(obj, sig): + """Return whether a given object is up-to-date with the + specified signature. + """ + return obj.signature() == sig + +def set(): + pass # XXX + +def invalidate(): + pass # XXX + +def collect(*objects): + """Collect signatures from a list of objects, returning the + aggregate signature of the list. + """ + if len(objects) == 1: + sig = objects[0].signature() + else: + contents = string.join(map(lambda o: o.signature(), objects), ', ') + sig = signature(contents) +# if debug: +# pass + return sig + +def signature(contents): + """Generate a signature for a byte string. + """ + return hexdigest(md5.new(contents).digest()) + +def cmdsig(): + pass # XXX + +def srcsig(): + pass # XXX diff --git a/src/engine/SCons/Sig/MD5Tests.py b/src/engine/SCons/Sig/MD5Tests.py new file mode 100644 index 0000000..ac67f1d --- /dev/null +++ b/src/engine/SCons/Sig/MD5Tests.py @@ -0,0 +1,76 @@ +__revision__ = "Sig/MD5Tests.py __REVISION__ __DATE__ __DEVELOPER__" + +import sys +import unittest + +import SCons.Sig.MD5 + + + +class my_obj: + """A dummy object class that satisfies the interface + requirements of the MD5 class. + """ + + def __init__(self, value = ""): + self.value = value + self.sig = None + + def signature(self): + if not self.sig: + self.sig = SCons.Sig.MD5.signature(self.value) + return self.sig + + def current(self, sig): + return SCons.Sig.MD5.current(self, sig) + + + +class MD5TestCase(unittest.TestCase): + + def test__init(self): + pass # XXX + + def test__end(self): + pass # XXX + + def test_current(self): + """Test deciding if an object is up-to-date + + Simple comparison of different "signature" values. + """ + o111 = my_obj(value = '111') + assert not o111.current(SCons.Sig.MD5.signature('110')) + assert o111.current(SCons.Sig.MD5.signature('111')) + assert not o111.current(SCons.Sig.MD5.signature('112')) + + def test_set(self): + pass # XXX + + def test_invalidate(self): + pass # XXX + + def test_collect(self): + """Test collecting a list of signatures into a new signature value + """ + o1 = my_obj(value = '111') + o2 = my_obj(value = '222') + o3 = my_obj(value = '333') + assert '698d51a19d8a121ce581499d7b701668' == SCons.Sig.MD5.collect(o1) + assert '8980c988edc2c78cc43ccb718c06efd5' == SCons.Sig.MD5.collect(o1, o2) + assert '53fd88c84ff8a285eb6e0a687e55b8c7' == SCons.Sig.MD5.collect(o1, o2, o3) + + def test_signature(self): + pass # XXX + + def test_cmdsig(self): + pass # XXX + + def test_srcsig(self): + pass # XXX + + +if __name__ == "__main__": + suite = unittest.makeSuite(MD5TestCase, 'test_') + if not unittest.TextTestRunner().run(suite).wasSuccessful(): + sys.exit(1) diff --git a/src/engine/SCons/Sig/TimeStamp.py b/src/engine/SCons/Sig/TimeStamp.py new file mode 100644 index 0000000..b821742 --- /dev/null +++ b/src/engine/SCons/Sig/TimeStamp.py @@ -0,0 +1,49 @@ +"""SCons.Sig.TimeStamp + +The TimeStamp signature package for the SCons software construction +utility. + +""" + +__revision__ = "Sig/TimeStamp.py __REVISION__ __DATE__ __DEVELOPER__" + +def _init(): + pass # XXX + +def _end(): + pass # XXX + +def current(obj, sig): + """Return whether the object's timestamp is up-to-date. + """ + return obj.signature() >= sig + +def set(): + pass # XXX + +def invalidate(): + pass # XXX + +def collect(*objects): + """Collect timestamps from a list of objects, returning + the most-recent timestamp from the list. + """ + r = 0 + for obj in objects: + s = obj.signature() + if s > r: + r = s + return r + +def signature(contents): + """Generate a timestamp. + """ + pass # XXX +# return md5.new(contents).hexdigest() # 2.0 + return hexdigest(md5.new(contents).digest()) + +def cmdsig(): + pass # XXX + +def srcsig(): + pass # XXX diff --git a/src/engine/SCons/Sig/TimeStampTests.py b/src/engine/SCons/Sig/TimeStampTests.py new file mode 100644 index 0000000..4cc72e4 --- /dev/null +++ b/src/engine/SCons/Sig/TimeStampTests.py @@ -0,0 +1,74 @@ +__revision__ = "Sig/TimeStampTests.py __REVISION__ __DATE__ __DEVELOPER__" + +import sys +import unittest + +import SCons.Sig.TimeStamp + + + +class my_obj: + """A dummy object class that satisfies the interface + requirements of the TimeStamp class. + """ + + def __init__(self, value = ""): + self.value = value + + def signature(self): + return self.value + + + +class TimeStampTestCase(unittest.TestCase): + + def test__init(self): + pass # XXX + + def test__init(self): + pass # XXX + + def test__end(self): + pass # XXX + + def test_current(self): + """Test deciding if an object is up-to-date + + Simple comparison of different timestamp values. + """ + o1 = my_obj(value = 111) + assert SCons.Sig.TimeStamp.current(o1, 110) + assert SCons.Sig.TimeStamp.current(o1, 111) + assert not SCons.Sig.TimeStamp.current(o1, 112) + + def test_set(self): + pass # XXX + + def test_invalidate(self): + pass # XXX + + def test_collect(self): + """Test collecting a list of signatures into a new signature value + into a new timestamp value. + """ + o1 = my_obj(value = 111) + o2 = my_obj(value = 222) + o3 = my_obj(value = 333) + assert 111 == SCons.Sig.TimeStamp.collect(o1) + assert 222 == SCons.Sig.TimeStamp.collect(o1, o2) + assert 333 == SCons.Sig.TimeStamp.collect(o1, o2, o3) + + def test_signature(self): + pass # XXX + + def test_cmdsig(self): + pass # XXX + + def test_srcsig(self): + pass # XXX + + +if __name__ == "__main__": + suite = unittest.makeSuite(TimeStampTestCase, 'test_') + if not unittest.TextTestRunner().run(suite).wasSuccessful(): + sys.exit(1) diff --git a/src/engine/SCons/Sig/__init__.py b/src/engine/SCons/Sig/__init__.py new file mode 100644 index 0000000..c3b06ed --- /dev/null +++ b/src/engine/SCons/Sig/__init__.py @@ -0,0 +1,7 @@ +"""SCons.Sig + +The Signature package for the SCons software construction utility. + +""" + +__revision__ = "Sig/__init__.py __REVISION__ __DATE__ __DEVELOPER__" |