diff --git a/README.md b/README.md index 7bda380e..a8302e6f 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ package. - [Install](#install) - [Usage](#usage) + * [Enable logging](#enable-logging) * [Authentication](#authentication) * [Artifactory SaaS](#artifactory-saas) * [Walking Directory Tree](#walking-directory-tree) @@ -85,6 +86,19 @@ pip install dohq-artifactory==0.5.dev243 ``` # Usage +## Enable logging +For purpose of debugging or need of additional information you can configure logger to work with current library +Just configure logging module in your python script. Simpliest example: +~~~python +import logging +from artifactory import ArtifactoryPath + +logging.basicConfig(level=logging.DEBUG) +path = ArtifactoryPath( + "http://my-artifactory/artifactory/myrepo/restricted-path", apikey="MY_API_KEY" +) +~~~ +This will add debug messages to StdOut ## Authentication ## @@ -474,19 +488,19 @@ You can use [Artifactory Query Language](https://www.jfrog.com/confluence/displa ```python from artifactory import ArtifactoryPath -aql = ArtifactoryPath( +arti_path = ArtifactoryPath( "http://my-artifactory/artifactory" ) # path to artifactory, NO repo # dict support # Send query: # items.find({"repo": "myrepo"}) -artifacts = aql.aql("items.find", {"repo": "myrepo"}) +artifacts = arti_path.aql("items.find", {"repo": "myrepo"}) # list support. # Send query: # items.find().include("name", "repo") -artifacts = aql.aql("items.find()", ".include", ["name", "repo"]) +artifacts = arti_path.aql("items.find()", ".include", ["name", "repo"]) # support complex query # Example 1 @@ -498,7 +512,7 @@ artifacts = aql.aql("items.find()", ".include", ["name", "repo"]) # ] # } # ) -args = [ +aqlargs = [ "items.find", { "$and": [ @@ -515,7 +529,7 @@ args = [ # artifacts_list contains raw data (list of dict) # Send query -artifacts_list = aql.aql(*args) +artifacts_list = arti_path.aql(*aqlargs) # Example 2 # The query will find all items in repo docker-prod that are of type file and were created after timecode. The @@ -541,11 +555,11 @@ aqlargs = [ ".sort", {"$asc": ["repo", "path", "name"]}, ] -artifacts_list = aql.aql(*args) +artifacts_list = arti_path.aql(*aqlargs) # You can convert to pathlib object: -artifact_pathlib = map(aql.from_aql, artifacts_list) -artifact_pathlib_list = list(map(aql.from_aql, artifacts_list)) +artifact_pathlib = map(arti_path.from_aql, artifacts_list) +artifact_pathlib_list = list(map(arti_path.from_aql, artifacts_list)) ``` diff --git a/artifactory.py b/artifactory.py index 95e037ae..f5126d82 100755 --- a/artifactory.py +++ b/artifactory.py @@ -64,6 +64,10 @@ default_config_path = "~/.artifactory_python.cfg" global_config = None +# set logger to be configurable from external +log = logging.getLogger(__name__) +log.addHandler(logging.NullHandler()) + def read_config(config_path=default_config_path): """ @@ -397,6 +401,7 @@ def quote_url(url): quoted_path = requests.utils.quote(url.rpartition(parsed_url.host)[2]) quoted_url = f"{parsed_url.scheme}://{parsed_url.host}{quoted_path}" + logging.debug(f"Percent-encoded URL: {quoted_url}") return quoted_url @@ -1920,7 +1925,7 @@ def aql(self, *args): @staticmethod def create_aql_text(*args): """ - Create AQL querty from string or list or dict arguments + Create AQL query from string or list or dict arguments """ aql_query_text = "" for arg in args: @@ -1929,6 +1934,8 @@ def create_aql_text(*args): elif isinstance(arg, list): arg = "({})".format(json.dumps(arg)).replace("[", "").replace("]", "") aql_query_text += arg + + logging.debug(f"AQL query request text: {aql_query_text}") return aql_query_text def from_aql(self, result):