import fcntl
import hashlib
+import httplib2
import os
import re
import subprocess
import errno
import sys
-from arvados.collection import *
+
+import arvados
+from arvados.collection import CollectionReader
HEX_RE = re.compile(r'^[0-9a-fA-F]+$')
Ensure the given directory (or TASK_TMPDIR if none given)
exists and is empty.
"""
- if path == None:
+ if path is None:
path = arvados.current_task().tmpdir
if os.path.exists(path):
p = subprocess.Popen(['rm', '-rf', path])
"""
num_length_args = len(length_args)
if num_length_args > 2:
- raise ArgumentError("is_hex accepts up to 3 arguments ({} given)".
- format(1 + num_length_args))
+ raise errors.ArgumentError("is_hex accepts up to 3 arguments ({} given)"
+ .format(1 + num_length_args))
elif num_length_args == 2:
good_len = (length_args[0] <= len(s) <= length_args[1])
elif num_length_args == 1:
items_available = c['items_available']
offset = c['offset'] + len(c['items'])
return items
+
+def ca_certs_path(fallback=httplib2.CA_CERTS):
+ """Return the path of the best available CA certs source.
+
+ This function searches for various distribution sources of CA
+ certificates, and returns the first it finds. If it doesn't find any,
+ it returns the value of `fallback` (httplib2's CA certs by default).
+ """
+ for ca_certs_path in [
+ # Debian:
+ '/etc/ssl/certs/ca-certificates.crt',
+ # Red Hat:
+ '/etc/pki/tls/certs/ca-bundle.crt',
+ ]:
+ if os.path.exists(ca_certs_path):
+ return ca_certs_path
+ return fallback