cmd.py 697 Bytes
Newer Older
Will Daly committed
1 2 3 4
"""
Helper functions for constructing shell commands.
"""

5

Will Daly committed
6 7 8 9
def cmd(*args):
    """
    Concatenate the arguments into a space-separated shell command.
    """
10
    return " ".join(str(arg) for arg in args if arg)
Will Daly committed
11 12 13 14 15 16 17 18 19 20 21 22 23 24


def django_cmd(sys, settings, *args):
    """
    Construct a Django management command.

    `sys` is either 'lms' or 'studio'.
    `settings` is the Django settings module (such as "dev" or "test")
    `args` are concatenated to form the rest of the command.
    """
    # Maintain backwards compatibility with manage.py,
    # which calls "studio" "cms"
    sys = 'cms' if sys == 'studio' else sys
    return cmd("python manage.py", sys, "--settings={}".format(settings), *args)