Plugin creator script
[vuplus_dvbapp] / lib / python / Plugins / newplugin.py
1 #!/usr/bin/python
2
3 import os
4
5 name = raw_input("Plugin name: ")
6
7 print
8
9 dirlist = []
10 count = 0
11 print "Plugin categories:"
12 for dir in os.listdir("."):
13         if os.path.isdir(dir):
14                 count += 1
15                 dirlist.append(dir)
16                 print count, dir
17                 
18 category = raw_input("Select plugin category: ")
19 category = dirlist[int(category) - 1]
20
21 def add_where_extensionsmenu(name, fnc):
22         description = raw_input("Plugin description: ")
23         return 'PluginDescriptor(name = "%s", description = _("%s"), where = PluginDescriptor.WHERE_EXTENSIONSMENU, fnc = %s)' % (name, description, fnc) 
24
25 def add_where_pluginmenu(name, fnc):
26         description = raw_input("Plugin description: ")
27         icon = raw_input("Icon (default: 'plugin.png': ")
28         if icon == "":
29                 icon = "plugin.png"
30         return 'PluginDescriptor(name = "%s", description = _("%s"), icon = "%s", where = PluginDescriptor.WHERE_PLUGINMENU, fnc = %s)' % (name, description, icon, fnc) 
31
32 wherelist = []
33 wherelist.append(("WHERE_EXTENSIONSMENU", add_where_extensionsmenu))
34 wherelist.append(("WHERE_PLUGINMENU", add_where_extensionsmenu))
35
36 targetlist = []
37
38 stop = False
39
40 while not stop:
41         os.system("clear")
42         print "selected targets:"
43         for where in targetlist:
44                 print where[0]
45         
46         print
47         print "available targets:"
48         count = 0
49         for where in wherelist:
50                 count += 1
51                 print count, where[0]
52         print "x break"
53                 
54         target = raw_input("Select WHERE-target: ")
55         if target == "x":
56                 stop = True
57         else:
58                 if wherelist[int(target) - 1] not in targetlist:
59                         targetlist.append(wherelist[int(target) - 1])
60                 else:
61                         targetlist.remove(wherelist[int(target) - 1])
62
63
64 file = open("plugin.py", "w")
65
66 importlist = []
67 for where in targetlist:
68         importlist.append(where[0])
69
70 file.write("""from Screens.Screen import Screen
71 from Plugins.Plugin import PluginDescriptor, %s
72 """ % ', '.join(importlist))
73
74 mainlist = []
75 for count in range(len(targetlist)):
76         if count == 0:
77                 mainlist.append("main")
78         else:
79                 mainlist.append("main" + str(count))
80
81 for main in mainlist:
82         file.write("""
83 def %s(session, **kwargs):
84         pass
85 """ % main)
86
87 descriptorlist = []
88 for count in range(len(targetlist)):
89         os.system("clear")
90         where = targetlist[count]
91         print "Options for target %s" % where[0]
92         descriptorlist.append(where[1](name, mainlist[count]))
93         
94 if len(descriptorlist) == 1:
95         descriptorlist = descriptorlist[0]
96 else:
97         descriptorlist = "[" + ', '.join(descriptorlist) + "]"
98
99 file.write("""
100 def Plugins(**kwargs):
101         return %s
102         """ % descriptorlist)
103
104 file.close()