From: Frederic Massart Date: Tue, 22 Jul 2014 02:27:20 +0000 (+0800) Subject: Resolve scripts using the package resource API X-Git-Tag: v1.3~14 X-Git-Url: http://git.cameron1729.xyz/?a=commitdiff_plain;h=11510ac5b3ccb9bbb8414682f76fa155e95b76cd;p=mdk.git Resolve scripts using the package resource API --- 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: