Example #1
0
    def run(self, cmdargs):
        # TODO: bash completion file
        parser = argparse.ArgumentParser(
            prog="%s scaffold" % sys.argv[0].split(os.path.sep)[-1],
            description=self.__doc__
        )
        parser.add_argument('--init', type=identifier, help='Initialize a new Odoo module')

        parser.add_argument('--dest', default=".",
            help='Directory where the module should be created/updated (default to current directory)')

        parser.add_argument('--model', type=identifier, help="Name of the model to add")

        parser.add_argument('--controller', type=identifier, help="Name of the controller to add")

        parser.add_argument('--web', action='store_true', default=False,
                         help="Generate structure for a webclient module")

        parser.add_argument('--theme', action='store_true', default=False,
                         help="Generate structure for a Website theme")

        if not cmdargs:
            sys.exit(parser.print_help())
        args = parser.parse_args(args=cmdargs)

        dest = directory(args.dest)
        if args.init:
            dest = os.path.join(dest, args.init)
            if os.path.exists(dest):
                die("Can't initialize module in `%s`: Directory already exists." % dest)
            if get_module_root(dest):
                die("Can't init a new module in another Odoo module, you probably want to run this "
                    "command from your project's root")
        else:
             mroot = get_module_root(dest)
             if not mroot:
                 die("The path `%s` provided does not point to an existing Odoo module. "
                     "Forgot to `--init` ?" % dest)
             dest = mroot

        logging.disable(logging.CRITICAL)
        scaffold = ScaffoldModule(dest)
        if args.model:
            scaffold.add_model(snake(args.model))
        if args.controller:
            scaffold.add_controller(args.controller)
        if args.web:
            scaffold.add_webclient_structure()
        if args.theme:
            scaffold.add_theme_structure()
Example #2
0
    def run(self, cmdargs):
        parser = argparse.ArgumentParser(
            prog="%s start" % sys.argv[0].split(os.path.sep)[-1],
            description=self.__doc__
        )
        parser.add_argument('--path', default=".",
            help="Directory where your project's modules are stored (will autodetect from current dir)")
        parser.add_argument("-d", "--database", dest="db_name", default=None,
                         help="Specify the database name (default to project's directory name")


        args, unknown = parser.parse_known_args(args=cmdargs)

        project_path = os.path.abspath(os.path.expanduser(os.path.expandvars(args.path)))
        module_root = get_module_root(project_path)
        db_name = None
        if module_root:
            # started in a module so we choose this module name for database
            db_name = project_path.split(os.path.sep)[-1]
            # go to the parent's directory of the module root
            project_path = os.path.abspath(os.path.join(project_path, os.pardir))

        # check if one of the subfolders has at least one module
        mods = self.get_module_list(project_path)
        if mods and '--addons-path' not in cmdargs:
            cmdargs.append('--addons-path=%s' % project_path)

        if not args.db_name:
            args.db_name = db_name or project_path.split(os.path.sep)[-1]
            cmdargs.extend(('-d', args.db_name))

        # TODO: forbid some database names ? eg template1, ...
        try:
            _create_empty_database(args.db_name)
        except DatabaseExists as e:
            pass
        except Exception as e:
            die("Could not create database `%s`. (%s)" % (args.db_name, e))

        if '--db-filter' not in cmdargs:
            cmdargs.append('--db-filter=^%s$' % args.db_name)

        # Remove --path /-p options from the command arguments
        def to_remove(i, l):
            return l[i] == '-p' or l[i].startswith('--path') or \
                (i > 0 and l[i-1] in ['-p', '--path'])
        cmdargs = [v for i, v in enumerate(cmdargs)
                   if not to_remove(i, cmdargs)]

        main(cmdargs)
Example #3
0
    def run(self, cmdargs):
        parser = argparse.ArgumentParser(prog="%s start" %
                                         sys.argv[0].split(os.path.sep)[-1],
                                         description=self.__doc__)
        parser.add_argument(
            '--path',
            default=".",
            help=
            "Directory where your project's modules are stored (will autodetect from current dir)"
        )
        parser.add_argument(
            "-d",
            "--database",
            dest="db_name",
            default=None,
            help=
            "Specify the database name (default to project's directory name")

        args, unknown = parser.parse_known_args(args=cmdargs)

        project_path = os.path.abspath(
            os.path.expanduser(os.path.expandvars(args.path)))
        module_root = get_module_root(project_path)
        db_name = None
        if module_root:
            # started in a module so we choose this module name for database
            db_name = project_path.split(os.path.sep)[-1]
            # go to the parent's directory of the module root
            project_path = os.path.abspath(
                os.path.join(project_path, os.pardir))

        # check if one of the subfolders has at least one module
        mods = self.get_module_list(project_path)
        if mods and '--addons-path' not in cmdargs:
            cmdargs.append('--addons-path=%s' % project_path)

        if not args.db_name:
            args.db_name = db_name or project_path.split(os.path.sep)[-1]
            cmdargs.extend(('-d', args.db_name))

        # TODO: forbid some database names ? eg template1, ...
        try:
            _create_empty_database(args.db_name)
            openerp.tools.config['init']['base'] = True
        except DatabaseExists, e:
            pass
Example #4
0
File: start.py Project: 0k/odoo
    def run(self, cmdargs):
        parser = argparse.ArgumentParser(prog="%s start" % sys.argv[0].split(os.path.sep)[-1], description=self.__doc__)
        parser.add_argument(
            "--path",
            default=".",
            help="Directory where your project's modules are stored (will autodetect from current dir)",
        )
        parser.add_argument(
            "-d",
            "--database",
            dest="db_name",
            default=None,
            help="Specify the database name (default to project's directory name",
        )

        args, unknown = parser.parse_known_args(args=cmdargs)

        project_path = os.path.abspath(os.path.expanduser(os.path.expandvars(args.path)))
        module_root = get_module_root(project_path)
        db_name = None
        if module_root:
            # started in a module so we choose this module name for database
            db_name = project_path.split(os.path.sep)[-1]
            # go to the parent's directory of the module root
            project_path = os.path.abspath(os.path.join(project_path, os.pardir))

        # check if one of the subfolders has at least one module
        mods = self.get_module_list(project_path)
        if mods and "--addons-path" not in cmdargs:
            cmdargs.append("--addons-path=%s" % project_path)

        if not args.db_name:
            args.db_name = db_name or project_path.split(os.path.sep)[-1]
            cmdargs.extend(("-d", args.db_name))

        # TODO: forbid some database names ? eg template1, ...
        try:
            _create_empty_database(args.db_name)
        except DatabaseExists, e:
            pass