cavisson-pythonagent 0.0.1__py3-none-any.whl

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.
Files changed (180) hide show
  1. cavisson_pythonagent-0.0.1.dist-info/METADATA +32 -0
  2. cavisson_pythonagent-0.0.1.dist-info/RECORD +180 -0
  3. cavisson_pythonagent-0.0.1.dist-info/WHEEL +5 -0
  4. cavisson_pythonagent-0.0.1.dist-info/licenses/LICENSE +19 -0
  5. cavisson_pythonagent-0.0.1.dist-info/top_level.txt +1 -0
  6. pythonagent/__init__.py +22 -0
  7. pythonagent/agent/__init__.py +219 -0
  8. pythonagent/agent/internal/__init__.py +1 -0
  9. pythonagent/agent/internal/agent.py +1651 -0
  10. pythonagent/agent/internal/framesinfo.py +152 -0
  11. pythonagent/agent/internal/heap_dump.py +39 -0
  12. pythonagent/agent/internal/intercept_module.py +70 -0
  13. pythonagent/agent/internal/logs.py +122 -0
  14. pythonagent/agent/internal/metadata/__init__.py +0 -0
  15. pythonagent/agent/internal/metadata/agent_meta_data.py +276 -0
  16. pythonagent/agent/internal/proc_compat.py +75 -0
  17. pythonagent/agent/internal/profile.py +47 -0
  18. pythonagent/agent/internal/provider.py +83 -0
  19. pythonagent/agent/internal/thread_dump.py +85 -0
  20. pythonagent/agent/internal/udp.py +245 -0
  21. pythonagent/agent/internal/udp_message.py +800 -0
  22. pythonagent/agent/probes/Instrumentation/__init__.py +340 -0
  23. pythonagent/agent/probes/Instrumentation/find.py +243 -0
  24. pythonagent/agent/probes/Instrumentation/module_version_resolver.py +155 -0
  25. pythonagent/agent/probes/Instrumentation/new_parser.py +64 -0
  26. pythonagent/agent/probes/Instrumentation/parser.py +129 -0
  27. pythonagent/agent/probes/__init__.py +219 -0
  28. pythonagent/agent/probes/base.py +303 -0
  29. pythonagent/agent/probes/cache/__init__.py +51 -0
  30. pythonagent/agent/probes/cache/redis.py +119 -0
  31. pythonagent/agent/probes/cache/redis_asyncio.py +83 -0
  32. pythonagent/agent/probes/coroutines/__init__.py +1 -0
  33. pythonagent/agent/probes/coroutines/asyncio.py +63 -0
  34. pythonagent/agent/probes/elasticdb/__init__.py +7 -0
  35. pythonagent/agent/probes/elasticdb/aelastic.py +54 -0
  36. pythonagent/agent/probes/frameworks/__init__.py +27 -0
  37. pythonagent/agent/probes/frameworks/agentprofiler.py +105 -0
  38. pythonagent/agent/probes/frameworks/aiohttp_web.py +155 -0
  39. pythonagent/agent/probes/frameworks/aisess.py +151 -0
  40. pythonagent/agent/probes/frameworks/asgi.py +340 -0
  41. pythonagent/agent/probes/frameworks/bottle.py +27 -0
  42. pythonagent/agent/probes/frameworks/cherry.py +25 -0
  43. pythonagent/agent/probes/frameworks/django.py +128 -0
  44. pythonagent/agent/probes/frameworks/falcon.py +21 -0
  45. pythonagent/agent/probes/frameworks/fastapi.py +35 -0
  46. pythonagent/agent/probes/frameworks/flask.py +30 -0
  47. pythonagent/agent/probes/frameworks/pyramid.py +56 -0
  48. pythonagent/agent/probes/frameworks/test.py +108 -0
  49. pythonagent/agent/probes/frameworks/tornado_async_web.py +117 -0
  50. pythonagent/agent/probes/frameworks/tornado_web.py +133 -0
  51. pythonagent/agent/probes/frameworks/wsgi.py +353 -0
  52. pythonagent/agent/probes/grpc/__init__.py +76 -0
  53. pythonagent/agent/probes/grpc/client_interceptor.py +132 -0
  54. pythonagent/agent/probes/grpc/server_interceptor.py +129 -0
  55. pythonagent/agent/probes/havoc/__init__.py +0 -0
  56. pythonagent/agent/probes/havoc/custom_memory_stress.py +186 -0
  57. pythonagent/agent/probes/havoc/custom_thread_stress.py +187 -0
  58. pythonagent/agent/probes/havoc/havoc_constants.py +218 -0
  59. pythonagent/agent/probes/havoc/havoc_manager.py +981 -0
  60. pythonagent/agent/probes/http/__init__.py +49 -0
  61. pythonagent/agent/probes/http/aiohttp_client.py +59 -0
  62. pythonagent/agent/probes/http/boto.py +12 -0
  63. pythonagent/agent/probes/http/httplib.py +110 -0
  64. pythonagent/agent/probes/http/httpx_client.py +116 -0
  65. pythonagent/agent/probes/http/requests.py +15 -0
  66. pythonagent/agent/probes/http/tornado_httpclient.py +85 -0
  67. pythonagent/agent/probes/http/urllib3.py +16 -0
  68. pythonagent/agent/probes/langchain/__init__.py +21 -0
  69. pythonagent/agent/probes/langchain/base_tool.py +95 -0
  70. pythonagent/agent/probes/langchain/langchain_community.py +136 -0
  71. pythonagent/agent/probes/langchain/langchain_core.py +32 -0
  72. pythonagent/agent/probes/langchain/langchain_openai.py +110 -0
  73. pythonagent/agent/probes/logging/__init__.py +106 -0
  74. pythonagent/agent/probes/message_brokers/__init__.py +4 -0
  75. pythonagent/agent/probes/message_brokers/pika.py +126 -0
  76. pythonagent/agent/probes/mongodb/__init__.py +6 -0
  77. pythonagent/agent/probes/mongodb/pymongo.py +286 -0
  78. pythonagent/agent/probes/openai/__init__.py +3 -0
  79. pythonagent/agent/probes/openai/openai.py +797 -0
  80. pythonagent/agent/probes/span.py +101 -0
  81. pythonagent/agent/probes/sql/__init__.py +13 -0
  82. pythonagent/agent/probes/sql/botocores3.py +51 -0
  83. pythonagent/agent/probes/sql/dbapi.py +285 -0
  84. pythonagent/agent/probes/sql/dynamodb.py +90 -0
  85. pythonagent/agent/probes/sql/mysql_connector.py +24 -0
  86. pythonagent/agent/probes/sql/mysql_connector_cext.py +24 -0
  87. pythonagent/agent/probes/sql/mysqldb.py +43 -0
  88. pythonagent/agent/probes/sql/psycopg2.py +174 -0
  89. pythonagent/agent/probes/sql/pymysql.py +25 -0
  90. pythonagent/bootstrap/__init__.py +0 -0
  91. pythonagent/bootstrap/cav_gunicorn.py +26 -0
  92. pythonagent/bootstrap/cavagent_lambda_wrapper.py +291 -0
  93. pythonagent/bootstrap/run.py +47 -0
  94. pythonagent/bootstrap/sitecustomize.py +287 -0
  95. pythonagent/cavisson/netdiagnostics/CavAgent/instrumentationprofile.json +26 -0
  96. pythonagent/cavisson/netdiagnostics/CavAgent/interceptor_points.txt +29 -0
  97. pythonagent/cavisson/netdiagnostics/python/CavAgent/instrumentationprofile.json +42 -0
  98. pythonagent/cavisson/netdiagnostics/python/CavAgent/interceptor_points.txt +29 -0
  99. pythonagent/cavisson/netdiagnostics/python/config/ndsettings.conf +6 -0
  100. pythonagent/config.py +279 -0
  101. pythonagent/find.py +72 -0
  102. pythonagent/find_mod_cls_name.py +54 -0
  103. pythonagent/lang.py +131 -0
  104. pythonagent/lib.py +91 -0
  105. pythonagent/main/__init__.py +0 -0
  106. pythonagent/main/pytrace/__init__.py +79 -0
  107. pythonagent/main/pytrace/commands/__init__.py +0 -0
  108. pythonagent/main/pytrace/commands/auto_discovery.py +25 -0
  109. pythonagent/main/pytrace/commands/run.py +401 -0
  110. pythonagent/main/pytrace/pytrace.py +133 -0
  111. pythonagent/main/wsgi.py +6 -0
  112. pythonagent/main.py +27 -0
  113. pythonagent/run.py +46 -0
  114. pythonagent/sqins.py +8 -0
  115. pythonagent/test.py +73 -0
  116. pythonagent/utils.py +168 -0
  117. pythonagent/vendor/__init__.py +0 -0
  118. pythonagent/vendor/pympler/__init__.py +1 -0
  119. pythonagent/vendor/pympler/asizeof.py +2810 -0
  120. pythonagent/vendor/pympler/charts.py +62 -0
  121. pythonagent/vendor/pympler/classtracker.py +590 -0
  122. pythonagent/vendor/pympler/classtracker_stats.py +780 -0
  123. pythonagent/vendor/pympler/garbagegraph.py +80 -0
  124. pythonagent/vendor/pympler/mprofile.py +97 -0
  125. pythonagent/vendor/pympler/muppy.py +275 -0
  126. pythonagent/vendor/pympler/panels.py +115 -0
  127. pythonagent/vendor/pympler/process.py +238 -0
  128. pythonagent/vendor/pympler/py.typed +0 -0
  129. pythonagent/vendor/pympler/refbrowser.py +451 -0
  130. pythonagent/vendor/pympler/refgraph.py +350 -0
  131. pythonagent/vendor/pympler/summary.py +321 -0
  132. pythonagent/vendor/pympler/tracker.py +267 -0
  133. pythonagent/vendor/pympler/util/__init__.py +0 -0
  134. pythonagent/vendor/pympler/util/bottle.py +3809 -0
  135. pythonagent/vendor/pympler/util/compat.py +23 -0
  136. pythonagent/vendor/pympler/util/stringutils.py +77 -0
  137. pythonagent/vendor/pympler/web.py +346 -0
  138. pythonagent/vendor/werkzeug/__init__.py +20 -0
  139. pythonagent/vendor/werkzeug/_compat.py +228 -0
  140. pythonagent/vendor/werkzeug/_internal.py +473 -0
  141. pythonagent/vendor/werkzeug/_reloader.py +341 -0
  142. pythonagent/vendor/werkzeug/datastructures.py +3120 -0
  143. pythonagent/vendor/werkzeug/debug/__init__.py +498 -0
  144. pythonagent/vendor/werkzeug/debug/console.py +218 -0
  145. pythonagent/vendor/werkzeug/debug/repr.py +297 -0
  146. pythonagent/vendor/werkzeug/debug/tbtools.py +628 -0
  147. pythonagent/vendor/werkzeug/exceptions.py +829 -0
  148. pythonagent/vendor/werkzeug/filesystem.py +64 -0
  149. pythonagent/vendor/werkzeug/formparser.py +584 -0
  150. pythonagent/vendor/werkzeug/http.py +1307 -0
  151. pythonagent/vendor/werkzeug/local.py +420 -0
  152. pythonagent/vendor/werkzeug/middleware/__init__.py +25 -0
  153. pythonagent/vendor/werkzeug/middleware/dispatcher.py +66 -0
  154. pythonagent/vendor/werkzeug/middleware/http_proxy.py +219 -0
  155. pythonagent/vendor/werkzeug/middleware/lint.py +408 -0
  156. pythonagent/vendor/werkzeug/middleware/profiler.py +132 -0
  157. pythonagent/vendor/werkzeug/middleware/proxy_fix.py +169 -0
  158. pythonagent/vendor/werkzeug/middleware/shared_data.py +293 -0
  159. pythonagent/vendor/werkzeug/posixemulation.py +117 -0
  160. pythonagent/vendor/werkzeug/routing.py +2210 -0
  161. pythonagent/vendor/werkzeug/security.py +249 -0
  162. pythonagent/vendor/werkzeug/serving.py +1117 -0
  163. pythonagent/vendor/werkzeug/test.py +1123 -0
  164. pythonagent/vendor/werkzeug/testapp.py +241 -0
  165. pythonagent/vendor/werkzeug/urls.py +1138 -0
  166. pythonagent/vendor/werkzeug/useragents.py +202 -0
  167. pythonagent/vendor/werkzeug/utils.py +778 -0
  168. pythonagent/vendor/werkzeug/wrappers/__init__.py +36 -0
  169. pythonagent/vendor/werkzeug/wrappers/accept.py +50 -0
  170. pythonagent/vendor/werkzeug/wrappers/auth.py +33 -0
  171. pythonagent/vendor/werkzeug/wrappers/base_request.py +673 -0
  172. pythonagent/vendor/werkzeug/wrappers/base_response.py +700 -0
  173. pythonagent/vendor/werkzeug/wrappers/common_descriptors.py +341 -0
  174. pythonagent/vendor/werkzeug/wrappers/cors.py +100 -0
  175. pythonagent/vendor/werkzeug/wrappers/etag.py +304 -0
  176. pythonagent/vendor/werkzeug/wrappers/json.py +145 -0
  177. pythonagent/vendor/werkzeug/wrappers/request.py +49 -0
  178. pythonagent/vendor/werkzeug/wrappers/response.py +84 -0
  179. pythonagent/vendor/werkzeug/wrappers/user_agent.py +14 -0
  180. pythonagent/vendor/werkzeug/wsgi.py +1000 -0
