def uploadFile()

in benchmarking/remote/file_handler.py [0:0]


    def uploadFile(self, filename, md5, basefilename, cache_file):
        if filename.startswith("https://") or filename.startswith("http://"):
            return filename, md5
        if filename.startswith("specifications"):
            """We will handle the spcical case here that the file is from
            internal binary. We will first load it, save it as a temp file, and
            then return the temp path. In general, we don't encourage this case.
            """
            if not pkg_resources.resource_exists("aibench", filename):
                getLogger().error("Cannot find {}".format(filename))
            raw_context = pkg_resources.resource_string("aibench", filename)
            temp_name = filename.split("/")[-1]
            temp_dir = tempfile.mkdtemp(prefix="aibench")
            path = os.path.join(temp_dir, temp_name)
            with open(path, "w") as f:
                f.write(raw_context.decode("utf-8"))
        elif filename.startswith("//"):
            assert self.root_dir, "root_dir must be specified for relative path"
            path = self.root_dir + filename[1:]
        elif filename.startswith("/"):
            path = filename
        else:
            path = os.path.join(
                os.path.dirname(os.path.realpath(basefilename)), filename
            )

        if not os.path.isfile(path) or filename.startswith("//manifold"):
            getLogger().info("Skip uploading {}".format(filename))
            return filename, md5

        upload_path, cached_md5 = self._getCachedFile(path)
        base_filename = os.path.basename(filename)
        if upload_path is None or not cache_file or md5 is not cached_md5:
            upload_path = self.file_storage.upload(
                orig_path=filename, file=path, permanent=False
            )
            if cache_file or md5 is not cached_md5:
                md5 = self._saveCachedFile(path, upload_path)
        else:
            getLogger().info("File {} cached, skip uploading".format(base_filename))
        return upload_path, md5