Annotation of /trunk/indra/lib/python/indra/ipc/compatibility.py
Parent Directory
|
Revision Log
Revision 61 -
(view)
(download)
(as text)
Original Path: trunk/linden/indra/lib/python/indra/ipc/compatibility.py
| 1 : | mjm | 57 | """\ |
| 2 : | @file compatibility.py | ||
| 3 : | @brief Classes that manage compatibility states. | ||
| 4 : | |||
| 5 : | $LicenseInfo:firstyear=2007&license=mit$ | ||
| 6 : | |||
| 7 : | Copyright (c) 2007-2008, Linden Research, Inc. | ||
| 8 : | |||
| 9 : | Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| 10 : | of this software and associated documentation files (the "Software"), to deal | ||
| 11 : | in the Software without restriction, including without limitation the rights | ||
| 12 : | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| 13 : | copies of the Software, and to permit persons to whom the Software is | ||
| 14 : | furnished to do so, subject to the following conditions: | ||
| 15 : | |||
| 16 : | The above copyright notice and this permission notice shall be included in | ||
| 17 : | all copies or substantial portions of the Software. | ||
| 18 : | |||
| 19 : | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 20 : | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| 21 : | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| 22 : | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| 23 : | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| 24 : | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| 25 : | THE SOFTWARE. | ||
| 26 : | $/LicenseInfo$ | ||
| 27 : | """ | ||
| 28 : | |||
| 29 : | |||
| 30 : | """Compatibility combination table: | ||
| 31 : | |||
| 32 : | I M O N S | ||
| 33 : | -- -- -- -- -- | ||
| 34 : | I: I I I I I | ||
| 35 : | M: I M M M M | ||
| 36 : | O: I M O M O | ||
| 37 : | N: I M M N N | ||
| 38 : | S: I M O N S | ||
| 39 : | |||
| 40 : | """ | ||
| 41 : | |||
| 42 : | class _Compatibility(object): | ||
| 43 : | def __init__(self, reason): | ||
| 44 : | self.reasons = [ ] | ||
| 45 : | if reason: | ||
| 46 : | self.reasons.append(reason) | ||
| 47 : | |||
| 48 : | def combine(self, other): | ||
| 49 : | if self._level() <= other._level(): | ||
| 50 : | return self._buildclone(other) | ||
| 51 : | else: | ||
| 52 : | return other._buildclone(self) | ||
| 53 : | |||
| 54 : | def prefix(self, leadin): | ||
| 55 : | self.reasons = [ leadin + r for r in self.reasons ] | ||
| 56 : | |||
| 57 : | def same(self): return self._level() >= 1 | ||
| 58 : | def deployable(self): return self._level() > 0 | ||
| 59 : | def resolved(self): return self._level() > -1 | ||
| 60 : | def compatible(self): return self._level() > -2 | ||
| 61 : | |||
| 62 : | def explain(self): | ||
| 63 : | return self.__class__.__name__ + "\n" + "\n".join(self.reasons) + "\n" | ||
| 64 : | |||
| 65 : | def _buildclone(self, other=None): | ||
| 66 : | c = self._buildinstance() | ||
| 67 : | c.reasons = self.reasons | ||
| 68 : | if other: | ||
| 69 : | c.reasons = c.reasons + other.reasons | ||
| 70 : | return c | ||
| 71 : | |||
| 72 : | def _buildinstance(self): | ||
| 73 : | return self.__class__(None) | ||
| 74 : | |||
| 75 : | # def _level(self): | ||
| 76 : | # raise RuntimeError('implement in subclass') | ||
| 77 : | |||
| 78 : | |||
| 79 : | class Incompatible(_Compatibility): | ||
| 80 : | def _level(self): | ||
| 81 : | return -2 | ||
| 82 : | |||
| 83 : | class Mixed(_Compatibility): | ||
| 84 : | def __init__(self, *inputs): | ||
| 85 : | _Compatibility.__init__(self, None) | ||
| 86 : | for i in inputs: | ||
| 87 : | self.reasons += i.reasons | ||
| 88 : | |||
| 89 : | def _buildinstance(self): | ||
| 90 : | return self.__class__() | ||
| 91 : | |||
| 92 : | def _level(self): | ||
| 93 : | return -1 | ||
| 94 : | |||
| 95 : | class _Aged(_Compatibility): | ||
| 96 : | def combine(self, other): | ||
| 97 : | if self._level() == other._level(): | ||
| 98 : | return self._buildclone(other) | ||
| 99 : | if int(self._level()) == int(other._level()): | ||
| 100 : | return Mixed(self, other) | ||
| 101 : | return _Compatibility.combine(self, other) | ||
| 102 : | |||
| 103 : | class Older(_Aged): | ||
| 104 : | def _level(self): | ||
| 105 : | return -0.25 | ||
| 106 : | |||
| 107 : | class Newer(_Aged): | ||
| 108 : | def _level(self): | ||
| 109 : | return 0.25 | ||
| 110 : | |||
| 111 : | class Same(_Compatibility): | ||
| 112 : | def __init__(self): | ||
| 113 : | _Compatibility.__init__(self, None) | ||
| 114 : | |||
| 115 : | def _buildinstance(self): | ||
| 116 : | return self.__class__() | ||
| 117 : | |||
| 118 : | def _level(self): | ||
| 119 : | return 1 | ||
| 120 : | |||
| 121 : | |||
| 122 : | |||
| 123 : |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |

