source: lliurex-store/trunk/fuentes/python3-lliurex-store.install/usr/share/lliurexstore/plugins/example.py @ 7432

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

fix wrong update

File size: 2.8 KB
Line 
1#The name of the main class must match the file name in lowercase
2
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        #def __init__
24       
25        #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
26        def set_debug(self,dbg=True):
27                self.dbg=int(dbg)
28                self.debug ("Debug enabled")
29        #def set_debug
30
31        def _debug(self,msg=''):
32                if self.dbg:
33                        print ('DEBUG Example: '+msg)
34        #def debug
35
36        #public function accessed by storemanager in order to register the plugin and its actions
37        def register(self):
38                #This function MUST return the dict with the action:package_type pair
39                return(self.plugin_actions)
40
41        #storeManager calls this method when launchs an action.
42        def execute_action(self,action,applist):
43                #applist is a list of appinfo elements
44                #This function must return a dict with the dicts 'status' and 'data'
45                #Status stores the returning status, 0=succesful, !0=error
46                #Data stores the resulting data of the operation
47                self.progress=0
48                self.result['status']={'status':-1,'msg':''}
49                self.result['data']=''
50                if self.disabled:
51                        self._set_status(9)
52                else:
53                        for app in applist:
54                                if action=='example':
55                                        datalist.append(self._exec_example(app))
56                        self.result['data']=list(dataList)
57                        self.progress=100 #When all actions are launched we must assure that progress=100.
58                return(self.result)
59
60        def _callback(self):
61                self.progress=self.progress+1
62
63#End of needed functions-------->
64
65# Put your code ----> #
66
67        def _exec_example(self,app):
68                while (self.progress<100):
69                        self._callback()
70                return(app)
71
72# <---- #
Note: See TracBrowser for help on using the repository browser.