Esempio n. 1
0
def makeModelFromFile(modelFile):
    f = open(modelFile, 'r')
    lines = [x.replace('\n','') for x in f.readlines()]
    modelList = []

    m=Model()
    for line in lines:
        if not m.Name:
            m.Name = line[line.rindex('.')+1:]
            m.Package = line[:line.rindex('.')]
            m.InheritsFrom = inherits_from
        elif line:
            setProperties(line, m)
        else:
            modelList.append(m)
            m=Model()
    f.close()
    return modelList
Esempio n. 2
0
def makeModelFromFile(modelFile):
    f = open(modelFile, 'r')
    lines = [x.replace('\n', '') for x in f.readlines()]
    modelList = []

    m = Model()
    for line in lines:
        if not m.Name:
            m.Name = line[line.rindex('.') + 1:]
            m.Package = line[:line.rindex('.')]
            m.InheritsFrom = inherits_from
        elif line:
            setProperties(line, m)
        else:
            modelList.append(m)
            m = Model()
    f.close()
    return modelList
Esempio n. 3
0
def makeMvc(args):
    arg = args[0]
    package = ''
    name = ''
    magicLevel = settings.MagicLevel
    modelList = []
    #TODO: set the MagicLevel
    #TODO: make try catch and display proper output if wrong sintax is entered
    if len(args) > 1:
        if args[1][:len('path=')] == 'path=':
            modelList = makeModelFromFile(args[1][len('path='):])
        else:
            name = args[1][args[1].rindex('.') + 1:]
            package = args[1][:args[1].rindex('.')]
    if len(args) > 2:
        magicLevel = int(args[2])
    magicType = 'magic' + str(magicLevel)

    mvcTemplateFiles = mvcPaths.getTemplateFiles(magicType)
    mvcTemplateDirs = mvcPaths.getTemplatesDirs(magicType)
    if not modelList:
        m = Model()
        #TODO: Validation needs to be added here
        if not (name and package):
            m.Package = ask('PackageName: ', '*')
            m.Name = ask('ModelName: ', '*')
        else:
            m.Package = package
            m.Name = name

        if 'm' in arg:
            #TODO: set to according to an argument
            m.InheritsFrom = inherits_from
            i = 0
            print '.' * 14 + 'class ' + m.FullName + '(' + m.InheritsFrom + '):'
            p = True  #Do-While
            while p:
                p = raw_input('Property' + str(i) + '>' + '.' *
                              (9 - len(str(i))))
                if setProperties(p, m): i += 1


#        else:
#            #Create a Model instance out of specific class if exists
#            raise NotImplemented('This feature is not implemented yet')
        modelList.append(m)

    for m in modelList:
        if ask('Save ' + m.FullName + '?'):
            if 'm' in arg:
                #Model setup
                modelFile = locators.LocateModelModule(m.Package)
                baseBlock = None
                if exists(modelFile):
                    baseBlock = Block.loadFromFile(modelFile, cblPy)
                else:
                    baseBlock = Block.loadFromFile(mvcTemplateFiles["MBTPath"],
                                                   cblPy, render, {'m': m})
                stream = open(modelFile, 'w')
                renderModel(m, baseBlock, stream, magicType=magicType, arg)
                stream.close()
                #End Model Setup
            if 'f' in arg:
                #ModelForm Setup
                mfPath = locators.LocateFormModelModule(m.Package)
                baseBlock = None
                if exists(mfPath):
                    baseBlock = Block.loadFromFile(mfPath, cblPy)
                else:
                    baseBlock = Block.loadFromFile(mvcTemplateFiles['FBTPath'],
                                                   cblPy, render, {'m': m})
                stream = open(mfPath, 'w')
                renderModelForm(m, baseBlock, stream, magicType, arg)
                stream.close()
                #End ModelForm Setup
            if 'c' in arg:
                #Controller Setup
                controllerPath = locators.LocateControllerModule(m.Package)
                baseBlock = None
                if exists(controllerPath):
                    baseBlock = Block.loadFromFile(controllerPath, cblPy)
                else:
                    baseBlock = Block.loadFromFile(mvcTemplateFiles["CBTPath"],
                                                   cblPy, render, {'m': m})
                stream = open(controllerPath, 'w')
                renderController(m, baseBlock, stream, magicType, arg)
                stream.close()
                #End Controller Setup
            if 'v' in arg:
                viewFolder = locators.LocatePagesDir(m.Package)
                formFolder = locators.LocateFormsDir(m.Package)
                #if we only want an empty view
                if not m:
                    pass
                #if we want to generate the view by the model provided
                else:
                    #if we dont want to use magic but to generate the default code instead
                    if not magicLevel:
                        for k, v in operations:
                            templateName = isinstance(
                                v['method'],
                                str) and v['method'] or v['method'].__name__
                            formTemplatePath = pjoin(
                                mvcTemplateDirs['FRMTMPL_DIR'],
                                templateName + '.txt')
                            viewPath = pjoin(
                                viewFolder, m.Name + '_' +
                                (k == 'default' and [''] or [k])[0] + '.html')
                            baseBlock = Block.loadFromFile(
                                mvcTemplateFiles['VTPath'], cblHal, render, {
                                    'm': m,
                                    'formTemplate': m.Name + 'Form_' + k
                                })
                            baseBlock.saveToFile(viewPath)

                            formPath = pjoin(
                                formFolder, m.Name +
                                settings.FORM_VIEW_SUFFIX + '_' + k + '.html')
                            baseBlock = Block.loadFromFile(
                                formTemplatePath, cblHal, render, {'m': m})
                            baseBlock.saveToFile(formPath)
                    else:  #here the magic will be used and we dont need some special view
                        pass
            if 'h' in arg:
                #HandlerMap Setup
                baseBlock = Block.loadFromFile(
                    config.proj_settings.HANDLER_MAP_FILE, cblPy)
                stream = open(config.proj_settings.HANDLER_MAP_FILE, 'w')
                renderHandlerMap(m, baseBlock, stream, magicLevel, arg)
                stream.close()
