def command(self): self.modelname = self.options.modelname self.modelpackage = self.options.modelpackage self.modelform = self.options.modelform self.primary_key = self.options.primary_key try: try: # Determine the package name from the .egg-info top_level.txt. here_dir = os.getcwd() egg_info = find_egg_info_dir(here_dir) f = open(os.path.join(egg_info, 'top_level.txt')) packages = [l.strip() for l in f.readlines() if l.strip() and not l.strip().startswith('#')] f.close() #upper 2 levels baselink = os.path.dirname( os.path.dirname(os.path.abspath(__file__))) file_op = FileOp( source_dir=os.path.join(baselink, 'templates')) self.base_package, directory = \ file_op.find_dir('controllers', True) except: raise command.BadCommand('No egg_info directory was found') except command.BadCommand, e: raise command.BadCommand('An error occurred. %s' % e)
def command(self): """Main command to create mapfish model""" try: fileOp = FileOp(source_dir=os.path.join( os.path.dirname(__file__), 'templates')) try: name, directory = fileOp.parse_path_name_args(self.args[0]) except: raise BadCommand('No egg_info directory was found') # read layers.ini config = ConfigParser() config.read(['layers.ini']) # check passed layer is in layers.ini if not config.has_section(name): raise BadCommand( 'There is no layer named %s in layers.ini' % name) # get layer parameters singularName = config.get(name, 'singular') table = config.get(name, 'table') epsg = config.get(name, 'epsg') geomColName = config.get(name, 'geomcolumn') if config.has_option(name, 'schema'): schema = config.get(name, 'schema') else: schema = None # check the name isn't the same as the package basePkg = fileOp.find_dir('controllers', True)[0] if basePkg.lower() == name.lower(): raise BadCommand( 'Your controller name should not be the same as ' 'the package name %s' % basePkg) # validate the name name = name.replace('-', '_') validateName(name) # set template vars modelClass = util.class_name_from_module_name(singularName) modelTabObj = name + '_table' # setup the model fileOp.template_vars.update( {'modelClass': modelClass, 'modelTabObj': modelTabObj, 'table': table, 'epsg': epsg, 'geomColName': geomColName, 'basePkg': basePkg, 'schema': schema}) fileOp.copy_file(template='model.py_tmpl', dest=os.path.join('model', directory), filename=name, template_renderer=paste_script_template_renderer) except BadCommand, e: raise BadCommand('An error occurred. %s' % e)
def command(self): try: file_op = FileOp(source_dir=('pylons', 'templates')) file_op.template_vars.update({ 'name': self.args[0], 'file_name': self.args[1] }) except: traceback.print_exc(file=sys.stdout) print traceback.format_exc() file_op.copy_file(template='site_tutorial.mako_tmpl', dest='templates', filename='tutorial_' + self.args[0] + '.mako', template_renderer=paste_script_template_renderer)
def command(self): """Main command to create controller""" try: file_op = FileOp(source_dir=('pylons', 'templates')) try: name, directory = file_op.parse_path_name_args(self.args[0]) 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() == name.lower(): raise BadCommand( 'Your controller name should not be the same as ' 'the package name %r.' % base_package) # Validate the name 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' # Setup the controller fullname = os.path.join(directory, name) controller_name = util.class_name_from_module_name( name.split('/')[-1]) if not fullname.startswith(os.sep): fullname = os.sep + fullname testname = fullname.replace(os.sep, '_')[1:] module_dir = directory.replace('/', os.path.sep) check_controller_existence(base_package, module_dir, name) file_op.template_vars.update({ 'name': controller_name, 'fname': os.path.join(directory, name), 'tmpl_name': name, 'package': base_package, 'importstatement': importstatement }) file_op.copy_file(template='controller.py_tmpl', dest=os.path.join('controllers', directory), filename=name, template_renderer=paste_script_template_renderer) if not self.options.no_test: file_op.copy_file( template='test_controller.py_tmpl', dest=os.path.join('tests', 'functional'), filename='test_' + testname, template_renderer=paste_script_template_renderer) except BadCommand, e: raise BadCommand('An error occurred. %s' % e)
def command(self): """Main command to create controller""" try: file_op = FileOp(source_dir=('pylons', 'templates')) try: name, directory = file_op.parse_path_name_args(self.args[0]) 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() == name.lower(): raise BadCommand( 'Your controller name should not be the same as ' 'the package name %r.' % base_package) # Validate the name 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' # Setup the controller fullname = os.path.join(directory, name) controller_name = util.class_name_from_module_name( name.split('/')[-1]) if not fullname.startswith(os.sep): fullname = os.sep + fullname testname = fullname.replace(os.sep, '_')[1:] module_dir = directory.replace('/', os.path.sep) check_controller_existence(base_package, module_dir, name) file_op.template_vars.update( {'name': controller_name, 'fname': os.path.join(directory, name).replace('\\', '/'), 'tmpl_name': name, 'package': base_package, 'importstatement': importstatement}) file_op.copy_file(template='controller.py_tmpl', dest=os.path.join('controllers', directory), filename=name, template_renderer=paste_script_template_renderer) if not self.options.no_test: file_op.copy_file( template='test_controller.py_tmpl', dest=os.path.join('tests', 'functional'), filename='test_' + testname, template_renderer=paste_script_template_renderer) except BadCommand, e: raise BadCommand('An error occurred. %s' % e)
def command(self): try: file_op = FileOp(source_dir=("pylons", "templates")) try: name, directory = file_op.parse_path_name_args(self.args[0]) except: raise BadCommand("No egg_info directory was found") base_package = file_op.find_dir("controllers", True)[0] if base_package.lower() == name.lower(): raise BadCommand( "Your controller name should not be the same as " "the package name %r." % base_package ) name = name.replace("-", "_") validate_name(name) 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" fullname = os.path.join(directory, name) controller_name = util.class_name_from_module_name(name.split("/")[-1]) if not fullname.startswith(os.sep): fullname = os.sep + fullname testname = fullname.replace(os.sep, "_")[1:] module_dir = directory.replace("/", os.path.sep) check_controller_existence(base_package, module_dir, name) file_op.template_vars.update( { "name": controller_name, "fname": os.path.join(directory, name).replace("\\", "/"), "tmpl_name": name, "package": base_package, "importstatement": importstatement, } ) file_op.copy_file( template="controller.py_tmpl", dest=os.path.join("controllers", directory), filename=name, template_renderer=paste_script_template_renderer, ) if not self.options.no_test: file_op.copy_file( template="test_controller.py_tmpl", dest=os.path.join("tests", "functional"), filename="test_" + testname, template_renderer=paste_script_template_renderer, ) except BadCommand, e: raise BadCommand("An error occurred. %s" % e)
def command(self): try: file_op = FileOp(source_dir=('pylons', 'templates')) try: name, directory = file_op.parse_path_name_args(self.args[0]) except: raise BadCommand('No egg_info directory was found') base_package = file_op.find_dir('model', True)[0] if base_package.lower() == name.lower(): raise BadCommand('Your moedl name should not be the same as ' 'the package name %r.' % base_package) name = name.replace('-', '_') if not is_minimal_template(base_package): importstatement = 'from %s.model.meta import *' % base_package fullname = os.path.join(directory, name) model_name = util.class_name_from_module_name(name.split('/')[-1]) if not fullname.startswith(os.sep): fullname = os.sep + fullname module_dir = directory.replace('/', os.path.sep) fields = {} for arg in self.args[1:]: field_args = arg.split(':') field_name = field_args[0] if field_args[1] != 'ForeignKey': if len(field_args) == 2: field_type = field_args[1] elif len(field_args) == 3: field_type = "%s(%s)" % (field_args[1], field_args[2]) fields[field_name] = field_type file_op.template_vars.update( {'name': model_name, 'tablename': name, 'importstatement': importstatement, 'fields': fields}) file_op.copy_file(template='model.py_tmpl', dest=os.path.join('model', directory), filename=name, template_renderer=paste_script_template_renderer) model_directory = file_op.find_dir('model', True)[1] self.insert_into_file(os.path.join(model_directory, '__init__.py'), 'model_declaration', 'from %s.model.%s import %s\n' % (base_package, name, model_name)) self.run_command('alembic', 'revision', '--autogenerate', '-m', 'add %s model' % model_name) except BadCommand, e: raise BadCommand('An error occurred. %s' % e)
def command(self): """Main command to create controller""" try: file_op = FileOp(source_dir=os.path.join( os.path.dirname(__file__), '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 [singularname, pluralname]: name = name.replace('-', '_') validate_name(name) # Determine the module's import statement if is_minimal_template(base_package): importstatement = "from %s.controllers import *" % base_package else: importstatement = "from %s.lib.base import *" % base_package # 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 = '' if pluraldirectory: nameprefix = pluraldirectory.replace(os.path.sep, '_') + '_' controller_c = '' if nameprefix: controller_c = ", controller='%s', \n\t" % \ '/'.join([pluraldirectory, pluralname]) controller_c += "path_prefix='/%s', name_prefix='%s_'" % \ (pluraldirectory, pluraldirectory) 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, '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) if not self.options.no_test: file_op.copy_file(template='test_controller.py_tmpl', dest=os.path.join('tests', 'functional'), filename='test_'+testname) print resource_command except BadCommand, e: raise BadCommand('An error occurred. %s' % e)
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") 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 ) for name in [pluralname]: name = name.replace("-", "_") validate_name(name) 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) 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)
def command(self): """Main command to create mapfish model""" try: # read layers.ini config = ConfigParser() config.read(['layers.ini']) # check passed layer is in layers.ini sectionName = self.args[0] if not config.has_section(sectionName): raise BadCommand( 'There is no layer section named %s in layers.ini' % \ sectionName) # get layer parameters singular = config.get(sectionName, 'singular') plural = config.get(sectionName, 'plural') table = config.get(sectionName, 'table') epsg = config.get(sectionName, 'epsg') geomColName = config.get(sectionName, 'geomcolumn') if config.has_option(sectionName, 'schema'): schema = config.get(sectionName, 'schema') else: schema = None # get geometry type if not config.has_option(sectionName, 'geomtype'): geomtype = 'Geometry' else: raw_geomtype = config.get(sectionName, 'geomtype') # check if the value is valid (geometries supported by GeoAlchemy) valid_types = ['Geometry', 'Point', 'Curve', 'LineString', 'Polygon', 'MultiPoint', 'MultiLineString', 'MultiPolygon', 'GeometryCollection'] if raw_geomtype in valid_types: geomtype = raw_geomtype else: raise BadCommand('Geometry type "%s" is unknown, valid values are: %s' % (raw_geomtype, valid_types)) fileOp = FileOp(source_dir=os.path.join( os.path.dirname(__file__), 'templates')) try: singularName, singularDirectory = \ fileOp.parse_path_name_args(singular) pluralName, pluralDirectory = \ fileOp.parse_path_name_args(plural) except: raise BadCommand('No egg_info directory was found') # check the name isn't the same as the package basePkg = fileOp.find_dir('model', True)[0] if basePkg.lower() == pluralName.lower(): raise BadCommand( 'Your model name should not be the same as ' 'the package name %s' % basePkg) # validate the name name = pluralName.replace('-', '_') validateName(name) # set template vars modelClass = util.class_name_from_module_name(singularName) # setup the model fileOp.template_vars.update( {'modelClass': modelClass, 'table': table, 'epsg': epsg, 'geomColName': geomColName, 'geomType': geomtype, 'basePkg': basePkg, 'schema': schema}) fileOp.copy_file(template='model.py_tmpl', dest=os.path.join('model', pluralDirectory), filename=name, template_renderer=paste_script_template_renderer) except BadCommand, e: raise BadCommand('An error occurred. %s' % e)
def command(self): """Main command to create a mapfish controller""" try: # read layers.ini config = ConfigParser() config.read(['layers.ini']) # check passed layer is in layers.ini sectionName = self.args[0] if not config.has_section(sectionName): raise BadCommand( 'There is no layer section named %s in layers.ini' % \ sectionName) # get layer parameters singular = config.get(sectionName, 'singular') plural = config.get(sectionName, 'plural') epsg = config.get(sectionName, 'epsg') fileOp = FileOp(source_dir=os.path.join( os.path.dirname(__file__), 'templates')) try: singularName, singularDirectory = \ fileOp.parse_path_name_args(singular) pluralName, pluralDirectory = \ fileOp.parse_path_name_args(plural) except Exception, e: raise BadCommand('No egg_info directory was found') # check the name isn't the same as the package basePkg = fileOp.find_dir('controllers', True)[0] if basePkg.lower() == pluralName.lower(): raise BadCommand( 'Your controller name should not be the same as ' 'the package name %s' % basePkg) # validate the name name = pluralName.replace('-', '_') validateName(name) # set test file name fullName = os.path.join(pluralDirectory, name) if not fullName.startswith(os.sep): fullName = os.sep + fullName testName = fullName.replace(os.sep, '_')[1:] # set template vars modName = name fullModName = os.path.join(pluralDirectory, name) contrClass = util.class_name_from_module_name(name) modelClass = util.class_name_from_module_name(singularName) # setup the controller fileOp.template_vars.update( {'modName': modName, 'fullModName': fullModName, 'singularName': singularName, 'pluralName': pluralName, 'contrClass': contrClass, 'modelClass': modelClass, 'basePkg': basePkg}) fileOp.copy_file(template='controller.py_tmpl', dest=os.path.join('controllers', pluralDirectory), filename=name, template_renderer=paste_script_template_renderer) if not self.options.no_test: fileOp.copy_file(template='test_controller.py_tmpl', dest=os.path.join('tests', 'functional'), filename='test_' + testName, template_renderer=paste_script_template_renderer) resource_command = ("\nTo create the appropriate RESTful mapping, " "add a map statement to your\n") resource_command += ("config/routing.py file in the CUSTOM ROUTES section " "like this:\n\n") resource_command += ('map.connect("/%s/count", controller="%s", ' 'action="count")\n' % (pluralName, pluralName)) resource_command += 'map.resource("%s", "%s")\n' % \ (singularName, pluralName) print resource_command
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)
def command(self): """Main command to create a mapfish controller""" try: fileOp = FileOp(source_dir=os.path.join( os.path.dirname(__file__), 'templates')) try: name, directory = fileOp.parse_path_name_args(self.args[0]) except: raise BadCommand('No egg_info directory was found') # read layers.ini config = ConfigParser() config.read(['layers.ini']) # check passed layer is in layers.ini if not config.has_section(name): raise BadCommand( 'There is no layer named %s in layers.ini' % name) # get layer parameters singularName = config.get(name, 'singular') pluralName = config.get(name, 'plural') epsg = config.get(name, 'epsg') units = config.get(name, 'units') # check the name isn't the same as the package basePkg = fileOp.find_dir('controllers', True)[0] if basePkg.lower() == name.lower(): raise BadCommand( 'Your controller name should not be the same as ' 'the package name %s' % basePkg) # validate the name name = name.replace('-', '_') validateName(name) # set test file name fullName = os.path.join(directory, name) if not fullName.startswith(os.sep): fullName = os.sep + fullName testName = fullName.replace(os.sep, '_')[1:] # set template vars modName = name fullModName = os.path.join(directory, name) contrClass = util.class_name_from_module_name(name) modelClass = util.class_name_from_module_name(singularName) modelTabObj = name + '_table' # setup the controller fileOp.template_vars.update( {'modName': modName, 'fullModName': fullModName, 'singularName': singularName, 'pluralName': pluralName, 'contrClass': contrClass, 'modelClass': modelClass, 'modelTabObj': modelTabObj, 'basePkg': basePkg, 'epsg': epsg, 'units': units}) fileOp.copy_file(template='controller.py_tmpl', dest=os.path.join('controllers', directory), filename=name) if not self.options.no_test: fileOp.copy_file(template='test_controller.py_tmpl', dest=os.path.join('tests', 'functional'), filename='test_' + testName) except BadCommand, e: raise BadCommand('An error occurred. %s' % e)