pythonagent/find.py ADDED
@@ -0,0 +1,72 @@
1
+ import os
2
+ import ast
3
+ import json
4
+
5
+ import sys
6
+ py_ver = sys.version_info[0]
7
+
8
+ local = False
9
+
10
+ def find(path):
11
+ modules = []
12
+ default_path = []
13
+ for root, dirs, files in os.walk(path):
14
+ for file in files:
15
+ # print(file)
16
+ if file.endswith(".py"):
17
+ default_path.append(os.path.join(root, file))
18
+ file = file[:-3] # Remove .py extension
19
+ modules.append(file)
20
+
21
+ # print("modules", modules)
22
+ # print("\n\n")
23
+ # print("default_path", default_path)
24
+ # print("\n\n")
25
+
26
+ path_module_dict = dict(zip(default_path, modules))
27
+
28
+ data = {
29
+ "modules": [
30
+ {
31
+ "moduleName": path_module_dict[filename],
32
+ "moduleLevelMethod": [
33
+ {
34
+ "name": f_name.name,
35
+ "signature": [a.arg if py_ver == 3 else a.id for a in f_name.args.args]
36
+ # "signature": [[a.arg for a in f_name.args.args],[f_name.returns]]
37
+
38
+ }
39
+ for f_name in [n for n in ast.parse(open(filename).read()).body if isinstance(n, ast.FunctionDef)]
40
+ ],
41
+ "classes": [
42
+ {
43
+ "className": cname.name,
44
+ "classLevelMethods": [
45
+ {
46
+ "name": clm_name.name,
47
+ "signature": [a.arg if py_ver == 3 else a.id for a in clm_name.args.args]
48
+ # "signature": [[a.arg for a in clm_name.args.args], [clm_name.returns]]
49
+
50
+ }
51
+ for clm_name in [n for n in cname.body if isinstance(n, ast.FunctionDef)]
52
+ ]
53
+ }
54
+ for cname in [n for n in ast.parse(open(filename).read()).body if isinstance(n, ast.ClassDef)]
55
+ ]
56
+ }
57
+ for filename in default_path
58
+ ]
59
+ }
60
+
61
+ json_object = json.dumps(data, indent=2)
62
+ # print("\n\n\n\n")
63
+ # print(json_object)
64
+ # return str(json_object)
65
+
66
+ with open(os.environ.get('NDHOME') + "/python/CavAgent/instrumentationprofile.json", "w") as outfile:
67
+ outfile.write(json_object)
68
+ #print(outfile)
69
+
70
+ if local:
71
+ path = "/home/cavisson/shop/my-shop/pythonagent/"
72
+ find(path)
@@ -0,0 +1,54 @@
1
+ import sys
2
+ import os
3
+ import ast
4
+ import json
5
+
6
+ #path ="C:/Users/garima.singh/PycharmProjects/django_redis_demo"
7
+ path ="/home/cavisson/shop/my-shop/pythonagent_garima"
8
+
9
+ modules = []
10
+ default_path = []
11
+
12
+ for root, dirs, files in os.walk(path):
13
+ for file in files:
14
+ if(file.endswith(".py")):
15
+ modules.append(file)
16
+ default_path.append(os.path.join(root,file))
17
+
18
+ print("modules",modules)
19
+ print("default_path",default_path)
20
+
21
+
22
+ data = {
23
+ "modules": [
24
+ {
25
+ "moduleName": filename,
26
+ "moduleLevelMethod": [
27
+ {
28
+ "name":fname.name ,
29
+ "signature":"NA"
30
+ }
31
+ for fname in [n for n in ast.parse(open(filename).read()).body if isinstance(n, ast.FunctionDef)]
32
+ ],
33
+ "classes": [
34
+ {
35
+ "className": cname.name,
36
+ "classLevelMethods": [
37
+ {
38
+ "name":clmname.name,
39
+ "signature":"NA"
40
+
41
+ }
42
+ for clmname in [n for n in cname.body if isinstance(n, ast.FunctionDef)]
43
+ ]
44
+ }
45
+ for cname in [n for n in ast.parse(open(filename).read()).body if isinstance(n, ast.ClassDef)]
46
+ ]
47
+ }
48
+ for filename in default_path
49
+ ]
50
+ }
51
+
52
+ json_object = json.dumps(data, indent = 2)
53
+ with open("sample_json.json", "w") as outfile:
54
+ outfile.write(json_object)
pythonagent/lang.py ADDED
@@ -0,0 +1,131 @@
1
+ from __future__ import unicode_literals
2
+ import functools
3
+ import inspect
4
+ import itertools
5
+ import os
6
+ import sys
7
+
8
+ # The aim here is make Python 2 behave like Python 3.
9
+ # This means we write code in modern Python 3 style, where everything is an
10
+ # iterator, everything is unicode etc.
11
+
12
+ # pylint: disable=import-error,no-name-in-module,no-member,undefined-variable
13
+
14
+ SUPER_FUN_HAPPY_PYTHON = sys.version_info[0] > 2
15
+
16
+ if SUPER_FUN_HAPPY_PYTHON:
17
+ # Imports
18
+ # from configparser import SafeConfigParser
19
+ # from http.client import HTTPConnection, HTTPSConnection
20
+ # from http.cookies import SimpleCookie
21
+ try:
22
+ from importlib import reload
23
+ except ImportError:
24
+ from imp import reload
25
+ import queue
26
+ import _thread as thread
27
+ from urllib.request import urlopen
28
+ from urllib.parse import parse_qs, parse_qsl, urlparse
29
+
30
+ # Types
31
+ bytes_t = bytes
32
+ long_t = int
33
+ str_t = str
34
+
35
+ # Functions
36
+ filter = filter
37
+ getcwd = os.getcwd
38
+ items = lambda d: d.items()
39
+ keys = lambda d: d.keys()
40
+ long = int
41
+ map = map
42
+ range = range
43
+ wraps = functools.wraps
44
+ values = lambda d: d.values()
45
+ zip = zip
46
+
47
+ def get_args(callable):
48
+ return inspect.signature(callable).parameters
49
+
50
+ import importlib
51
+
52
+ def import_module(name):
53
+ return importlib.import_module(name)
54
+ else:
55
+ # Imports
56
+ from __builtin__ import reload
57
+ from ConfigParser import SafeConfigParser
58
+ from Cookie import SimpleCookie
59
+ from httplib import HTTPConnection, HTTPSConnection
60
+ import Queue as queue
61
+ import thread
62
+ from urllib import urlopen
63
+ from urlparse import parse_qs, parse_qsl, urlparse
64
+
65
+ # Types
66
+ bytes_t = bytes
67
+ long_t = long
68
+ str_t = unicode
69
+
70
+ # Functions
71
+ filter = lambda f, it: itertools.ifilter(f, it)
72
+ getcwd = os.getcwdu
73
+ items = lambda d: d.iteritems()
74
+ keys = lambda d: d.iterkeys()
75
+ long = long
76
+ map = lambda f, *it: itertools.imap(f, *it)
77
+ range = xrange
78
+ values = lambda d: d.itervalues()
79
+ zip = lambda *it: itertools.izip(*it)
80
+
81
+ def get_args(callable):
82
+ return inspect.getargspec(callable).args
83
+
84
+ import imp
85
+
86
+ def import_module(name):
87
+ file, pathname, desc = imp.find_module(name)
88
+ try:
89
+ return imp.load_module(name, file, pathname, desc)
90
+ finally:
91
+ if file is not None:
92
+ file.close()
93
+
94
+ # modified from https://github.com/michilu/python-functools32/blob/master/functools32/functools32.py
95
+ def _update_wrapper(wrapper, wrapped, assigned=functools.WRAPPER_ASSIGNMENTS, updated=functools.WRAPPER_UPDATES):
96
+ wrapper.__wrapped__ = wrapped
97
+ for attr in assigned:
98
+ try:
99
+ value = getattr(wrapped, attr)
100
+ except AttributeError:
101
+ pass
102
+ else:
103
+ setattr(wrapper, attr, value)
104
+ for attr in updated:
105
+ getattr(wrapper, attr).update(getattr(wrapped, attr, {}))
106
+ return wrapper
107
+
108
+ def wraps(wrapped, assigned=functools.WRAPPER_ASSIGNMENTS, updated=functools.WRAPPER_UPDATES):
109
+ return functools.partial(_update_wrapper, wrapped=wrapped, assigned=assigned, updated=updated)
110
+
111
+ # Common Stuff
112
+ native_str = str
113
+ reduce = functools.reduce
114
+
115
+
116
+ def bytes(s, encoding='utf-8'):
117
+ # Encode all bytes strings as utf-8.
118
+ if isinstance(s, bytes_t):
119
+ return s
120
+ else:
121
+ # This None thing isn't ideal, but since we use this function mainly
122
+ # for making byte strings for protobufs, we want None to stay None.
123
+ return None if s is None else s.encode(encoding)
124
+
125
+
126
+ def str(s, encoding='utf-8'):
127
+ # Assume all bytes strings are utf-8 encoded.
128
+ if isinstance(s, bytes_t):
129
+ return s.decode(encoding)
130
+ else:
131
+ return str_t(s)
pythonagent/lib.py ADDED
@@ -0,0 +1,91 @@
1
+
2
+ """Utilities for Cavisson Python Agent code.
3
+
4
+ """
5
+
6
+ from __future__ import unicode_literals
7
+ import errno
8
+
9
+ from logging import Formatter
10
+ import os
11
+
12
+ #mport _thread as thread
13
+ from .lang import thread
14
+
15
+ get_ident = lambda: thread.get_native_id()
16
+
17
+ items = lambda d: d.items()
18
+
19
+
20
+ default_log_formatter = Formatter('%(asctime)s [%(levelname)s] %(funcName)s(%(lineno)d) <%(process)d>: %(message)s')
21
+
22
+ class LazyWsgiRequest(object):
23
+ """Lazily read request line and headers from a WSGI environ.
24
+
25
+ This matches enough of the Werkzeug Request API for the agent's needs: it
26
+ only provides access to the information in the request line and the
27
+ headers that is needed for the agent. (Since the agent doesn't inspect
28
+ the request body, we don't touch any of that.)
29
+
30
+ Parameters
31
+ ----------
32
+ environ : dict
33
+ A WSGI environment.
34
+
35
+ Attributes
36
+ ----------
37
+ headers : dict
38
+ A dictionary of the HTTP headers. The headers are lowercase with
39
+ dashes separating words.
40
+ method : str
41
+ The request method (e.g., GET).
42
+ url : str
43
+ The URL of the request (reconstructed according to PEP 333).
44
+ cookies : dict
45
+ The cookies passed in the request header (if any).
46
+ path : str
47
+ The path part of the request. Note that unlike raw WSGI, this will be
48
+ just '/' if it would otherwise be empty.
49
+ args : dict
50
+ The query parameters. This is not a multi-dict: if a parameter is
51
+ repeated multiple times, one of them wins.
52
+ referer : str
53
+ The HTTP Referer string.
54
+ user_agent : str
55
+ The HTTP User-Agent string.
56
+ is_ajax : bool
57
+ True if this request is AJAX.
58
+ is_mobile : bool
59
+ True if this request is from mobile.
60
+
61
+ """
62
+ DEFAULT_PORTS = {
63
+ 'http': 80,
64
+ 'https': 443,
65
+ }
66
+
67
+ def __init__(self, environ):
68
+ super(LazyWsgiRequest, self).__init__()
69
+ self.environ = environ.copy()
70
+
71
+ self._headers = None
72
+ self._host = None
73
+ self._port = None
74
+ self._http_host = None
75
+ self._url = None
76
+ self._path = None
77
+ self._args = None
78
+ self._cookies = None
79
+
80
+ def mkdir(path):
81
+ """Create the directory in path, creating any intermediate directories.
82
+
83
+ Does not complain if the directory already exists.
84
+
85
+ """
86
+ try:
87
+ os.makedirs(path)
88
+ #print("Logging path: ",path)
89
+ except OSError as exc:
90
+ if exc.errno != errno.EEXIST:
91
+ raise
File without changes
@@ -0,0 +1,79 @@
1
+
2
+
3
+ HELP_OPTIONS = ('--help', '-h', '-?')
4
+
5
+ items = lambda d: d.items()
6
+ keys = lambda d: d.keys()
7
+
8
+ class CommandInvocationError(Exception):
9
+ pass
10
+
11
+
12
+ class CommandExecutionError(Exception):
13
+ pass
14
+
15
+
16
+ def parse_options(option_descrs, args):
17
+ options = {}
18
+
19
+ required = set()
20
+ short_flags = {}
21
+ for opt, opt_descr in items(option_descrs):
22
+ if isinstance(opt_descr, dict):
23
+ if 'short' in opt_descr:
24
+ # short_flags[opt_descr['short'][0]] = opt
25
+ short_flags[opt_descr['short']] = opt
26
+ if opt_descr.get('required', False):
27
+ required.add(opt)
28
+
29
+ i = 0
30
+ argc = len(args)
31
+
32
+ while i < argc and args[i][:1] == '-': # While there's an arg and it's an option...
33
+ arg = args[i]
34
+
35
+ if arg == '--' or arg == '-': # The option to end all options.
36
+ i += 1 # Skip the dash.
37
+ break
38
+
39
+ if arg in HELP_OPTIONS: # Help options short circuit everything.
40
+ return {'help': True}, []
41
+
42
+ if arg[1] == '-': # Long option.
43
+ opt = arg[2:]
44
+ else: # Short option.
45
+ # opt = short_flags.get(arg[1:])
46
+ opt = short_flags.get(arg[1:])
47
+
48
+ if opt not in option_descrs:
49
+ raise CommandInvocationError('unrecognized option: %s' % arg)
50
+
51
+ option_descr = option_descrs[opt]
52
+
53
+ if isinstance(option_descr, dict) and option_descr.get('value'):
54
+ value_label = option_descr.get('value_help', '<value>')
55
+ i += 1
56
+
57
+ if i >= argc:
58
+ raise CommandInvocationError('missing value for option: %s %s' % (arg, value_label))
59
+
60
+ options[opt] = args[i]
61
+ else:
62
+ options[opt] = True
63
+
64
+ i += 1
65
+
66
+ missing = ['--%s' % r for r in required - set(keys(options))]
67
+
68
+ if missing:
69
+ plural = 's' if len(missing) != 1 else ''
70
+ missing = ', '.join(missing)
71
+ raise CommandInvocationError('missing required option%s: %s' % (plural, missing))
72
+
73
+ return options, args[i:]
74
+
75
+
76
+
77
+
78
+
79
+
File without changes
@@ -0,0 +1,25 @@
1
+ from pythonagent.find import find
2
+ import traceback
3
+ import sys
4
+
5
+ py_ver = sys.version_info[0]
6
+
7
+ USAGE = "auto discovery to generate instrumentation profile"
8
+ ABOUT = "Command to push auto discovery feature of Python Agent"
9
+
10
+
11
+ def command(options, args):
12
+ # Calling auto discovery method to discover and create instrumentation profile
13
+ #print(args[0])
14
+ #if args[0] is None:
15
+ # raise TypeError("'None' value provided for application path !!")
16
+ try:
17
+ find(args[0])
18
+ print('auto discovery called, Instrumentation profile has been generated !!')
19
+ except:
20
+ if py_ver == 3:
21
+ traceback.print_exc(limit=None, file=None, chain=True)
22
+ else:
23
+ print_exception(sys.exc_type, sys.exc_value, sys.exc_traceback, limit, file)
24
+ print('No path provided for application !!\nPlease provide application path along with commond.')
25
+