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 |
---|
5 | class example: |
---|
6 | def __init__(self): |
---|
7 | self.dbg=0 |
---|
8 | self.progress=0 |
---|
9 | #This dict defines wich package_type relies on what action |
---|
10 | #actions are defined in storeManager. |
---|
11 | #Non contempled actions must declare its related functions on storeManager (threads dict) and define relationships with other actions in relatedActions. |
---|
12 | #action=example |
---|
13 | #package='*' (in this case all package_types. It could be "deb", "zmd" or whatever package type) |
---|
14 | self.pluginInfo={'example':'*'} |
---|
15 | #def __init__ |
---|
16 | |
---|
17 | #public function that sets the debug mode. If we execute storeManager in debug mode all plugins will be launched in this mode. |
---|
18 | def set_debug(self,dbg='1'): |
---|
19 | self.dbg=int(dbg) |
---|
20 | self.debug ("Debug enabled") |
---|
21 | #def set_debug |
---|
22 | |
---|
23 | def _debug(self,msg=''): |
---|
24 | if self.dbg==1: |
---|
25 | print ('DEBUG Example: '+msg) |
---|
26 | #def debug |
---|
27 | |
---|
28 | #public function accessed by sotremanager in order to register the plugin and its actions |
---|
29 | def register(self): |
---|
30 | #This function MUST return the dict with the action:package_type pair |
---|
31 | #In this example it returns nothing |
---|
32 | self.pluginInfo={} |
---|
33 | return(self.pluginInfo) |
---|
34 | |
---|
35 | #storeManager calls this method when launchs an action. |
---|
36 | def execute_action(self,action,applist): |
---|
37 | #applist is a list of appinfo elements |
---|
38 | #This function must return a dict with the dicts 'status' and 'data' |
---|
39 | #Status stores the returning status, 0=succesful, !0=error |
---|
40 | #Data stores the resulting data of the operation |
---|
41 | self.progress=0 |
---|
42 | self.result['status']={'status':-1,'msg':''} |
---|
43 | self.result['data']='' |
---|
44 | for app in applist: |
---|
45 | if action=='example': |
---|
46 | datalist.append(self._exec_example(app)) |
---|
47 | self.result['data']=list(dataList) |
---|
48 | self.progress=100 #When all actions are launched we must assure that progress=100. |
---|
49 | return(self.result) |
---|
50 | |
---|
51 | def _callback(self): |
---|
52 | self.progress=self.progress+1 |
---|
53 | |
---|
54 | #End of needed functions--------> |
---|
55 | |
---|
56 | # Put your code ----> # |
---|
57 | |
---|
58 | def _exec_example(self,app): |
---|
59 | while (self.progress<100): |
---|
60 | self._callback() |
---|
61 | return(app) |
---|
62 | |
---|
63 | # <---- # |
---|