def create(cls, name, size): '''create a vhd ,size MB''' args = [ "create", "-n %s", "-s %s", ] cmd = cls.vhdutil + " ".join(args) % (name, size) try: execute(cmd) msg = "vhd-util create a new vhd succesfully" log.info(msg) except Exception, e: msg = "vhd-util create a new vhd failed, detail: %s" % e raise Exception(msg)
def snapshot(cls, name, parent): '''create a vhd snapshot for parent, which name is name''' args = [ "snapshot", "-n %s", "-p %s", ] cmd = cls.vhdutil + " ".join(args) % (name, parent) try: execute(cmd) msg = "vhd-util snapshot succesfully" log.info(msg) return 0, msg except Exception, e: msg = "vhd-util snapshot failed, detail: %s" % e raise Exception(msg)
def query_size(cls, path): """query vhd's size""" args = ["query", "-n %s", "-v"] cmd = cls.vhdutil + " ".join(args) % path log.debug(cmd) try: ret = execute(cmd) return ret except Exception, e: msg = "vhd-util query size failed, detail: %s" % e import traceback traceback.print_exc() raise Exception(msg)
def empty(cls, path): """judge if a vhd is empty""" args = ["query", "-n %s", "-a"] cmd = cls.vhdutil + " ".join(args) % path log.debug(cmd) try: ret = execute(cmd) if ret == "0": return True else: return False except Exception, e: msg = "vhd-util read vhd BAT failed, detail: %s" % e raise Exception(msg)
def query_parent(cls, path): """query vhd's parent""" args = ["query", "-n %s", "-p"] cmd = cls.vhdutil + " ".join(args) % path log.debug(cmd) try: ret = execute(cmd) if ret and "no parent" in ret: return None print "parent is", ret return ret except Exception, e: msg = "vhd-util query parent failed, detail: %s" % e import traceback traceback.print_exc() raise Exception(msg)
def on_make_archive(self, widget): xorg_backup_name = "failsafeX-backup-${timestamp}" xorg_backup_dir = "/tmp" # TODO: $(mktemp -d -t ${xorg_backup_name}.XXX) xorg_backup_file = "/var/log/%s.tar" %(xorg_backup_name) shutils.copy("/etc/X11/xorg.conf", xorg_backup_dir) shutils.copy("/var/log/Xorg.0.log", xorg_backup_dir) shutils.copy("/var/log/Xorg.0.log.old", xorg_backup_dir) shutils.copytree("/var/log/gdm", xorg_backup_dir) shutils.copytree("/var/log/lightdm", xorg_backup_dir) execute("lspci -vvnn > %s/lspci-vvnn.txt" %(xorg_backup_dir)) execute("xrandr --verbose > %s/xrandr-verbose.txt" %(xorg_backup_dir)) execute("tar -cf %s %s" %(xorg_backup_file, xorg_backup_dir)) shutils.rmtree(xorg_backup_dir)
def execute(self): """ take action based on the values submitted in the form. :return: """ data = self.dataset_subject_chooser.get_data() data['subject_key'] = self.key_file.subject_to_key(data['subject']) data['path'] = self.user_file_path data['option_type'] = self.option_type options_data = self.options_chooser.get_data() all_data = {**data, **options_data} missing_data = False for k in all_data: if all_data[k] == '' or all_data[k] is None: missing_data = True break if missing_data: show_message('Missing data', 'Please fill the entire form') else: res, sub_path = execute(all_data) if res: show_message('Success', 'Successfully uploaded to {0}'.format(sub_path), success=True)
def on_edit_file(self, widget, filename): if not os.path.exists(self.xorg_conf_path): # TODO: Stub in an xorg.conf pass execute("zenity --text-info --editable --filename=%s --width=640 --height=480" %(self.xorg_conf_path))
def on_view_file(self, widget, filename): execute("zenity --text-info --filename=%s --width=640 --height=480" %(filename))