From 9dc4d6c7b6dcbfaf613fbdf853b0d2777b9c825c Mon Sep 17 00:00:00 2001 From: Adam Coldrick Date: Tue, 4 Mar 2014 09:18:14 +0000 Subject: Update lorry-controller to allow it to make http requests --- lorry-controller | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lorry-controller b/lorry-controller index 01c0225..a3efa2c 100755 --- a/lorry-controller +++ b/lorry-controller @@ -21,6 +21,7 @@ import logging import os import time import re +import urllib2 from lorrycontroller.confparser import LorryControllerConfig @@ -274,6 +275,19 @@ class LorryController(cliapp.Application): self.runcmd(['git']+args, cwd=os.path.join(self.settings['work-area'], 'git')) + def maybe_http_request(self, url, dry=False): + if (not self.settings['dry-run']) or dry: + request = urllib2.Request(url, None, {}) + response = urllib2.urlopen(request) + code = response.getcode() + if code == 200: + return 0, response.read(), '' + else: + return code, response.read(), str(code) + else: + logging.debug('DRY-RUN: Not sending a request to %s' % url) + return 0, 'DRY-RUN', 'DRY-RUN' + def maybe_runcmd(self, cmdline, dry=False, *args, **kwargs): if (not self.settings['dry-run']) or dry: return self.runcmd_unchecked(cmdline, *args, **kwargs) -- cgit v1.2.1