source: lliurex-store/trunk/fuentes/python3-lliurex-store.install/usr/share/lliurexstore/plugins/

Last change on this file was 8223, checked in by Juanma, 2 years ago

Implemented cache

File size: 3.5 KB
1#The name of the main class must match the file name in lowercase
3#<---- Main scheme for a store plugin
4#Init: Could accept parameters if we declare them in storeManager's threads dict
5class example:
6        def __init__(self):
7                self.dbg=False
8                self.progress=0
9                #This dict defines wich package_type relies on what action
10                #actions could be defined in storeManager or per-plugin
11                #Non contempled actions must declare its related functions on storeManager (threads dict) and define relationships with other actions in relatedActions.
12                #package='*' (in this case action 'example' is related to all package_types. It could be "deb", "zmd" or whatever package type)
13                self.plugin_actions={'example':'*'}
14                #This switch enables cli_mode for the plugin, just in case some function difers from the gui mode (take a look at snapManager)
15                self.cli_mode=False
16                #This one controls if the plugin is enabled or not
17                #It could be activated from two ways:
18                # - storeManager having a parameter with name=package_type (simply add it to the arg list passed when invoking storeManager)
19                # - Internal failure controls (see zmdManager for an example)
20                #If there'll be no parameter for enable/disable then the plugin manages it's own state and self.disabled must be None
21                #This example plugin is disabled by default
22                self.disabled=True
23                #A plugin must declare autostart actions thar must be invoked when storemanager registers the plugin
24                #The dict's key is the action's name and the value is the parameter (or None) needed for launch the action
25                self.autostart_actions={'example':''} #The parameter list refers to 'stringfieds' storeManager members !!
26                #This dict registers actions to be launched after storemanager registered actions.
27                #In this example the action 'install' of the plugin is launched after storemanager does any 'install' action. As in autostart_actions the parameter referes to storemanager members
28                self.postaction_actions={'install':'app','remove':'app'}
29                #If an action requires some parameter to be launched you could declare here.
30                self.requires={'cache':''}
31        #def __init__
33        #public function that sets the debug mode. If we execute storeManager in debug mode all plugins will be launched in this mode if propaate_debug==True
34        def set_debug(self,dbg=True):
35                self.dbg=int(dbg)
36                self.debug ("Debug enabled")
37        #def set_debug
39        def _debug(self,msg=''):
40                if self.dbg:
41                        print ('DEBUG Example: '+msg)
42        #def debug
44        #public function accessed by storemanager in order to register the plugin and its actions
45        def register(self):
46                #This function MUST return the dict with the action:package_type pair
47                return(self.plugin_actions)
49        #storeManager calls this method when launchs an action.
50        def execute_action(self,action,applist):
51                #applist is a list of appinfo elements
52                #This function must return a dict with the dicts 'status' and 'data'
53                #Status stores the returning status, 0=succesful, !0=error
54                #Data stores the resulting data of the operation
55                self.progress=0
56                self.result['status']={'status':-1,'msg':''}
57                self.result['data']=''
58                if self.disabled:
59                        self._set_status(9)
60                else:
61                        for app in applist:
62                                if action=='example':
63                                        datalist.append(self._exec_example(app))
64                        self.result['data']=list(dataList)
65                        self.progress=100 #When all actions are launched we must assure that progress=100.
66                return(self.result)
68        def _callback(self):
69                self.progress=self.progress+1
71#End of needed functions-------->
73# Put your code ----> #
75        def _exec_example(self,app):
76                while (self.progress<100):
77                        self._callback()
78                return(app)
80# <---- #
Note: See TracBrowser for help on using the repository browser.