本文整理汇总了Python中lib.db.DB.run_messages方法的典型用法代码示例。如果您正苦于以下问题:Python DB.run_messages方法的具体用法?Python DB.run_messages怎么用?Python DB.run_messages使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lib.db.DB
的用法示例。
在下文中一共展示了DB.run_messages方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: RunDetailsWindow
# 需要导入模块: from lib.db import DB [as 别名]
# 或者: from lib.db.DB import run_messages [as 别名]
#.........这里部分代码省略.........
##################################################################
#
# Utilities
#
##################################################################
def load_run_details(self):
#(run_id=3, name=u'test', type=1, start_time=u'2010-12-28T15:09:39.455313', hash=u'6da92e0e7f25d003bfcc2cc7d845868fe6a433e1c0fe349300659fc86c8f66ba', size=59764, nfiles=0, status=u'Succeeded')
self.lstDetails.InsertColumn(0, _("Name"))
self.lstDetails.InsertColumn(1, _("Value"))
self.lstDetails.Append([_("Backup Name"), self.run.name])
self.lstDetails.Append([_("Run Date"), self.run.start_time_str])
self.lstDetails.Append([_("Run Type"), self.run.type])
self.lstDetails.Append([_("Status"), self.run.status])
self.lstDetails.Append([_("Files Backed Up"), str(self.run.nfiles)])
self.lstDetails.Append([_("Folders Backed Up"), str(self.run.nfolders)])
self.lstDetails.Append([_("Installed Software List"), _("Included") if self.run.packages else _("Not included")])
self.lstDetails.Append([_("Total Size"), utils.readable_form(self.run.size)])
self.lstDetails.Append([_("Hash"), self.run.hash])
self.lstDetails.SetColumnWidth(0, wx.LIST_AUTOSIZE)
self.lstDetails.SetColumnWidth(1, wx.LIST_AUTOSIZE)
def load_files(self, limit):
with ProgressDialog(self, _("Loading"), _("Loading run files.\nPlease wait...")):
self.lstFiles.DeleteAllColumns()
self.lstFiles.DeleteAllItems()
self.lstFiles.InsertColumn(0, _("Path"))
self.lstFiles.InsertColumn(1, _("Size"))
self.lstFiles.InsertColumn(2, _("Mod Time"))
self.lstFiles.Freeze()
try:
files = self.db.run_contents(self.run.run_id, limit)
for file in files:
wx.Yield()
if file.type == "F":
size = utils.readable_form(file.size)
mod_time = file.mod_time
elif file.type == 'D':
size = _("Folder")
mod_time = file.mod_time
elif file.type == 'X':
size = _("(deleted)")
mod_time = ""
else:
size = "ERROR: Bad type"
path = os.path.join(self.get_path(file.parent_id), file.name)
item = (utils.display_escape(path), size, mod_time)
self.lstFiles.Append(item)
self.lstFiles.SetColumnWidth(0, wx.LIST_AUTOSIZE)
self.lstFiles.SetColumnWidth(1, wx.LIST_AUTOSIZE)
self.lstFiles.SetColumnWidth(2, wx.LIST_AUTOSIZE)
finally:
self.lstFiles.Thaw()
if self.lstFiles.GetItemCount() < limit:
# There probably aren't that many files.
self.pnlAllFiles.Hide()
self.pnlFiles.Fit()
def load_messages(self):
self.lstMessages.InsertColumn(0, _("Time"))
self.lstMessages.InsertColumn(1, _("Message"))
messages = self.db.run_messages(self.run.run_id)
for msg in messages:
item = (msg.time, msg.message)
self.lstMessages.Append(item)
self.lstMessages.SetColumnWidth(0, wx.LIST_AUTOSIZE)
self.lstMessages.SetColumnWidth(1, wx.LIST_AUTOSIZE)
def get_path(self, fs_id):
if fs_id in self.paths:
return self.paths[fs_id]
if fs_id == 0:
return "/"
# Get THIS node
fs = self.db.get_fs(fs_id)
path = os.path.join(self.get_path(fs.parent_id), fs.name)
self.paths[fs.fs_id] = path
return path
def get_paths(self, files):
# For each file, we need to calculate the full path.
# That requires getting paths for any path that we dont have yet.
paths = {}
for file in files:
parent_id = file.parent_id
# Do we know this parent_id yet?
file.path = os.path.join(self.get_path(paths, parent_id), file.name)
示例2: Run
# 需要导入模块: from lib.db import DB [as 别名]
# 或者: from lib.db.DB import run_messages [as 别名]
#.........这里部分代码省略.........
if status == 0 or status == 5:
print("Running shutdown")
subprocess.Popen(["shutdown", "-P", "now"])
print("Done running shutdown")
except Exception as e:
msg = _("Unable to shutdown PC: {error}").format(
error=str(e))
if not self.dry_run:
self.db.save_message(message)
log.error(msg)
def send_email(self, result, head):
'''
Send a message to the appropriate users.
If result is False (failure) then error message will contain the reason.
@param result:
@param error_message:
'''
log.debug("send_email: ", result, head)
if result:
message_text = head + \
_("\n\nStatistics:\n {files} files backed up.\n "
"{folders} folders backed up.\n {size} copied.\n"
).format(files=self.nfiles, folders=self.nfolders, size=utils.readable_form(self.bytes))
subject = _("Backup {server}/{backup}/{type} completed").format(server=utils.get_hostname(), backup=self.backup.name, type=self.type)
else:
message_text = head
subject = _("Backup {server}/{backup}/{type} failed").format(server=utils.get_hostname(), backup=self.backup.name, type=self.type)
if not self.options.dry_run:
messages = " " + "\n ".join([message.time + " " + message.message for message in self.db.run_messages(self.run_id)])
message_text += _("\nBackup messages:\n") + messages
else:
message_text = "\n"
log.debug("Starting mail send")
try:
sendemail.sendemail(subject, message_text)
except Exception as e:
msg = _("Unable to email results. {error}").format(error=str(e))
if not self.dry_run:
self.db.save_message(msg)
else:
print(msg)
log.trace("send_email completed")
def backup_packages(self):
'''
Build the package list. Then send to the backup server
'''
log.info("Backing up packages")
package_list = utils.get_packages()
f = tempfile.NamedTemporaryFile(delete=False)
f.write("\n".join(package_list))
f.close()
self.copy_file(f.name, const.PackageFile)
os.remove(f.name)