(self)
Main command to create controller
Main command to create controller
Main command to create controller
def command(self):
        """Main command to create controller"""
        try:
            file_op = FileOp(source_dir=('pylons', 'templates'))
            try:
                singularname, singulardirectory = \
                    file_op.parse_path_name_args(self.args[0])
                pluralname, pluraldirectory = \
                    file_op.parse_path_name_args(self.args[1])

            except:
                raise BadCommand('No egg_info directory was found')

            # Check the name isn't the same as the package
            base_package = file_op.find_dir('controllers', True)[0]
            if base_package.lower() == pluralname.lower():
                raise BadCommand(
                    'Your controller name should not be the same as '
                    'the package name %r.' % base_package)
            # Validate the name
            for name in [pluralname]:
                name = name.replace('-', '_')
                validate_name(name)

            # Determine the module's import statement
            if is_minimal_template(base_package):
                importstatement = ('from %s.controllers import BaseController'
                                   % base_package)
            else:
                importstatement = ('from %s.lib.base import BaseController' %
                                   base_package)
            if defines_render(base_package):
                importstatement += ', render'

            module_dir = pluraldirectory.replace('/', os.path.sep)
            check_controller_existence(base_package, module_dir, name)

            # Setup the controller
            fullname = os.path.join(pluraldirectory, pluralname)
            controller_name = util.class_name_from_module_name(
                pluralname.split('/')[-1])
            if not fullname.startswith(os.sep):
                fullname = os.sep + fullname
            testname = fullname.replace(os.sep, '_')[1:]

            nameprefix = ''
            path = ''
            if pluraldirectory:
                nameprefix = pluraldirectory.replace(os.path.sep, '_') + '_'
                path = pluraldirectory + '/'

            controller_c = ''
            if nameprefix:
                controller_c = ", controller='%s', \n\t" % \
                    '/'.join([pluraldirectory, pluralname])
                controller_c += "path_prefix='/%s', name_prefix='%s'" % \
                    (pluraldirectory, nameprefix)
            command = "map.resource('%s', '%s'%s)\n" % \
                (singularname, pluralname, controller_c)

            file_op.template_vars.update(
                {'classname': controller_name,
                 'pluralname': pluralname,
                 'singularname': singularname,
                 'name': controller_name,
                 'nameprefix': nameprefix,
                 'package': base_package,
                 'path': path,
                 'resource_command': command.replace('\n\t', '\n%s#%s' % \
                                                         (' ' * 4, ' ' * 9)),
                 'fname': os.path.join(pluraldirectory, pluralname),
                 'importstatement': importstatement})

            resource_command = ("\nTo create the appropriate RESTful mapping, "
                                "add a map statement to your\n")
            resource_command += ("config/routing.py file near the top like "
                                 "this:\n\n")
            resource_command += command
            file_op.copy_file(template='restcontroller.py_tmpl',
                              dest=os.path.join('controllers', pluraldirectory),
                              filename=pluralname,
                              template_renderer=paste_script_template_renderer)
            if not self.options.no_test:
                file_op.copy_file(
                    template='test_restcontroller.py_tmpl',
                    dest=os.path.join('tests', 'functional'),
                    filename='test_' + testname,
                    template_renderer=paste_script_template_renderer)
            print resource_command
        except BadCommand, e:
            raise BadCommand('An error occurred. %s' % e)
        except:
            msg = str(sys.exc_info()[1])
            raise BadCommand('An unknown error occurred. %s' % msg)
def command ( self ) : try : file_op = FileOp ( source_dir = ( 'pylons' , 'templates' ) ) try : singularname , singulardirectory = file_op . parse_path_name_args ( self . args [ 0 ] ) pluralname , pluraldirectory = file_op . parse_path_name_args ( self . args [ 1 ] ) except : raise BadCommand ( 'No egg_info directory was found' ) # Check the name isn't the same as the package base_package = file_op . find_dir ( 'controllers' , True ) [ 0 ] if base_package . lower ( ) == pluralname . lower ( ) : raise BadCommand ( 'Your controller name should not be the same as ' 'the package name %r.' % base_package ) # Validate the name for name in [ pluralname ] : name = name . replace ( '-' , '_' ) validate_name ( name ) # Determine the module's import statement if is_minimal_template ( base_package ) : importstatement = ( 'from %s.controllers import BaseController' % base_package ) else : importstatement = ( 'from %s.lib.base import BaseController' % base_package ) if defines_render ( base_package ) : importstatement += ', render' module_dir = pluraldirectory . replace ( '/' , os . path . sep ) check_controller_existence ( base_package , module_dir , name ) # Setup the controller fullname = os . path . join ( pluraldirectory , pluralname ) controller_name = util . class_name_from_module_name ( pluralname . split ( '/' ) [ - 1 ] ) if not fullname . startswith ( os . sep ) : fullname = os . sep + fullname testname = fullname . replace ( os . sep , '_' ) [ 1 : ] nameprefix = '' path = '' if pluraldirectory : nameprefix = pluraldirectory . replace ( os . path . sep , '_' ) + '_' path = pluraldirectory + '/' controller_c = '' if nameprefix : controller_c = ", controller='%s', \n\t" % '/' . join ( [ pluraldirectory , pluralname ] ) controller_c += "path_prefix='/%s', name_prefix='%s'" % ( pluraldirectory , nameprefix ) command = "map.resource('%s', '%s'%s)\n" % ( singularname , pluralname , controller_c ) file_op . template_vars . update ( { 'classname' : controller_name , 'pluralname' : pluralname , 'singularname' : singularname , 'name' : controller_name , 'nameprefix' : nameprefix , 'package' : base_package , 'path' : path , 'resource_command' : command . replace ( '\n\t' , '\n%s#%s' % ( ' ' * 4 , ' ' * 9 ) ) , 'fname' : os . path . join ( pluraldirectory , pluralname ) , 'importstatement' : importstatement } ) resource_command = ( "\nTo create the appropriate RESTful mapping, " "add a map statement to your\n" ) resource_command += ( "config/routing.py file near the top like " "this:\n\n" ) resource_command += command file_op . copy_file ( template = 'restcontroller.py_tmpl' , dest = os . path . join ( 'controllers' , pluraldirectory ) , filename = pluralname , template_renderer = paste_script_template_renderer ) if not self . options . no_test : file_op . copy_file ( template = 'test_restcontroller.py_tmpl' , dest = os . path . join ( 'tests' , 'functional' ) , filename = 'test_' + testname , template_renderer = paste_script_template_renderer ) print resource_command except BadCommand , e : raise BadCommand ( 'An error occurred. %s' % e ) except : msg = str ( sys . exc_info ( ) [ 1 ] ) raise BadCommand ( 'An unknown error occurred. %s' % msg )