Ejemplo n.º 1
0
 def __buildCodeFiles(self):
     templateFiles = FileUtils().getFileMatches(self.TemplateDir,
                                                'module_*.tpl')
     for tpl in templateFiles:
         FileUtils.copyFile(
             self.TemplateDir + tpl, self.ModuleDir +
             tpl.replace('module', self.ModuleName).replace('.tpl', '.py'))
Ejemplo n.º 2
0
 def __init__(self, moduleName):
     fsep = PlatformProperty.FileSep
     self.ModuleName = moduleName.lower()
     self.ProjectBaseDir = FileUtils.getWorkingDir() + fsep
     self.ModuleBaseDir = 'app' + fsep + 'modules' + fsep
     self.ModuleDir = self.ModuleBaseDir + self.ModuleName + fsep
     self.ConfDir = 'app' + fsep + 'conf' + fsep
     self.TemplateDir = FileUtils.getParentDir(
         __file__) + fsep + 'templates' + fsep
Ejemplo n.º 3
0
 def __buildManifest(self):
     sep = PlatformProperty.FileSep
     sourceFile = self.TemplateDir+'config'+sep+'project_base_manifest.tpl'
     targetFile = self.ProjectBaseDir+'app'+sep+'conf'+sep+self.ProjectName.lower()+'_manifest.ini'
     FileUtils.copyFile(sourceFile, targetFile)
     configManager = ConfigManager(targetFile)
     configManager.setValue('APP', 'AppName', self.ProjectName)
     configManager.setValue('APP', 'Version', {'MAJOR': '0.1', 'MINOR': '.0'})
     configManager.setValue('PYTHON', 'RuntimeVersions', '['+PlatformProperty.getPythonVersion()+']')
     configManager.save()
Ejemplo n.º 4
0
 def __init__(self, moduleName):
     fsep = PlatformProperty.FileSep
     self.ModuleName = moduleName.lower()
     self.ProjectBaseDir = FileUtils.getWorkingDir()+fsep
     projectDirArray = self.ProjectBaseDir.strip(fsep).split(fsep)
     self.ProjectName = projectDirArray[len(projectDirArray)-1].lower()
     self.ModuleBaseDir = 'app'+fsep+'modules'+fsep
     self.ModuleDir = self.ModuleBaseDir+self.ModuleName+fsep
     self.ConfDir = 'app'+fsep+'conf'+fsep
     self.TemplateDir = FileUtils.getParentDir(__file__)+fsep+'templates'+fsep
Ejemplo n.º 5
0
    def __init__(self):
        sep = PlatformProperty.FileSep
        self.ProjectBaseDir = FileUtils.getParentDir(__file__) + sep
        projectDirArray = self.ProjectBaseDir.strip(sep).split(sep)
        self.ProjectName = projectDirArray[len(projectDirArray) - 1].lower()
        self.DistDir = self.ProjectBaseDir + 'dist' + sep

        if not FileUtils().dirExists(self.DistDir):
            FileUtils().createDir(self.DistDir)
            FileUtils().touchFile(self.DistDir + 'build.log')
Ejemplo n.º 6
0
 def __buildManifest(self):
     fsep = PlatformProperty.FileSep
     manifestFilename = self.ProjectBaseDir+'app'+fsep+'conf'+fsep+self.ModuleName.lower()+'_manifest.ini'
     FileUtils.copyFile(self.TemplateDir+'modBaseManifest.tpl', manifestFilename)
     manFile = open(manifestFilename, 'r')
     fileContents = manFile.read()
     manFile.close()
     fileContents = fileContents.replace('{{MODNAME}}', self.ModuleName.lower())
     manFile = open(manifestFilename, 'w')
     manFile.write(fileContents)
     manFile.close()
