本文整理汇总了Python中database.DatabaseManager.connect方法的典型用法代码示例。如果您正苦于以下问题:Python DatabaseManager.connect方法的具体用法?Python DatabaseManager.connect怎么用?Python DatabaseManager.connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类database.DatabaseManager
的用法示例。
在下文中一共展示了DatabaseManager.connect方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _add_message
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import connect [as 别名]
def _add_message(self, data):
database = DatabaseManager()
security = Security()
user = security.user
password = security.password
database.connect(dialect=self.dialect, user=user, passwd=password, database=self.db)
database.add_messages(data)
示例2: Security
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import connect [as 别名]
from database import DatabaseManager
from security import Security
sec = Security()
user = sec.user
passwd = sec.password
dialect = sec.dialect
db = sec.database
database = DatabaseManager()
database.connect(dialect=dialect, user=user, passwd=passwd, database=db)
print database.get_messages()
#print database.add_payee("BRITAM")
# database.add_cheque_type("Type")
#database.add_bank("Equity")
# database.delete_cheque_type("Standard")
# database.delete_bank("Equity")
# database.delete_cheque("BRITAM")
# database.delete_payee("BRITAM")
print database.get_bank()
print database.get_payee()
print database.get_chequetype()
示例3: Controller
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import connect [as 别名]
class Controller(object, Initializer):
def __init__(self):
self.now = datetime.datetime.today()
self.latter = datetime.timedelta(hours=24) + self.now
self.db = DatabaseManager()
self.sec = Security()
self.user = self.sec.user
self.password = self.sec.password
self.dialect = self.sec.dialect
self.database = self.sec.database
self.db.connect(dialect=self.dialect, user=self.user, passwd=self.password, database=self.database)
self.waiting_messages = list()
Initializer.__init__(self)
def daily_messenger(self):
"""
Manages the application clock
"""
seconds = 30
while True:
time.sleep(seconds)
if self.now.hour < 8:
hour = (8 - self.now.hour) + 24
elif self.now.hour > 8:
hour = (24 - self.now.hour)
else:
hour = 24
self.latter = datetime.timedelta(hours=hour) + self.now
seconds = hour * 60 * 60
self.now = datetime.datetime.now()
msg = "Daily Thread initiating messenger"
log.info(msg)
print >>sys.stdout, msg
if self.time_checker():
log.debug("Daily Thread system update")
message_controller = MessageController(self.db)
message_controller.central_command()
self.message_sender()
with closing(open("bin/details.txt", "w")) as fl:
fl.write(time.ctime())
def hourly_messenger(self):
while True:
time.sleep(3600)
collect_data()
self.message_collector()
msg = "Hourly Thread initiating messenger"
log.info(msg)
print >>sys.stdout , msg
self.message_sender()
def hustler(self):
daily_thread = Thread(target=self.daily_messenger, name="Daily Thread")
hourly_thread = Thread(target=self.hourly_messenger, name="Hourly Thread")
daily_thread.start()
hourly_thread.start()
def message_collector(self):
self.waiting_messages = list()
messages = self.db.get_outbox("waiting")
if isinstance(messages, list) and messages:
for message in messages:
inst = PhoneNumber(message["phone"])
phn = inst.list_of_numbers()
if phn:
message_tuple = (message["phone"], message["message"])
else:
continue
self.waiting_messages.append(message_tuple)
def time_checker(self):
if not os.path.exists("bin/details.txt"):
return True
with closing(open("bin/details.txt", "rb")) as fl:
start_date = fl.readline()
if start_date[:10] == time.ctime()[:10]:
print False, start_date[:10], time.ctime()[:10]
return False
else:
print True, start_date[:10], time.ctime()[:10]
return True
def message_sender(self):
self.message_collector()
msg = "%d messages waiting to be sent" % len(self.waiting_messages)
log.info(msg)
print >>sys.stdout, msg
sent_list = []
for message in self.waiting_messages:
sender = Messenger([message])
sender.check_config("smsleopard")
sent_msg = sender.send_sms()[0]
sent_list.extend(sent_msg)
msg = "%d sent messages" % len(sent_list)
log.info(msg)
for sent in sent_list:
self.db.update_outbox(sent)
示例4: FileManager
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import connect [as 别名]
class FileManager(object):
"""
Contains methods responsible for managing the crucial file components of the application
This files include:
allclients.dat
balance.dat
extensions.dat
expiry.dat
config.conf
etc.
"""
def __init__(self):
self.files = {
"clients": "allclients.dat",
"balance": "balance.dat",
"renewal": "expiry.dat",
"newinvoice": "renewal.dat",
"extension": "extensions.dat",
"birthday": "allclients.dat"
}
self.database = DatabaseManager()
self.report_file = "bin/report"
self.message_file = "bin/messages"
self.config_file = "bin/config.conf"
self.folders = ["bin"]
self.initializer()
self.configarations()
self.security = Security()
self.user = self.security.user
self.password = self.security.password
self.dialect = self.security.dialect
self.db = self.security.database
self.database.connect(dialect=self.dialect, user=self.user, passwd=self.password, database=self.db)
def initializer(self):
for name in self.folders:
if not os.path.exists(name):
os.mkdir(name)
for key, name in self.files.items():
name = "bin/" + name
if not os.path.exists(name):
msg = key + " file missing"
self.reporter((False, msg))
log.warning(msg)
else:
msg = key + " file found"
self.reporter(("server", msg))
def configarations(self):
"""
interval is the date differences that the messages should be sent.
status determines if the messages are to be sent or not
next means the next date general messages have to be sent
"""
config_types = {
'clients': {"interval": False, "status": False, "next": False},
'balance': {"interval": False, "status": False, "amount": 500},
'renewal': {"interval": [15, 5], "status": True},
'newinvoice': {"interval": [15, 5], "status": False},
'extension': {"interval": [15, 5], "status": False},
'birthday': {"status": True},
'cheque': {"interval": [15, 5], "status": True},
'connection': {'dialect': "mysql", 'database': "bima"},
}
if not os.path.exists(self.config_file):
with closing(open(self.config_file, "wb")) as fl:
Pickle.dump(config_types, fl)
log.info("Setting up system configurations")
if not os.path.exists(self.message_file):
self.initialize_messages()
def reporter(self, details):
"""
Manages a report file that has details on errors and ho the application
executes the most important steps.
The details parameter is either a Tuple or a list of Tuples.
The tuple has a type of message and the message itself. Error messages
are represented by a False object while the rest have there specific names
written out.
"""
if not os.path.exists(self.report_file):
with open(self.report_file, "wb") as fl:
Pickle.dump([], fl)
with closing(open(self.report_file, "rb")) as fl:
data = Pickle.load(fl)
with closing(open(self.report_file, "wb")) as fl:
if isinstance(details, tuple):
now = time.ctime()
type_ = details[0]
message = details[1]
data.append((now, type_, message))
elif isinstance(details, list):
for detail in details:
now = time.ctime()
type_ = detail[0]
message = detail
data.append((now, type_, message))
#.........这里部分代码省略.........
示例5: LoginProtocol
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import connect [as 别名]
return pb.IPerspective, avatar, lambda: None
class LoginProtocol(basic.LineReceiver):
pass
class LoginFactory(protocol.ServerFactory):
protocol = LoginProtocol
def __init__(self, portal):
self.portal = portal
db_access = DatabaseManager()
db_access.connect(dialect="mysql", user="monte", passwd="creawib", database="bima")
users = db_access.get_user_details("users")
passwords = db_access.get_user_details("passwords")
p = portal.Portal(ClassRealm(ServerFunctions(users, passwords, db_access), users))
p.registerChecker(PasswordDictChecker(passwords))
checker = checkers.InMemoryUsernamePasswordDatabaseDontUse()
def register(name, passwd):
checker.addUser(name, passwd)
p.registerChecker(checker)
def main():
c2 = AllowAnonymousAccess()
p.registerChecker(c2)
if not os.path.exists('tmp'):
os.mkdir('tmp')
示例6: ping
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import connect [as 别名]
ioloop = tornado.ioloop.IOLoop.instance()
ioloop.start()
def ping(self):
print("pong!")
# =============================================================================================================
_main = None
_db = None
#_menu = None
if __name__ == "__main__":
print("main")
_main = main()
#Menu.Instance().number = 10
print("creating menu")
_menu = Menu()
print("created menu")
_menu.number = 10
_db = DatabaseManager()
_db.connect()
_main.launch_server()
_main.show_index()