1515from newrelic .admin import command , usage
1616
1717
18- @command ('run-program' , '...' ,
19- """Executes the command line but forces the initialisation of the agent
18+ @command (
19+ "run-program" ,
20+ "..." ,
21+ """Executes the command line but forces the initialisation of the agent
2022automatically at startup.
2123
2224If using an agent configuration file the path to the file should be
2325supplied by the environment variable NEW_RELIC_CONFIG_FILE. Alternatively,
2426just the licence key, application and log file details can be supplied via
2527environment variables NEW_RELIC_LICENSE_KEY, NEW_RELIC_APP_NAME and
26- NEW_RELIC_LOG.""" )
28+ NEW_RELIC_LOG.""" ,
29+ )
2730def run_program (args ):
2831 import os
2932 import sys
3033 import time
3134
3235 if len (args ) == 0 :
33- usage (' run-program' )
36+ usage (" run-program" )
3437 sys .exit (1 )
3538
36- startup_debug = os .environ .get ('NEW_RELIC_STARTUP_DEBUG' ,
37- 'off' ).lower () in ('on' , 'true' , '1' )
39+ startup_debug = os .environ .get ("NEW_RELIC_STARTUP_DEBUG" , "off" ).lower () in ("on" , "true" , "1" )
3840
3941 def log_message (text , * args ):
4042 if startup_debug :
4143 text = text % args
42- timestamp = time .strftime (' %Y-%m-%d %H:%M:%S' , time .localtime ())
43- print (f' NEWRELIC: { timestamp } ({ os .getpid ()} ) - { text } ' )
44+ timestamp = time .strftime (" %Y-%m-%d %H:%M:%S" , time .localtime ())
45+ print (f" NEWRELIC: { timestamp } ({ os .getpid ()} ) - { text } " )
4446
45- log_message (' New Relic Admin Script (%s)' , __file__ )
47+ log_message (" New Relic Admin Script (%s)" , __file__ )
4648
47- log_message (' working_directory = %r' , os .getcwd ())
48- log_message (' current_command = %r' , sys .argv )
49+ log_message (" working_directory = %r" , os .getcwd ())
50+ log_message (" current_command = %r" , sys .argv )
4951
50- log_message (' sys.prefix = %r' , os .path .normpath (sys .prefix ))
52+ log_message (" sys.prefix = %r" , os .path .normpath (sys .prefix ))
5153
5254 try :
53- log_message (' sys.real_prefix = %r' , sys .real_prefix )
55+ log_message (" sys.real_prefix = %r" , sys .real_prefix )
5456 except AttributeError :
5557 pass
5658
57- log_message (' sys.version_info = %r' , sys .version_info )
58- log_message (' sys.executable = %r' , sys .executable )
59- log_message (' sys.flags = %r' , sys .flags )
60- log_message (' sys.path = %r' , sys .path )
59+ log_message (" sys.version_info = %r" , sys .version_info )
60+ log_message (" sys.executable = %r" , sys .executable )
61+ log_message (" sys.flags = %r" , sys .flags )
62+ log_message (" sys.path = %r" , sys .path )
6163
6264 for name in sorted (os .environ .keys ()):
63- if name .startswith (' NEW_RELIC_' ) or name .startswith (' PYTHON' ):
64- if name == ' NEW_RELIC_LICENSE_KEY' :
65+ if name .startswith (" NEW_RELIC_" ) or name .startswith (" PYTHON" ):
66+ if name == " NEW_RELIC_LICENSE_KEY" :
6567 continue
66- log_message (' %s = %r' , name , os .environ .get (name ))
68+ log_message (" %s = %r" , name , os .environ .get (name ))
6769
6870 from newrelic import __file__ as root_directory
6971
7072 root_directory = os .path .dirname (root_directory )
71- boot_directory = os .path .join (root_directory , ' bootstrap' )
73+ boot_directory = os .path .join (root_directory , " bootstrap" )
7274
73- log_message (' root_directory = %r' , root_directory )
74- log_message (' boot_directory = %r' , boot_directory )
75+ log_message (" root_directory = %r" , root_directory )
76+ log_message (" boot_directory = %r" , boot_directory )
7577
7678 python_path = boot_directory
7779
78- if ' PYTHONPATH' in os .environ :
79- path = os .environ [' PYTHONPATH' ].split (os .path .pathsep )
80+ if " PYTHONPATH" in os .environ :
81+ path = os .environ [" PYTHONPATH" ].split (os .path .pathsep )
8082 if boot_directory not in path :
8183 python_path = f"{ boot_directory } { os .path .pathsep } { os .environ ['PYTHONPATH' ]} "
8284
83- os .environ [' PYTHONPATH' ] = python_path
85+ os .environ [" PYTHONPATH" ] = python_path
8486
85- os .environ [' NEW_RELIC_ADMIN_COMMAND' ] = repr (sys .argv )
87+ os .environ [" NEW_RELIC_ADMIN_COMMAND" ] = repr (sys .argv )
8688
87- os .environ ['NEW_RELIC_PYTHON_PREFIX' ] = os .path .realpath (
88- os .path .normpath (sys .prefix ))
89- os .environ ['NEW_RELIC_PYTHON_VERSION' ] = '.' .join (
90- map (str , sys .version_info [:2 ]))
89+ os .environ ["NEW_RELIC_PYTHON_PREFIX" ] = os .path .realpath (os .path .normpath (sys .prefix ))
90+ os .environ ["NEW_RELIC_PYTHON_VERSION" ] = "." .join (map (str , sys .version_info [:2 ]))
9191
9292 # If not an absolute or relative path, then we need to
9393 # see if program can be found in PATH. Note that can
@@ -97,14 +97,14 @@ def log_message(text, *args):
9797 program_exe_path = args [0 ]
9898
9999 if not os .path .dirname (program_exe_path ):
100- program_search_path = os .environ .get (' PATH' , '' ).split (os .path .pathsep )
100+ program_search_path = os .environ .get (" PATH" , "" ).split (os .path .pathsep )
101101 for path in program_search_path :
102102 path = os .path .join (path , program_exe_path )
103103 if os .path .exists (path ) and os .access (path , os .X_OK ):
104104 program_exe_path = path
105105 break
106106
107- log_message (' program_exe_path = %r' , program_exe_path )
108- log_message (' execl_arguments = %r' , [program_exe_path ] + args )
107+ log_message (" program_exe_path = %r" , program_exe_path )
108+ log_message (" execl_arguments = %r" , [program_exe_path ] + args )
109109
110110 os .execl (program_exe_path , * args )
0 commit comments