forked from seung-lab/python-task-queue
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpaths.py
More file actions
46 lines (33 loc) · 1.04 KB
/
paths.py
File metadata and controls
46 lines (33 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from collections import namedtuple
import os
import posixpath
import re
import sys
from .lib import yellow, toabs
ExtractedPath = namedtuple('ExtractedPath',
('protocol', 'path')
)
ALLOWED_PROTOCOLS = [ 'sqs', 'fq', 'mem' ]
def mkpath(extracted_path):
return extracted_path.protocol + "://" + extracted_path.path
def get_protocol(cloudpath):
protocol_re = re.compile(r'(?P<proto>\w+)://')
match = re.match(protocol_re, cloudpath)
if not match:
return None
return match.group("proto")
def pop_protocol(cloudpath):
protocol_re = re.compile(r'(\w+)://')
match = re.match(protocol_re, cloudpath)
if not match:
return ("sqs", cloudpath)
(protocol,) = match.groups()
cloudpath = re.sub(protocol_re, '', cloudpath, count=1)
return (protocol, cloudpath)
def extract_path(cloudpath):
protocol, queue_path = pop_protocol(cloudpath)
if protocol in ('http', 'https'):
if 'sqs' in queue_path and 'amazonaws.com' in queue_path:
protocol = 'sqs'
queue_path = cloudpath
return ExtractedPath(protocol, queue_path)