summaryrefslogtreecommitdiff
path: root/lib/python/Plugins/newplugin.py
blob: 32c7269d734dd5bd28ce9db228781a967c5f55b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/python

import os

os.system("clear")
internalname = raw_input("Internal plugin name (no whitespaces, plugin directory): ")
name = raw_input("Visible plugin name: ")
print

os.system("clear")
dirlist = []
count = 0
print "Plugin categories:"
for dir in os.listdir("."):
	if os.path.isdir(dir):
		count += 1
		dirlist.append(dir)
		print count, dir
		
category = raw_input("Select plugin category: ")
category = dirlist[int(category) - 1]

def add_where_extensionsmenu(name, fnc):
	description = raw_input("Plugin description: ")
	return 'PluginDescriptor(name = "%s", description = _("%s"), where = PluginDescriptor.WHERE_EXTENSIONSMENU, fnc = %s)' % (name, description, fnc) 

def add_where_pluginmenu(name, fnc):
	description = raw_input("Plugin description: ")
	icon = raw_input("Icon (default: 'plugin.png': ")
	if icon == "":
		icon = "plugin.png"
	return 'PluginDescriptor(name = "%s", description = _("%s"), icon = "%s", where = PluginDescriptor.WHERE_PLUGINMENU, fnc = %s)' % (name, description, icon, fnc) 

wherelist = []
wherelist.append(("WHERE_EXTENSIONSMENU", add_where_extensionsmenu))
wherelist.append(("WHERE_PLUGINMENU", add_where_pluginmenu))

targetlist = []

stop = False

while not stop:
	os.system("clear")
	print "selected targets:"
	for where in targetlist:
		print where[0]
	
	print
	print "available targets:"
	count = 0
	for where in wherelist:
		count += 1
		print count, where[0]
	print "x break"
		
	target = raw_input("Select WHERE-target: ")
	if target == "x":
		stop = True
	else:
		if wherelist[int(target) - 1] not in targetlist:
			targetlist.append(wherelist[int(target) - 1])
		else:
			targetlist.remove(wherelist[int(target) - 1])


pluginpath = category + "/" +  internalname
os.mkdir(pluginpath)

makefile = open(category + "/Makefile.am", "r")
lines = makefile.readlines()
lines = ''.join(lines)
lines = lines.strip()
lines += " " + internalname
makefile.close()

makefile = open(category + "/Makefile.am", "w")
makefile.write(lines)
makefile.close()

lines = []
print "open"
configure = open("../../../configure.ac", "r")
while True:
	line = configure.readline()
	if not line:
		break
	lines.append(line)
	if line.strip() == "lib/python/Plugins/" + category + "/Makefile":
		lines.append("lib/python/Plugins/" + pluginpath + "/Makefile\n")
configure.close()
print "close"

configure = open("../../../configure.ac", "w")
configure.writelines(lines)
configure.close()

file = open(pluginpath + "/plugin.py", "w")

importlist = []
for where in targetlist:
	importlist.append(where[0])

file.write("""from Screens.Screen import Screen
from Plugins.Plugin import PluginDescriptor
""")

mainlist = []
for count in range(len(targetlist)):
	if count == 0:
		mainlist.append("main")
	else:
		mainlist.append("main" + str(count))

for main in mainlist:
	file.write("""
def %s(session, **kwargs):
	pass
""" % main)

descriptorlist = []
for count in range(len(targetlist)):
	os.system("clear")
	where = targetlist[count]
	print "Options for target %s" % where[0]
	descriptorlist.append(where[1](name, mainlist[count]))
	
if len(descriptorlist) == 1:
	descriptorlist = descriptorlist[0]
else:
	descriptorlist = "[" + ', '.join(descriptorlist) + "]"

file.write("""
def Plugins(**kwargs):
	return %s
	""" % descriptorlist)

file.close()

makefile = open(pluginpath + "/Makefile.am", "w")
makefile.write("""installdir = $(pkglibdir)/python/Plugins/%s/%s

install_PYTHON = \\
	__init__.py \\
	plugin.py
""" % (category, internalname))
makefile.close()