def _check_hashes (hashes, remote_repo, remote_password):

    host, port, path = parse_URL(remote_repo)

    hashtext = string.join(hashes, "\n")

    # create zipfile of the folder
    errcode, errmsg, headers, text = https_post_multipart(host, port, remote_password,
                                                          "/action/SynchronizeRepositories/check_hashes",
                                                          [("hashes", hashtext),],
                                                          ())
    if errcode != 200:
        note("Errcode %s received.  Error text from repository was\n%s.\n", errcode, errmsg)
        return None

    else:
        results = []
        resultsA = text.split("\n")
        for result in resultsA:
            rr = string.strip(result)
            if rr:
                results.append(string.split(rr))
        return results
def _push_doc (doc, remote_repo_url, remote_password):

    note(3, "pushing %s  (%s)...", doc.id, doc.get_metadata("title"))
    tdir = tempfile.mktemp()
    os.mkdir(tdir)
    try:
        if os.path.isdir(os.path.join(doc.folder(), "page-images")):
            shutil.copytree(os.path.join(doc.folder(), "page-images"), os.path.join(tdir, "page-images"))
        else:
            shutil.copyfile(os.path.join(doc.folder(), "document.tiff"), os.path.join(tdir, "document.tiff"))
        if os.path.exists(doc.text_path()):
            shutil.copyfile(os.path.join(doc.folder(), "contents.txt"), os.path.join(tdir, "contents.txt"))
        if os.path.exists(os.path.join(doc.folder(), "paragraphs.txt")):
            shutil.copyfile(os.path.join(doc.folder(), "paragraphs.txt"), os.path.join(tdir, "paragraphs.txt"))
        if os.path.exists(os.path.join(doc.folder(), "wordbboxes")):
            shutil.copyfile(os.path.join(doc.folder(), "wordbboxes"), os.path.join(tdir, "wordbboxes"))
        if os.path.exists(os.path.join(doc.folder(), "images")):
            shutil.copytree(os.path.join(doc.folder(), "images"), os.path.join(tdir, "images"))
        if os.path.exists(os.path.join(doc.folder(), "originals")):
            shutil.copytree(os.path.join(doc.folder(), "originals"), os.path.join(tdir, "originals"))
        if os.path.exists(os.path.join(doc.folder(), "links")):
            shutil.copytree(os.path.join(doc.folder(), "links"), os.path.join(tdir, "links"))

        # filter the metadata
        conf = configurator()
        md = doc.get_metadata()
        newmd = {}
        properties = string.split(conf.get('synchronizing-properties') or
                                  conf.get('metadata-sharing-properties') or
                                  conf.get('metadata-sharing-default-properties'), ':')

        for property in ["title", "date", "authors", "citation"]:
            if not property in properties:
                properties.append(property)

        for prop in properties:
            if md.has_key(prop):
                newmd[prop] = md[prop]
        update_metadata(os.path.join(tdir, "metadata.txt"), newmd)

        host, port, path = parse_URL(remote_repo_url)

        # create zipfile of the folder
        tmpfilename = zipup(tdir)
        try:
            # send it to the repository
            errcode, errmsg, headers, text = https_post_multipart(host, port, remote_password,
                                                                  "/action/basic/repo_add",
                                                                  (("password", remote_password,),
                                                                   ("filetype", "zipped-folder",)),
                                                                  (("newfile", tmpfilename),))
            if errcode != 200:
                raise ValueError("Posting of data to repository %s resulted in error %d (%s).\nReturned text was:\n%s" % (remote_repo_url, errcode, errmsg, text))
            note(3, "text from remote repository was\n%s.\n", text)
            note(3, "%s successfully posted to %s.", tdir, remote_repo_url)

        finally:
            if os.path.exists(tmpfilename):
                os.unlink(tmpfilename)

        return text.strip()

    finally:
        if os.path.exists(tdir):
            shutil.rmtree(tdir)