本文整理汇总了Python中utils.platform.Platform.is_windows方法的典型用法代码示例。如果您正苦于以下问题:Python Platform.is_windows方法的具体用法?Python Platform.is_windows怎么用?Python Platform.is_windows使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utils.platform.Platform
的用法示例。
在下文中一共展示了Platform.is_windows方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_subprocess_output
# 需要导入模块: from utils.platform import Platform [as 别名]
# 或者: from utils.platform.Platform import is_windows [as 别名]
def get_subprocess_output(command, log, shell=False, stdin=None, output_expected=True):
"""
Run the given subprocess command and return it's output. Raise an Exception
if an error occurs.
"""
# Use tempfile, allowing a larger amount of memory. The subprocess.Popen
# docs warn that the data read is buffered in memory. They suggest not to
# use subprocess.PIPE if the data size is large or unlimited.
with nested(tempfile.TemporaryFile(), tempfile.TemporaryFile()) as (stdout_f, stderr_f):
proc = subprocess.Popen(command,
close_fds=not Platform.is_windows(), # only set to True when on Unix, for WIN compatibility
shell=shell,
stdin=stdin,
stdout=stdout_f,
stderr=stderr_f)
proc.wait()
stderr_f.seek(0)
err = stderr_f.read()
if err:
log.debug("Error while running {0} : {1}".format(" ".join(command),
err))
stdout_f.seek(0)
output = stdout_f.read()
if output_expected and output is None:
raise SubprocessOutputEmptyError("get_subprocess_output expected output but had none.")
return (output, err, proc.returncode)
示例2: is_my_process
# 需要导入模块: from utils.platform import Platform [as 别名]
# 或者: from utils.platform.Platform import is_windows [as 别名]
def is_my_process(pid):
"""
Check if the pid in the pid given corresponds to a running process
and if psutil is available, check if it's process corresponding to
the current executable
"""
pid_existence = pid_exists(pid)
if not psutil or not pid_existence:
return pid_existence
if Platform.is_windows():
# We can't check anything else on Windows
return True
else:
try:
command = psutil.Process(pid).cmdline() or []
except psutil.Error:
# If we can't communicate with the process,
# it's not an agent one
return False
# Check that the second arg contains (agent|dogstatsd).py
# see http://stackoverflow.com/a/2345265
exec_name = os.path.basename(inspect.stack()[-1][1]).lower()
return len(command) > 1 and exec_name in command[1].lower()
示例3: upload
# 需要导入模块: from utils.platform import Platform [as 别名]
# 或者: from utils.platform.Platform import is_windows [as 别名]
def upload(self, email=None):
self._check_size()
if self._cmdline:
self._ask_for_confirmation()
if not email:
email = self._ask_for_email()
log.info("Uploading {0} to Datadog Support".format(self._tar_path))
url = self._url
if self._case_id:
url = '{0}/{1}'.format(self._url, str(self._case_id))
url = "{0}?api_key={1}".format(url, self._api_key)
requests_options = {
'data': {
'case_id': self._case_id,
'hostname': self._hostname,
'email': email
},
'files': {'flare_file': open(self._tar_path, 'rb')},
'timeout': self.TIMEOUT
}
if Platform.is_windows():
requests_options['verify'] = os.path.realpath(os.path.join(
os.path.dirname(os.path.realpath(__file__)),
os.pardir, os.pardir,
'datadog-cert.pem'
))
self._resp = requests.post(url, **requests_options)
self._analyse_result()
return self._case_id
示例4: _add_conf_tar
# 需要导入模块: from utils.platform import Platform [as 别名]
# 或者: from utils.platform.Platform import is_windows [as 别名]
def _add_conf_tar(self):
conf_path = get_config_path()
if self._can_read(conf_path, output=False):
self._add_clean_conf(
conf_path,
'etc',
self.MAIN_CREDENTIALS
)
if not Platform.is_windows():
supervisor_path = os.path.join(
os.path.dirname(get_config_path()),
'supervisor.conf'
)
if self._can_read(supervisor_path, output=False):
self._add_clean_conf(
supervisor_path,
'etc'
)
for file_path in glob.glob(os.path.join(get_confd_path(), '*.yaml')) +\
glob.glob(os.path.join(get_confd_path(), '*.yaml.default')):
if self._can_read(file_path, output=False):
self._add_clean_conf(
file_path,
os.path.join('etc', 'confd'),
self.CHECK_CREDENTIALS
)
示例5: get_checks
# 需要导入模块: from utils.platform import Platform [as 别名]
# 或者: from utils.platform.Platform import is_windows [as 别名]
def get_checks():
checks = {}
conf_d_directory = get_confd_path()
for filename in sorted(os.listdir(conf_d_directory)):
module_name, ext = osp.splitext(filename)
if Platform.is_windows():
excluded_checks = EXCLUDED_WINDOWS_CHECKS
else:
excluded_checks = EXCLUDED_MAC_CHECKS
if filename.split(".")[0] in excluded_checks:
continue
if ext not in (".yaml", ".example", ".disabled"):
continue
agent_check = AgentCheck(filename, ext, conf_d_directory)
if (
agent_check.enabled
or agent_check.module_name not in checks
or (not agent_check.is_example and not checks[agent_check.module_name].enabled)
):
checks[agent_check.module_name] = agent_check
checks_list = checks.values()
checks_list.sort(key=lambda c: c.module_name)
return checks_list
示例6: get_config_path
# 需要导入模块: from utils.platform import Platform [as 别名]
# 或者: from utils.platform.Platform import is_windows [as 别名]
def get_config_path(cfg_path=None, os_name=None):
# Check if there's an override and if it exists
if cfg_path is not None and os.path.exists(cfg_path):
return cfg_path
# Check if there's a config stored in the current agent directory
try:
path = os.path.realpath(__file__)
path = os.path.dirname(path)
return _config_path(path)
except PathNotFound as e:
pass
# Check for an OS-specific path, continue on not-found exceptions
bad_path = ''
try:
if Platform.is_windows():
common_data = _windows_commondata_path()
return _config_path(os.path.join(common_data, 'Datadog'))
elif Platform.is_mac():
return _config_path(MAC_CONFIG_PATH)
else:
return _config_path(UNIX_CONFIG_PATH)
except PathNotFound as e:
if len(e.args) > 0:
bad_path = e.args[0]
# If all searches fail, exit the agent with an error
sys.stderr.write("Please supply a configuration file at %s or in the directory where "
"the Agent is currently deployed.\n" % bad_path)
sys.exit(3)
示例7: __init__
# 需要导入模块: from utils.platform import Platform [as 别名]
# 或者: from utils.platform.Platform import is_windows [as 别名]
def __init__(self, parent=None):
QMenu.__init__(self, parent)
self.options = {}
system_tray_menu = [
(self.START, lambda: agent_manager("start")),
(self.STOP, lambda: agent_manager("stop")),
(self.RESTART, lambda: agent_manager("restart")),
]
# First the version
self.addAction(self.ABOUT.format(get_version())).setEnabled(False)
self.addSeparator()
for name, action in system_tray_menu:
self.add_option(name, action)
# enable or disable mac login
if Platform.is_mac():
self.add_option(self.MAC_LOGIN.format(self.enable_or_disable_mac()),
lambda: self.enable_or_disable_login())
elif Platform.is_windows():
self.add_option(self.FLARE, lambda: thread.start_new_thread(windows_flare, ()))
# And finally the exit
self.add_option(self.EXIT, lambda: sys.exit(0))
self.connect(self, SIGNAL("aboutToShow()"), lambda: self.update_options())
示例8: _add_conf_tar
# 需要导入模块: from utils.platform import Platform [as 别名]
# 或者: from utils.platform.Platform import is_windows [as 别名]
def _add_conf_tar(self):
conf_path = get_config_path()
if self._can_read(conf_path):
self._add_file_tar(
self._strip_comment(conf_path),
os.path.join('etc', 'datadog.conf'),
original_file_path=conf_path
)
if not Platform.is_windows():
supervisor_path = os.path.join(
os.path.dirname(get_config_path()),
'supervisor.conf'
)
if self._can_read(supervisor_path):
self._add_file_tar(
self._strip_comment(supervisor_path),
os.path.join('etc', 'supervisor.conf'),
original_file_path=supervisor_path
)
for file_path in glob.glob(os.path.join(get_confd_path(), '*.yaml')) +\
glob.glob(os.path.join(get_confd_path(), '*.yaml.default')):
if self._can_read(file_path, output=False):
self._add_clean_confd(file_path)
示例9: set_ssl_validation
# 需要导入模块: from utils.platform import Platform [as 别名]
# 或者: from utils.platform.Platform import is_windows [as 别名]
def set_ssl_validation(self, options):
if self._config.get('skip_ssl_validation', False):
options['verify'] = False
elif Platform.is_windows():
options['verify'] = os.path.realpath(os.path.join(
os.path.dirname(os.path.realpath(__file__)),
os.pardir, os.pardir,
'datadog-cert.pem'
))
示例10: get_jmx_pipe_path
# 需要导入模块: from utils.platform import Platform [as 别名]
# 或者: from utils.platform.Platform import is_windows [as 别名]
def get_jmx_pipe_path():
if Platform.is_windows():
pipe_path = SD_PIPE_WIN_PATH
else:
pipe_path = SD_PIPE_UNIX_PATH
if not os.path.isdir(pipe_path):
pipe_path = '/tmp'
return pipe_path
示例11: get_checksd_path
# 需要导入模块: from utils.platform import Platform [as 别名]
# 或者: from utils.platform.Platform import is_windows [as 别名]
def get_checksd_path(osname=None):
if Platform.is_windows():
return _windows_checksd_path()
# Mac & Linux
else:
# Unix only will look up based on the current directory
# because checks.d will hang with the other python modules
cur_path = os.path.dirname(os.path.realpath(__file__))
return _checksd_path(cur_path)
示例12: test_check
# 需要导入模块: from utils.platform import Platform [as 别名]
# 或者: from utils.platform.Platform import is_windows [as 别名]
def test_check(self):
config = {'instances': self.MYSQL_CONFIG}
self.run_check_twice(config)
# Test service check
self.assertServiceCheck('mysql.can_connect', status=AgentCheck.OK,
tags=self.SC_TAGS, count=1)
# Travis MySQL not running replication - FIX in flavored test.
self.assertServiceCheck('mysql.replication.slave_running', status=AgentCheck.CRITICAL,
tags=self.SC_TAGS, count=1)
ver = map(lambda x: int(x), self.service_metadata[0]['version'].split("."))
ver = tuple(ver)
testable_metrics = (self.STATUS_VARS + self.VARIABLES_VARS + self.INNODB_VARS
+ self.BINLOG_VARS + self.SYSTEM_METRICS + self.SCHEMA_VARS + self.SYNTHETIC_VARS)
if ver >= (5, 6, 0):
testable_metrics.extend(self.PERFORMANCE_VARS)
# Test metrics
for mname in testable_metrics:
# These two are currently not guaranteed outside of a Linux
# environment.
if mname == 'mysql.performance.user_time' and not Platform.is_linux():
continue
if mname == 'mysql.performance.kernel_time' and not Platform.is_linux():
continue
if mname == 'mysql.performance.cpu_time' and Platform.is_windows():
continue
if mname == 'mysql.performance.query_run_time.avg':
self.assertMetric(mname, tags=self.METRIC_TAGS+['schema:testdb'], count=1)
elif mname == 'mysql.info.schema.size':
self.assertMetric(mname, tags=self.METRIC_TAGS+['schema:testdb'], count=1)
self.assertMetric(mname, tags=self.METRIC_TAGS+['schema:information_schema'], count=1)
self.assertMetric(mname, tags=self.METRIC_TAGS+['schema:performance_schema'], count=1)
else:
self.assertMetric(mname, tags=self.METRIC_TAGS, count=1)
# Assert service metadata
self.assertServiceMetadata(['version'], count=1)
# test custom query metrics
self.assertMetric('alice.age', value=25)
self.assertMetric('bob.age', value=20)
# test optional metrics
self._test_optional_metrics((self.OPTIONAL_REPLICATION_METRICS
+ self.OPTIONAL_INNODB_VARS
+ self.OPTIONAL_STATUS_VARS
+ self.OPTIONAL_STATUS_VARS_5_6_6), 1)
# Raises when COVERAGE=true and coverage < 100%
self.coverage_report()
示例13: _save_logs_path
# 需要导入模块: from utils.platform import Platform [as 别名]
# 或者: from utils.platform.Platform import is_windows [as 别名]
def _save_logs_path(self):
prefix = ''
if Platform.is_windows():
prefix = 'windows_'
config = get_logging_config()
self._collector_log = config.get('{0}collector_log_file'.format(prefix))
self._forwarder_log = config.get('{0}forwarder_log_file'.format(prefix))
self._dogstatsd_log = config.get('{0}dogstatsd_log_file'.format(prefix))
self._jmxfetch_log = config.get('jmxfetch_log_file')
示例14: test_my_own_pid
# 需要导入模块: from utils.platform import Platform [as 别名]
# 或者: from utils.platform.Platform import is_windows [as 别名]
def test_my_own_pid(self):
my_pid = os.getpid()
self.assertTrue(pid_exists(my_pid))
if not Platform.is_windows():
'''Test is currently not valid under windows, because
of the way nosetests is implemented. The command
is 'runpy.py', but the executable command line is
['d:\\devtools\\python27\\python.exe', 'D:\\devtools\\python27\\Scripts\\nosetests.exe', 'tests.core']
Removing until we can make an more accurate test
'''
self.assertTrue(is_my_process(my_pid))
示例15: _get_supervisor_socket
# 需要导入模块: from utils.platform import Platform [as 别名]
# 或者: from utils.platform.Platform import is_windows [as 别名]
def _get_supervisor_socket(self, agentConfig):
if Platform.is_windows():
return None
sockfile = agentConfig.get('supervisor_socket', DEFAULT_SUPERVISOR_SOCKET)
supervisor_proxy = xmlrpclib.ServerProxy(
'http://127.0.0.1',
transport=supervisor.xmlrpc.SupervisorTransport(
None, None, serverurl="unix://{socket}".format(socket=sockfile))
)
return supervisor_proxy