Example #1
0
    def deploy(self):
        self.clean()
        if not self.config['init']:
            self.clone(self.url)

        # Read current version's config
        self.config = self.parseConfig(FileSystem.join(self.tmpRepoDir, self.configFileName))

        # Copy current config to config cache
        if FileSystem.delete(self.tmpCacheDir) and FileSystem.createDirectory(self.tmpCacheDir):
            if FileSystem.copy(FileSystem.join(self.tmpRepoDir, self.configFileName), self.tmpCacheDir):
                print('Cached configuration file.')

        # Create root directory if configured
        if self.config['root']:
            if FileSystem.createDirectory(self.config['root']):
                print('Created root directory as configured.')

        if self.config['actions']:
            for actions in self.config['actions']:
                if actions['type'] == 'move':
                    to_path = FileSystem.join(self.config['root'], actions['to'])
                    to_path = FileSystem.resolve(to_path)
                    if actions['to'][-1:] == '/' and not FileSystem.dirExists(to_path):
                        FileSystem.createDirectory(to_path)

                    from_path = FileSystem.join(self.tmpRepoDir, actions['from'])
                    from_path = FileSystem.resolve(from_path)
                    print('ACTION: MOVING.', from_path, to_path)
                    FileSystem.move(from_path, to_path)
                    print('OK: Moved.')
                elif actions['type'] == 'mkdir':
                    path = FileSystem.join(self.config['root'], actions['path'])
                    print('ACTION: MKDIR: ' + path)
                    if not FileSystem.exists(path):
                        if FileSystem.createDirectory(path):
                            print('OK: Directory created.')
                        else:
                            print('ERROR: Could not create directory.')
                    else:
                        print('ERROR: Already exists. Nothing to do.')
                elif actions['type'] == 'delete':
                    path = FileSystem.join(self.config['root'], actions['path'])
                    if not FileSystem.exists(path):
                        print('Path marked for deletion does not exits. Nothing to do.')
                    else:
                        print('ACTION: DELETING ' + path)
                        if FileSystem.delete(path):
                            print('OK: File or directory deleted')
                        else:
                            print('ERROR: Could not delete path: '+path)

        self.runScripts('start')

        # Delete TMP folder
        if FileSystem.delete(self.tmpRepoDir):
            print('Successfully deleted temporary repository directory.')

        return True
Example #2
0
 def rootAndResolve(self, path):
     path = FileSystem.join(self.config['root'], path)
     return FileSystem.resolve(path)