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

pinkopy user-friendly updation in README.md file and base_session.py … #33

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

Mamlesh18
Copy link

I updated the code to use pinkopy for interacting with Commvault's API more flexibly. Now, instead of using a context manager (with statement) every time, you can create a CommvaultSession instance directly. This allows you to manage the session manually and use the API methods directly on the session instance. Additionally, the code remains compatible with older usage patterns, so methods can still be called in the old way for familiarity and ease of transition.

Copy link
Owner

@theherk theherk left a comment

Choose a reason for hiding this comment

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

First, thank you for contributing. However, it is very difficult to sift through all the imposed personal preferences to see what actually changed. Please separate into commits that illustrate what is actually changing the execution and those that are trivial changes to formatting.

Also, please use imperative mood in your commits.


except Exception as e:
print(f"An error occurred: {e}")

Copy link
Owner

Choose a reason for hiding this comment

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

I don't think recommending catching the base Exception is a good idea in any case. I don't see a reason to store client_id as a separate variable. I can see no other functional changes in the README.

use_cache (bool, optional): Use cache? Defaults to True.
cache_ttl (int, optional): Duration cache lives. Defaults to 1200 seconds.
cache_methods (list, optional): List of methods to cache. Defaults to an empty list.
token (str, optional): Auth token for headers.
Copy link
Owner

Choose a reason for hiding this comment

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

I don't understand what is actually changing here, but okay.

def __init__(self, service, user, pw, use_cache=True, cache_ttl=1200,
cache_methods=None, token=None):

def __init__(self, service, user, pw, use_cache=True, cache_ttl=1200, cache_methods=None, token=None):
Copy link
Owner

Choose a reason for hiding this comment

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

This seems to just be enforcing a style preference. If that is true, I hope it is based on black or something universal.

self.service = service
self.user = user
self.pw = pw
self.headers = {
'Authtoken': token,
'Accept': 'application/json',
'Content-type': 'application/json'
'Content-Type': 'application/json'
Copy link
Owner

Choose a reason for hiding this comment

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

Good catch.

if not self.headers['Authtoken']:
self.get_token()
self.__use_cache = bool(use_cache)
Copy link
Owner

Choose a reason for hiding this comment

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

The reason this used bool, was to handle truthy and non-truthy values like "false". Is that problematic?

@@ -56,23 +57,23 @@ def __init__(self, service, user, pw, use_cache=True, cache_ttl=1200,
self.__enable_method_cache(method_name)

def __enable_method_cache(self, method_name):
"""Enable cache for a method.
"""
Enable cache for a method.
Copy link
Owner

Choose a reason for hiding this comment

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

This was following the Google Styleguide.

headers = headers if headers else self.headers
attempt = attempt or 1
service = service or self.service
headers = headers or self.headers
Copy link
Owner

Choose a reason for hiding this comment

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

I don't think it is an improvement to short circuit this way, and is generally more preferred to use the removed structure, so it seems like more preferences.

# Token went bad, login again.
log.info('Commvault token logged out. Logging back in.')
# Delay is so I don't get into recursion trouble if I can't login right away.
raise ValueError(f'HTTP method {method} not supported')
Copy link
Owner

Choose a reason for hiding this comment

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

Just another preference for f-string over format.

@theherk
Copy link
Owner

theherk commented Jul 10, 2024

Also, this could already be used not as a context manager; this is mentioned in the documentation. Did that not work for you? And I see you're contributing similar ambiguous pull requests elsewhere? Are you just trying to pump some contrib numbers or are you actually using Commvault?

If you're an actual user, and you can clarify what this change is really about, I do really appreciate your effort.

@Mamlesh18
Copy link
Author

Mamlesh18 commented Jul 10, 2024 via email

@theherk
Copy link
Owner

theherk commented Jul 12, 2024

Okay, so will you be updating the patch as requested? Can you explain what errors you had using the package as it is?

Also, why did you start your reply with your own name like it is a message to yourself? Really just makes this feel like AI spam.

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