sys.exit(0) # Looking up for an alias alias = C.get('aliases.%s' % cmd) if alias != None: if alias.startswith('!'): cmd = alias[1:] i = 0 # Replace $1, $2, ... with passed arguments for arg in args: i += 1 cmd = cmd.replace('$%d' % i, arg) # Remove unknown $[0-9] cmd = re.sub(r'\$[0-9]', '', cmd) result = process(cmd, stdout=None, stderr=None) sys.exit(result[0]) else: cmd = alias.split(' ')[0] args = alias.split(' ')[1:] + args cls = getCommand(cmd) Cmd = cls(C) Runner = CommandRunner(Cmd) try: Runner.run(args, prog='%s %s' % (os.path.basename(sys.argv[0]), cmd)) except Exception as e: import traceback info = sys.exc_info() logging.error('%s: %s', e.__class__.__name__, e) logging.debug(''.join(traceback.format_tb(info[2])))
(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/>. http://github.com/FMCorz/mdk """ import sys from os.path import basename from lib.command import CommandRunner from lib.commands import getCommand from lib.config import Conf f = basename(__file__) sys.stderr.write("Do not call %s directly.\n" % (f)) sys.stderr.write("This file will be removed in a later version.\n") sys.stderr.write("Please use `mdk [command] [arguments]`\n") sys.stderr.write("\n") cmd = f.replace('moodle-', '').replace('.py', '') cls = getCommand(cmd) Cmd = cls(Conf()) Runner = CommandRunner(Cmd) Runner.run(None, prog='%s %s' % ('mdk', cmd))