def handle(self):
        name = self.argument('name')
        singular = inflection.singularize(inflection.tableize(name))
        directory = self._get_path()
        filepath = self._get_path(singular + '.py')

        if os.path.exists(filepath):
            raise RuntimeError('The model file already exists.')

        mkdir_p(directory)

        parent = os.path.join(directory, '__init__.py')
        if not os.path.exists(parent):
            with open(parent, 'w'):
                pass

        stub = self._get_stub()
        stub = self._populate_stub(name, stub)

        with open(filepath, 'w') as f:
            f.write(stub)

        self.info('Model <comment>%s</> successfully created.' % name)

        if self.option('migration'):
            table = inflection.tableize(name)

            self.call(
                'make:migration',
                [
                    ('name', 'create_%s_table' % table),
                    ('--table', table),
                    ('--create', True)
                ]
            )
dataset/ETHPy150Open sdispater/orator/orator/commands/models/make_command.py/ModelMakeCommand.handle/original