summaryrefslogtreecommitdiff
path: root/yarns/lib.py
diff options
context:
space:
mode:
Diffstat (limited to 'yarns/lib.py')
-rw-r--r--yarns/lib.py111
1 files changed, 0 insertions, 111 deletions
diff --git a/yarns/lib.py b/yarns/lib.py
deleted file mode 100644
index fc4acfc..0000000
--- a/yarns/lib.py
+++ /dev/null
@@ -1,111 +0,0 @@
-import errno
-import json
-import os
-import StringIO
-import time
-
-import cliapp
-import requests
-import yaml
-import yarnutils
-
-
-datadir = os.environ['DATADIR']
-srcdir = os.environ['SRCDIR']
-
-vars = yarnutils.Variables(datadir)
-
-
-MAX_CAT_TIME = 5 # seconds
-def cat(filename):
- start = time.time()
- while time.time() - start < MAX_CAT_TIME:
- try:
- with open(filename) as f:
- data = f.read()
- if len(data) == 0:
- continue
- return data
- except (IOError, OSError) as e:
- if e.errno == errno.ENOENT:
- continue
- raise
- raise Exception("cat took more then %s seconds" % MAX_CAT_TIME)
-
-
-def write(filename, content):
- with open(filename, 'w') as f:
- f.write(content)
-
-
-def git(repo, *argv):
- return cliapp.runcmd(['git'] + list(argv), cwd=repo)
-
-
-def controller_url(port, path):
- return 'http://localhost:{}{}'.format(port, path)
-
-
-def request(method, url, body=None):
- funcs = {
- 'POST': requests.post,
- 'PUT': requests.put,
- 'GET': requests.get,
- 'DELETE': requests.delete,
- }
-
- headers = {
- 'Content-Type': 'application/json',
- }
-
- response = funcs[method](
- url,
- headers=headers,
- data=body,
- )
-
- return response.status_code, response.text
-
-
-def parse_json(text):
- return json.loads(text, object_pairs_hook=dictify)
-
-
-
-def dictify(pairs):
- return {
- stringify(key): stringify(value)
- for key, value in pairs
- }
-
-
-def stringify(x):
- if isinstance(x, unicode):
- return str(x)
- if isinstance(x, list):
- return [stringify(y) for y in x]
- if isinstance(x, dict):
- return {
- stringify(key): stringify(value)
- for key, value in pairs
- }
- return x
-
-
-def parse_yaml(text):
- f = StringIO.StringIO(text)
- return yaml.safe_load(stream=f)
-
-
-def unescape(text):
- def helper(text):
- while text:
- if text.startswith('\\n'):
- skip = 2
- answer = '\n'
- else:
- skip = 1
- answer = text[0]
- text = text[skip:]
- yield answer
- return ''.join(helper(text))