예제 #1
0
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()
예제 #2
0
 def delete(self, pname):
     print 'This paths will be permanently deleted'
     for key in self.packageStructure.keys():
         if key.find('_')>0:
             destName=dType=''
             destName, dType = key.split('_')
             destName=self.packageStructure[key].replace('${package}', os.path.sep.join(pname.split('.')))
 
             if dType=='d':
                 if os.path.exists(destName):
                     print destName
                     dirtree.tree(destName, ' ', print_files=True, depth=3)
             else:
                 if os.path.exists(destName):
                     print destName
     if ask('Are you sure you want to delete the Package %s?'%pname, input=self.input_method):
         pcks = projectManager.currentProject.packages
         for key in self.packageStructure.keys():
             if key.find('_')>0:
                 destName=dType=''
                 destName, dType = key.split('_')
                 destName=self.packageStructure[key].replace('${package}', os.path.sep.join(pname.split('.')))
                 if dType=='d':
                     if os.path.exists(destName):
                         print 'removing %s directory'%destName
                         shutil.rmtree(destName)
                 else:
                     if os.path.exists(destName):
                         print 'removing %s file'%destName
                         os.remove(destName)
         print 'Package %s was removed'%pname
예제 #3
0
def delete(pname):
    handlermapblock1 = pname + settings.CONTROLLER_MODULE_SUFIX
    handlermapblock2 = pname
    handlermapimport = 'from ' + basename(
        settings.CONTROLLERS_DIR
    ) + ' import ' + pname + settings.CONTROLLER_MODULE_SUFIX

    print 'This paths will be permanently deleted'
    for key in packageStructure.keys():
        if key.find('_') > 0:
            destName = dType = ''
            destName, dType = key.split('_')
            destName = packageStructure[key].replace(
                '${package}', os.path.sep.join(pname.split('.')))

            if dType == 'd':
                if os.path.exists(destName):
                    print destName
                    dirtree.tree(destName, ' ', print_files=True, depth=3)
            else:
                if os.path.exists(destName):
                    print destName
    if ask('Are you sure you want to delete the Package %s?' % pname):
        for key in packageStructure.keys():
            if key.find('_') > 0:
                destName = dType = ''
                destName, dType = key.split('_')
                destName = packageStructure[key].replace(
                    '${package}', os.path.sep.join(pname.split('.')))
                if dType == 'd':
                    if os.path.exists(destName):
                        print 'removing %s directory' % destName
                        shutil.rmtree(destName)
                else:
                    if os.path.exists(destName):
                        print 'removing %s file' % destName
                        os.remove(destName)
        handlerMap = Block.loadFromFile(settings.HANDLER_MAP_FILE, cblPy)
        impLine = handlerMap['imports'][handlermapimport]
        #remove the import
        if impLine:
            handlerMap['imports'].remove(impLine)
        else:
            print 'import \'', handlermapimport, '\'does not exists'
        #Remove the urlMap Block
        mapBl = handlerMap['ApplicationControllers'][handlermapblock2]
        if mapBl:
            print 'removing block:'
            print str(mapBl)
            handlerMap['ApplicationControllers'].remove(mapBl)
        mapBl = handlerMap['ApplicationControllers'][handlermapblock1]
        if mapBl:
            print 'removing block:'
            print str(mapBl)
            handlerMap['ApplicationControllers'].remove(mapBl)
        handlerMap.saveToFile(settings.HANDLER_MAP_FILE)
        print 'Package %s was removed' % pname