Ejemplo n.º 7
0
 def __buildCodeFiles(self):
     templateFiles = FileUtils().getFileMatches(self.TemplateDir, 'module_*.tpl')
     for tpl in templateFiles:
         codeFilename = self.ModuleDir+tpl.replace('module', self.ModuleName).replace('.tpl', '.py')
         FileUtils.copyFile(self.TemplateDir+tpl, codeFilename)
         codeFile = open(codeFilename, 'r')
         fileContents = codeFile.read()
         codeFile.close()
         fileContents = fileContents.replace('{{MODNAME_OBJECT}}', NameConverter.getObjectName(self.ModuleName))
         fileContents = fileContents.replace('{{MODNAME}}', NameConverter.getObjectName(self.ModuleName))
         codeFile = open(codeFilename, 'w')
         codeFile.write(fileContents)
         codeFile.close()
Ejemplo n.º 8
0
 def run():
     sep = PlatformProperty.FileSep
     projectBaseDir = FileUtils().getWorkingDir() + sep
     if FileUtils().dirExists(projectBaseDir + 'app'):
         cmd = 'build/build.py'
         try:
             CommandRunner().run(command=cmd)
         except CommandError as ce:
             print(ce.message)
             exit(1)
     else:
         raise RuntimeError(
             'You need to be at the top level directory of your project "project_base", when running build option'
         )
Ejemplo n.º 9
0
 def __buildTestFiles(self):
     fsep = PlatformProperty.FileSep
     modTestDir = self.ProjectBaseDir+'test'+fsep+'app'+fsep+'modules'+fsep+self.ModuleName+fsep
     FileUtils.createDir(modTestDir)
     FileUtils.touchFile(modTestDir+'test_'+self.ModuleName+'.py')
     FileUtils.touchFile(modTestDir+'test_'+self.ModuleName+'_controllers.py')
     FileUtils.touchFile(modTestDir+'test_'+self.ModuleName+'_services.py')
Ejemplo n.º 10
0
 def __init__(self, name):
     self.ProjectName = name
     self.AppName = name.lower()
     self.ProjectBaseDir = self.ProjectName + PlatformProperty.FileSep
     self.TemplateDir = FileUtils.getParentDir(
         __file__
     ) + PlatformProperty.FileSep + 'templates' + PlatformProperty.FileSep
Ejemplo n.º 11
0
    def __createDatabaseScripts(self):
        s = PlatformProperty.FileSep

        objectScripts = [
            'dblinks.sql', 'synonyms.sql', 'sequences.sql', 'types.sql',
            'queues.sql', 'tables.sql', 'triggers.sql', 'views.sql',
            'indexes.sql', 'constraints_ck.sql', 'constraints_pk.sql',
            'constraints_uk.sql', 'constraints_fk.sql'
        ]
        dataScripts = ['seed.sql']

        for obj in objectScripts:
            FileUtils.touchFile(self.ProjectBaseDir + 'app' + s + 'database' +
                                s + 'ddl' + s + 'objects' + s + obj)

        for data in dataScripts:
            FileUtils.touchFile(self.ProjectBaseDir + 'app' + s + 'database' +
                                s + 'data' + s + data)

        FileUtils.copyFile(
            self.TemplateDir + 'config' + s + 'database-userInfo.tpl',
            self.ProjectBaseDir + 'app' + s + 'database' + s + 'user' + s +
            'user_info.ini')
        FileUtils.copyFile(
            self.TemplateDir + 'config' + s + 'database-userPrivs.tpl',
            self.ProjectBaseDir + 'app' + s + 'database' + s + 'user' + s +
            'user_privs.ini')
        # REPLACE TOKENS IN INFO FILE
        iniFile = open(
            self.ProjectBaseDir + 'app' + s + 'database' + s + 'user' + s +
            'user_info.ini', 'r')
        fileContents = iniFile.read()
        iniFile.close()
        fileContents = fileContents.replace('{{APPNAME}}',
                                            self.AppName.upper())
        iniFile = open(
            self.ProjectBaseDir + 'app' + s + 'database' + s + 'user' + s +
            'user_info.ini', 'w')
        iniFile.write(fileContents)
        iniFile.close()
        # REPLACE TOKENS IN PRIV FILE
        iniFile = open(
            self.ProjectBaseDir + 'app' + s + 'database' + s + 'user' + s +
            'user_privs.ini', 'r')
        fileContents = iniFile.read()
        iniFile.close()
        fileContents = fileContents.replace('{{APPNAME}}',
                                            self.AppName.upper())
        iniFile = open(
            self.ProjectBaseDir + 'app' + s + 'database' + s + 'user' + s +
            'user_privs.ini', 'w')
        iniFile.write(fileContents)
        iniFile.close()
