def _launch_indicator(self): """ environ: the Gnome-session environ is accessable for root and the user who owns the session. :note: import D-Bus related modules only if using D-Bus is enabled """ print("Attempt to launch indicator application (status icon).") _path_to_app = get_resource_file(constants.INDICATORAPP_FILE) session_env = system.get_session_environment() if session_env is None: print( "No desktop session found. Indicator application is not started." ) else: _cmd = [_path_to_app] if self.__options_given.legacy_appindicator is True: _cmd.append("--legacy") if not system.is_superuser(): if system.get_user_from_uid() != session_env["USER"]: _cmd = None print("Unable to launch indicator application as current user.\n"\ "You must own current desktop session.") if _cmd is None: print("Unable to launch indicator application") else: pid = system.exec_command_async(args=_cmd, env=session_env) print("Indicator application started (PID: %s)" % pid) time.sleep(constants.INDICATOR_LAUNCH_PAUSE_SECONDS)
def do_upgrade(self): """Public method that performs the setting. Returns always `NO_ERRORS` as exit code. """ if system.is_superuser(): try: self._query_default_conffile() if self._conffile is not None: self._make_conffile_backup() self._clean_opts() self._update_compress_format() self._update_schedule() except Exception, error: print "Error while upgrading configuration 0.10 to 0.11: %s" % error traceback.print_exc()
def do_upgrade(self): """Public method that performs the setting. Returns always `NO_ERRORS` as exit code. """ if system.is_superuser(): try: print "Reading schedule info from superuser's default profile" _conffilehdl = ConfigManager.ConfigurationFileHandler() _defconffile = _conffilehdl.get_default_conffile_fullpath() print "Configuration: `%s`" % _defconffile if os.path.exists(_defconffile): _conf = ConfigManager.ConfigManager(_defconffile) _conf.write_schedule() except Exception, error: print "Error while writing CRON settings: %s" % error traceback.print_exc()
def show_about_dialog(set_transient_for = None): _icon_file = util.get_resource_file(constants.DEFAULT_ICON_FILENAME) about = Gtk.AboutDialog() about.set_name(Infos.NAME) about.set_version(Infos.VERSION) about.set_comments(Infos.DESCRIPTION) if set_transient_for is not None: about.set_transient_for(set_transient_for) about.set_copyright(Infos.COPYRIGHT) about.set_translator_credits(Infos.TRANSLATORS) about.set_authors(Infos.AUTHORS) if not system.is_superuser(): about.set_website(Infos.WEBSITE) about.set_logo(GdkPixbuf.Pixbuf.new_from_file(_icon_file)) about.set_icon_from_file(_icon_file) about.run() about.destroy()
def main(self): """Main method that actually does the upgrade process. It returns an appropriate error code. """ print "-" * 60 print "%s %s upgrade tool" % (Infos.NAME, Infos.VERSION) print "-" * 60 if not system.is_superuser(): print "Upgrade script must be run with root privileges!" retcode = NO_SUPERUSER else: retcode = NO_ERRORS self.__upgrader_v010.do_upgrade() self.__nssbackup_configs.do_upgrade() self.__upgrader_v011.do_upgrade() self.__cron_setter.do_upgrade() return retcode
def mount(self, source, mountbase): """ Mount the source intor the mountbase dir . This method should create a mount point to mount the source. The name of the mount point should be very expressive so that we avoid collision with other mount points @param source: The remote path @param mountbase: The mount points base dir @return: The mount point complete path """ exp = re.compile(ssh_url_re) match = exp.search(source) if not match: raise FuseFAMException( _("Error matching the schema 'ssh://*****:*****@example.com/home/' with '%s' (The '/' after server is mandatory)" ) % source) else: remoteSource = "ssh://" + match.group(1) if match.group(3): remoteSource += ":" + match.group(3) remoteSource += "@" + match.group(4) if match.group(6): remoteSource += ":" + match.group(6) remoteSource += "/" user = match.group(1) mountpoint = local_file_utils.joinpath( mountbase, self._defineMountDirName(source)) if match.group(7): pathinside = match.group(7) else: pathinside = "" #If the path is already mounted No need to retry if self.checkifmounted(source, mountbase): return (remoteSource, mountpoint, pathinside) cmd = "sshfs " + user + "@" + match.group(4) + ":/" cmd = cmd + " " + mountpoint port = match.group(6) if port: cmd += " -p " + port if not local_file_utils.path_exists(mountpoint): local_file_utils.makedir(mountpoint) if system.is_superuser(): cmd += " -o allow_root" self.logger.debug("Spawning: " + cmd) password = match.group(3) sshfsp = pexpect.spawn(cmd) i = sshfsp.expect(['(yes/no)', 'password:'******'Password:'******'yes') i = sshfsp.expect( ['(yes/no)', 'password:'******'Password:'******'(yes/no)', 'password:'******'Password:'******'%(command)s' didn't perform normally. Output => %(erroroutput)s " ) % { "command": cmd, "erroroutput": result }) return (remoteSource, mountpoint, pathinside)
def get_statusbar_msg_mode(statusmessage): if system.is_superuser(): stattxt = _("%s (Administrator mode)") % statusmessage else: stattxt = statusmessage return stattxt