/usr/lib/python2.7/dist-packages/yapsy/PluginInfo.py is in python-yapsy 1.10.423-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | #!/usr/bin/python
# -*- coding: utf-8; tab-width: 4; indent-tabs-mode: t; python-indent: 4 -*-
"""
Role
====
Encapsulate a plugin instance as well as some metadata.
API
===
"""
from ConfigParser import ConfigParser
from distutils.version import StrictVersion
class PluginInfo(object):
"""Representation of the most basic set of information related to a
given plugin such as its name, author, description...
Any additional information can be stored ad retrieved in a
PluginInfo, when this one is created with a
``ConfigParser.ConfigParser`` instance.
This typically means that when metadata is read from a text file
(the original way for yapsy to describe plugins), all info that is
not part of the basic variables (name, path, version etc), can
still be accessed though the ``details`` member variables that
behaves like Python's ``ConfigParser.ConfigParser``.
Warning: the instance associated with the ``details`` member
variable is never copied and used to store all plugin infos. If
you set it to a custom instance, it will be modified as soon as
another member variale of the plugin info is
changed. Alternatively, if you change the instance "outside" the
plugin info, it will also change the plugin info.
"""
def __init__(self, plugin_name, plugin_path):
"""
Set the basic information (at least name and path) about the
plugin as well as the default values for other usefull
variables.
*plugin_name* is a simple string describing the name of
the plugin.
*plugin_path* describe the location where the plugin can be
found.
.. warning:: The ``path`` attribute is the full path to the
plugin if it is organised as a directory or the
full path to a file without the ``.py`` extension
if the plugin is defined by a simple file. In the
later case, the actual plugin is reached via
``plugin_info.path+'.py'``.
"""
self.__details = ConfigParser()
self.name = plugin_name
self.path = plugin_path
self._ensureDetailsDefaultsAreBackwardCompatible()
# Storage for stuff created during the plugin lifetime
self.plugin_object = None
self.categories = []
self.error = None
def __setDetails(self,cfDetails):
"""
Fill in all details by storing a ``ConfigParser`` instance.
.. warning: The values for ``plugin_name`` and
``plugin_path`` given a init time will superseed
any value found in ``cfDetails`` in section
'Core' for the options 'Name' and 'Module' (this
is mostly for backward compatibility).
"""
bkp_name = self.name
bkp_path = self.path
self.__details = cfDetails
self.name = bkp_name
self.path = bkp_path
self._ensureDetailsDefaultsAreBackwardCompatible()
def __getDetails(self):
return self.__details
def __getName(self):
return self.details.get("Core","Name")
def __setName(self, name):
if not self.details.has_section("Core"):
self.details.add_section("Core")
self.details.set("Core","Name",name)
def __getPath(self):
return self.details.get("Core","Module")
def __setPath(self,path):
if not self.details.has_section("Core"):
self.details.add_section("Core")
self.details.set("Core","Module",path)
def __getVersion(self):
return StrictVersion(self.details.get("Documentation","Version"))
def setVersion(self, vstring):
"""
Set the version of the plugin.
Used by subclasses to provide different handling of the
version number.
"""
if isinstance(vstring,StrictVersion):
vstring = str(vstring)
if not self.details.has_section("Documentation"):
self.details.add_section("Documentation")
self.details.set("Documentation","Version",vstring)
def __getAuthor(self):
return self.details.get("Documentation","Author")
def __setAuthor(self,author):
if not self.details.has_section("Documentation"):
self.details.add_section("Documentation")
self.details.set("Documentation","Author",author)
def __getCopyright(self):
return self.details.get("Documentation","Copyright")
def __setCopyright(self,copyrightTxt):
if not self.details.has_section("Documentation"):
self.details.add_section("Documentation")
self.details.set("Documentation","Copyright",copyrightTxt)
def __getWebsite(self):
return self.details.get("Documentation","Website")
def __setWebsite(self,website):
if not self.details.has_section("Documentation"):
self.details.add_section("Documentation")
self.details.set("Documentation","Website",website)
def __getDescription(self):
return self.details.get("Documentation","Description")
def __setDescription(self,description):
if not self.details.has_section("Documentation"):
self.details.add_section("Documentation")
return self.details.set("Documentation","Description",description)
def __getCategory(self):
"""
DEPRECATED (>1.9): Mimic former behaviour when what is
noz the first category was considered as the only one the
plugin belonged to.
"""
if self.categories:
return self.categories[0]
else:
return "UnknownCategory"
def __setCategory(self,c):
"""
DEPRECATED (>1.9): Mimic former behaviour by making so
that if a category is set as it it was the only category to
which the plugin belongs, then a __getCategory will return
this newly set category.
"""
self.categories = [c] + self.categories
name = property(fget=__getName,fset=__setName)
path = property(fget=__getPath,fset=__setPath)
version = property(fget=__getVersion,fset=setVersion)
author = property(fget=__getAuthor,fset=__setAuthor)
copyright = property(fget=__getCopyright,fset=__setCopyright)
website = property(fget=__getWebsite,fset=__setWebsite)
description = property(fget=__getDescription,fset=__setDescription)
details = property(fget=__getDetails,fset=__setDetails)
# deprecated (>1.9): plugins are not longer associated to a
# single category !
category = property(fget=__getCategory,fset=__setCategory)
def _getIsActivated(self):
"""
Return the activated state of the plugin object.
Makes it possible to define a property.
"""
return self.plugin_object.is_activated
is_activated = property(fget=_getIsActivated)
def _ensureDetailsDefaultsAreBackwardCompatible(self):
"""
Internal helper function.
"""
if not self.details.has_option("Documentation","Author"):
self.author = "Unknown"
if not self.details.has_option("Documentation","Version"):
self.version = "0.0"
if not self.details.has_option("Documentation","Website"):
self.website = "None"
if not self.details.has_option("Documentation","Copyright"):
self.copyright = "Unknown"
if not self.details.has_option("Documentation","Description"):
self.description = ""
|