Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating PR with the latest changes #92

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

tommyg-cld
Copy link
Contributor

Brief Summary of Changes

What does this PR address?

  • GitHub issue (Add reference - #XX)
  • Refactoring
  • New feature
  • Bug fix
  • Adds more tests

Are tests included?

  • Yes
  • No

Reviewer, please note:

  • Updates made to sync module to accommodate this new module as well changes to functions on api_utils which is used by other modules so need to pay extra attention here.

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I ran the full test suite before pushing the changes and all the tests pass.

@@ -116,18 +117,20 @@ def upload_file(file_path, options, uploaded=None, failed=None):
verbose = logger.getEffectiveLevel() < logging.INFO

try:
size = path.getsize(file_path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can change this to:

size = 0 if cloudinary.utils.is_remote_url(file_path) else path.getsize(file_path)

result = upload_func(file_path, **options)
disp_path = _display_path(result)
disp_str = f"as {result['public_id']}" if not disp_path \
else f"as {disp_path} with public_id: {result['public_id']}"
logger.info(style(f"Successfully uploaded {file_path} {disp_str}", fg="green"))
if verbose:
print_json(result)
uploaded[file_path] = {"path": asset_source(result), "display_path": disp_path}
if "async" not in options:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a good catch!

I would change line 127 to:

        if "batch_id" in result:
            disp_str = f"asynchnously with batch_id: {result['batch_id']}"
        else:
            disp_str = f"as {result['public_id']}" if not disp_path \
                else f"as {disp_path} with public_id: {result['public_id']}"

then you can remove this line (if "async" not in options:)

and in
def asset_source(asset_details):

change to

  base_name = asset_details.get('public_id', '')

    if not base_name:
        return base_name

Copy link
Contributor Author

@tommyg-cld tommyg-cld Nov 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is done.

I had to also update the last line to asset_details.get('format', '') as non-raw files still get the public_id as we specify them so this will prevent no format error as the response won't contain the format

Finally, I updated the display message to say it's processing when uploading asynchronously as well.

You need to specify the target cloud via `-t` or `-T` (not both)
e.g. cld clone -t cloudinary://<api_key>:<api_secret>@<cloudname> -f tags,context -O
""")
@option("-T", "--target_saved",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can combine -Tand -t into one. it's easy to check if it's a saved config, or a cloudinary url or not both.

help="Tell the CLI the target environemnt to run the command on by specifying a saved configuration - see `config` command.")
@option("-t", "--target",
help="Tell the CLI the target environemnt to run the command on by specifying an environment variable.")
@option("-A", "--auto_paginate", is_flag=True, default=False,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed

@option("-F", "--force", is_flag=True,
help="Skip confirmation.")
@option("-O", "--overwrite", is_flag=True, default=False,
help="Skip confirmation.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doc string seems to be invalid

help="Specify whether to copy tags and context.")
@option("-se", "--search_exp", default="",
help="Define a search expression.")
@option("--async", "async_", is_flag=True, default=False,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"async_" seems to be redundant, you can just specify one ("--async") option

print_help_and_exit()

base_cloudname_url = os.environ.get('CLOUDINARY_URL')
base_cloudname = cloudinary.config().cloud_name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rename base_cloudname to source_cloud_name

logger.info("Target environment cannot be the "
"same as source environment.")
return True
refresh_config(base_cloudname_url)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of loading target, and then resetting, you can just create a new instance of cloudinary.Config() class and use it.

'secure_url', 'display_name'])
search.max_results(DEFAULT_MAX_RESULTS)
res = execute_single_request(search, fields_to_keep="")
if auto_paginate:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

auto paginate looks redundant

if "context" in copy_fields:
cloned_options['context'] = res.get('context')
if res.get('folder'):
cloned_options['asset_folder'] = res.get('folder')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cloned_options['asset_folder'] = res.get('folder')
cloned_options['folder'] = res.get('folder')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so need cloned_options['asset_folder'] = res.get('folder') to put the asset in the right asset folder if the user is copying from fixed to dynamic. If you pass a folder to a dynamic folder account then it will append this to the public_id as well and we don't want this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would put a comment explaining that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants