summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Coldrick <adam.coldrick@codethink.co.uk>2014-03-04 09:18:14 +0000
committerAdam Coldrick <adam.coldrick@codethink.co.uk>2014-03-05 16:42:45 +0000
commit9dc4d6c7b6dcbfaf613fbdf853b0d2777b9c825c (patch)
tree05a67ef3bbdf3c99f25ddc1e059ec1d044c5bf2c
parent90cfc7566a962a99890035b948cfc8b155f0e3f9 (diff)
downloadlorry-controller-9dc4d6c7b6dcbfaf613fbdf853b0d2777b9c825c.tar.gz
Update lorry-controller to allow it to make http requests
-rwxr-xr-xlorry-controller14
1 files changed, 14 insertions, 0 deletions
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)