forked from KenV99/script.service.kodi.callbacks
-
Notifications
You must be signed in to change notification settings - Fork 5
/
testme.py
91 lines (82 loc) · 2.7 KB
/
testme.py
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
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2014 KenV99
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
######################################################################
#
# Use to test scripts and arguments
#
######################################################################
import sys
def stripquotes(st):
if st.startswith('"') and st.endswith('"'):
return st[1:-1].strip()
else:
return st.strip()
def showNotification(args, kwargs):
# Note that using execfile will not allow for module level imports!
try:
import xbmcgui
except ImportError:
pass
else:
mdialog = xbmcgui.Dialog()
argmsg = ", ".join(args)
kwargmsg = []
for key in list(kwargs.keys()):
kwargmsg.append('%s:%s' % (key, kwargs[key]))
mdialog.ok('Test', 'args: %s\nkwargs:: %s' % (argmsg, ', '.join(kwargmsg)))
def processargs(args, kwargs):
nargs = []
if isinstance(args, str):
kwargs = {}
args = args.split(' ')
nargs = []
for arg in args:
if ":" in arg:
tmp = arg.split(":", 1)
try:
key = tmp[0]
val = tmp[1]
val2 = stripquotes(val)
kwargs[key] = val2
except (KeyError, LookupError):
pass
else:
nargs.append(stripquotes(arg))
elif isinstance(args, list):
nargs = args
if kwargs is None:
kwargs = {}
return nargs, kwargs
def run(args=None, kwargs=None):
args, kwargs = processargs(args, kwargs)
showNotification(args, kwargs)
if __name__ == '__main__' or __name__ == 'Tasks':
xargs = []
kwargs = {}
if __name__ == '__main__':
sysargv = sys.argv[1:]
else:
sysargv = locals()['args'].strip().split(' ')
for i, xarg in enumerate(sysargv):
if ":" in xarg:
key, entry = xarg.split(':', 1)
kwargs[key] = stripquotes(entry)
else:
xargs.append(stripquotes(xarg))
run(xargs, kwargs)