def suggest_cb(self, b): nic_list=glob('/etc/sysconfig/networking/devices/*') nm=0 for nic in nic_list: d=self.nic_parse(nic) if not d: continue ch=0 if d.get('ONBOOT','yes')!='yes' and sure(_("The device [%s] named [%s] is not set to be started automatically on each boot.\nDo you like to start it automatically on boot?") % (d['DEVICE'], d.get('NAME','unnamed')), self.ccw): self.ccw.mechanism('net','nic_set_onboot', nic) if d.get('NM_CONTROLLED','yes')!='yes' and sure(_("The device [%s] named [%s] is not set to be controlled with Network Manager.\nDo you like to allow Network Manager to control this device?") % (d['DEVICE'], d.get('NAME','unnamed')), self.ccw): self.ccw.mechanism('net','nic_set_nm', nic) ch=1 if d.get('USERCTL','yes')!='yes' and sure(_("The device [%s] named [%s] is not allowed to be controlled by unprivileged users.\nDo you like to allow them?") % (d['DEVICE'], d.get('NAME','unnamed')), self.ccw): self.ccw.mechanism('net','nic_set_userctl', nic) # if something is changed reload conf if ch: d=self.nic_parse(nic) if not d: continue if d.get('NM_CONTROLLED','yes')!='yes': nm|=1 fix_nm_service=chkconfig(5, 'network') or not chkconfig(5, 'NetworkManager') if nm and fix_nm_service and sure(_("Network Manager is used by some device, but you are using the legacy network service.\nWould you like to fix that?") % (d['DEVICE'], d.get('NAME','unnamed')), self.ccw): self.ccw.mechanism('net','set_nm_service', nic) info(_("We got no more suggestions.\nIf you have made any changes it will take effect on next boot"), self.ccw)
def import_fonts(self,*args): M=("ar", "co", "ta","ti","tr", "ve") f=[] m=[] d=[] if not sure(_("Are you sure you want to search and install fonts ?\nMake sure that the partitions are mounted and you have a license to use the fonts.\n"), self.ccw): return for i in open('/proc/mounts','rt'): p=self.__ch_re.sub(lambda m: chr(int(m.group(1),8)), i.split()[1].strip()) if p=='/': continue d.extend(glob(os.path.join(p,'*','[Ff][Oo][Nn][Tt][Ss]'))) for i in d: f.extend(glob(os.path.join(i,'*.[Tt][Tt][Ff]'))) # make f uniq k={} for i in f: k[os.path.basename(i).lower()]=i f=k.values() m=filter(lambda i: os.path.basename(i).lower()[:2] in M,f) a=True lf,lm=len(f),len(m) if lf-lm>10: a=sure(_("There are %i fonts found, only %i could be important to you. Do you want to install all the fonts?\n") % (lf,lm), self.ccw) d=os.path.expanduser('~/.fonts/') if not os.path.exists(d): os.mkdir(d) os.system('xdg-open "%s"' % d) if not a: f=m for i in f: shutil.copy(i,d) info(_("Done. %d font were installed.") % len(f), self.ccw)
def execute(self, *args): f = "/usr/bin/livecd-iso-to-disk" if not os.path.exists(f): f = "/mnt/live/LiveOS/livecd-iso-to-disk" if not os.path.exists(f): error(_("The package 'livecd-tools' is not installed."), self.ccw) if sure(_("Would you like to install 'livecd-tools'?"), self.ccw): self.ccw.install_packages(['livecd-tools']) info(_("Please try again."), self.ccw) return ov = self.overlay_size.get_value() opt = "--noverify" dst, s, l = self.dst_parse(self.target_dev_ls.get_active_text()) if not dst: error(_('Please choose valid target device.'), self.ccw) return if self.format.get_active(): opt += " --format" if not sure( _("Are you sure you want to format target device (labeled %s)?" ) % l, self.ccw): return if self.reset_mbr.get_active(): opt += " --reset-mbr" if ov > 0: opt += " --overlay-size-mb %i" % ov if self.src_iso_file.get_active(): src = self.iso_file_b.get_filename() if not src or not os.path.exists(src) or not src.lower().endswith( '.iso'): error(_('Please choose a valid iso file'), self.ccw) return else: src = self.iso_dev_ls.get_active_text() if not src: error(_('Please choose a source device.'), self.ccw) return os.system("umount '%s'" % dst) cmd = '''%s %s "%s" "%s"''' % (f, opt, src, dst) print cmd dlg = wait(self.ccw) p = self.__dev_re.findall(dst)[0] dst0 = self.__dev_re.sub('', dst) self.ccw.mechanism('run', 'system', '''echo ",,,*" | sfdisk %s -N%s''' % (dst0, p)) while (Gtk.main_iteration_do()): pass r = self.ccw.mechanism('run', 'system', cmd, on_fail='0') if r != '0' and r != 'NotAuth': error( _("An error occurred while creating the live system.\nYou may run the following command in terminal to see the error:\n%s" ) % cmd, self.ccw) while (Gtk.main_iteration_do()): pass dlg.hide() if dlg: dlg.destroy()
def rm_rpms_cb(self, b): cmd = '/bin/rm -f' dlg = wait(self.ccw) dlg.show_all() p = self.get_ls() if not p: dlg.hide() info(_("There are no repeated RPM files!"), self.ccw) return s = self.get_size(p)[1] dlg.hide() if not sure( _("Delete %d RPM Files, will save %s!\nAre you sure?" % (len(p), s)), self.ccw): return cmd = '%s %s' % (cmd, ' '.join(p)) dlg.show_all() r = self.ccw.mechanism('run', 'system', cmd) dlg.hide() if r == 'NotAuth': return if r: info( _("%d RPM files has been deleted, TO save %s!") % (len(p), s), self.ccw) else: info( _("We can't complete this action at this time, due unknown error, you can try again!" ), self.ccw)
def __restore_default_file_config(self,button): if not sure(_("Are you sure you want to continue?"), self.ccw): return check=self.ccw.mechanism('run','system',"cp /etc/default/tlp.backup_by_ojuba_occ /etc/default/tlp") if check!='0': return info (_("Done"))
def __on_button_clicked(self, button): if not sure(_("Are you sure you want to continue?"), self.ccw): return count = 0 for n in self.__to_order_d: if count == 0: subprocess.call(r"echo '%s=%s' >/tmp/ojuba_grub_plugin" % (self.config[n][0], self.config[n][1]), shell=True) count = 1 else: subprocess.call(r"echo '%s=%s' >>/tmp/ojuba_grub_plugin" % (self.config[n][0], self.config[n][1]), shell=True) check = self.ccw.mechanism( 'run', 'system', "cp /tmp/ojuba_grub_plugin /etc/default/grub") if check != '0': return info(_("Change Config Fail")) check = self.__update_grub() if not check: return info( _("Update Grub Menu Fail Restore Default Config File And Restart occ" )) info(_("Done"))
def apply_cb(self, w): if not sure(_('Are you sure you want to apply changes?'), self.ccw): return dlg=wait(self.ccw) self.convert_img(self.bg_fn, self.bg_nm) self.conf[0]['GRUB_TIMEOUT'] = int(self.Time_Out.get_value()) self.conf[0]['GRUB_DISTRIBUTOR'] = self.conf[0]['GRUB_DISTRIBUTOR'] self.conf[0]['GRUB_DISABLE_RECOVERY'] = str(not self.recovery_c.get_active()).lower() self.conf[0]['GRUB_DEFAULT'] = self.conf[0]['GRUB_DEFAULT'] self.conf[0]['GRUB_CMDLINE_LINUX'] = '"' + self.Kernel_Opt.get_text() + '"' self.conf[0]['GRUB_GFXMODE'] = self.gfxmode self.conf[0]['GRUB_GFXPAYLOAD_LINUX'] = "keep" self.conf[0]['GRUB_BACKGROUND'] = '/boot/grub2/oj.grub2.png' self.conf[1]['BACKGROUND'] = self.bg_fn self.conf[1]['FONT_FILE'] = self.font_fn self.conf[1]['FONT_NAME'] = self.font_nm font=self.font_fn if not self.theme_c.get_active(): font='' cfg = '\n'.join(map(lambda k: "%s=%s" % (k,str(self.conf[0][k])), self.conf[0].keys())) cfg +='\n' usr_cfg = '\n'.join(map(lambda k: "%s=%s" % (k,str(self.conf[1][k])), self.conf[1].keys())) try: open(self.user_conf, 'w+').write(usr_cfg) except IOError: pass #print usr_cfg, '\n\n',cfg,font, self.bg_fn,self.bg_nm r = self.ccw.mechanism('grub2', 'apply_cfg', self.conf_fn, cfg, font, self.bg_nm) dlg.destroy() if r == 'NotAuth': return if r.startswith("Error"): return error('%s: %s' %(_('Error!'),r),self.ccw) info(_('Done!'),self.ccw)
def save(self, b): v = {} modes = map(lambda m: m.get_child().get_text(), filter(lambda r: r.get_active(), self.res)) v['modes'] = self.modestr(modes) v['driver'] = self.driver.get_text().strip() v['compiz'] = ('Disable', 'Enable')[self.compiz.get_active()] v['aiglx'] = ('off', 'on')[self.aiglx.get_active()] if ' ' in v['driver'] or '\t' in v['driver']: error(_('driver should be one word')) return if v['driver'].lower() != v['driver']: error(_('driver should be lower case'), self.ccw) return if not sure( _('Are you sure you want to overwrite your currently working xorg.conf file and generate a new one ?' ), self.ccw): return xorgconf = self.xorgconf_t % v s = self.ccw.mechanism('vga', 'saveXorgConf', xorgconf) if s == 'NotAuth': return if s == '0': info(_('Done. Changes will take effect when you login next time.'), self.ccw) else: error(_('unexpected return code, possible an error had occurred.'), self.ccw) return self.mkinitrd(b)
def remove_from_boot(self, *args): if not sure( _("Are you sure you want to disable an already enabled hda fix ?" ), self.ccw): return r = self.ccw.mechanism('snd', 'remove_hda_verb') if r == 'NotAuth': return info(_('Done. New settings will take effect on next boot.'), self.ccw)
def apply_cb(self, w): if not sure(_('Are you sure you want to detect and add other operating systems?'), self.ccw): return dlg=wait(self.ccw) dlg.show_all() r=self.ccw.mechanism('grub2','os_prober_cb') dlg.hide() if r == 'NotAuth': return if r.startswith("Error"): return info('%s: %s'%(_('Error'),r[6:])) info(_('Operating systems found:\n%s') % r,self.ccw)
def always_apply(self,*args): k=self.k_ls.get_active_text() i=self.m_ls.get_active() if not k or i<0: error(_("no method selected.")); return if not sure(_('Are you sure you want to apply this method automatically. You may want to try the "apply now" button first.')): return if not self.usbsw_info.has_key(k): error(_("Could not find suitable method.")); return r=self.ccw.mechanism('usbsw','add_rule',self.usbsw_info[k][m][1]) if r!='0': error(_("unexpected return code [%s]." % r)) else: info(_("Applied successfully"))
def __restore_default_file_config(self,button): if not sure(_("Are you sure you want to continue?"), self.ccw): return check=self.ccw.mechanism('run','system',"cp /etc/default/grub.backup_by_ojuba_occ /etc/default/grub") if check!='0': return info (_("Restore Default Config File Fail")) check=self.__update_grub() if not check: return info(_("Update Grub Menu Fail")) info (_("Done"))
def execute(self, *args): f="/usr/bin/livecd-iso-to-disk" if not os.path.exists(f): f="/mnt/live/LiveOS/livecd-iso-to-disk" if not os.path.exists(f): error(_("The package 'livecd-tools' is not installed."), self.ccw) if sure(_("Would you like to install 'livecd-tools'?"), self.ccw): self.ccw.install_packages(['livecd-tools']) info(_("Please try again."), self.ccw) return ov=self.overlay_size.get_value() opt="--noverify" dst,s,l=self.dst_parse(self.target_dev_ls.get_active_text()) if not dst: error(_('Please choose valid target device.'), self.ccw); return if self.format.get_active(): opt+=" --format" if not sure(_("Are you sure you want to format target device (labeled %s)?") % l, self.ccw): return if self.reset_mbr.get_active(): opt+=" --reset-mbr" if ov>0: opt+=" --overlay-size-mb %i" % ov if self.src_iso_file.get_active(): src=self.iso_file_b.get_filename() if not src or not os.path.exists(src) or not src.lower().endswith('.iso'): error(_('Please choose a valid iso file'), self.ccw); return else: src=self.iso_dev_ls.get_active_text() if not src: error(_('Please choose a source device.'), self.ccw); return os.system("umount '%s'" % dst) cmd='''%s %s "%s" "%s"''' % (f, opt,src,dst) print cmd dlg=wait(self.ccw) p=self.__dev_re.findall(dst)[0] dst0=self.__dev_re.sub('',dst) self.ccw.mechanism('run','system','''echo ",,,*" | sfdisk %s -N%s''' % (dst0, p)) while(Gtk.main_iteration_do()): pass r=self.ccw.mechanism('run','system',cmd, on_fail='0') if r!='0' and r!='NotAuth': error(_("An error occurred while creating the live system.\nYou may run the following command in terminal to see the error:\n%s") % cmd, self.ccw) while(Gtk.main_iteration_do()): pass dlg.hide() if dlg: dlg.destroy()
def apply_cb(self, w): if not sure( _('Are you sure you want to detect and add other operating systems?' ), self.ccw): return dlg = wait(self.ccw) dlg.show_all() r = self.ccw.mechanism('grub2', 'os_prober_cb') dlg.hide() if r == 'NotAuth': return if r.startswith("Error"): return info('%s: %s' % (_('Error'), r[6:])) info(_('Operating systems found:\n%s') % r, self.ccw)
def apply_cb(self, w): if not sure( _('Make sure all disks are mounted. Are you sure you want to detect and add other operating systems?' ), self.ccw): return dlg = wait() dlg.show_all() r = self.ccw.mechanism('grub', 'set_grub_items') dlg.hide() if r == 'NotAuth': return if not r: return info(_('No operating systems were found')) info(_('Operating systems found:\n%s') % r, self.ccw)
def __restore_default_file_config(self, button): if not sure(_("Are you sure you want to continue?"), self.ccw): return check = self.ccw.mechanism( 'run', 'system', "cp /etc/default/grub.backup_by_ojuba_occ /etc/default/grub") if check != '0': return info(_("Restore Default Config File Fail")) check = self.__update_grub() if not check: return info(_("Update Grub Menu Fail")) info(_("Done"))
def delete(self, b): if not sure( _('Do you like to remove xorg.conf file to use default settings?' ), self.ccw): return s = self.ccw.mechanism('run', 'system', 'rm /etc/X11/xorg.conf') if s == 'NotAuth': return if s == '0': info(_('Done. Changes will take effect when you login next time.'), self.ccw) else: error(_('unexpected return code, possible an error had occurred.'), self.ccw) return
def suggest_cb(self, b): nic_list = glob('/etc/sysconfig/networking/devices/*') nm = 0 for nic in nic_list: d = self.nic_parse(nic) if not d: continue ch = 0 if d.get('ONBOOT', 'yes') != 'yes' and sure( _("The device [%s] named [%s] is not set to be started automatically on each boot.\nDo you like to start it automatically on boot?" ) % (d['DEVICE'], d.get('NAME', 'unnamed')), self.ccw): self.ccw.mechanism('net', 'nic_set_onboot', nic) if d.get('NM_CONTROLLED', 'yes') != 'yes' and sure( _("The device [%s] named [%s] is not set to be controlled with Network Manager.\nDo you like to allow Network Manager to control this device?" ) % (d['DEVICE'], d.get('NAME', 'unnamed')), self.ccw): self.ccw.mechanism('net', 'nic_set_nm', nic) ch = 1 if d.get('USERCTL', 'yes') != 'yes' and sure( _("The device [%s] named [%s] is not allowed to be controlled by unprivileged users.\nDo you like to allow them?" ) % (d['DEVICE'], d.get('NAME', 'unnamed')), self.ccw): self.ccw.mechanism('net', 'nic_set_userctl', nic) # if something is changed reload conf if ch: d = self.nic_parse(nic) if not d: continue if d.get('NM_CONTROLLED', 'yes') != 'yes': nm |= 1 fix_nm_service = chkconfig( 5, 'network') or not chkconfig(5, 'NetworkManager') if nm and fix_nm_service and sure( _("Network Manager is used by some device, but you are using the legacy network service.\nWould you like to fix that?" ) % (d['DEVICE'], d.get('NAME', 'unnamed')), self.ccw): self.ccw.mechanism('net', 'set_nm_service', nic) info( _("We got no more suggestions.\nIf you have made any changes it will take effect on next boot" ), self.ccw)
def __on_button_clicked(self,button): if not sure(_("Are you sure you want to continue?"), self.ccw): return count=0 for l in self.config.values(): if count==0: subprocess.call("echo \'%s=%s\' >/tmp/ojuba_tlp_plugin"%(l[0],l[1]),shell=True) count=1 else: subprocess.call("echo \'%s=%s\' >>/tmp/ojuba_tlp_plugin"%(l[0],l[1]),shell=True) check=self.ccw.mechanism('run','system',"cat /tmp/ojuba_tlp_plugin >/etc/default/tlp") if check!='0': return self.ccw.mechanism('run','system',"tlp start") info(_("Done"))
def save(self, b): v={} modes=map(lambda m: m.get_child().get_text(), filter(lambda r: r.get_active() ,self.res)) v['modes']=self.modestr(modes) v['driver']=self.driver.get_text().strip() v['compiz']=('Disable','Enable')[self.compiz.get_active()] v['aiglx']=('off','on')[self.aiglx.get_active()] if ' ' in v['driver'] or '\t' in v['driver']: error(_('driver should be one word')); return if v['driver'].lower()!=v['driver']: error(_('driver should be lower case'), self.ccw); return if not sure(_('Are you sure you want to overwrite your currently working xorg.conf file and generate a new one ?'), self.ccw): return xorgconf=self.xorgconf_t % v s=self.ccw.mechanism('vga', 'saveXorgConf', xorgconf) if s == 'NotAuth': return if s=='0': info(_('Done. Changes will take effect when you login next time.'), self.ccw) else: error(_('unexpected return code, possible an error had occurred.'), self.ccw); return self.mkinitrd(b)
def mkinitrd(self, b): if not sure( _('Some proprietary require rebuild initrd.\nWould you like to do that?' ), self.ccw): return s = self.ccw.mechanism( 'run', 'system', 'mkinitrd -f --allow-missing /boot/initrd-`uname -r`.img `uname -r`' ) if s == 'NotAuth': return if s == '0': info(_('Done. Changes will take effect when you reboot.'), self.ccw) else: error(_('unexpected return code, possible an error had occurred.'), self.ccw) return
def rm_rpms_cb(self, b): cmd = '/bin/rm -f' dlg=wait(self.ccw) dlg.show_all() p = self.get_ls() if not p: dlg.hide() info(_("There are no repeated RPM files!"), self.ccw) return s = self.get_size(p)[1] dlg.hide() if not sure(_("Delete %d RPM Files, will save %s!\nAre you sure?"%(len(p), s)), self.ccw): return cmd = '%s %s'%(cmd, ' '.join(p)) dlg.show_all() r = self.ccw.mechanism('run', 'system', cmd) dlg.hide() if r == 'NotAuth': return if r: info(_("%d RPM files has been deleted, TO save %s!") %(len(p), s), self.ccw) else: info(_("We can't complete this action at this time, due unknown error, you can try again!"), self.ccw)
def __on_button_clicked(self,button): if not sure(_("Are you sure you want to continue?"), self.ccw): return count=0 for n in self.__to_order_d: if count==0: subprocess.call(r"echo '%s=%s' >/tmp/ojuba_grub_plugin"%(self.config[n][0],self.config[n][1]),shell=True) count=1 else: subprocess.call(r"echo '%s=%s' >>/tmp/ojuba_grub_plugin"%(self.config[n][0],self.config[n][1]),shell=True) check=self.ccw.mechanism('run','system',"cp /tmp/ojuba_grub_plugin /etc/default/grub") if check!='0': return info(_("Change Config Fail")) check=self.__update_grub() if not check: return info(_("Update Grub Menu Fail Restore Default Config File And Restart occ")) info(_("Done"))
def delete(self, b): if not sure(_('Do you like to remove xorg.conf file to use default settings?'), self.ccw): return s=self.ccw.mechanism('run', 'system', 'rm /etc/X11/xorg.conf') if s == 'NotAuth': return if s=='0': info(_('Done. Changes will take effect when you login next time.'), self.ccw) else: error(_('unexpected return code, possible an error had occurred.'), self.ccw); return
def hda_verb_sure(self): if self.is_hda_verb_needed(): msg = "It seems that your sound card does not need this fix\nAre you still sure you want to run it?" else: msg = "Are you sure you want to send HDA fix command?" return sure(msg, self.ccw)
def mkinitrd(self, b): if not sure(_('Some proprietary require rebuild initrd.\nWould you like to do that?'), self.ccw): return s=self.ccw.mechanism('run', 'system','mkinitrd -f --allow-missing /boot/initrd-`uname -r`.img `uname -r`') if s == 'NotAuth': return if s=='0': info(_('Done. Changes will take effect when you reboot.'), self.ccw) else: error(_('unexpected return code, possible an error had occurred.'), self.ccw); return
def hda_verb_sure(self): if self.is_hda_verb_needed(): msg="It seems that your sound card does not need this fix\nAre you still sure you want to run it?" else: msg="Are you sure you want to send HDA fix command?" return sure(msg, self.ccw)
def remove_from_boot(self,*args): if not sure(_("Are you sure you want to disable an already enabled hda fix ?"), self.ccw): return r=self.ccw.mechanism('snd','remove_hda_verb') if r == 'NotAuth': return info(_('Done. New settings will take effect on next boot.'), self.ccw)
def remove_applied(self,*args): if not sure(_('Are you sure you want to remove all permanently applied methods.')): return r=self.ccw.mechanism('usbsw','remove_all_rules') if r!='0': error(_("unexpected return code [%s]." % r)) else: info(_("Applied successfully"))