-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.py
More file actions
64 lines (56 loc) · 2.1 KB
/
utils.py
File metadata and controls
64 lines (56 loc) · 2.1 KB
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
import os
import sys
import imp
import xbmc
try: import cPickle as pickle
except: import pickle
from t0mm0.common.addon import Addon
addon = Addon('plugin.video.waldo', sys.argv)
def import_module(name, globals=None, locals=None, fromlist=None):
# Fast path: see if the module has already been imported.
try: return sys.modules[name]
except KeyError:
pass
# If any of the following calls raises an exception,
# there's a problem we can't handle -- let the caller handle it.
addon.log_debug('Finding module %s in %s' %(name, fromlist))
fp, pathname, description = imp.find_module(name,fromlist)
try: return imp.load_module(name, fp, pathname, description)
finally:
# Since we may exit via an exception, close fp explicitly.
if fp: fp.close()
def get_index_name(index):
addon.log( 'Getting index name of %s' %index)
return index.__name__.rsplit('.',1)[-1]
def has_requirements(list):
for addon in list:
condition = 'System.HasAddon(%s)' %addon
if not xbmc.getCondVisibility(condition):
return False
return True
def update_settings_xml(list):
'''
This function writes a new ``resources/settings.xml`` file which contains
all settings for this addon and its plugins.
'''
settings_file = os.path.join(addon.get_path(), 'resources', 'settings.xml')
try:
try:
os.makedirs(os.path.dirname(settings_file))
except OSError:
pass
f = open(settings_file, 'w')
try:
f.write('<?xml version="1.0" encoding="utf-8" standalone="yes"?>\n')
f.write('<settings>\n')
for mod in list:
settings_xml = mod.get_settings_xml()
f.write('<category label="%s">\n' % mod.display_name)
f.write('<setting id="enabled" type="bool" default="true"/>')
if settings_xml: f.write(settings_xml)
f.write('</category>\n')
f.write('</settings>')
finally:
f.close
except IOError:
addon.log_error('Error writing ' + common.settings_file)