Ejemplo n.º 12
0
 def __validate(self):
     if not FileUtils.dirExists(self.ModuleBaseDir):
         message = """ It does not appear you are in your project directory.  This command must be run from within your project directory.
         If you are inside your project directory, then you are getting this error because your project was not initialized as modular. To
         make it modular.  Navigate to your project base directory and run the following:
         
         pylegos project modularize --name <project name>
         
         """
         raise RuntimeError(message)
Ejemplo n.º 13
0
 def __buildCodeFiles(self):
     sep = PlatformProperty.FileSep
     appDir = self.ProjectBaseDir+sep+'app'+sep
     appName = self.ProjectName.lower()
     templateFiles = FileUtils().getFileMatches(self.TemplateDir+'code'+sep, 'app*.tpl')
     for tf in templateFiles:
         file = open(self.TemplateDir+'code'+sep+tf, 'r')
         fileContent = file.read()
         file.close()
         fileContent = fileContent.replace('{{APPNAME_OBJECT}}', NameConverter.getObjectName(self.AppName))
         codeFile = open(appDir+tf.replace('app', self.AppName).replace('.tpl', '.py'), 'w')
         codeFile.write(fileContent)
         codeFile.close()
Ejemplo n.º 14
0
 def modularize(self):
     sep = PlatformProperty.FileSep
     modDir = self.ProjectBaseDir+'app'+sep+'modules'
     modTestDir = self.ProjectBaseDir+'test'+sep+'app'+sep+'modules'
     if not FileUtils.dirExists(modDir):
         FileUtils.createDir(modDir)
     if not FileUtils.dirExists(modTestDir):
         FileUtils.createDir(modTestDir)
Ejemplo n.º 15
0
 def __buildModDir(self):
     FileUtils.createDir(self.ModuleBaseDir+self.ModuleName)
Ejemplo n.º 16
0
class TestFileUtils(TestCase):

    Sut = FileUtils()

    def test_pathUtils(self):

        pd = self.Sut.getParentDir(filePath=__file__)
        self.assertEqual(
            '/Users/gchristiansen/projects/pyLegos/tests/velexio/pylegos/core',
            pd)

        pd = self.Sut.getAppBase()
        self.assertEqual(
            '/Users/gchristiansen/projects/pyLegos/tests/velexio/pylegos', pd)

        self.assertTrue(
            self.Sut.dirExists('/Users/gchristiansen/projects/pyLegos'),
            'Method dirExists determined existing dir does not exist')
        self.assertFalse(
            self.Sut.dirExists(
                '/Users/gchristiansen/projects/pyLegos/xxxpylegos'),
            'Method dirExists returned True on a non-existent directory')
        self.assertFalse(
            self.Sut.dirExists(
                '/Users/gchristiansen/projects/pyLegos/pylegos/tests/test_FileUtils.py'
            ), 'Method dirExists returned True on a check against a file')

        self.assertTrue(
            self.Sut.fileExists(__file__),
            'Method fileExists returned false file that DOES exist')
        self.assertFalse(
            self.Sut.fileExists('/Users/gchristiansen/projects/pyLegos/tests'),
            'Method fileExists returned true on dir')
        self.assertFalse(
            self.Sut.fileExists(
                '/Users/gchristiansen/projects/pyLegos/tests/xxxx.py'),
            'Method fileExists returned true file that DOES NOT exist')

        # Create some tmp dirs
        self.Sut.removeDirMatch(dirPath='/tmp', pattern='conf*')
        self.Sut.createDirectory('/tmp/conf')
        self.Sut.createDirectory('/tmp/config')

        self.assertEqual(
            len(self.Sut.getDirMatches(baseDir='/tmp', pattern='conf*')), 2,
            'Method getDirMatches returns more than expected')
        self.assertEqual(
            self.Sut.getDirMatches(baseDir='/tmp', pattern='conf')[0], 'conf',
            'Method getDirMatches does not return full path')

    def test_DeleteFiles(self):
        testFiles = ['/tmp/app_test1', '/tmp/app_test2']
        for tf in testFiles:
            self.Sut.touchFile(tf)
        self.Sut.deleteFiles(baseDir='/tmp', pattern='app*')
        for file in listdir('/tmp'):
            if fnmatch(file, 'app*'):
                self.fail()

    def test_GetFileMatches(self):
        testFiles = ['/tmp/app_test1', '/tmp/app_test2', '/tmp/vapp_test1']
        for tf in testFiles:
            self.Sut.touchFile(tf)
        fileList = self.Sut.getFileMatches(baseDir='/tmp', pattern='app*')
        self.assertEqual(len(fileList), 2)