Esempio n. 4
0
def makeMvc(args):
    arg = args[0]
    package = ''
    name =''
    magicLevel = settings.MagicLevel
    modelList = []
    #TODO: set the MagicLevel
    #TODO: make try catch and display proper output if wrong sintax is entered
    if len(args)>1:
        if args[1][:len('path=')]=='path=':
            modelList = makeModelFromFile(args[1][len('path='):])
        else:
            name = args[1][args[1].rindex('.')+1:]
            package = args[1][:args[1].rindex('.')] 
    if len(args)>2:
        magicLevel = int(args[2])
    magicType = 'magic'+str(magicLevel)
    
    mvcTemplateFiles = mvcPaths.getTemplateFiles(magicType)
    mvcTemplateDirs = mvcPaths.getTemplatesDirs(magicType)
    if not modelList:
        m = Model()
        #TODO: Validation needs to be added here
        if not (name and package):
            m.Package = ask('PackageName: ', '*')
            m.Name = ask('ModelName: ', '*')
        else:
            m.Package = package
            m.Name = name
    
        if 'm' in arg:
            #TODO: set to according to an argument
            m.InheritsFrom = inherits_from
            i = 0
            print '.'*14+'class '+m.FullName+'('+m.InheritsFrom+'):'
            p = True #Do-While
            while p:
                p = raw_input('Property'+str(i)+'>'+'.'*(9-len(str(i))))
                if setProperties(p, m): i+=1
#        else:
#            #Create a Model instance out of specific class if exists
#            raise NotImplemented('This feature is not implemented yet')
        modelList.append(m)
        
    for m in modelList:
        if ask('Save '+m.FullName+'?'):
            if 'm' in arg:
                #Model setup
                modelFile = locators.LocateModelModule(m.Package)
                baseBlock = None
                if exists(modelFile): 
                    baseBlock = Block.loadFromFile(modelFile, cblPy)
                else:
                    baseBlock =Block.loadFromFile(mvcTemplateFiles["MBTPath"], cblPy, render, {'m':m})
                stream = open(modelFile, 'w')
                renderModel(m, baseBlock, stream, magicType=magicType, arg)
                stream.close()
                #End Model Setup
            if 'f' in arg:
                #ModelForm Setup
                mfPath = locators.LocateFormModelModule(m.Package)
                baseBlock = None
                if exists(mfPath):
                    baseBlock = Block.loadFromFile(mfPath, cblPy)
                else:
                    baseBlock = Block.loadFromFile(mvcTemplateFiles['FBTPath'], cblPy, render, {'m':m})
                stream = open(mfPath, 'w')
                renderModelForm(m, baseBlock,stream,magicType, arg)
                stream.close()
                #End ModelForm Setup
            if 'c' in arg:
                #Controller Setup
                controllerPath = locators.LocateControllerModule(m.Package)
                baseBlock = None
                if exists(controllerPath):
                    baseBlock = Block.loadFromFile(controllerPath, cblPy)
                else:
                    baseBlock = Block.loadFromFile(mvcTemplateFiles["CBTPath"], cblPy, render, {'m':m})
                stream = open(controllerPath, 'w')
                renderController(m, baseBlock, stream, magicType, arg)
                stream.close()
                #End Controller Setup
            if 'v' in arg:
                viewFolder = locators.LocatePagesDir(m.Package)
                formFolder =locators.LocateFormsDir(m.Package)
                #if we only want an empty view
                if not m:
                    pass
                #if we want to generate the view by the model provided
                else:
                    #if we dont want to use magic but to generate the default code instead
                    if not magicLevel:
                        for k, v in operations:
                            templateName = isinstance(v['method'],str) and v['method'] or v['method'].__name__
                            formTemplatePath = pjoin(mvcTemplateDirs['FRMTMPL_DIR'], templateName+'.txt')
                            viewPath = pjoin(viewFolder, m.Name+'_'+(k=='default' and [''] or [k])[0] +'.html')
                            baseBlock  = Block.loadFromFile(mvcTemplateFiles['VTPath'], cblHal, render,{'m':m,'formTemplate': m.Name+'Form_'+k })
                            baseBlock.saveToFile(viewPath)
                            
                            formPath = pjoin(formFolder, m.Name+settings.FORM_VIEW_SUFFIX+'_'+k+'.html')
                            baseBlock  = Block.loadFromFile(formTemplatePath, cblHal, render,{'m':m})
                            baseBlock.saveToFile(formPath)
                    else: #here the magic will be used and we dont need some special view
                        pass
            if 'h' in arg:
                #HandlerMap Setup
                baseBlock = Block.loadFromFile(config.proj_settings.HANDLER_MAP_FILE, cblPy)
                stream = open(config.proj_settings.HANDLER_MAP_FILE, 'w')
                renderHandlerMap(m, baseBlock, stream, magicLevel, arg)
                stream.close()