def git_update(data, queue=None): """Perform a git pull in the repository.""" repo_dir = 'repos/{0}/{1}'.format(data["name"], data["repo_name"]) with open(os.devnull, 'w') as devnull: subprocess.Popen( ['git', 'pull', 'origin', 'master'], cwd=repo_dir, stdout=devnull, stderr=devnull ) subprocess.Popen( ['git', 'submodule', 'init'], cwd=repo_dir, stdout=devnull, stderr=devnull ) subprocess.Popen( ['git', 'submodule', 'update'], cwd=repo_dir, stdout=devnull, stderr=devnull ) notify('Pulled down {2} commit(s) for project `{0}/{1}`'.format( data["name"], data["repo_name"], data["commits"] ), queue)
def check_repository_existence(data): """ Check if a repository exists (and the subsequent owner), else, clone down the repository from the url received with the hook. """ logging.info("Checking if repository `{0}/{1}` exists...".format( data["name"], data["repo_name"] )) repo_dir = rel(['repos', data["name"], data["repo_name"]]) if not os.path.isdir(repo_dir): notify('Cloning `{0}/{1}`...'.format(data["name"], data["repo_name"])) with open(os.devnull, 'w') as devnull: subprocess.Popen( [ 'git', 'clone', data["url"], os.sep.join(['repos', data["name"], data["repo_name"]]) ], cwd=BASE_PATH, stdout=devnull, stderr=devnull )
def execute_shell_script(data, queue=None): """Execute the accompanying shell/deploy script for the repo.""" script = '{0}_{1}'.format( data["name"].lower(), data["repo_name"].lower() ) script_path = rel(['scripts']) if os.path.exists(script_path): try: notify('Starting build for job `{0}/{1}` ...'.format( data["name"], data["repo_name"] ), queue) start = time.time() with open(os.devnull, 'w') as devnull: subprocess.Popen( ['./{0}'.format(script)], cwd=script_path, stdout=devnull, stderr=devnull ) end = time.time() - start minutes = end / 60 seconds = end % 60 elapsed = "%ds" % seconds if minutes >= 1: elapsed = "%dm%s" % (minutes, elapsed) notify('Project `{0}/{1}` build in {2} !'.format( data["name"], data["repo_name"], elapsed ), queue) except OSError, excep: exception = str(excep) if exception.startswith('[Errno 2]'): notify('No script to execute. Please create one first!', queue) elif exception.startswith('[Errno 13]'): notify('The script is not executable!', queue) elif exception.startswith('[Errno 8]'): notify('Format error with the script!', queue) else: notify('Uncaught error, calling script: {0}'.format(exception), queue) logging.exception("Job for `{0}/{1}` threw an exception".format( data["name"], data["repo_name"] ))
) end = time.time() - start minutes = end / 60 seconds = end % 60 elapsed = "%ds" % seconds if minutes >= 1: elapsed = "%dm%s" % (minutes, elapsed) notify('Project `{0}/{1}` build in {2} !'.format( data["name"], data["repo_name"], elapsed ), queue) except OSError, excep: exception = str(excep) if exception.startswith('[Errno 2]'): notify('No script to execute. Please create one first!', queue) elif exception.startswith('[Errno 13]'): notify('The script is not executable!', queue) elif exception.startswith('[Errno 8]'): notify('Format error with the script!', queue) else: notify('Uncaught error, calling script: {0}'.format(exception), queue) logging.exception("Job for `{0}/{1}` threw an exception".format( data["name"], data["repo_name"] )) else: notify('Project `{0}/{1}` build in {2}'.format( data["name"], data["repo_name"] ), queue) notify('No build script found for job `{0}/{1}`'.format( data["name"], data["repo_name"] ), queue)