本文整理汇总了Python中neubot.database.DATABASE.connection方法的典型用法代码示例。如果您正苦于以下问题:Python DATABASE.connection方法的具体用法?Python DATABASE.connection怎么用?Python DATABASE.connection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类neubot.database.DATABASE
的用法示例。
在下文中一共展示了DATABASE.connection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: got_response_collecting
# 需要导入模块: from neubot.database import DATABASE [as 别名]
# 或者: from neubot.database.DATABASE import connection [as 别名]
def got_response_collecting(self, stream, request, response):
logging.info("BitTorrent: collecting ... done")
if self.success:
#
# Always measure at the receiver because there is more
# information at the receiver and also to make my friend
# Enrico happier :-P.
# The following is not a bug: it's just that the server
# returns a result using the point of view of the client,
# i.e. upload_speed is _our_ upload speed.
#
m = json.loads(response.body.read())
self.my_side["upload_speed"] = m["upload_speed"]
upload = utils.speed_formatter(m["upload_speed"])
STATE.update("test_progress", "100%", publish=False)
STATE.update("test_upload", upload)
logging.info('BitTorrent: upload speed: %s', upload)
if privacy.collect_allowed(self.my_side):
if DATABASE.readonly:
logging.warning('bittorrent_client: readonly database')
else:
table_bittorrent.insert(DATABASE.connection(), self.my_side)
# Update the upstream channel estimate
target_bytes = int(m["target_bytes"])
if target_bytes > 0:
estimate.UPLOAD = target_bytes
self.final_state = True
stream.close()
示例2: main
# 需要导入模块: from neubot.database import DATABASE [as 别名]
# 或者: from neubot.database.DATABASE import connection [as 别名]
def main(args):
''' Main function '''
try:
options, arguments = getopt.getopt(args[1:], 'f:nv')
except getopt.error:
sys.exit(USAGE)
database_path = system.get_default_database_path()
auto_discover = True
for name, value in options:
if name == '-f':
database_path = value
elif name == '-n':
auto_discover = False
elif name == '-v':
CONFIG['verbose'] = 1
if len(arguments) != 1 and len(arguments) != 2:
sys.exit(USAGE)
DATABASE.set_path(database_path)
CONFIG.merge_database(DATABASE.connection())
if len(arguments) == 2:
RUNNER_TESTS.update({arguments[0]: [arguments[1]]})
ctx = {'uri': arguments[1]}
else:
ctx = None
deferred = Deferred()
deferred.add_callback(lambda param: None)
RUNNER_CORE.run(arguments[0], deferred, auto_discover, ctx)
POLLER.loop()
示例3: main
# 需要导入模块: from neubot.database import DATABASE [as 别名]
# 或者: from neubot.database.DATABASE import connection [as 别名]
def main(args):
''' Main() function '''
try:
options, arguments = getopt.getopt(args[1:], '')
except getopt.error:
sys.exit('usage: neubot background_win32')
if options or arguments:
sys.exit('usage: neubot background_win32')
# Read settings from database
CONFIG.merge_database(DATABASE.connection())
#
# Save logs into the database, to easily access
# and show them via the web user interface.
#
LOG.use_database()
# Complain if privacy settings are not OK
privacy.complain_if_needed()
background_api.start('127.0.0.1 ::1', '9774')
BACKGROUND_RENDEZVOUS.start()
__start_updater()
POLLER.loop()
示例4: collect
# 需要导入模块: from neubot.database import DATABASE [as 别名]
# 或者: from neubot.database.DATABASE import connection [as 别名]
def collect(self, m):
btid = _make_btid(m["ident"])
if btid not in AUTH_PEERS:
raise NegotiatorEOF()
d = m["request_body"]
result = AUTH_PEERS[btid]
#
# Note that the following is not a bug: it's just that
# the server saves results using the point of view of the
# client, i.e. upload_speed _is_ client's upload speed.
#
d["timestamp"] = result["timestamp"]
d["upload_speed"] = result["upload_speed"]
if privacy.collect_allowed(d):
table_bittorrent.insert(DATABASE.connection(), d)
#
# After we've saved the result into the dictionary we
# can add extra information we would like to return to
# the client.
#
d["target_bytes"] = result["target_bytes"]
m["response_body"] = d
示例5: speedtest_store
# 需要导入模块: from neubot.database import DATABASE [as 别名]
# 或者: from neubot.database.DATABASE import connection [as 别名]
def speedtest_store(self, message):
''' Saves the results of a speedtest test '''
DATABASE.connect()
if DATABASE.readonly:
logging.warning('backend_neubot: readonly database')
return
table_speedtest.insert(DATABASE.connection(), message)
示例6: listify
# 需要导入模块: from neubot.database import DATABASE [as 别名]
# 或者: from neubot.database.DATABASE import connection [as 别名]
def listify(self):
if self._use_database:
lst = table_log.listify(DATABASE.connection())
lst.extend(self._queue)
return lst
else:
return []
示例7: main
# 需要导入模块: from neubot.database import DATABASE [as 别名]
# 或者: from neubot.database.DATABASE import connection [as 别名]
def main(args):
''' Main function '''
try:
options, arguments = getopt.getopt(args[1:], 'f:n')
except getopt.error:
sys.exit('Usage: %s [-n] [-f database] test [negotiate_uri]' % args[0])
if len(arguments) != 1 and len(arguments) != 2:
sys.exit('Usage: %s [-n] [-f database] test [negotiate_uri]' % args[0])
database_path = system.get_default_database_path()
auto_rendezvous = True
for name, value in options:
if name == '-f':
database_path = value
elif name == '-n':
auto_rendezvous = False
DATABASE.set_path(database_path)
CONFIG.merge_database(DATABASE.connection())
if len(arguments) == 2:
RUNNER_TESTS.update({arguments[0]: [arguments[1]]})
ctx = {'uri': arguments[1]}
else:
ctx = None
RUNNER_CORE.run(arguments[0], lambda *args: None, auto_rendezvous, ctx)
POLLER.loop()
示例8: api_results
# 需要导入模块: from neubot.database import DATABASE [as 别名]
# 或者: from neubot.database.DATABASE import connection [as 别名]
def api_results(stream, request, query):
''' Provide results for queried tests '''
since, until = -1, -1
test = ''
dictionary = cgi.parse_qs(query)
if dictionary.has_key("test"):
test = str(dictionary["test"][0])
if dictionary.has_key("since"):
since = int(dictionary["since"][0])
if dictionary.has_key("until"):
until = int(dictionary["until"][0])
if test == 'bittorrent':
table = table_bittorrent
elif test == 'speedtest':
table = table_speedtest
else:
raise NotImplementedTest("Test '%s' is not implemented" % test)
indent, mimetype, sort_keys = None, "application/json", False
if "debug" in dictionary and utils.intify(dictionary["debug"][0]):
indent, mimetype, sort_keys = 4, "text/plain", True
response = Message()
lst = table.listify(DATABASE.connection(), since, until)
body = json.dumps(lst, indent=indent, sort_keys=sort_keys)
response.compose(code="200", reason="Ok", body=body, mimetype=mimetype)
stream.send_response(request, response)
示例9: _api_config
# 需要导入模块: from neubot.database import DATABASE [as 别名]
# 或者: from neubot.database.DATABASE import connection [as 别名]
def _api_config(self, stream, request, query):
response = Message()
indent, mimetype, sort_keys = None, "application/json", False
dictionary = cgi.parse_qs(query)
if "debug" in dictionary and utils.intify(dictionary["debug"][0]):
indent, mimetype, sort_keys = 4, "text/plain", True
if request.method == "POST":
s = request.body.read()
updates = qs_to_dictionary(s)
privacy.check(updates)
# Very low barrier to prevent damage from kiddies
if "agent.interval" in updates:
interval = int(updates["agent.interval"])
if interval < 1380 and interval != 0:
raise ConfigError("Bad agent.interval")
CONFIG.merge_api(updates, DATABASE.connection())
STATE.update("config", updates)
# Empty JSON b/c '204 No Content' is treated as an error
s = "{}"
else:
s = json.dumps(CONFIG.conf, sort_keys=sort_keys, indent=indent)
stringio = StringIO.StringIO(s)
response.compose(code="200", reason="Ok", body=stringio,
mimetype=mimetype)
stream.send_response(request, response)
示例10: got_response_collecting
# 需要导入模块: from neubot.database import DATABASE [as 别名]
# 或者: from neubot.database.DATABASE import connection [as 别名]
def got_response_collecting(self, stream, request, response):
LOG.complete()
if self.success:
#
# Always measure at the receiver because there is more
# information at the receiver and also to make my friend
# Enrico happier :-P.
# The following is not a bug: it's just that the server
# returns a result using the point of view of the client,
# i.e. upload_speed is _our_ upload speed.
#
m = json.loads(response.body.read())
self.my_side["upload_speed"] = m["upload_speed"]
upload = utils.speed_formatter(m["upload_speed"])
STATE.update("test_upload", upload)
if privacy.collect_allowed(self.my_side):
table_bittorrent.insert(DATABASE.connection(), self.my_side)
# Update the upstream channel estimate
target_bytes = int(m["target_bytes"])
if target_bytes > 0:
estimate.UPLOAD = target_bytes
stream.close()
示例11: api_data
# 需要导入模块: from neubot.database import DATABASE [as 别名]
# 或者: from neubot.database.DATABASE import connection [as 别名]
def api_data(stream, request, query):
''' Get data stored on the local database '''
since, until = -1, -1
test = ''
dictionary = cgi.parse_qs(query)
if "test" in dictionary:
test = str(dictionary["test"][0])
if "since" in dictionary:
since = int(dictionary["since"][0])
if "until" in dictionary:
until = int(dictionary["until"][0])
if test == 'bittorrent':
table = table_bittorrent
elif test == 'speedtest':
table = table_speedtest
elif test == 'raw':
table = table_raw
else:
raise NotImplementedTest("Test not implemented")
indent, mimetype, sort_keys = None, "application/json", False
if "debug" in dictionary and utils.intify(dictionary["debug"][0]):
indent, mimetype, sort_keys = 4, "text/plain", True
response = Message()
lst = table.listify(DATABASE.connection(), since, until)
body = json.dumps(lst, indent=indent, sort_keys=sort_keys)
response.compose(code="200", reason="Ok", body=body, mimetype=mimetype)
stream.send_response(request, response)
示例12: __create_empty
# 需要导入模块: from neubot.database import DATABASE [as 别名]
# 或者: from neubot.database.DATABASE import connection [as 别名]
def __create_empty(path):
'''
This functions creates an empty Neubot database at @path,
jusing Neubot internals to do that.
'''
DATABASE.set_path(path)
connection = DATABASE.connection()
connection.commit()
connection.close()
示例13: main
# 需要导入模块: from neubot.database import DATABASE [as 别名]
# 或者: from neubot.database.DATABASE import connection [as 别名]
def main(args):
""" Main function """
try:
options, arguments = getopt.getopt(args[1:], "6A:np:vy")
except getopt.error:
sys.exit("usage: neubot skype [-6nvy] [-A address] [-p port]")
if arguments:
sys.exit("usage: neubot skype [-6nvy] [-A address] [-p port]")
prefer_ipv6 = 0
# address = 'master.neubot.org'
address = "localhost"
runner = 1
port = 8080
noisy = 0
fakeprivacy = 0
for name, value in options:
if name == "-6":
prefer_ipv6 = 1
elif name == "-A":
address = value
elif name == "-n":
runner = 0
elif name == "-p":
port = int(value)
elif name == "-v":
noisy = 1
elif name == "-y":
fakeprivacy = 1
if os.path.isfile(DATABASE.path):
DATABASE.connect()
CONFIG.merge_database(DATABASE.connection())
else:
logging.warning("skype: database file is missing: %s", DATABASE.path)
BACKEND.use_backend("null")
if noisy:
log.set_verbose()
if runner:
result = runner_clnt.runner_client(
CONFIG["agent.api.address"], CONFIG["agent.api.port"], CONFIG["verbose"], "skype"
)
if result:
sys.exit(0)
logging.info("skype: running the test in the local process context...")
if not fakeprivacy and not privacy.allowed_to_run():
privacy.complain()
logging.info("skype: otherwise use -y option to temporarily provide " "privacy permissions")
sys.exit(1)
handler = SkypeNegotiate()
handler.connect((address, port), prefer_ipv6, 0, {})
POLLER.loop()
示例14: do_collect
# 需要导入模块: from neubot.database import DATABASE [as 别名]
# 或者: from neubot.database.DATABASE import connection [as 别名]
def do_collect(self, stream, request):
self._speedtest_complete(request)
s = request.body.read()
m = marshal.unmarshal_object(s, "text/xml", compat.SpeedtestCollect)
if privacy.collect_allowed(m):
table_speedtest.insertxxx(DATABASE.connection(), m)
response = Message()
response.compose(code="200", reason="Ok")
stream.send_response(request, response)
示例15: __writeback
# 需要导入模块: from neubot.database import DATABASE [as 别名]
# 或者: from neubot.database.DATABASE import connection [as 别名]
def __writeback(self):
"""Really commit pending log records into the database"""
connection = DATABASE.connection()
table_log.prune(connection, DAYS_AGO, commit=False)
for record in self._queue:
table_log.insert(connection, record, False)
connection.commit()
connection.execute("VACUUM;")
connection.commit()