Skip to content

Commit

Permalink
Added license and license_url field to the upload-new function
Browse files Browse the repository at this point in the history
  • Loading branch information
Moasib-Arif committed Oct 8, 2024
1 parent 27b67e2 commit a1a1b7d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
4 changes: 3 additions & 1 deletion dpytools/http/upload/base_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ def _upload_new(
mimetype: str,
alias_name: Optional[str],
title: Optional[str],
license: Optional[str],
license_url: Optional[str],
chunk_size: int = 5242880,
) -> None:
"""
Expand All @@ -76,7 +78,7 @@ def _upload_new(

# Generate upload request params
upload_params = _generate_upload_new_params(
file_path, chunk_size, mimetype, alias_name, title
file_path, chunk_size, mimetype, alias_name, title, license, license_url
)
logger.info(
"Upload parameters generated", data={"upload_params": upload_params}
Expand Down
20 changes: 19 additions & 1 deletion dpytools/http/upload/upload_service_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ def upload_new_csv(
csv_path: Union[Path, str],
alias_name: Optional[str] = None,
title: Optional[str] = None,
license: Optional[str] = None,
license_url: Optional[str] = None,
chunk_size: int = 5242880,
) -> None:
"""
Expand All @@ -69,6 +71,8 @@ def upload_new_csv(
"text/csv",
alias_name,
title,
license,
license_url,
chunk_size,
)

Expand All @@ -77,6 +81,8 @@ def upload_new_sdmx(
sdmx_path: Union[Path, str],
alias_name: Optional[str] = None,
title: Optional[str] = None,
license: Optional[str] = None,
license_url: Optional[str] = None,
chunk_size: int = 5242880,
) -> None:
"""
Expand All @@ -89,6 +95,8 @@ def upload_new_sdmx(
"application/xml",
alias_name,
title,
license,
license_url,
chunk_size,
)

Expand All @@ -97,11 +105,21 @@ def upload_new_json(
json_path: Union[Path, str],
alias_name: Optional[str] = None,
title: Optional[str] = None,
license: Optional[str] = None,
license_url: Optional[str] = None,
chunk_size: int = 5242880,
) -> None:
"""
Upload json files to the DP Upload Service `/upload-new` endpoint. The file to be uploaded (located at `json_path`) is chunked (default chunk size 5242880 bytes) and uploaded to an S3 bucket.
`alias_name` and `title` are optional arguments. If these are not explicitly provided, `alias_name` will default to the filename with the extension, and `title` will default to the filename without the extension - e.g. if the filename is "data.json", `alias_name` defaults to "data.json" and `title` defaults to "data".
"""
self._upload_new(json_path, "application/json", alias_name, title, chunk_size)
self._upload_new(
json_path,
"application/json",
alias_name,
title,
license,
license_url,
chunk_size,
)
7 changes: 7 additions & 0 deletions dpytools/http/upload/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ def _generate_upload_new_params(

if title is None:
title = filename.split(".")[0]

if licence is None:
licence = "Open Government Licence v3.0"

if licence_url is None:
licence_url = "http://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/"


# Generate upload request params
upload_params = {
Expand Down

0 comments on commit a1a1b7d

Please sign in to comment.