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
def __init__(self, type_of_event, branch, url, keypair, git_init_url=None): self.type = type_of_event self.branch = branch self.url = url self.tmpDir = '/tmp/ferrymang' self.tmpRepoDir = FileSystem.join(self.tmpDir, 'repository') self.tmpCacheDir = FileSystem.join(self.tmpDir, 'cache') self.gitInitUrl = git_init_url or '' self.Keypair = Keypair('git', keypair['pubkpath'], keypair['prvkpath'], keypair['pkpasswd']) FileSystem.createDirectory(self.tmpDir) self.config = self.loadCachedConfig() self.dispatch()
def clone(self, url): FileSystem.delete(self.tmpRepoDir) if FileSystem.createDirectory(self.tmpRepoDir): print('Downloading repository...', url) repository = clone_repository(url, self.tmpRepoDir, credentials=self.Keypair, checkout_branch=self.branch) print('Done.') return not repository.is_empty return False