27 |
return result |
return result |
28 |
|
|
29 |
|
|
30 |
|
class Request2(urllib2.Request): |
31 |
|
|
32 |
|
def __init__(self, url, data=None, headers={}, |
33 |
|
origin_req_host=None, unverifiable=False, method="GET"): |
34 |
|
|
35 |
|
urllib2.Request.__init__(self, url, data, headers, origin_req_host, unverifiable) |
36 |
|
self.method = method |
37 |
|
|
38 |
|
def get_method(self): |
39 |
|
if self.has_data(): |
40 |
|
return "POST" |
41 |
|
else: |
42 |
|
return self.method |
43 |
|
|
44 |
|
|
45 |
def getLastModifiedTime(url): |
def getLastModifiedTime(url): |
46 |
"""Makes a request for url and returns the Last-Modified header""" |
"""Makes a request for url and returns the Last-Modified header""" |
47 |
|
|
48 |
request = urllib2.Request(url) |
request = urllib2.Request2(url) |
49 |
opener = urllib2.build_opener() |
opener = urllib2.build_opener() |
50 |
data = opener.open(request) |
data = opener.open(request) |
51 |
return(data.headers.dict["last-modified"]) |
return(data.headers.dict["last-modified"]) |
54 |
def URLisNewerThan(url, epoch): |
def URLisNewerThan(url, epoch): |
55 |
"""Makes an IMS request for url with epoch as the modification time and returns if URL has changed""" |
"""Makes an IMS request for url with epoch as the modification time and returns if URL has changed""" |
56 |
|
|
57 |
request = urllib2.Request(url) |
request = urllib2.Request2(url) |
58 |
request.add_header('If-Modified-Since', time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(epoch))) |
request.add_header('If-Modified-Since', time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(epoch))) |
59 |
opener = urllib2.build_opener(DefaultErrorHandler()) |
opener = urllib2.build_opener(DefaultErrorHandler()) |
60 |
data = opener.open(request) |
data = opener.open(request) |
63 |
else: |
else: |
64 |
return True |
return True |
65 |
|
|
66 |
|
def isSyncing(): |
67 |
|
"""Returns if the upstream mirror has a lock file indicating it is currently syncing with its upstream""" |
68 |
|
|
69 |
|
pass |
70 |
|
|
71 |
def main(): |
def main(): |
72 |
parser = OptionParser() |
parser = OptionParser() |