Beispiel #1
0
def compare_jblob(jblob1, jblob2):
    if jblob1 == jblob2:
        return True
    blob1 = utils.jblob2bytes(jblob1)
    blob2 = utils.jblob2bytes(jblob2)
    if blob1 == blob2:
        return True
    jjblob1 = utils.bytes2jblob(blob1)
    jjblob2 = utils.bytes2jblob(blob2)
    return jjblob1 == jjblob2
Beispiel #2
0
def export(conf, url, prnt=None):
    bucket, root = get_bucket(url)
    manifest_files = {}

    def upload(entry, bdata):
        h = hash(bdata)
        entrypath = os.path.join(root, "_pool", h)
        manifest_files[entry] = h
        if not bucket.exists(entrypath):
            iodata = io.BytesIO(bdata)
            iodata.seek(0)
            if prnt:
                prnt("Uploading new version of [%s]" % entry)
            bucket.upload_blob(iodata,
                               entrypath,
                               meta_data={},
                               content_type="text/json")

    for doc, content in conf["documents"].items():
        upload(utils.DOCUMENTS_PATH[doc],
               json.dumps(content, indent=4).encode("utf-8"))
    for blob, jblob in conf["blobs"].items():
        upload(utils.BLOBS_PATH[blob], utils.jblob2bytes(jblob))

    manifest = {
        "meta": conf["meta"],
        "files": manifest_files,
    }
    upload_manifest(
        manifest, bucket, root, None,
        prnt=prnt)  # no config name; always upload to manifest.json
Beispiel #3
0
def get(config:str, blob:BlobsEnum, fname:str=typer.Argument(None),
        version:str=typer.Option(None, "--version", "-v")):
    f = open(fname, "wb") if fname else sys.stdout.buffer
    if version is None:
        b = state.api.blobs.get(config, blob.value).body
    else:
        b = state.api.blobs.get_version(config, blob.value, version).body
    f.write(utils.jblob2bytes(b))
Beispiel #4
0
def test_bytes2jblob_json():
    vec = b'A' * 500
    res = utils.bytes2jblob(vec)
    assert res == {
        "format": "bz2+base64",
        "blob": "QlpoOTFBWSZTWYtV77YAAACEAKAAIAggACEmQZioDi7kinChIRar32w="
    }
    res2 = utils.jblob2bytes(res)
    assert res2 == vec
Beispiel #5
0
    def add_blob(self, blobname, jblob):
        if blobname not in utils.BLOBS_PATH:
            abort(404, "blob type [%s] does not exist" % blobname)
        bpath = utils.BLOBS_PATH[blobname]
        try:
            blob = utils.jblob2bytes(jblob)
        except:
            abort(400, "could not decode blob [%s]" % blobname)

        self.add_file(bpath, blob)
Beispiel #6
0
def test_jblob2bytes_json():
    res = utils.jblob2bytes({"format": "json", "blob": jsonvec})
    decjson = json.loads(res.decode("utf-8"))
    assert decjson == jsonvec
Beispiel #7
0
def test_jblob2bytes_bin(fmt, blob):
    res = utils.jblob2bytes({
        "format": fmt,
        "blob": blob,
    })
    assert res == binvec