|
|
@@ -20,16 +20,16 @@ import numpy as np |
|
|
|
import cStringIO |
|
|
|
|
|
|
|
class MissingDestination(Exception): |
|
|
|
def __init__(self, src, dest): |
|
|
|
def __init__(self, args, src, dest): |
|
|
|
self.args = args |
|
|
|
self.src = src |
|
|
|
self.dest = dest |
|
|
|
Exception.__init__(self, "destination path " + dest.path + " not found") |
|
|
|
|
|
|
|
class StreamInfo(object): |
|
|
|
def __init__(self, url, info, interhost = False): |
|
|
|
def __init__(self, url, info): |
|
|
|
self.url = url |
|
|
|
self.info = info |
|
|
|
self.interhost = interhost |
|
|
|
try: |
|
|
|
self.path = info[0] |
|
|
|
self.layout = info[1] |
|
|
@@ -43,15 +43,26 @@ class StreamInfo(object): |
|
|
|
except IndexError, TypeError: |
|
|
|
pass |
|
|
|
|
|
|
|
def string(self, interhost): |
|
|
|
"""Return stream info as a string. If interhost is true, |
|
|
|
include the host URL.""" |
|
|
|
if interhost: |
|
|
|
return sprintf("[%s] ", self.url) + str(self) |
|
|
|
return str(self) |
|
|
|
|
|
|
|
def __str__(self): |
|
|
|
"""Print stream info as a string""" |
|
|
|
res = "" |
|
|
|
if self.interhost: |
|
|
|
res = sprintf("[%s] ", self.url) |
|
|
|
res += sprintf("%s (%s), %.2fM rows, %.2f hours", |
|
|
|
"""Return stream info as a string.""" |
|
|
|
return sprintf("%s (%s), %.2fM rows, %.2f hours", |
|
|
|
self.path, self.layout, self.rows / 1e6, |
|
|
|
self.seconds / 3600.0) |
|
|
|
return res |
|
|
|
|
|
|
|
def get_stream_info(client, path): |
|
|
|
"""Return a StreamInfo object about the given path, or None if it |
|
|
|
doesn't exist""" |
|
|
|
streams = client.stream_list(path, extended = True) |
|
|
|
if len(streams) != 1: |
|
|
|
return None |
|
|
|
return StreamInfo(client.geturl(), streams[0]) |
|
|
|
|
|
|
|
class Filter(object): |
|
|
|
|
|
|
@@ -129,20 +140,17 @@ class Filter(object): |
|
|
|
raise Exception("source and destination path must be different") |
|
|
|
|
|
|
|
# Open and print info about the streams |
|
|
|
src = self._client_src.stream_list(args.srcpath, extended = True) |
|
|
|
if len(src) != 1: |
|
|
|
self.src = get_stream_info(self._client_src, args.srcpath) |
|
|
|
if not self.src: |
|
|
|
raise Exception("source path " + args.srcpath + " not found") |
|
|
|
self.src = StreamInfo(args.url, src[0], self.interhost) |
|
|
|
|
|
|
|
dest = self._client_dest.stream_list(args.destpath, extended = True) |
|
|
|
if len(dest) != 1: |
|
|
|
raise MissingDestination(self.src, |
|
|
|
StreamInfo(args.dest_url, [args.destpath], |
|
|
|
self.interhost)) |
|
|
|
self.dest = StreamInfo(args.dest_url, dest[0], self.interhost) |
|
|
|
self.dest = get_stream_info(self._client_dest, args.destpath) |
|
|
|
if not self.dest: |
|
|
|
raise MissingDestination(args, self.src, |
|
|
|
StreamInfo(args.dest_url, [args.destpath])) |
|
|
|
|
|
|
|
print "Source:", self.src |
|
|
|
print " Dest:", self.dest |
|
|
|
print "Source:", self.src.string(self.interhost) |
|
|
|
print " Dest:", self.dest.string(self.interhost) |
|
|
|
|
|
|
|
if args.dry_run: |
|
|
|
for interval in self.intervals(): |
|
|
|