diff options
Diffstat (limited to 'src/scons/Sig')
-rw-r--r-- | src/scons/Sig/.aeignore | 4 | ||||
-rw-r--r-- | src/scons/Sig/MD5.py | 70 | ||||
-rw-r--r-- | src/scons/Sig/MD5Tests.py | 76 | ||||
-rw-r--r-- | src/scons/Sig/TimeStamp.py | 49 | ||||
-rw-r--r-- | src/scons/Sig/TimeStampTests.py | 73 | ||||
-rw-r--r-- | src/scons/Sig/__init__.py | 7 |
6 files changed, 279 insertions, 0 deletions
diff --git a/src/scons/Sig/.aeignore b/src/scons/Sig/.aeignore new file mode 100644 index 0000000..43fe851 --- /dev/null +++ b/src/scons/Sig/.aeignore @@ -0,0 +1,4 @@ +*,D +*.pyc +.*.swp +.consign diff --git a/src/scons/Sig/MD5.py b/src/scons/Sig/MD5.py new file mode 100644 index 0000000..36e4230 --- /dev/null +++ b/src/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/scons/Sig/MD5Tests.py b/src/scons/Sig/MD5Tests.py new file mode 100644 index 0000000..ac43f1b --- /dev/null +++ b/src/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 the ability to decide if an object is up-to-date + with 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 the ability to collect a sequence of object 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/scons/Sig/TimeStamp.py b/src/scons/Sig/TimeStamp.py new file mode 100644 index 0000000..cab44bf --- /dev/null +++ b/src/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/scons/Sig/TimeStampTests.py b/src/scons/Sig/TimeStampTests.py new file mode 100644 index 0000000..aa61af8 --- /dev/null +++ b/src/scons/Sig/TimeStampTests.py @@ -0,0 +1,73 @@ +__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 the ability to decide if an object is up-to-date + with 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 the ability to collect a sequence of object timestamps + 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/scons/Sig/__init__.py b/src/scons/Sig/__init__.py new file mode 100644 index 0000000..411a94b --- /dev/null +++ b/src/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__" |