Skip to content

Commit 9bc5b41

Browse files
committed
v1.0.0
1 parent f5ce854 commit 9bc5b41

File tree

8 files changed

+222
-39
lines changed

8 files changed

+222
-39
lines changed

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,30 @@
22

33
Kodi addon to execute shell scripts or commands. It displays a menu to select the script that shall be executed. The menu is defined in a text file, that is ":" separated (see example.menu). The menu file can be selected in the addon settings.
44

5-
[Version 0.9.1](https://github.com/wastis/LinuxAddonRepo)
5+
[Version 1.0.0](https://github.com/wastis/LinuxAddonRepo)
66

77
<img src="resources/media/icon.png" alt="drawing" width="200"/>
88

9+
## Menu file
10+
11+
The menu file defines the menu items, script success flags and the command. It is a colon delimited table file, that can be assigned in the addon settings.
12+
13+
Name 1:flags:command 1
14+
Name 2:flags:command 1
15+
....
16+
17+
The flags are comma separated. Currently there are two flags defined
18+
19+
- notify (*displays a notification window, when the script has ended*)
20+
- exitcode value (*checks if the return value of the script equals value. Displays a message box if it does not match.*)
21+
22+
### example.menu
23+
Backup addon data:notify:/bin/tar -czf ~/kodi_addon_data.tgz ~/.kodi/userdata/addon_data
24+
Backup keymaps::/bin/tar -czf ~/kodi_keymaps.tgz ~/.kodi/userdata/keymaps
25+
Backup userdata ::/bin/tar -czf ~/kodi_userdata.tgz ~/.kodi/userdata
26+
Ping Server:notify,exitcode 0:ping -c 1 192.168.1.1
27+
28+
929
2022 wastis
1030

1131

addon.xml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2-
<addon id="script.shellscript.launcher" name="Shell Script Launcher" version="0.9.1" provider-name="wastis">
2+
<addon id="script.shellscript.launcher" name="Shell Script Launcher" version="1.0.0" provider-name="wastis">
33
<requires>
44
<import addon="xbmc.python" version="3.0.0"/>
55
</requires>
@@ -9,16 +9,23 @@
99
<extension point="xbmc.addon.metadata">
1010
<platform>linux</platform>
1111
<summary lang="en">Execute Shell Scripts</summary>
12-
<summary lang="de_DE">Führt Shellscripte aus</summary>
13-
<description lang="en">It displays a script selection menu. The menu is defined in a text file, that is ":" separated (see example.menu in addon folder).</description>
14-
<description lang="de_DE">Zeigt ein Scriptauswahlmenü zum Ausführen von Scripten an. Das Menü ist in einer Textdatei definiert (siehe example.menu im Addonverzeichnis).</description>
12+
<summary lang="de_DE">Führt Shellprogramme aus</summary>
13+
<description lang="en">It displays a script selection menu. The menu is defined in a text file (see README.md).</description>
14+
<description lang="de_DE">Zeigt ein Auswahlmenü zum Ausführen von Programmen an. Das Menü ist in einer Textdatei definiert (siehe README.md).</description>
1515
<license>GPL-3.0-or-later</license>
1616
<source></source>
1717
<disclaimer lang="en_GB"></disclaimer>
1818
<disclaimer lang="de_DE"></disclaimer>
1919
<news>
20+
21+
v1.0.0
22+
- removed blocking flag as non blocking it produced zombie processes
23+
- introduced flags notify, exitcode
24+
- improved error handling
25+
2026
v0.9.1
2127
- added skins
28+
2229
v0.9.0
2330
- Initial Version</news>
2431
<assets>

example.menu

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
backup addon data :blocking : /bin/tar -czf ~/kodi_addon_data.tgz ~/.kodi/userdata/addon_data
2-
backup keymaps : : /bin/tar -czf ~/kodi_keymaps.tgz ~/.kodi/userdata/keymaps
3-
backup userdata : : /bin/tar -czf ~/kodi_userdata.tgz ~/.kodi/userdata
1+
Backup addon data:notify:/bin/tar -czf ~/kodi_addon_data.tgz ~/.kodi/userdata/addon_data
2+
Backup keymaps::/bin/tar -czf ~/kodi_keymaps.tgz ~/.kodi/userdata/keymaps
3+
Backup userdata ::/bin/tar -czf ~/kodi_userdata.tgz ~/.kodi/userdata
4+
Ping Server:notify,exitcode 0:ping -c 1 192.168.1.1

resources/language/resource.language.de_de/strings.po

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,43 @@ msgctxt "#32006"
1515
msgid "menu file"
1616
msgstr "Menüdatei"
1717

18+
msgctxt "#32100"
19+
msgid "Menu File Error"
20+
msgstr "Menüdatei Fehler"
21+
22+
msgctxt "#32101"
23+
msgid "Menu file not found. Please select a file in the addon settings. Please visit https://github.com/wastis/ShellScriptLauncher for more information."
24+
msgstr "Menüdatei wurde nicht gefunden. Bitte wähle Sie eine Menüdatei in den Addon-Einstellungen aus. Besuchen sie auch https://github.com/wastis/ShellScriptLauncher für weitere Informationen."
25+
26+
msgctxt "#32102"
27+
msgid "Menu file is a directory. Please select a file in the addon settings. Please visit https://github.com/wastis/ShellScriptLauncher for more information."
28+
msgstr "Menüdatei ist ein Verzeichnis. Bitte wähle Sie eine Menüdatei in den Addon-Einstellungen aus. Besuchen sie auch https://github.com/wastis/ShellScriptLauncher für weitere Informationen."
29+
30+
msgctxt "#32103"
31+
msgid "Cannot access menu file, permission problem."
32+
msgstr "Kann nicht auf Menüdatei zugreifen, Berechtigungsprobleme."
33+
34+
msgctxt "#32104"
35+
msgid "Please see Kodi log for more information."
36+
msgstr "Bitte sehen Sie die Kodi Logdatei für weitere Informationen ein."
37+
38+
msgctxt "#32105"
39+
msgid "Menu file is empty or might not have the correct format. Please visit https://github.com/wastis/ShellScriptLauncher for more information."
40+
msgstr "Menüdatei ist leer oder hat das falsche Format. Besuchen sie auch https://github.com/wastis/ShellScriptLauncher für weitere Informationen."
41+
42+
43+
msgctxt "#32110"
44+
msgid "Command Error."
45+
msgstr "Befehlsfehler."
46+
47+
msgctxt "#32111"
48+
msgid "Error executing command: %s"
49+
msgstr "Fehler beim Ausführen des Befehls: %s"
50+
51+
msgctxt "#32112"
52+
msgid "Execution completed."
53+
msgstr "Ausführung abgeschlossen."
54+
55+
msgctxt "#32113"
56+
msgid "%s did not return the expected value. Error code: %s"
57+
msgstr "%s hat nicht den erwarteten Wert zurückgeliefert. Fehlerwert: %s"

resources/language/resource.language.en_gb/strings.po

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,44 @@ msgstr "General"
1212
msgctxt "#32006"
1313
msgid "menu file"
1414
msgstr "menu file"
15+
16+
msgctxt "#32100"
17+
msgid "Menu File Error"
18+
msgstr "Menu File Error"
19+
20+
msgctxt "#32101"
21+
msgid "Menu file not found. Please select a file in the addon settings. Please visit https://github.com/wastis/ShellScriptLauncher for more information."
22+
msgstr "Menu file not found. Please select a file in the addon settings. Please visit https://github.com/wastis/ShellScriptLauncher for more information."
23+
24+
msgctxt "#32102"
25+
msgid "Menu file is a directory. Please select a file in the addon settings. Please visit https://github.com/wastis/ShellScriptLauncher for more information."
26+
msgstr "Menu file is a directory. Please select a file in the addon settings. Please visit https://github.com/wastis/ShellScriptLauncher for more information."
27+
28+
msgctxt "#32103"
29+
msgid "Cannot access menu file, permission problem."
30+
msgstr "Cannot access menu file, permission problem."
31+
32+
msgctxt "#32104"
33+
msgid "Please see Kodi log for more information."
34+
msgstr "Please see Kodi log for more information."
35+
36+
msgctxt "#32105"
37+
msgid "Menu file is empty or might not have the correct format. Please visit https://github.com/wastis/ShellScriptLauncher for more information."
38+
msgstr "Menu file is empty or might not have the correct format. Please visit https://github.com/wastis/ShellScriptLauncher for more information."
39+
40+
41+
msgctxt "#32110"
42+
msgid "Command Error."
43+
msgstr "Command Error."
44+
45+
msgctxt "#32111"
46+
msgid "Error executing command: %s"
47+
msgstr "Error executing command: %s"
48+
49+
msgctxt "#32112"
50+
msgid "Execution completed."
51+
msgstr "Execution completed."
52+
53+
msgctxt "#32113"
54+
msgid "%s did not return the expected value. Error code: %s"
55+
msgstr "%s did not return the expected value. Error code: %s"

resources/lib/menu.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@
1313
import xbmcaddon
1414
from xbmcgui import ListItem
1515

16-
from log import log
17-
from handle import handle
18-
from handle import opthandle
19-
2016
addon = xbmcaddon.Addon()
2117
def tr(lid):
2218
return addon.getLocalizedString(lid)
@@ -34,8 +30,6 @@ def onInit( self ):
3430
dx = -self.item_list_bk.getX()
3531
dy = -self.item_list_bk.getY()
3632

37-
log("size :" + str(dx))
38-
3933
item_height = 80
4034
item_cnt = len(self.menu)
4135

@@ -48,8 +42,6 @@ def onInit( self ):
4842

4943
y = int((1080 - window_height) / 2)
5044

51-
log(str(y))
52-
5345
self.item_list.setHeight(window_height)
5446
self.item_list_bk.setHeight(window_height+2*dy)
5547

@@ -72,7 +64,6 @@ def onInit( self ):
7264
#
7365

7466
def end_gui(self):
75-
log("end_gui")
7667
self.selected = -1
7768
self.close()
7869

@@ -87,6 +78,6 @@ def onAction( self, action ):
8778
if action.getId() in [7, 100]:
8879
self.ok_pressed()
8980

90-
#Cancel
81+
#Cancel / Fullscreen
9182
if action.getId() in [92,10,18]:
9283
self.end_gui()

resources/lib/runaddon.py

Lines changed: 104 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,48 +14,90 @@
1414

1515
import xbmcaddon
1616
import xbmc
17+
import xbmcgui
1718

1819
from log import log
1920
from handle import handle
2021

2122
from menu import MenuGui
2223

24+
addon = xbmcaddon.Addon()
25+
def tr(lid):
26+
return addon.getLocalizedString(lid)
27+
28+
def parse_flags(flags):
29+
# takes comma seperated string like "notify,exitcode 0"
30+
31+
notify = False
32+
check_exit = False
33+
expect = 0
34+
35+
for flag in flags.split(","):
36+
flag = flag.strip()
37+
if flag == "notify":
38+
notify = True
39+
if flag.startswith("exitcode"):
40+
expect = int(flag[8:].strip())
41+
check_exit = True
42+
43+
return notify, check_exit, expect
44+
2345
def run_addon():
2446
try:
2547
cwd = xbmcaddon.Addon().getAddonInfo('path')
2648
menufile = os.path.expanduser(xbmcaddon.Addon().getSettingString("menufile"))
2749

2850
log("menufile: " + menufile)
2951

30-
with open(menufile, "r") as f:
31-
content = f.read().split("\n")
52+
try:
53+
with open(menufile, "r") as f:
54+
content = f.read().split("\n")
55+
except FileNotFoundError:
56+
xbmcgui.Dialog().ok(tr(32100),tr(32101))
57+
return
58+
except IsADirectoryError:
59+
xbmcgui.Dialog().ok(tr(32100),tr(32102))
60+
return
61+
except PermissionError:
62+
xbmcgui.Dialog().ok(tr(32100),tr(32103))
63+
return
64+
except Exception as e:
65+
handle(e)
66+
xbmcgui.Dialog().ok(tr(32100),tr(32104))
67+
return
3268

69+
# parse menu items
3370
menu_items = []
3471
for line in content:
3572
try:
36-
pos = line.find(":")
37-
if pos <0 : continue
38-
expos = line.find(":",pos + 1)
73+
cols = line.split(":")
74+
if len(cols) < 3:
75+
continue
3976

40-
name = line[:pos].strip()
41-
block = line[pos + 1:expos].strip() == "blocking"
42-
exe = line[expos + 1:].strip()
77+
name = cols[0].strip()
78+
flags = cols[1].lower()
79+
exe = ":".join(cols[2:])
4380

44-
if name == "":
45-
continue
46-
if exe == "":
81+
if name == "" or exe == "":
4782
continue
48-
menu_items.append((name, block, exe))
83+
84+
menu_items.append((name, exe, flags))
4985

5086
except:
5187
continue
88+
#
89+
# check if menu file is empty
90+
#
5291

5392
if not menu_items:
54-
log("no menu entries found in menu file")
93+
xbmcgui.Dialog().ok(tr(32100),tr(32105))
5594
return
5695

96+
#
97+
# show menu dialog
98+
#
99+
57100
current_skin = xbmc.getSkinDir()
58-
log(current_skin)
59101

60102
if os.path.exists(os.path.join(cwd,"resources","skins",current_skin)):
61103
skin = current_skin
@@ -65,19 +107,60 @@ def run_addon():
65107
ui = MenuGui("menu.xml", cwd, skin, "1080i", menu = menu_items, width = 400)
66108
ui.doModal()
67109
selected = ui.selected
110+
111+
#
112+
# check if back has been pressed
113+
#
114+
68115
if selected < 0:
69116
log("nothing selected")
70117
return
71118

72-
cmd = [os.path.expanduser(item) for item in menu_items[selected][2].split(" ")]
73-
block = menu_items[selected][1]
74-
log("run: " + str(block) + " "+ " ".join(cmd))
119+
#
120+
# expand user home ~
121+
#
122+
123+
cmd = [\
124+
os.path.expanduser(item) \
125+
for item in menu_items[selected][1].split(" ")\
126+
]
127+
128+
#
129+
# parse flags
130+
#
131+
132+
notify, check_exit, expect = parse_flags(menu_items[selected][2])
133+
134+
#
135+
# execute command
136+
#
137+
138+
log("execute: " + " ".join(cmd))
139+
140+
try:
141+
exitcode = int(subprocess.Popen(cmd).wait())
142+
143+
except Exception as e:
144+
handle(e)
145+
xbmcgui.Dialog().ok(tr(32110),tr(32111) % cmd)
75146

76-
if block:
77-
os.system(" ".join(cmd))
78147
else:
79-
subprocess.Popen(cmd)
80-
log("done")
148+
log("done with exitcode %s " % str(exitcode))
149+
150+
if check_exit and exitcode != expect:
151+
xbmcgui.Dialog().ok\
152+
(\
153+
tr(32110), \
154+
tr(32113) % (menu_items[selected][0], exitcode)\
155+
)
156+
157+
elif notify:
158+
xbmcgui.Dialog().notification\
159+
(
160+
tr(32112), \
161+
menu_items[selected][0],\
162+
os.path.join(cwd,"resources","media","notify.png")\
163+
)
81164

82165
except Exception as e:
83166
handle(e)

resources/media/notify.png

3.21 KB
Loading

0 commit comments

Comments
 (0)