def handle(self, *args, **options):
     if args:
         try:
             rlist = map(
                 lambda r: Repository.objects.get(label=r), args)
         except Repository.DoesNotExist, error:
             raise management.CommandError(error)
예제 #2
0
def start_cms_project():
    argv = list(sys.argv)
    if len(argv) != 2:
        raise management.CommandError("start_cms_project accepts one argument - the name of the project to create.")
    management.call_command("startproject",
        argv[1],
        template = "{}/../project_template/".format(os.path.dirname( __file__ )),
        n = "js,scss,rb,py,css,html,gitignore",
    )
예제 #3
0
def start_herokuapp_project():
    argv = list(sys.argv)
    if len(argv) != 2:
        raise management.CommandError("start_herokuapp_project accepts one argument - the name of the project to create.")
    project_name = argv[1]
    management.call_command("startproject",
        project_name,
        template = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "project_template")),
        extensions = ("py", "txt", "slugignore", "conf", "gitignore,sh",),
        files = ("Procfile",),
        app_name = project_name.replace("_", "-"),
        user = getpass.getuser(),
    )
예제 #4
0
파일: runner.py 프로젝트: arashm/pootle
def init_command(parser, settings_template, args):
    """Parse and run the `pootle init` command

    :param parser: `argparse.ArgumentParser` instance to use for parsing
    :param settings_template: Template file for initializing settings from.
    :param args: Arguments to call init command with.
    """

    src_dir = os.path.abspath(os.path.dirname(__file__))
    add_help_to_parser(parser)
    parser.add_argument("--db",
                        default="sqlite",
                        help=(u"Use the specified database backend (default: "
                              u"'sqlite'; other options: 'mysql', "
                              u"'postgresql')."))
    parser.add_argument("--db-name",
                        default="",
                        help=(u"Database name (default: 'pootledb') or path "
                              u"to database file if using sqlite (default: "
                              u"'%s/dbs/pootle.db')" % src_dir))
    parser.add_argument("--db-user",
                        default="",
                        help=(u"Name of the database user. Not used with "
                              u"sqlite."))
    parser.add_argument("--db-host",
                        default="",
                        help=(u"Database host. Defaults to localhost. Not "
                              u"used with sqlite."))
    parser.add_argument("--db-port",
                        default="",
                        help=(u"Database port. Defaults to backend default. "
                              u"Not used with sqlite."))

    args, remainder = parser.parse_known_args(args)
    config_path = os.path.expanduser(args.config)

    if os.path.exists(config_path):
        resp = None
        if args.noinput:
            resp = 'n'
        else:
            resp = input("File already exists at %r, overwrite? [Ny] " %
                         config_path).lower()
        if resp not in ("y", "yes"):
            print("File already exists, not overwriting.")
            exit(2)

    if args.db not in ["mysql", "postgresql", "sqlite"]:
        raise management.CommandError("Unrecognised database '%s': should "
                                      "be one of 'sqlite', 'mysql' or "
                                      "'postgresql'" % args.db)

    try:
        init_settings(config_path,
                      settings_template,
                      db=args.db,
                      db_name=args.db_name,
                      db_user=args.db_user,
                      db_host=args.db_host,
                      db_port=args.db_port)
    except (IOError, OSError) as e:
        raise e.__class__('Unable to write default settings file to %r' %
                          config_path)

    if args.db in ['mysql', 'postgresql']:
        print("Configuration file created at %r. Your database password is "
              "not currently set . You may want to update the database "
              "settings now" % config_path)
    else:
        print("Configuration file created at %r" % config_path)
예제 #5
0
 def error(self, message):
     if self.cmd._called_from_command_line:
         super(CommandParser, self).error(message)
     else:
         raise management.CommandError("Error: %s" % message)
예제 #6
0
 def handle_error(self, *args, **kwargs):
     raise management.CommandError("This command is not implemented")
예제 #7
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from django.conf import settings
from django.core import management

settings.configure()
if __name__ == "__main__":
    if sys.argv[1] == 'startproject':
        if len(sys.argv) < 2:
            raise management.CommandError(
                "accepet accepts one argument - the name of the project "
                "to create.")
        management.call_command(
            'startproject',
            sys.argv[2],
            template='https://github.com/opps/opps-project-template/zipball/'
            'master',
            extensions=('py', 'md', 'dev'))