Exemple #1
0
def help(cmd=None, **opts):
    """%prog help COMMAND

    Displays help on a given command.
    """
    if cmd is None:
        raise exceptions.UsageError(None)
    try:
        func = globals()[cmd]
    except:
        raise exceptions.UsageError(
            "'%s' isn't a valid command. Try 'help COMMAND'" % cmd)
    ret = func.__doc__
    if sys.argv[0]:
        ret = ret.replace('%prog', sys.argv[0])
    return ret
Exemple #2
0
def source(version, dest=None, repository=None, **opts):
    """%prog source VERSION [DESTINATION] --repository=REPOSITORY_PATH

    Display the Python code for a particular version in this repository.
    Save it to the file at DESTINATION or, if omitted, send to stdout. 
    """
    if repository is None:
        raise exceptions.UsageError("A repository must be specified")
    repos = Repository(repository)
    ret = repos.version(version).script().source()
    if dest is not None:
        dest = open(dest, 'w')
        dest.write(ret)
        ret = None
    return ret
Exemple #3
0
def script(description, repository=None, **opts):
    """%prog script [--repository=REPOSITORY_PATH] DESCRIPTION

    Create an empty change script using the next unused version number
    appended with the given description.

    For instance, manage.py script "Add initial tables" creates:
    repository/versions/001_Add_initial_tables.py
    """
    try:
        if repository is None:
            raise exceptions.UsageError("A repository must be specified")
        repos = cls_repository(repository)
        repos.create_script(description, **opts)
    except exceptions.PathFoundError, e:
        raise exceptions.KnownError("The path %s already exists" % e.args[0])
Exemple #4
0
def script_sql(database, repository=None, **opts):
    """%prog script_sql [--repository=REPOSITORY_PATH] DATABASE

    Create empty change SQL scripts for given DATABASE, where DATABASE
    is either specific ('postgres', 'mysql', 'oracle', 'sqlite', etc.)
    or generic ('default').

    For instance, manage.py script_sql postgres creates:
    repository/versions/001_upgrade_postgres.py and
    repository/versions/001_downgrade_postgres.py
    """
    try:
        if repository is None:
            raise exceptions.UsageError("A repository must be specified")
        repos = cls_repository(repository)
        repos.create_script_sql(database, **opts)
    except exceptions.PathFoundError, e:
        raise exceptions.KnownError("The path %s already exists" % e.args[0])