towhee.utils.hub_utils.HubUtils¶
- class towhee.utils.hub_utils.HubUtils(author: Optional[str] = None, repo: Optional[str] = None, root: str = 'https://towhee.io')[source]¶
Bases:
object
The Hub Utils to deal with the http request. And other staticmethod for hub.
- Parameters:
author (str) – The author of the repo.
repo (str) – The name of the repo.
root (str) – The root url where the repo located.
Methods
Create a repo under current account.
Convert all the values in a dictionary to str and replace char.
Create a repo under current account.
Create a repo under current account with token.
Create an account verification token.
Delete the token with the given name.
Get a list of all commits of a repo.
Get a file from a repo.
Get a repo.
Get a file from a repo.
Get a git tree in the current repo at the given commit.
Get the user info with token.
Login with Authenticated user.
Logout with token.
set_author
set_repo
Update the file from ori_str_list to tar_str_list and rename it with the new filename.
Attributes
author
repo
root
- __init__(author: Optional[str] = None, repo: Optional[str] = None, root: str = 'https://towhee.io')[source]¶
- add_tag(password, tag, tag_num)[source]¶
Create a repo under current account.
- Parameters:
password (str) – Current author’s password.
tag (str) – The tag name to attach.
tag_num (int) – Which enum # for tag.
- Raises:
(HTTPError) – Raise error in request.
- static convert_dict(dicts: dict) dict [source]¶
Convert all the values in a dictionary to str and replace char.
For example: <class ‘torch.Tensor’>(unknow type) to torch.Tensor(str type).
- Parameters:
dicts (dict) – The dictionary to convert.
- Returns:
- (dict)
The converted dictionary.
- create(password: str, repo_class: int) None [source]¶
Create a repo under current account.
- Parameters:
password (str) – Current author’s password.
repo_class (int) – The repo class
- Raises:
(HTTPError) – Raise error in request.
- create_repo(token: str, repo_class: int) None [source]¶
Create a repo under current account with token.
- Parameters:
token (str) – Authenticated user’s token.
- Raises:
(HTTPError) – Raise error in request.
- create_token(token_name: str, password: str) Response [source]¶
Create an account verification token. This token allows for avoiding HttpBasicAuth for subsequent calls.
- Parameters:
token_name (str) – The name to be given to the token.
password (str) – The password of current author.
- Returns:
- (Response)
Return the token(id, name, sha1, token_last_eight).
- Raises:
(HTTPError) – Raise the error in request.
- delete_token(token_id: int, password: str) None [source]¶
Delete the token with the given name. Useful for cleanup after changes.
- Parameters:
token_id (int) – The token id.
password (str) – The password of current author.
- Raises:
(HTTPError) – Raise error in request.
- get_commits(limit: int, page: int, tag: str) Response [source]¶
Get a list of all commits of a repo.
- Parameters:
limit (int) – Page size of results.
page (int) – Page number of results.
tag (str) – The tag name.
- Returns:
- (Response)
A list of all commits of a repo.
- Raises:
(HTTPError) – Raise error in request.
- get_file(file_path: str, tag: str) Response [source]¶
Get a file from a repo.
- Parameters:
file_path (str) – filepath of the file to get.
tag (str) – The tag name.
- Returns:
- (Response)
A file content in the file_path.
- Raises:
(HTTPError) – Raise error in request.
- get_info() Response [source]¶
Get a repo.
- Returns:
- (Response)
The information about the repo.
- Raises:
(HTTPError) – Raise the error in request.
- get_lfs(file_path: str, tag: str) Response [source]¶
Get a file from a repo.
- Parameters:
file_path (str) – filepath of the file to get.
tag (str) – The tag name.
- Returns:
- (Response)
A file content in the file_path.
- Raises:
(HTTPError) – Raise error in request.
- get_tree(commit: str) Response [source]¶
Get a git tree in the current repo at the given commit.
- Parameters:
commit (str) – The commit to base current existing files.
- Returns:
- (Response)
A git tree for the repo
- Raises:
(HTTPError) – Raise error in request.
- get_user(token: str) Response [source]¶
Get the user info with token.
- Parameters:
token (str) – Authenticated user’s token.
- Returns:
- (Response)
Return the user(id, username etc.).
- Raises:
(HTTPError) – Raise error in request.
- login(password, token)[source]¶
Login with Authenticated user.
- Parameters:
password (str) – Authenticated user’s password.
token (str) – Authenticated user’s token.
- Raises:
(HTTPError) – Raise error in request.
- static update_text(ori_str_list: list, tar_str_list: list, file: str, new_file: str) None [source]¶
Update the file from ori_str_list to tar_str_list and rename it with the new filename.
- Parameters:
ori_str_list (list) – The original str list to be replaced
tar_str_list (list) – The target str list after replace
file (str) – The original file name to be updated
new_file (str) – The target file name after update