Newer
Older
Wannes Rombouts
committed
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
#!/usr/bin/env python2.7
# -*- coding: utf-8 -*-
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# #
# MapServer REST API is a python wrapper around MapServer which #
# allows to manipulate a mapfile in a RESTFul way. It has been #
# developped to match as close as possible the way the GeoServer #
# REST API acts. #
# #
# Copyright (C) 2011-2013 Neogeo Technologies. #
# #
# This file is part of MapServer Rest API. #
# #
# MapServer Rest API 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. #
# #
# MapServer Rest API 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. #
# #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
import sys
import os.path
import logging
class ExtensionManager(object):
def __init__(self, ):
self.extentions = {}
def load_plugins(self, pkg_name):
sys.path.append(__file__)
__import__(pkg_name, globals(), locals(), ["*"])
sys.path.remove(__file__)
def load_plugins_dir(self, dir_path):
path, pkg = os.path.split(os.path.abspath(dir_path))
pkg, _ = os.path.splitext(pkg)
print "Loading %s from %s" % (pkg, path)
sys.path.append(path)
try:
self.load_plugins(pkg)
except ImportError:
logging.error("Could not load plugin package '%s' from %s" % (pkg, path))
else:
logging.info("Loaded plugin package '%s' from %s" % (pkg, path))
sys.path.remove(path)
def extend(self, name, *args, **kwargs):
for f in self.extentions.get(name, []):
f(*args, **kwargs)
def register(self, name, f=None):
if f == None:
def decorator(f):
self.register(name, f)
return f
return decorator
self.extentions.setdefault(name, []).append(f)
plugins = ExtensionManager()