From 11510ac5b3ccb9bbb8414682f76fa155e95b76cd Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Tue, 22 Jul 2014 10:27:20 +0800 Subject: [PATCH] Resolve scripts using the package resource API --- mdk/scripts.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/mdk/scripts.py b/mdk/scripts.py index 94066a6..e42b356 100644 --- a/mdk/scripts.py +++ b/mdk/scripts.py @@ -26,6 +26,7 @@ import os import shutil import stat import logging +from pkg_resources import resource_filename from .tools import process from .config import Conf from .exceptions import ScriptNotFound, ConflictInScriptName, UnsupportedScript @@ -47,8 +48,17 @@ class Scripts(object): dirs = ['~/.moodle-sdk'] if C.get('dirs.moodle') != None: dirs.insert(0, C.get('dirs.moodle')) + dirs.append('/etc/moodle-sdk') - dirs.append(os.path.join(os.path.dirname(__file__), '..')) + + # Directory within the package. + # This can point anywhere when the package is installed, or to the folder containing the module when it is not. + packageDir = resource_filename('mdk', 'scripts') + dirs.append(os.path.split(packageDir)[0]) + + # Legacy: directory part of the root git repository, only if we can be sure that the parent directory is still MDK. + if os.path.isfile(os.path.join(os.path.dirname(__file__), '..', 'mdk.py')): + dirs.append(os.path.join(os.path.dirname(__file__), '..')) i = 0 for d in dirs: -- 2.11.0