Exemplo n.º 1
0
 def makeModelListFromFile(self, modelFile):
     f = open(modelFile, 'r')
     lines = [x.replace('\n','') for x in f.readlines()]
     modelList = []
 
     m=Model()
     print 'Parsing the File '+modelFile
     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:
             self.setProperties(line, m)
         else:
             modelList.append(m)
             m=Model()
     f.close()
     print 'created Models'+str(modelList)
     return modelList
Exemplo n.º 2
0
 def makeMvc(self, args):
     arg = args[0]
     package = ''
     name =''
     magicLevel = settings.MagicLevel
     modelList = []
     #TODO: set the MagicLevel
     #TODO: make try catch and display proper output if wrong syntax is entered
     if len(args)>1:
         if args[1][:len('path=')]=='path=':
             modelList = self.makeModelListFromFile(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 = self.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 self.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, self.cblPy)
                 else:
                     baseBlock =Block.loadFromFile(mvcTemplateFiles["MBTPath"], self.cblPy, self.render, {'m':m})
                 stream = open(modelFile, 'w')
                 self.renderModel(m, baseBlock, stream, magicType=magicType)
                 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, self.cblPy)
                 else:
                     baseBlock = Block.loadFromFile(mvcTemplateFiles['FBTPath'], self.cblPy, self.render, {'m':m})
                 stream = open(mfPath, 'w')
                 self.renderModelForm(m, baseBlock,stream,magicType)
                 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"], self.cblPy, self.render, {'m':m})
                 stream = open(controllerPath, 'w')
                 self.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:
                     #Find the operations for the templates
                     ops=[]
                     if os.path.exists(mvcTemplateDirs['FRMTMPL_DIR']):
                         ops = [x[:x.rindex('.')] for x in os.listdir(mvcTemplateDirs['FRMTMPL_DIR'])]
                     if ops:
                         for k in ops:
                             templateName = k
                             formTemplatePath = pjoin(mvcTemplateDirs['FRMTMPL_DIR'], templateName+'.txt')
                             viewPath = pjoin(viewFolder, m.Name+'_'+(k=='default' and [''] or [k])[0] +'.html')
                             baseBlock  = Block.loadFromFile(mvcTemplateFiles['VTPath'], self.cblHal, self.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, self.cblHal, self.render,{'m':m})
                             baseBlock.saveToFile(formPath)
                     else: #here the magic will be used and we dont need some special view
                         viewPath = pjoin(viewFolder, m.Name+'.html')
                         baseBlock  = Block.loadFromFile(mvcTemplateFiles['VTPath'], self.cblHal, self.render,{'m':m})
                         baseBlock.saveToFile(viewPath)