Merge remote-tracking branch 'oe_21/master' into vuplus-3.0-next
[vuplus_openvuplus_3.0] / meta-openvuplus / recipes-vuplus / enigma2 / enigma2 / enigma2_vuplus_pluginbrowser.patch
1 diff --git a/lib/python/Screens/PluginBrowser.py b/lib/python/Screens/PluginBrowser.py
2 index d423f46..0a029ed 100755
3 --- a/lib/python/Screens/PluginBrowser.py
4 +++ b/lib/python/Screens/PluginBrowser.py
5 @@ -14,6 +14,9 @@ from Tools.LoadPixmap import LoadPixmap
6  
7  from time import time
8  
9 +import os
10 +import glob
11 +
12  def languageChanged():
13         plugins.clearPluginList()
14         plugins.readPluginList(resolveFilename(SCOPE_PLUGINS))
15 @@ -179,7 +182,8 @@ class PluginDownloadBrowser(Screen):
16                                 self.container.execute("opkg update")
17                                 PluginDownloadBrowser.lastDownloadDate = time()
18                         else:
19 -                               self.startIpkgListAvailable()
20 +                               self.run = 1
21 +                               self.startIpkgListInstalled()
22                 elif self.type == self.REMOVE:
23                         self.run = 1
24                         self.startIpkgListInstalled()
25 @@ -198,7 +202,16 @@ class PluginDownloadBrowser(Screen):
26                                 self.startIpkgListInstalled()
27                 elif self.run == 1 and self.type == self.DOWNLOAD:
28                         self.run = 2
29 -                       self.startIpkgListAvailable()
30 +                       for x in self.getPluginListAvailable():
31 +                               if x[0] not in self.installedplugins:
32 +                                       self.pluginlist.append(x)
33 +
34 +                       if self.pluginlist:
35 +                               self.pluginlist.sort()
36 +                               self.updateList()
37 +                               self["list"].instance.show()
38 +                       else:
39 +                               self["text"].setText(_("No new plugins found"))
40                 else:
41                         if len(self.pluginlist) > 0:
42                                 self.updateList()
43 @@ -220,17 +233,18 @@ class PluginDownloadBrowser(Screen):
44                         self.remainingdata = ""
45  
46                 for x in lines:
47 -                       plugin = x.split(" - ")
48 +                       plugin = x.split(" - ", 2)
49                         if len(plugin) >= 2:
50 -                               if self.run == 1 and self.type == self.DOWNLOAD:
51 +                               if plugin[0].startswith('enigma2-plugin-') and not plugin[0].endswith('-dev') and not plugin[0].endswith('-staticdev') and not plugin[0].endswith('-dbg') and not plugin[0].endswith('-doc') and not plugin[0].endswith('-src'):
52                                         if plugin[0] not in self.installedplugins:
53 -                                               self.installedplugins.append(plugin[0])
54 -                               else:
55 -                                       if plugin[0] not in self.installedplugins:
56 -                                               plugin.append(plugin[0][15:])
57 +                                               if self.run == 1 and self.type == self.DOWNLOAD:
58 +                                                       self.installedplugins.append(plugin[0])
59 +                                               else:
60 +                                                       if len(plugin) == 2:
61 +                                                               plugin.append('')
62 +                                                       plugin.append(plugin[0][15:])
63 +                                                       self.pluginlist.append(plugin)
64  
65 -                                               self.pluginlist.append(plugin)
66 -       
67         def updateList(self):
68                 list = []
69                 expandableIcon = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/expandable-plugins.png"))
70 @@ -239,13 +253,6 @@ class PluginDownloadBrowser(Screen):
71                 
72                 self.plugins = {}
73                 for x in self.pluginlist:
74 -                       if len(x) < 4:
75 -                               split = x[0].split('-',3)
76 -                               if not self.plugins.has_key(split[2]):
77 -                                       self.plugins[split[2]] = []
78 -                               self.plugins[split[2]].append((PluginDescriptor(name = x[2], description = " ", icon = verticallineIcon), split[3]))
79 -                               continue
80 -
81                         split = x[3].split('-', 1)
82                         if len(split) < 2:
83                                 continue
84 @@ -263,4 +270,56 @@ class PluginDownloadBrowser(Screen):
85                 self.list = list
86                 self["list"].l.setList(list)
87  
88 +       def getPluginListAvailable(self):
89 +                       plugin_list = []
90 +                       # get feed names
91 +                       feeds = []
92 +                       for fn in glob.glob("/etc/opkg/*-feed.conf"):
93 +                               feeds.append(open(fn, 'r').read().split()[1])
94 +
95 +                       #get list_dir
96 +                       list_dir = "/var/lib/opkg"
97 +                       for line in open("/etc/opkg/opkg.conf", 'r'):
98 +                               if line.startswith('lists_dir'):
99 +                                       list_dir = line.split()[-1]
100 +
101 +                       for feed in feeds:
102 +                               Package = None
103 +                               for line in open(os.path.join(list_dir, feed), 'r'):
104 +                                       if line.startswith("Package:"):
105 +                                               pkg = line.split(":", 1)[1].strip()
106 +                                               if pkg.startswith('enigma2-plugin-') and not pkg.endswith('-dev') and not pkg.endswith('-staticdev') and not pkg.endswith('-dbg') and not pkg.endswith('-doc') and not pkg.endswith('-src'):
107 +                                                       Package = pkg
108 +                                                       Version = ''
109 +                                                       Description = ''
110 +                                               continue
111 +
112 +                                       if Package is None:
113 +                                               continue
114 +
115 +                                       if line.startswith("Version:"):
116 +                                               Version = line.split(":", 1)[1].strip()
117 +
118 +                                       elif line.startswith("Description:"):
119 +                                               Description = line.split(":", 1)[1].strip()
120 +
121 +                                       elif Description and line.startswith(' '):
122 +                                               Description += line[:-1]
123 +
124 +                                       elif len(line) <= 1:
125 +                                               sp = Description.split(' ', 3)
126 +                                               if sp[1] == "version":
127 +                                                       Description = sp[3].strip()
128 +
129 +                                               pn = Package.split('enigma2-plugin-')[1]
130 +
131 +                                               sp = Description.split(' ', 1)
132 +                                               if sp[0] == pn and len(sp[1]) > 0:
133 +                                                       Description = sp[1].strip()
134 +
135 +                                               plugin_list.append((Package, Version, Description, pn))
136 +                                               Package = None
137 +
138 +                       return plugin_list
139 +
140  language.addCallback(languageChanged)