Package web :: Package pluginmanager :: Package plugins :: Module dependency
[hide private]
[frames] | no frames]

Source Code for Module web.pluginmanager.plugins.dependency

  1  import web 
  2   
3 -class Dependency:
4 ''' 5 This class relates a plugin with a version of another. When a plugin 6 has a dependency means this plugin NEEDS the specified version of 7 the plugin to work. If dependency not unmet the plugin can't be 8 installed. 9 ''' 10
11 - def __init__(self, dependon, relation, major, minor, release):
12 self.dependon = dependon 13 self.version = Version(major, minor, release) 14 self.relation = relation
15
16 - def __str__(self):
17 return "%s (%s%s)" % (self.dependon, self.relation, 18 self.version)
19
20 - def is_met_by(self, plugin):
21 ''' 22 Returns if the given plugin mets with the requierement of 23 the dependency. 24 ''' 25 if not plugin: 26 return False 27 28 if self.dependon != plugin.name: 29 return False 30 31 if self.relation == ">=": 32 return self.version >= plugin.version 33 elif self.relation == ">": 34 return self.version > plugin.version 35 elif self.relation == "=": 36 return self.version == plugin.version 37 elif self.relation == "<=": 38 return self.version <= plugin.version 39 elif self.relation == "<": 40 return self.version < plugin.version 41 return False
42
43 - def is_met(self):
44 ''' 45 Return whether there is a plugin that mets with the requirement of the 46 dependency. It will NOT check if the plugin is installed or enabled, 47 it will only check if the plugin has valid version. 48 ''' 49 plugin = web.ctx.plugin_manager.get_plugin_by_name(self.dependon) 50 51 return self.is_met_by(self, plugin)
52
53 - def get_plugin(self):
54 ''' 55 If is_met() returns true, this returns the instance of the plugin. 56 ''' 57 if self.is_met(): 58 return web.ctx.plugin_manager.get_plugin_by_name(self.dependon) 59 return None
60
61 -class Version:
62 ''' 63 This class represents the version of a plugin. 64 It has three numbers (ordered by importance): the major, the minor 65 and the release. 66 When two plugins have versions with the same major and minor numbers means 67 they have the same functions with the same arguments. More bugs have 68 been fixed in the plugin with the highest release number. 69 When the plugins have different minor number, plugin with highest 70 minor number works just like the other, but new features may 71 have been added. 72 '''
73 - def __init__(self, major, minor, release):
74 self.major = int(major) 75 self.minor = int(minor) 76 self.release = int(release)
77
78 - def __cmp__(self, other):
79 if self.major > other.major: 80 return 1 81 elif self.major < other.major: 82 return -1 83 if self.minor > other.minor: 84 return 1 85 elif self.minor < other.minor: 86 return -1 87 if self.release > other.release: 88 return 1 89 elif self.release < other.release: 90 return -1 91 92 return 0
93
94 - def __str__(self):
95 return u"%d.%d.%d" % (self.major, self.minor, self.release)
96
97 -class UnmetDependencyException(Exception):
98 - def __init__(self, dep):
99 self.dep = dep
100
101 - def __str__(self):
102 return "Unmet Dependency: " + self.dep.__str__()
103