def saveTextToFile(txt, skipAsk=False, skipOverwrite=False): save = skipAsk and ask('Save to File?') if save: filePath = raw_input('Enter the Path>') if os.path.exists(filePath): again = True while again: again = False p = skipOverwrite and ask('File already Exists, (o)verwrite, (a)ppend, (p)repend or (c)ancel?>', {'o':'o', 'a':'a','c':'c','p':'p',}) if p=='o' or p==False: f = open(filePath, 'w'); f.write(txt); f.close() elif p=='a': f = open(filePath, 'a'); f.write(txt); f.close() elif p=='p': f = open(filePath, 'r'); txt = txt+'\n'+f.read(); f.close() f = open(filePath, 'w'); f.write(txt); f.close() elif p == 'c': pass else: print 'Not Valid Command, Options: o, a, p, c lowercase only!' again = True if not again and p!='c': print 'File saved at \"%s\"!'%filePath else: f = open(p, 'w'); f.write(txt); f.close()
def newProject(toPath): doCopy = True if os.path.exists(toPath): overwrite = ask('Path Already Exists!, Do you want to overwrite?') if overwrite: shutil.rmtree(toPath) #os.makedirs(toPath) else: doCopy = False if doCopy: copy_directory(installPath, toPath, ['.git',], ['.gitignore','.pyc','.InRoot',]) str = open(pjoin(toPath,'src', 'app.yaml'), 'r').read() str = str.replace('{{appname}}', basename(toPath).lower()) str = str.replace('{{handler}}', basename(settings.HANDLER_MAP_FILE)) f = open(os.path.join(toPath,'src', 'app.yaml'), 'w') f.write(str) f.close() str = open(pjoin(toPath, '.project'), 'r').read() str = str.replace('{{appname}}', basename(toPath)) f = open(os.path.join(toPath, '.project'), 'w') f.write(str) f.close() str = open(pjoin(toPath, '.pydevproject'), 'r').read() str = str.replace('{{appname}}', basename(toPath)) str = str.replace('{{appengine_path}}', settings.APPENGINE_PATH) f = open(pjoin(toPath, '.pydevproject'), 'w') f.write(str) f.close() if os.path.exists(pjoin(toPath, 'halicea.py')): os.rename(pjoin(toPath,'halicea.py'), pjoin(toPath,'manage.py')) print 'Project is Created!'
def saveTextToFile(txt, skipAsk=False, skipOverwrite=False): save = skipAsk and ask('Save to File?') if save: filePath = raw_input('Enter the Path>') if os.path.exists(filePath): again = True while again: again = False p = skipOverwrite and ask( 'File already Exists, (o)verwrite, (a)ppend, (p)repend or (c)ancel?>', { 'o': 'o', 'a': 'a', 'c': 'c', 'p': 'p', }) if p == 'o' or p == False: f = open(filePath, 'w') f.write(txt) f.close() elif p == 'a': f = open(filePath, 'a') f.write(txt) f.close() elif p == 'p': f = open(filePath, 'r') txt = txt + '\n' + f.read() f.close() f = open(filePath, 'w') f.write(txt) f.close() elif p == 'c': pass else: print 'Not Valid Command, Options: o, a, p, c lowercase only!' again = True if not again and p != 'c': print 'File saved at \"%s\"!' % filePath else: f = open(p, 'w') f.write(txt) f.close()
def newProject(toPath): doCopy = True if os.path.exists(toPath): overwrite = ask('Path Already Exists!, Do you want to overwrite?') if overwrite: shutil.rmtree(toPath) #os.makedirs(toPath) else: doCopy = False if doCopy: copy_directory(installPath, toPath, [ '.git', ], [ '.gitignore', '.pyc', '.InRoot', ]) str = open(pjoin(toPath, 'src', 'app.yaml'), 'r').read() str = str.replace('{{appname}}', basename(toPath).lower()) str = str.replace('{{handler}}', basename(settings.HANDLER_MAP_FILE)) f = open(os.path.join(toPath, 'src', 'app.yaml'), 'w') f.write(str) f.close() str = open(pjoin(toPath, '.project'), 'r').read() str = str.replace('{{appname}}', basename(toPath)) f = open(os.path.join(toPath, '.project'), 'w') f.write(str) f.close() str = open(pjoin(toPath, '.pydevproject'), 'r').read() str = str.replace('{{appname}}', basename(toPath)) str = str.replace('{{appengine_path}}', settings.APPENGINE_PATH) f = open(pjoin(toPath, '.pydevproject'), 'w') f.write(str) f.close() if os.path.exists(pjoin(toPath, 'halicea.py')): os.rename(pjoin(toPath, 'halicea.py'), pjoin(toPath, 'manage.py')) print 'Project is Created!'
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()
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()