Ejemplo n.º 17
0
 def __copyModDefTemplate(self):
     s = PlatformProperty.FileSep
     FileUtils.copyFile(self.TemplateDir+'config'+s+'modelDef.tpl', self.ProjectBaseDir+'build'+s+'def-files'+s+'model.def')
     FileUtils.copyFile(self.TemplateDir+'config'+s+'model-def.README', self.ProjectBaseDir+'build'+s+'def-files'+s+'model-def.README')
Ejemplo n.º 18
0
 def __buildAppBinFile(self):
     sep = PlatformProperty.FileSep
     appName = self.ProjectName.lower()
     tplFile = 'app.sh'
     FileUtils.copyFile(self.TemplateDir+'launchers'+sep+tplFile, self.ProjectBaseDir+'bin'+sep+appName)
Ejemplo n.º 19
0
 def __buildConfFile(self):
     sep = PlatformProperty.FileSep
     appDir = self.ProjectBaseDir+'app'+sep
     FileUtils.copyFile(self.TemplateDir+'config'+sep+'app.ini', appDir+'conf'+sep+self.AppName+'.ini')
Ejemplo n.º 20
0
 def __validate(self):
     if FileUtils.dirExists(self.ProjectName):
         raise RuntimeError('A project by that name already exists')
Ejemplo n.º 21
0
 def __buildConfFile(self):
     FileUtils.copyFile(self.TemplateDir+'module.ini', self.ConfDir+self.ModuleName+'.ini')
Ejemplo n.º 22
0
 def __createBuildFiles(self):
     s = PlatformProperty.FileSep
     FileUtils.copyFile(self.TemplateDir+'code'+s+'build.py', self.ProjectBaseDir+'build'+s+'build.py')
Ejemplo n.º 23
0
    def __buildDirTree(self, isSimple):
        s = PlatformProperty.FileSep
        databaseDirs = ['database'+s+'ddl'+s+'objects',
                        'database'+s+'ddl'+s+'packages',
                        'database'+s+'data',
                        'database'+s+'user']
        containerDirs = ['build', 'test', 'app', 'dist']
        testDir = self.ProjectBaseDir+'test'+s
        appDirs = ['lib',
                   'conf',
                   'modules']
        FileUtils.createDir(self.ProjectName)
        for cDir in containerDirs:
            FileUtils.createDir(self.ProjectBaseDir+cDir)

        FileUtils.createDir(testDir+'app'+s+'lib')
        FileUtils.createDir(self.ProjectBaseDir+'build'+s+'def-files')

        for dDir in databaseDirs:
            FileUtils.createDir(self.ProjectBaseDir+'dist'+s+dDir)
            FileUtils.createDir(self.ProjectBaseDir+'app'+s+dDir)

        for appDir in appDirs:
            if appDir.endswith('modules'):
                if not isSimple:
                    FileUtils.createDir(self.ProjectBaseDir+'app'+s+appDir)
                    FileUtils.createDir(testDir+'app'+s+'modules')
            else:
                FileUtils.createDir(self.ProjectBaseDir+'app'+s+appDir)