Merge remote branch 'origin/bug_135_dvdburn_ts_only'
[enigma2.git] / lib / python / Plugins / newplugin.py
1 #!/usr/bin/python
2
3 import os
4
5 os.system("clear")
6 internalname = raw_input("Internal plugin name (no whitespaces, plugin directory): ")
7 name = raw_input("Visible plugin name: ")
8 print
9
10 os.system("clear")
11 dirlist = []
12 count = 0
13 print "Plugin categories:"
14 for dir in os.listdir("."):
15         if os.path.isdir(dir):
16                 count += 1
17                 dirlist.append(dir)
18                 print count, dir
19                 
20 category = raw_input("Select plugin category: ")
21 category = dirlist[int(category) - 1]
22
23 def add_where_extensionsmenu(name, fnc):
24         description = raw_input("Plugin description: ")
25         return 'PluginDescriptor(name = "%s", description = _("%s"), where = PluginDescriptor.WHERE_EXTENSIONSMENU, fnc = %s)' % (name, description, fnc) 
26
27 def add_where_pluginmenu(name, fnc):
28         description = raw_input("Plugin description: ")
29         icon = raw_input("Icon (default: 'plugin.png': ")
30         if icon == "":
31                 icon = "plugin.png"
32         return 'PluginDescriptor(name = "%s", description = _("%s"), icon = "%s", where = PluginDescriptor.WHERE_PLUGINMENU, fnc = %s)' % (name, description, icon, fnc) 
33
34 wherelist = []
35 wherelist.append(("WHERE_EXTENSIONSMENU", add_where_extensionsmenu))
36 wherelist.append(("WHERE_PLUGINMENU", add_where_pluginmenu))
37
38 targetlist = []
39
40 stop = False
41
42 while not stop:
43         os.system("clear")
44         print "selected targets:"
45         for where in targetlist:
46                 print where[0]
47         
48         print
49         print "available targets:"
50         count = 0
51         for where in wherelist:
52                 count += 1
53                 print count, where[0]
54         print "x break"
55                 
56         target = raw_input("Select WHERE-target: ")
57         if target == "x":
58                 stop = True
59         else:
60                 if wherelist[int(target) - 1] not in targetlist:
61                         targetlist.append(wherelist[int(target) - 1])
62                 else:
63                         targetlist.remove(wherelist[int(target) - 1])
64
65
66 pluginpath = category + "/" +  internalname
67 os.mkdir(pluginpath)
68
69 makefile = open(category + "/Makefile.am", "r")
70 lines = makefile.readlines()
71 lines = ''.join(lines)
72 lines = lines.strip()
73 lines += " " + internalname
74 makefile.close()
75
76 makefile = open(category + "/Makefile.am", "w")
77 makefile.write(lines)
78 makefile.close()
79
80 lines = []
81 print "open"
82 configure = open("../../../configure.ac", "r")
83 while True:
84         line = configure.readline()
85         if not line:
86                 break
87         lines.append(line)
88         if line.strip() == "lib/python/Plugins/" + category + "/Makefile":
89                 lines.append("lib/python/Plugins/" + pluginpath + "/Makefile\n")
90 configure.close()
91 print "close"
92
93 configure = open("../../../configure.ac", "w")
94 configure.writelines(lines)
95 configure.close()
96
97 file = open(pluginpath + "/plugin.py", "w")
98
99 importlist = []
100 for where in targetlist:
101         importlist.append(where[0])
102
103 file.write("""from Screens.Screen import Screen
104 from Plugins.Plugin import PluginDescriptor
105 """)
106
107 mainlist = []
108 for count in range(len(targetlist)):
109         if count == 0:
110                 mainlist.append("main")
111         else:
112                 mainlist.append("main" + str(count))
113
114 for main in mainlist:
115         file.write("""
116 def %s(session, **kwargs):
117         pass
118 """ % main)
119
120 descriptorlist = []
121 for count in range(len(targetlist)):
122         os.system("clear")
123         where = targetlist[count]
124         print "Options for target %s" % where[0]
125         descriptorlist.append(where[1](name, mainlist[count]))
126         
127 if len(descriptorlist) == 1:
128         descriptorlist = descriptorlist[0]
129 else:
130         descriptorlist = "[" + ', '.join(descriptorlist) + "]"
131
132 file.write("""
133 def Plugins(**kwargs):
134         return %s
135         """ % descriptorlist)
136
137 file.close()
138
139 makefile = open(pluginpath + "/Makefile.am", "w")
140 makefile.write("""installdir = $(LIBDIR)/enigma2/python/Plugins/%s/%s
141
142 install_PYTHON = \\
143         __init__.py \\
144         plugin.py
145 """ % (category, internalname))
146 makefile.close()