コード例 #1
0
    def upload_bundle(self, sources, follow_symlinks, exclude_patterns, git, unpack, remove_sources, info, worksheet_uuid, add_to_worksheet):
        """
        See local_bundle_client.py for documentation on the usage.
        Strategy:
        1) We copy the |sources| to a temporary directory on the server
          (streaming either a tar or tar.gz depending on whether compression is
          needed).
        2) We politely ask the server to finish_upload_bundle (performs a
          LocalBundleClient.upload_bundle from the temporary directory).
        """
        # URLs can be directly passed to the local client.
        if all(path_util.path_is_url(source) for source in sources):
            return self.upload_bundle_url(sources, follow_symlinks, exclude_patterns, git, unpack, remove_sources, info, worksheet_uuid, add_to_worksheet)

        # 1) Copy sources up to the server (temporary remote zip file)
        remote_file_uuids = []
        for source in sources:
            remote_file_uuid = self.open_temp_file(zip_util.add_packed_suffix(os.path.basename(source)))
            remote_file_uuids.append(remote_file_uuid)
            dest_handle = RPCFileHandle(remote_file_uuid, self.proxy)
            if zip_util.path_is_archive(source):
                source_handle = open(source)
            else:
                source_handle = zip_util.open_packed_path(source, follow_symlinks, exclude_patterns)
                unpack = True  # We packed it, so we have to unpack it
            status = 'Uploading %s%s to %s' % (source, ' ('+info['uuid']+')' if 'uuid' in info else '', self.address)
            # FileServer does not expose an API for forcibly flushing writes, so
            # we rely on closing the file to flush it.
            file_util.copy(source_handle, dest_handle, autoflush=False, print_status=status)
            dest_handle.close()

        # 2) Install upload (this call will be in charge of deleting the temporary file).
        result = self.finish_upload_bundle(remote_file_uuids, unpack, info, worksheet_uuid, add_to_worksheet)

        return result
コード例 #2
0
ファイル: file_server.py プロジェクト: kelvinguu/codalab-cli
 def open_packed_path(self, path):
     '''
     Open a file handle corresponding to streaming the archived version of |path|.
     '''
     if not os.path.exists(path) or os.path.islink(path):
         # Note: don't follow symlinks!
         return None
     file_uuid = uuid.uuid4().hex
     self.file_paths[file_uuid] = path
     self.file_handles[file_uuid] = zip_util.open_packed_path(path, follow_symlinks=False, exclude_patterns=None)
     return file_uuid