예제 #4
0
def delete(pname):
    handlermapblock1 = pname+settings.CONTROLLER_MODULE_SUFIX
    handlermapblock2 = pname
    handlermapimport = 'from '+basename(settings.CONTROLLERS_DIR)+' import '+pname+settings.CONTROLLER_MODULE_SUFIX
    
    print 'This paths will be permanently deleted'
    for key in packageStructure.keys():
        if key.find('_')>0:
            destName=dType=''
            destName, dType = key.split('_')
            destName=packageStructure[key].replace('${package}', os.path.sep.join(pname.split('.')))
            
            if dType=='d':
                if os.path.exists(destName):
                    print destName
                    dirtree.tree(destName, ' ', print_files=True, depth=3)
            else:
                if os.path.exists(destName):
                    print destName
    if ask('Are you sure you want to delete the Package %s?'%pname):
        for key in packageStructure.keys():
            if key.find('_')>0:
                destName=dType=''
                destName, dType = key.split('_')
                destName=packageStructure[key].replace('${package}', os.path.sep.join(pname.split('.')))
                if dType=='d':
                    if os.path.exists(destName):
                        print 'removing %s directory'%destName
                        shutil.rmtree(destName)
                else:
                    if os.path.exists(destName):
                        print 'removing %s file'%destName
                        os.remove(destName)
        handlerMap = Block.loadFromFile(settings.HANDLER_MAP_FILE, cblPy)
        impLine = handlerMap['imports'][handlermapimport]
        #remove the import
        if impLine:
            handlerMap['imports'].remove(impLine)
        else:
            print 'import \'', handlermapimport, '\'does not exists'
        #Remove the urlMap Block
        mapBl = handlerMap['ApplicationControllers'][handlermapblock2]
        if mapBl:
            print 'removing block:'
            print str(mapBl)
            handlerMap['ApplicationControllers'].remove(mapBl)
        mapBl = handlerMap['ApplicationControllers'][handlermapblock1]
        if mapBl:
            print 'removing block:'
            print str(mapBl) 
            handlerMap['ApplicationControllers'].remove(mapBl)
        handlerMap.saveToFile(settings.HANDLER_MAP_FILE)
        print 'Package %s was removed'%pname
예제 #5
0
def pack(packageName, destination):
    if os.path.exists(destination):
        if os.path.isdir(destination):
            if ask('Directory Already Exists, All contents will be deleted, Do you want to continue?'):
                shutil.rmtree(destination)
                os.makedirs(destination)
                __pack__(packageName, destination)
            else:
                return
        else:
            print 'There is file with the same name, Cannot continue!'
            return
    else:
        __pack__(packageName, destination)
예제 #6
0
def pack(packageName, destination):
    if os.path.exists(destination):
        if os.path.isdir(destination):
            if ask('Directory Already Exists, All contents will be deleted, Do you want to continue?'
                   ):
                shutil.rmtree(destination)
                os.makedirs(destination)
                __pack__(packageName, destination)
            else:
                return
        else:
            print 'There is file with the same name, Cannot continue!'
            return
    else:
        __pack__(packageName, destination)
예제 #7
0
 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:
         os.makedirs(toPath)
         os.makedirs(pjoin(toPath, 'src'))
         copy_directory(installPath, pjoin(toPath, 'src'), ['.git',], ['.pyc','.InRoot',])
 
         #set app.yaml file
         str = open(pjoin(toPath,'src', 'app.yaml'), 'r').read()
         str = str.replace('baseproject', basename(toPath).lower())
         f = open(os.path.join(toPath,'src', 'app.yaml'), 'w')
         f.write(str)
         f.close()
 
         #set the manage.py File
         str = open(pjoin(rooot, "halicea_manage.py"), 'r').read()
         str = str.replace('{{hal_path}}', rooot)
         f= open(pjoin(toPath,"manage.py"),'w')
         f.write(str)
         f.close()
 
         #set the .halProject File
         str = open(pjoin(rooot, '.halProject'), 'r').read()
         str = str.replace('baseProject', 'src')
         f = open(pjoin(toPath, '.halProject'), 'w')
         f.write(str)
         f.close()    
         
         #set the .halPackages File
         str = open(pjoin(rooot, '.halPackages'), 'r').read()
         f = open(pjoin(toPath, '.halPackages'), 'w')
         f.write(str)
         f.close()  
         
         print 'Project is Created!'
예제 #8
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)