本文整理汇总了Python中bigml.api.BigML.connection_info方法的典型用法代码示例。如果您正苦于以下问题:Python BigML.connection_info方法的具体用法?Python BigML.connection_info怎么用?Python BigML.connection_info使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bigml.api.BigML
的用法示例。
在下文中一共展示了BigML.connection_info方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: World
# 需要导入模块: from bigml.api import BigML [as 别名]
# 或者: from bigml.api.BigML import connection_info [as 别名]
class World(object):
def __init__(self):
self.USERNAME = None
self.API_KEY = None
self.api = None
self.api_dev_mode = None
self.reset_api()
self.clear()
self.dataset_ids = []
self.fields_properties_dict = {}
self.counters = {}
self.print_connection_info()
def print_connection_info(self):
self.USERNAME = os.environ.get('BIGML_USERNAME')
self.API_KEY = os.environ.get('BIGML_API_KEY')
if self.USERNAME is None or self.API_KEY is None:
assert False, ("Tests use the BIGML_USERNAME and BIGML_API_KEY"
" environment variables to authenticate the"
" connection, but they seem to be unset. Please,"
"set them before testing.")
else:
assert True
self.api = BigML(self.USERNAME, self.API_KEY)
print self.api.connection_info()
def count_resources(self, time_tag, changed=False):
"""Counts the existing resources and stores it keyed by time_tag.
If changed is set to True, only resources that are logged as
changed are listed.
"""
print "Counting resources (%s)." % time_tag
for resource_type in RESOURCE_TYPES:
resource_type = plural(resource_type)
if (not changed or len(getattr(self, resource_type))) > 0:
resources = getattr(self.api,"list_%s" % resource_type)()
if resource_type == 'source' and resources['code'] != HTTP_OK:
assert False, (
"Unable to list your sources. Please check the"
" BigML domain and credentials to be:\n\n%s" %
self.api.connection_info())
else:
if resources['code'] == HTTP_OK:
assert True
else:
assert False, ("HTTP returned code %s" %
resources['code'])
if (not resource_type in self.counters):
self.counters[resource_type] = {}
self.counters[resource_type][time_tag] = resources[
'meta']['total_count']
def clear(self):
"""Clears the stored resources' ids
"""
for resource_type in RESOURCE_TYPES:
setattr(self, plural(resource_type), [])
setattr(self, TRANSLATED_RESOURCES.get(resource_type,
resource_type), None)
def reset_api(self):
"""Reset the api connection values
"""
self.api = BigML(self.USERNAME, self.API_KEY)
self.api_dev_mode = BigML(self.USERNAME, self.API_KEY, dev_mode=True)
def delete_resources(self):
"""Deletes the created objects
"""
for resource_type in RESOURCE_TYPES:
object_list = getattr(self, plural(resource_type))
if object_list:
print "Deleting %s %s" % (len(object_list),
plural(resource_type))
delete_method = self.api.deleters[resource_type]
for obj_id in object_list:
counter = 0
result = delete_method(obj_id)
while (result['code'] != HTTP_NO_CONTENT and
counter < MAX_RETRIES):
print "Delete failed for %s. Retrying" % obj_id
time.sleep(3)
counter += 1
result = delete_method(obj_id)
if counter == MAX_RETRIES:
print ("Retries to delete the created resources are"
" exhausted. Failed to delete.")
示例2: World
# 需要导入模块: from bigml.api import BigML [as 别名]
# 或者: from bigml.api.BigML import connection_info [as 别名]
class World(object):
def __init__(self):
self.USERNAME = None
self.API_KEY = None
self.api = None
self.api_dev_mode = None
self.reset_api()
self.clear()
self.dataset_ids = []
self.fields_properties_dict = {}
self.counters = {}
self.print_connection_info()
self.test_project_name = "Test: python bindings %s" % \
datetime.datetime.now()
self.project_id = None
def print_connection_info(self):
self.USERNAME = os.environ.get('BIGML_USERNAME')
self.API_KEY = os.environ.get('BIGML_API_KEY')
if self.USERNAME is None or self.API_KEY is None:
assert False, ("Tests use the BIGML_USERNAME and BIGML_API_KEY"
" environment variables to authenticate the"
" connection, but they seem to be unset. Please,"
"set them before testing.")
else:
assert True
self.api = BigML(self.USERNAME, self.API_KEY)
print self.api.connection_info()
def clear(self):
"""Clears the stored resources' ids
"""
for resource_type in RESOURCE_TYPES:
setattr(self, plural(resource_type), [])
setattr(self, TRANSLATED_RESOURCES.get(resource_type,
resource_type), None)
def reset_api(self):
"""Reset the api connection values
"""
self.api = BigML(self.USERNAME, self.API_KEY)
self.api_dev_mode = BigML(self.USERNAME, self.API_KEY, dev_mode=True)
def delete_resources(self):
"""Deletes the created objects
"""
for resource_type in RESOURCE_TYPES:
object_list = getattr(self, plural(resource_type))
if object_list:
print "Deleting %s %s" % (len(object_list),
plural(resource_type))
delete_method = self.api.deleters[resource_type]
for obj_id in object_list:
counter = 0
result = delete_method(obj_id)
while (result['code'] != HTTP_NO_CONTENT and
counter < MAX_RETRIES):
print "Delete failed for %s. Retrying" % obj_id
time.sleep(3)
counter += 1
result = delete_method(obj_id)
if counter == MAX_RETRIES:
print ("Retries to delete the created resources are"
" exhausted. Failed to delete.")
示例3: World
# 需要导入模块: from bigml.api import BigML [as 别名]
# 或者: from bigml.api.BigML import connection_info [as 别名]
class World(object):
def __init__(self):
self.USERNAME = None
self.API_KEY = None
self.api = None
self.debug = False
self.api_debug = False
self.source_lower = None
self.source_upper = None
self.source_reference = None
self.clear()
self.dataset_ids = []
self.fields_properties_dict = {}
self.counters = {}
self.folders = []
self.test_project_name = "Test: BigMLer %s" % \
datetime.datetime.now()
self.project_id = None
self.print_connection_info()
def print_connection_info(self):
self.USERNAME = os.environ.get('BIGML_USERNAME')
self.API_KEY = os.environ.get('BIGML_API_KEY')
try:
self.debug = bool(os.environ.get('BIGMLER_DEBUG', 0))
self.api_debug = bool(os.environ.get('BIGML_DEBUG', 0))
except ValueError:
pass
if self.USERNAME is None or self.API_KEY is None:
assert False, ("Tests use the BIGML_USERNAME and BIGML_API_KEY"
" environment variables to authenticate the"
" connection, but they seem to be unset. Please,"
"set them before testing.")
else:
assert True
self.api = BigML(self.USERNAME, self.API_KEY, debug=self.api_debug)
print self.api.connection_info()
output_dir = "./last_run"
for _, subFolders, _ in os.walk("./"):
for folder in subFolders:
if folder.startswith("scenario"):
bigmler_delete(folder, output_dir=output_dir)
if os.path.exists(output_dir):
shutil.rmtree(output_dir)
def count_resources(self, time_tag, changed=False):
"""Counts the existing resources and stores it keyed by time_tag.
If changed is set to True, only resources that are logged as
changed are listed.
"""
print "Counting resources (%s)." % time_tag
for resource_type in RESOURCE_TYPES:
resource_type = plural(resource_type)
if resource_type == "time_series_set":
resource_type = "time_series"
if (not changed or len(getattr(self, resource_type))) > 0:
resources = getattr(self.api,"list_%s" % resource_type)()
if resource_type == 'source' and resources['code'] != HTTP_OK:
assert False, (
"Unable to list your sources. Please check the"
" BigML domain and credentials to be:\n\n%s" %
self.api.connection_info())
else:
if resources['code'] == HTTP_OK:
assert True
else:
assert False, ("HTTP returned code %s for %s" %
(resources['code'], resource_type))
if (not resource_type in self.counters):
self.counters[resource_type] = {}
self.counters[resource_type][time_tag] = resources[
'meta']['total_count']
def clear(self):
"""Clears the stored resources' ids
"""
for resource_type in RESOURCE_TYPES:
setattr(self, plural(resource_type), [])
setattr(self, TRANSLATED_RESOURCES.get(resource_type,
resource_type), None)
self.source_lower = None
self.source_upper = None
self.source_reference = None
def delete_resources(self):
"""Deletes the created objects
"""
for resource_type in RESOURCE_TYPES:
object_list = getattr(self, plural(resource_type))
if object_list:
print "Deleting %s %s" % (len(object_list),
plural(resource_type))
delete_method = self.api.deleters[resource_type]
for obj_id in object_list:
counter = 0
result = delete_method(obj_id)
#.........这里部分代码省略.........