示例#1
0
def download(key):
    try:
        fill_groups(node)
        data = node.read(key)
    except RuntimeError:
        return abort(404)

    return str(data)
示例#2
0
def find():
    key = request.args.get('key')
    if key:
        urlencoded_key = quote_plus(key)
        try:
            fill_groups(node)
            data = node.read(key)
            lookup_tuple = node.lookup(str(key))
            routes = node.get_routes()
            if len(routes):
                elliptics_id, ip = routes[0]
                hash = hashlib.sha512(key).hexdigest()
                p = subprocess.Popen("dnet_find -r %s:2 -I %s" % (ip, hash),
                                     stderr=subprocess.PIPE, shell=True)
                p.wait()
                dnet_find_stderr = p.stderr.read()
                if dnet_find_stderr:
                    objects = []
                    for index, line in enumerate(dnet_find_stderr.split('\n')):
                        print line
                        if "meta" in line:
                            break
                        if line.endswith('status: -2'):
                            continue

                        line = line.split(':', 3)[3].strip()
                        match = re.search(r'((?:\d+|\.){7}:\d+):\s*should live at:\s*((?:\d+|\.){7}:\d+)', line)
                        if match:
                            if match.groups()[0] != match.groups()[1]:
                                line = line.replace(match.groups()[0],
                                                    "<span class='alert-success'>%s</span>" % match.groups()[0])
                                line = line.replace(match.groups()[1],
                                                    "<span class='alert-danger'>%s</span>" % match.groups()[1])
                            else:
                                line = line.replace(match.groups()[0],
                                                    "<span class='alert-success'>%s</span>" % match.groups()[0])
                                line = line.replace(match.groups()[1],
                                                    "<span class='alert-success'>%s</span>" % match.groups()[1])

                        line = line.replace(hash[:12]+":", "")
                        line = line.replace("FIND-OK object:", "")
                        line = "Group " + line
                        objects.append(line)
                        objects.sort()

                    meta = []
                    for index, line in enumerate(dnet_find_stderr.split('\n')[index:]):
                        if line.endswith('status: -2') or hash in line or not line:
                            continue
                        line = line.split(':', 3)[3].strip()
                        match = re.match(r'(\d+).*?((?:\d+|\.){7}:\d+)', line)
                        if match:
                            group, ip = match.groups()
                            meta.append({'group': group, 'ip': ip, 'lines': []})
                        else:
                            meta[-1]['lines'].append(line)

                    meta.sort(key=itemgetter('group'))
                else:
                    log = []
        except RuntimeError:
            data = None

    return render_template('find.html', **locals())
示例#3
0
def write(key, value):
    fill_groups(node)
    node.write_data(key.encode('utf-8'), value.encode('utf-8'))
    return 'ok'