besapi 3.2.4__tar.gz → 3.3.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: besapi
3
- Version: 3.2.4
3
+ Version: 3.3.2
4
4
  Summary: Library for working with the BigFix REST API
5
5
  Home-page: https://github.com/jgstew/besapi
6
6
  Author: Matt Hansen, James Stewart
@@ -29,7 +29,7 @@ import requests
29
29
  from lxml import etree, objectify
30
30
  from pkg_resources import resource_filename
31
31
 
32
- __version__ = "3.2.4"
32
+ __version__ = "3.3.2"
33
33
 
34
34
  besapi_logger = logging.getLogger("besapi")
35
35
 
@@ -353,7 +353,7 @@ class BESConnection:
353
353
  def session_relevance_string(self, relevance, **kwargs):
354
354
  """Get Session Relevance Results string"""
355
355
  rel_result_array = self.session_relevance_array(
356
- "(it as string) of " + relevance, **kwargs
356
+ "(it as string) of ( " + relevance + " )", **kwargs
357
357
  )
358
358
  return "\n".join(rel_result_array)
359
359
 
@@ -0,0 +1,132 @@
1
+ """This is a set of utility functions for use in multiple plugins"""
2
+
3
+ import argparse
4
+ import logging
5
+ import logging.handlers
6
+ import ntpath
7
+ import os
8
+ import sys
9
+
10
+
11
+ def get_invoke_folder(verbose=0):
12
+ """Get the folder the script was invoked from"""
13
+ # using logging here won't actually log it to the file:
14
+
15
+ if getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS"):
16
+ if verbose:
17
+ print("running in a PyInstaller bundle")
18
+ invoke_folder = os.path.abspath(os.path.dirname(sys.executable))
19
+ else:
20
+ if verbose:
21
+ print("running in a normal Python process")
22
+ invoke_folder = os.path.abspath(os.path.dirname(__file__))
23
+
24
+ if verbose:
25
+ print(f"invoke_folder = {invoke_folder}")
26
+
27
+ return invoke_folder
28
+
29
+
30
+ def get_invoke_file_name(verbose=0):
31
+ """Get the filename the script was invoked from"""
32
+ # using logging here won't actually log it to the file:
33
+
34
+ if getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS"):
35
+ if verbose:
36
+ print("running in a PyInstaller bundle")
37
+ invoke_file_path = sys.executable
38
+ else:
39
+ if verbose:
40
+ print("running in a normal Python process")
41
+ invoke_file_path = __file__
42
+
43
+ if verbose:
44
+ print(f"invoke_file_path = {invoke_file_path}")
45
+
46
+ # get just the file name, return without file extension:
47
+ return os.path.splitext(ntpath.basename(invoke_file_path))[0]
48
+
49
+
50
+ def setup_plugin_argparse(plugin_args_required=False):
51
+ """setup argparse for plugin use"""
52
+ arg_parser = argparse.ArgumentParser(
53
+ description="Provde command line arguments for REST URL, username, and password"
54
+ )
55
+ arg_parser.add_argument(
56
+ "-v",
57
+ "--verbose",
58
+ help="Set verbose output",
59
+ required=False,
60
+ action="count",
61
+ default=0,
62
+ )
63
+ arg_parser.add_argument(
64
+ "-c",
65
+ "--console",
66
+ help="log output to console",
67
+ required=False,
68
+ action="store_true",
69
+ )
70
+ arg_parser.add_argument(
71
+ "-besserver", "--besserver", help="Specify the BES URL", required=False
72
+ )
73
+ arg_parser.add_argument(
74
+ "-r", "--rest-url", help="Specify the REST URL", required=plugin_args_required
75
+ )
76
+ arg_parser.add_argument(
77
+ "-u", "--user", help="Specify the username", required=plugin_args_required
78
+ )
79
+ arg_parser.add_argument(
80
+ "-p", "--password", help="Specify the password", required=False
81
+ )
82
+
83
+ return arg_parser
84
+
85
+
86
+ def setup_plugin_logging(log_file_name="", verbose=0, console=True):
87
+ """setup logging for plugin use"""
88
+ # get folder the script was invoked from:
89
+ invoke_folder = get_invoke_folder(verbose)
90
+
91
+ if not log_file_name or log_file_name == "":
92
+ log_file_name = get_invoke_file_name() + ".log"
93
+
94
+ # set different log levels:
95
+ log_level = logging.WARNING
96
+ if verbose:
97
+ log_level = logging.INFO
98
+ if verbose > 1:
99
+ log_level = logging.DEBUG
100
+
101
+ # get path to put log file in:
102
+ log_filename = os.path.join(invoke_folder, log_file_name)
103
+
104
+ handlers = [
105
+ logging.handlers.RotatingFileHandler(
106
+ log_filename, maxBytes=5 * 1024 * 1024, backupCount=1
107
+ )
108
+ ]
109
+
110
+ # log output to console if arg provided:
111
+ if console:
112
+ handlers.append(logging.StreamHandler())
113
+
114
+ # setup logging:
115
+ logging.basicConfig(
116
+ encoding="utf-8",
117
+ level=log_level,
118
+ format="%(asctime)s %(levelname)s:%(message)s",
119
+ handlers=handlers,
120
+ )
121
+
122
+
123
+ # if __name__ == "__main__":
124
+ # print(get_invoke_folder())
125
+ # print(get_invoke_file_name())
126
+ # setup_plugin_logging(console=True)
127
+ # logging.error("test logging")
128
+ # parser = setup_plugin_argparse()
129
+ # # allow unknown args to be parsed instead of throwing an error:
130
+ # args, _unknown = parser.parse_known_args()
131
+
132
+ # logging.error(args)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: besapi
3
- Version: 3.2.4
3
+ Version: 3.3.2
4
4
  Summary: Library for working with the BigFix REST API
5
5
  Home-page: https://github.com/jgstew/besapi
6
6
  Author: Matt Hansen, James Stewart
@@ -7,6 +7,7 @@ setup.py
7
7
  src/besapi/__init__.py
8
8
  src/besapi/__main__.py
9
9
  src/besapi/besapi.py
10
+ src/besapi/plugin_utilities.py
10
11
  src/besapi.egg-info/PKG-INFO
11
12
  src/besapi.egg-info/SOURCES.txt
12
13
  src/besapi.egg-info/dependency_links.txt
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes