1 import web
2
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
17 return "%s (%s%s)" % (self.dependon, self.relation,
18 self.version)
19
42
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
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
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
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
95 return u"%d.%d.%d" % (self.major, self.minor, self.release)
96
100
102 return "Unmet Dependency: " + self.dep.__str__()
103