Example #1
0
 def update_cache_size_label(self):
     def update_cb(th, page):
         size = th.get_result()
         page.cache_size_label.set_text(_("%d MB") % (size/(1024*1024)))
     server = rcd_util.get_server_proxy()
     th = server.rcd.system.get_cache_size()
     th.connect("ready", update_cb, self)
Example #2
0
    def update_download(self):

        if self.__working_query:
            return

        self.step_label.set_text(_("Downloading packages"))

        def download_pending_cb(th, pv):
            pv.__working_query = 0
            pending = th.get_result()
            pv.update_from_pending(pending)
            pv.update_total(pending["percent_complete"] * DOWNLOAD_MULTIPLIER)
            if pending["status"] == "finished":
                pv.download_complete = 1
                pv.update_fill()
            elif pending["status"] == "failed":
                pv.download_complete = 1
                pv.__finished = 1
                msg = _("Download Failed") + ":\n"
                msg += pending.get("error_msg", _("Unknown Error"))
                pv.transaction_finished(msg)

        serv = rcd_util.get_server_proxy()
        th = serv.rcd.system.poll_pending(self.download_id)
        th.connect("ready", download_pending_cb, self)
        self.__working_query = 1
Example #3
0
def poll_cb():
    global poll_count, working_polls, missed_polls

    poll_lock.acquire()

    if working_polls < 4 and freeze_count == 0:

        server = rcd_util.get_server_proxy()
        if server is None:
            poll_lock.release()
            return 1

        working_polls += 1

        snc = SeqNoChecker()
        t = server.rcd.system.sequence_numbers()

        def got_seqno_cb(th, snc):
            try:
                r = th.get_result()
            except ximian_xmlrpclib.Fault, f:
                # FIXME?  By doing nothing here, we keep the
                # user from being hammered by a whole bunch of exceptions
                # if something has gone badly wrong.
                pass
            else:
                snc.set_sequence_numbers(r)
Example #4
0
def poll_cb():
    global poll_count, working_polls, missed_polls

    poll_lock.acquire()

    if working_polls < 4 and freeze_count == 0:

        server = rcd_util.get_server_proxy()
        if server is None:
            poll_lock.release()
            return 1

        working_polls += 1

        snc = SeqNoChecker()
        t = server.rcd.system.sequence_numbers()

        def got_seqno_cb(th, snc):
            try:
                r = th.get_result()
            except ximian_xmlrpclib.Fault, f:
                # FIXME?  By doing nothing here, we keep the
                # user from being hammered by a whole bunch of exceptions
                # if something has gone badly wrong.
                pass
            else:
                snc.set_sequence_numbers(r)
Example #5
0
    def update_download(self):

        if self.__working_query:
            return

        self.step_label.set_text(_("Downloading packages"))

        def download_pending_cb(th, pv):
            pv.__working_query = 0
            pending = th.get_result()
            pv.update_from_pending(pending)
            pv.update_total(pending["percent_complete"] * DOWNLOAD_MULTIPLIER)
            if pending["status"] == "finished":
                pv.download_complete = 1
                pv.update_fill()
            elif pending["status"] == "failed":
                pv.download_complete = 1
                pv.__finished = 1
                msg = _("Download Failed") + ":\n"                
                msg += pending.get("error_msg", _("Unknown Error"))
                pv.transaction_finished(msg)
                
        serv = rcd_util.get_server_proxy()
        th = serv.rcd.system.poll_pending(self.download_id)
        th.connect("ready", download_pending_cb, self)
        self.__working_query = 1
Example #6
0
    def __init__(self, install_packages=[], remove_packages=[],
                 verify=0, transaction_type=rcd_util.PACKAGE_TYPE_PACKAGE):
        gobject.GObject.__init__(self)
        red_component.Component.__init__(self)

        self.server = rcd_util.get_server_proxy()

        self.install_packages = install_packages
        self.remove_packages = remove_packages
        self.verify = verify

        self.dep_install = []
        self.dep_remove = []
        self.dep_error = None

        self.__worker = None
        self.__worker_handler_id = 0

        self.transaction_type = transaction_type

        # Call get_deps in an idle so that we are fully initialized
        # before we being our computation.  (In particular, the
        # parent isn't properly set on the component at this point.)
        if transaction_type == rcd_util.PACKAGE_TYPE_PATCH:
            gtk.idle_add(lambda comp: comp.emit("got-results"), self)
        else:
            gtk.idle_add(lambda comp: comp.get_deps(), self)
Example #7
0
    def update(self):
        server = rcd_util.get_server_proxy()
        privs_str = string.join(self.privileges_get(), ", ")
        th = server.rcd.users.update(self.name_get(), self.pwd_get(),
                                     privs_str)
        th.connect("ready", self.rpc_call_ready_cb, 0)

        th = server.set_password(self.pwd_get())
        th.connect("ready", self.rpc_call_ready_cb)
Example #8
0
    def update(self):
        server = rcd_util.get_server_proxy()
        privs_str = string.join(self.privileges_get(), ", ")
        th = server.rcd.users.update(self.name_get(),
                                     self.pwd_get(),
                                     privs_str)
        th.connect("ready", self.rpc_call_ready_cb, 0)

        th = server.set_password(self.pwd_get())
        th.connect("ready", self.rpc_call_ready_cb)
Example #9
0
class UpdatedPackages(PackagesFromDaemon):

    def __init__(self):
        PackagesFromDaemon.__init__(self)
        self.__worker = None
        self.__worker_handler_id = 0
        self.refresh()

    def get_packages_from_daemon(self):

        if self.__worker:
            if self.__worker_handler_id:
                self.__worker.disconnect(self.__worker_handler_id)
                self.__worker_handler_id = 0
            self.__worker.cancel()

        def query_finished_cb(worker, array):
            if not worker.is_cancelled():
                packages = []
                try:
                    updates = worker.get_result()
                except ximian_xmlrpclib.Fault, f:
                    rcd_util.dialog_from_fault(f)
                else:
                    def pkg_to_key(p):
                        return "%s:%d:%s:%s" % \
                               (p["name"], p["epoch"],
                                p["version"], p["release"])
                    
                    dup_dict = {}
                    
                    for old_pkg, pkg, history in updates:
                        pkg["__old_package"] = old_pkg
                        pkg["__history"] = history

                        key = pkg_to_key(pkg)
                        if not dup_dict.has_key(key):
                            dup_dict[key] = pkg

                    packages = dup_dict.values()

                    del dup_dict
                    
                array.set_packages(packages)

            array.message_pop()
            self.refresh_end()

        self.message_push(_("Looking for updates..."))

        server = rcd_util.get_server_proxy()
        self.__worker = server.rcd.packsys.get_updates()
        self.__worker_handler_id = self.__worker.connect("ready",
                                                         query_finished_cb,
                                                         self)
Example #10
0
def toggle_lock(pkg):
    if not pkg:
        return

    server = rcd_util.get_server_proxy()

    def ready_cb(th):
        try:
            success = th.get_result()
        except ximian_xmlrpclib.Fault, f:
            rcd_util.dialog_from_fault(f)
            return
        red_serverlistener.reset_polling(1)
Example #11
0
def toggle_lock(pkg):
    if not pkg:
        return

    server = rcd_util.get_server_proxy()

    def ready_cb(th):
        try:
            success = th.get_result()
        except ximian_xmlrpclib.Fault, f:
            rcd_util.dialog_from_fault(f)
            return
        red_serverlistener.reset_polling(1)
Example #12
0
    def __init__(self, parent=None):
        gtk.Notebook.__init__(self)

        self.__parent = parent

        self.set_show_tabs(0)
        label = gtk.Label(_("Loading preferences..."))
        label.show()
        self.append_page(label, gtk.Label(""))

        self.pages = []
        
        self.server = rcd_util.get_server_proxy()
        self.get_prefs()
Example #13
0
    def get_bundles_from_daemon(self):

        if self.query is None:
            self.set_bundles([], quiet=1)
            self.refresh_end()
            print "query is empty"
            return

        cached = _get_query_from_cache(self.query)
        if cached is not None:
            if self.__query_filter:
                filter_fn = self.__query_filter()
                cached = filter(filter_fn, cached)
            self.set_bundles(cached)
            self.refresh_end()
            return

        server = rcd_util.get_server_proxy()

        if self.__worker:
            if self.__worker_handler_id:
                self.__worker.disconnect(self.__worker_handler_id)
                self.__worker_handler_id = 0
            self.__worker.cancel()

        def query_finished_cb(worker, array):
            array.message_pop()

            if not worker.is_cancelled():
                try:
                    bundles = worker.get_result()
                    bundles = fix_bundles(map(lambda x: x["bundle"], bundles))
                except ximian_xmlrpclib.Fault, f:
                    rcd_util.dialog_from_fault(f)
                    bundles = []
                else:
                    elapsed = time.time() - worker.t1


##                     bundles = self.filter_duplicates(packages)
##                     _cache_query_results(self.query, packages)

##                     if self.__query_filter:
##                         filter_fn = self.__query_filter()
##                         packages = filter(filter_fn, packages)

                array.set_bundles(bundles or [])
            array.refresh_end()
            array.__worker = None
Example #14
0
    def toggle_subscribed(self, channel):
        def subscribe_cb(th, model, channel, sub):
            def set_cb(m, ch, flag):
                ch["subscribed"] = (flag and 1) or 0

            model.changed(set_cb, channel, sub)

        server = rcd_util.get_server_proxy()

        if channel["subscribed"]:
            th = server.rcd.packsys.unsubscribe(channel["id"])
        else:
            th = server.rcd.packsys.subscribe(channel["id"])

        th.connect("ready", subscribe_cb, self, channel, not channel["subscribed"])
Example #15
0
    def get_bundles_from_daemon(self):

        if self.query is None:
            self.set_bundles([], quiet=1)
            self.refresh_end()
            print "query is empty"
            return

        cached = _get_query_from_cache(self.query)
        if cached is not None:
            if self.__query_filter:
                filter_fn = self.__query_filter()
                cached = filter(filter_fn, cached)
            self.set_bundles(cached)
            self.refresh_end()
            return

        server = rcd_util.get_server_proxy()
            
        if self.__worker:
            if self.__worker_handler_id:
                self.__worker.disconnect(self.__worker_handler_id)
                self.__worker_handler_id = 0
            self.__worker.cancel()

        def query_finished_cb(worker, array):
            array.message_pop()

            if not worker.is_cancelled():
                try:
                    bundles = worker.get_result()
                    bundles = fix_bundles(map(lambda x:x["bundle"], bundles))
                except ximian_xmlrpclib.Fault, f:
                    rcd_util.dialog_from_fault(f)
                    bundles = []
                else:
                    elapsed = time.time() - worker.t1

##                     bundles = self.filter_duplicates(packages)
##                     _cache_query_results(self.query, packages)

##                     if self.__query_filter:
##                         filter_fn = self.__query_filter()
##                         packages = filter(filter_fn, packages)

                array.set_bundles(bundles or [])
            array.refresh_end()
            array.__worker = None
Example #16
0
    def launch_poll_threads(self, launch_max=0):
        server = rcd_util.get_server_proxy()

        launch = 1
        if launch_max:
            launch = self.max_threads

        while launch > 0 and self.thread_space():
            if not self.poll_queue:
                self.poll_queue = self.pending_list
            tid = self.poll_queue[0]
            self.poll_queue = self.poll_queue[1:]
            th = server.rcd.system.poll_pending(tid)
            th.connect("ready", lambda x: self.process_pending(x))
            self.add_thread(th)
            launch -= 1
Example #17
0
    def toggle_subscribed(self, channel):
        def subscribe_cb(th, model, channel, sub):
            def set_cb(m, ch, flag):
                ch["subscribed"] = (flag and 1) or 0

            model.changed(set_cb, channel, sub)

        server = rcd_util.get_server_proxy()

        if channel["subscribed"]:
            th = server.rcd.packsys.unsubscribe(channel["id"])
        else:
            th = server.rcd.packsys.subscribe(channel["id"])

        th.connect("ready", subscribe_cb, self, channel,
                   not channel["subscribed"])
Example #18
0
    def launch_poll_threads(self, launch_max=0):
        server = rcd_util.get_server_proxy()

        launch = 1
        if launch_max:
            launch = self.max_threads

        while launch > 0 and self.thread_space():
            if not self.poll_queue:
                self.poll_queue = self.pending_list
            tid = self.poll_queue[0]
            self.poll_queue = self.poll_queue[1:]
            th = server.rcd.system.poll_pending(tid)
            th.connect("ready", lambda x: self.process_pending(x))
            self.add_thread(th)
            launch -= 1
Example #19
0
def mount_channel(path, name, recursive):
    # Handle ~ to mean $HOME
    if path[0] == "~":
        homedir = os.getenv("HOME")
        if homedir:
            path = homedir + path[1:]
            print path

    path_base = os.path.basename(path)
    alias = string.lower(path_base)

    aliases = map(lambda x: rcd_util.get_channel_alias(x["id"]),
                  rcd_util.get_all_channels())

    old_alias = alias
    count = 1
    while alias in aliases:
        alias = "%s%d" % (old_alias, count)
        count += 1

    if not name:
        name = path

    server = rcd_util.get_server_proxy()
    mount_th = server.rcd.packsys.mount_directory(path, name, alias,
                                                  int(recursive))

    def mount_cb(th, path):
        try:
            th.get_result()
        except ximian_xmlrpclib.Fault, f:
            if f.faultCode == rcd_util.fault.invalid_service:
                dialog = gtk.MessageDialog(None, 0, gtk.MESSAGE_ERROR,
                                           gtk.BUTTONS_OK,
                                           "%s" % f.faultString)

                def idle_cb(d):
                    gtk.threads_enter()
                    d.show()
                    d.run()
                    d.destroy()
                    gtk.threads_leave()

                # Always run the dialog in the main thread
                gtk.idle_add(idle_cb, dialog)
            else:
                raise
Example #20
0
def mount_channel(path, name, recursive):
    # Handle ~ to mean $HOME
    if path[0] == "~":
        homedir = os.getenv("HOME")
        if homedir:
            path = homedir + path[1:]
            print path

    path_base = os.path.basename(path)
    alias = string.lower(path_base)

    aliases = map(lambda x:rcd_util.get_channel_alias(x["id"]),
                  rcd_util.get_all_channels())

    old_alias = alias
    count = 1
    while alias in aliases:
        alias = "%s%d" % (old_alias, count)
        count += 1

    if not name:
        name = path

    server = rcd_util.get_server_proxy()
    mount_th = server.rcd.packsys.mount_directory(path, name, alias,
                                                  int(recursive))

    def mount_cb(th, path):
        try:
            th.get_result()
        except ximian_xmlrpclib.Fault, f:
            if f.faultCode == rcd_util.fault.invalid_service:
                dialog = gtk.MessageDialog(None, 0, gtk.MESSAGE_ERROR,
                                           gtk.BUTTONS_OK,
                                           "%s" % f.faultString)

                def idle_cb(d):
                    gtk.threads_enter()
                    d.show()
                    d.run()
                    d.destroy()
                    gtk.threads_leave()

                # Always run the dialog in the main thread
                gtk.idle_add(idle_cb, dialog)
            else:
                raise
Example #21
0
class PrivilegesModel(red_listmodel.ListModel):
    def __init__(self, opt, sort_fn=None, filter_fn=None):
        red_listmodel.ListModel.__init__(self, sort_fn, filter_fn)

        self.__worker = None
        self.__worker_handler_id = 0

        opt.connect("selected", lambda x, y: self.refresh())
        opt.connect("updated", lambda x: self.request_update())

        for name, callback, type in PRIVILEGE_COLUMNS:
            self.add_column(callback, type)

        self.refresh()

    def set_privileges(self, privs):
        def set_privileges_cb(this, privs):
            self.__privileges = privs

        self.changed(set_privileges_cb, privs)

    def refresh(self):
        if self.__worker:
            if self.__worker_handler_id:
                self.__worker.disconnect(self.__worker_handler_id)
                self.__worker_handler_is = 0
            self.__worker.cancel()

        def got_cb(worker, this):
            if not worker.is_cancelled():
                try:
                    privs = worker.get_result()
                except ximian_xmlrpclib.Fault, f:
                    rcd_util.dialog_from_fault(f)
                    return
                if privs:
                    privs = map(string.lower, privs)
                    privs.sort()
                    privs.append("superuser")

                    this.set_privileges(privs)

        self.set_privileges([])

        server = rcd_util.get_server_proxy()
        self.__worker = server.rcd.users.get_valid_privileges()
        self.__worker_handler_id = self.__worker.connect("ready", got_cb, self)
Example #22
0
    def __init__(self, transact_id, step_id, callback, *cb_args):
        self.__callback = callback
        self.__cb_args = cb_args
        self.__transact_pending = None
        self.__step_pending = None
        self.__count = 0

        serv = rcd_util.get_server_proxy()
        tran_th = serv.rcd.system.poll_pending(transact_id)
        step_th = serv.rcd.system.poll_pending(step_id)

        tran_th.connect("ready",
                        lambda th, ppt: \
                        ppt.set_transact_pending(th.get_result()), self)
        step_th.connect("ready",
                        lambda th, ppt: \
                        ppt.set_step_pending(th.get_result()), self)
Example #23
0
class NewsModel(red_listmodel.ListModel, red_serverlistener.ServerListener):
    def __init__(self):
        red_listmodel.ListModel.__init__(self)
        red_serverlistener.ServerListener.__init__(self)

        self.__worker = None
        self.__worker_handler_id = 0

        for name, callback, type in COLUMNS:
            self.add_column(callback, type)

        self.refresh()

    def set_news(self, news):
        def set_news_cb(this, n):
            this.__news = n

        self.changed(set_news_cb, news)

    def refresh(self):

        if self.__worker:
            if self.__worker_handler_id:
                self.__worker.disconnect(self.__worker_handler_id)
                self.__worker_handler_is = 0
            self.__worker.cancel()

        def get_news_cb(worker, this):
            if not worker.is_cancelled():
                try:
                    news = worker.get_result()
                except ximian_xmlrpclib.Fault, f:
                    rcd_util.dialog_from_fault(f)
                    return
                if news:
                    for item in news:
                        item["icon"] = this.get_icon(item["channel_name"])

                    this.set_news(news)

        self.set_news([])

        server = rcd_util.get_server_proxy()
        self.__worker = server.rcd.news.get_all()
        self.__worker_handler_id = self.__worker.connect(
            "ready", get_news_cb, self)
Example #24
0
    def __init__(self, transact_id, step_id, callback, *cb_args):
        self.__callback = callback
        self.__cb_args = cb_args
        self.__transact_pending = None
        self.__step_pending = None
        self.__count = 0

        serv = rcd_util.get_server_proxy()
        tran_th = serv.rcd.system.poll_pending(transact_id)
        step_th = serv.rcd.system.poll_pending(step_id)

        tran_th.connect("ready",
                        lambda th, ppt: \
                        ppt.set_transact_pending(th.get_result()), self)
        step_th.connect("ready",
                        lambda th, ppt: \
                        ppt.set_step_pending(th.get_result()), self)
Example #25
0
    def activate(self, button):
        service_id = self.service_opt.get_service_id()
        service = rcd_util.get_service_by_id(service_id)
        email = self.email.get_text()
        code = self.code.get_text()
        email_required = 1
        if service and service["type"] == "zenworks":
            email_required = 0
            email = ""

        if not code or (email_required and not email):
            dialog = gtk.MessageDialog(
                self, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR,
                gtk.BUTTONS_OK,
                _("Please fill in both email and registration code."))
            dialog.run()
            dialog.destroy()
            return

        server = rcd_util.get_server_proxy()

        def activate_finished_cb(worker, this):
            if worker.is_cancelled():
                return

            try:
                worker.get_result()
            except ximian_xmlrpclib.Fault, f:
                rcd_util.dialog_from_fault(
                    f,
                    error_text=_("Unable to activate"),
                    additional_text=_("Please ensure "
                                      "you typed the email address "
                                      "and registration code correctly"),
                    parent=self)
                return

            # Store email to config.
            config = red_settings.get_config()
            config.set("Activation/email", this.email_to_save)
            config.sync()

            rcd_util.refresh(this)

            this.destroy()
Example #26
0
def unmount_channel(cid):

    server = rcd_util.get_server_proxy()
    unmount_th = server.rcd.packsys.unmount_directory(cid)

    def unmount_cb(th, name):
        try:
            success = th.get_result()
        except ximian_xmlrpclib.Fault, f:
            rcd_util.dialog_from_fault(f)
            return

        if not success:
            msg = _("Unable to unmount '%s'") % name
            dialog = gtk.MessageDialog(None, 0, gtk.MESSAGE_ERROR,
                                       gtk.BUTTONS_OK, msg)
            dialog.run()
            dialog.destroy()
Example #27
0
def unmount_channel(cid):

    server = rcd_util.get_server_proxy()
    unmount_th = server.rcd.packsys.unmount_directory(cid)

    def unmount_cb(th, name):
        try:
            success = th.get_result()
        except ximian_xmlrpclib.Fault, f:
            rcd_util.dialog_from_fault(f)
            return
        
        if not success:
            msg = _("Unable to unmount '%s'") % name
            dialog = gtk.MessageDialog(None, 0, gtk.MESSAGE_ERROR,
                                       gtk.BUTTONS_OK, msg)
            dialog.run()
            dialog.destroy()
Example #28
0
class HistoryModel(red_listmodel.ListModel):
    def __init__(self):
        red_listmodel.ListModel.__init__(self)

        self.__worker = None
        self.__worker_handler_id = 0

        self.add_columns(COLUMNS)

        self.set_history([])

    def set_history(self, history):
        def set_history_cb(this, h):
            this.__history = h

        self.changed(set_history_cb, history)

    def refresh(self, query):
        if not query:
            return

        if self.__worker:
            if self.__worker_handler_id:
                self.__worker.disconnect(self.__worker_handler_id)
                self.__worker_handler_is = 0
            self.__worker.cancel()

        def get_history_cb(worker, this):
            this.busy(0)
            this.message_pop()
            if not worker.is_cancelled():
                try:
                    history = worker.get_result()
                except ximian_xmlrpclib.Fault, f:
                    rcd_util.dialog_from_fault(f)
                    return
                this.set_history(history)

        self.busy(1)
        self.message_push(_("Searching..."))
        server = rcd_util.get_server_proxy()
        self.__worker = server.rcd.log.query_log(query)
        self.__worker_handler_id = self.__worker.connect(
            "ready", get_history_cb, self)
Example #29
0
    def activate(self, button):
        service_id = self.service_opt.get_service_id()
        service = rcd_util.get_service_by_id(service_id)
        email = self.email.get_text()
        code = self.code.get_text()
        email_required = 1
        if service and service["type"] == "zenworks":
            email_required = 0
            email = ""

        if not code or (email_required and not email):
            dialog = gtk.MessageDialog(self, gtk.DIALOG_DESTROY_WITH_PARENT,
                                       gtk.MESSAGE_ERROR, gtk.BUTTONS_OK,
                                       _("Please fill in both email and registration code."))
            dialog.run()
            dialog.destroy()
            return

        server = rcd_util.get_server_proxy()

        def activate_finished_cb(worker, this):
            if worker.is_cancelled():
                return

            try:
                worker.get_result()
            except ximian_xmlrpclib.Fault, f:
                rcd_util.dialog_from_fault(f,
                                           error_text=_("Unable to activate"),
                                           additional_text=_("Please ensure "
                                           "you typed the email address "
                                           "and registration code correctly"),
                                           parent=self)
                return
            
            # Store email to config.
            config = red_settings.get_config()
            config.set("Activation/email", this.email_to_save)
            config.sync()

            rcd_util.refresh(this)
                
            this.destroy()
Example #30
0
        def flush_cache_cb(b):
            parent_window = self.get_toplevel()
            if not parent_window.flags() & gtk.TOPLEVEL:
                parent_window = None
                
            dialog = gtk.MessageDialog(parent_window,
                                       gtk.DIALOG_DESTROY_WITH_PARENT,
                                       gtk.MESSAGE_QUESTION,
                                       gtk.BUTTONS_YES_NO,
                                       _("Are you sure you want to delete "
                                         "the package files in your cache?"))
            response = dialog.run()
            dialog.destroy()

            if response != gtk.RESPONSE_YES:
                return
            
            def flush_cb(th, page):
                gtk.idle_add(page.update_cache_size_label)
            server = rcd_util.get_server_proxy()
            th = server.rcd.system.flush_cache()
            th.connect("ready", flush_cb, self)
Example #31
0
class UpdateIcon(red_tray.TrayIcon):
    def __init__(self):
        red_tray.TrayIcon.__init__(self, "Red Carpet Notification Icon")

        self.thread = None

        self.high_priority_icon = red_pixbuf.get_pixbuf('importance-necessary')
        self.low_priority_icon = red_pixbuf.get_pixbuf('importance-urgent')

        self.image = gtk.Image()
        self.box = gtk.EventBox()
        self.box.connect('button_press_event', self.image_press_cb, self)
        self.box.add(self.image)
        self.add(self.box)

        self.tooltips = gtk.Tooltips()

        self.check_updates(None)
        gtk.timeout_add(POLL_INTERVAL, self.check_updates, self)

    def image_press_cb(self, img, event, data):
        if event.button == 1:
            if not self.thread:
                self.thread = threading.Thread(target=self.run_red_carpet)
                self.thread.start()

    def run_red_carpet(self):
        os.system('red-carpet')
        gtk.idle_add(self.check_updates_idle, self)
        self.thread = None

    def check_updates_idle(self, icon):
        self.check_updates(icon)
        return gtk.FALSE

    def check_updates(self, icon):
        def query_finished_cb(worker, icon):
            if not worker.is_cancelled():
                try:
                    packages = worker.get_result()
                except ximian_xmlrpclib.Fault, f:
                    packages = []
                    print 'Failed to get available updates: ' + str(f)
                else:
                    max_importance = 10
                    importance_str = ""

                    for (old_pkg, new_pkg, history) in packages:
                        if new_pkg.has_key('importance_num') and new_pkg[
                                'importance_num'] < max_importance:
                            max_importance = new_pkg['importance_num']
                            importance_str = new_pkg['importance_str']

                if max_importance < 10:
                    update_str = ''

                    if importance_str == 'necessary':
                        self.image.set_from_pixbuf(self.high_priority_icon)
                        update_str = 'Urgent updates available'
                    else:
                        self.image.set_from_pixbuf(self.low_priority_icon)
                        update_str = 'Updates available'

                    self.box.show()
                    self.tooltips.set_tip(self.box, update_str)
                else:
                    self.box.hide()

        server = rcd_util.get_server_proxy()

        self.__worker = server.rcd.packsys.get_updates()
        self.__worker_handler_id = self.__worker.connect(
            "ready", query_finished_cb, self)

        return gtk.TRUE
Example #32
0
    app.server_info_window = dialog


def dump_xml(filename):
    try:
        f = open(filename, "w")
    except IOError, e:
        dialog = gtk.MessageDialog(None, 0, gtk.MESSAGE_ERROR,
                                   gtk.BUTTONS_OK,
                                   _("Could not open file '%s': %s") % (filename, e.strerror))
        dialog.run()
        dialog.destroy()
        return

    server = rcd_util.get_server_proxy()

    def dump_finished_cb(worker, f):
        if not worker.is_cancelled():
            try:
                dump = worker.get_result()
            except ximian_xmlrpclib.Fault, f:
                rcd_util.dialog_from_fault(f)
            else:
                f.write(zlib.decompress(dump.data))
        f.close()

    worker = server.rcd.packsys.dump()
    rcd_util.server_proxy_dialog(worker,
                                 callback=dump_finished_cb,
                                 user_data=f)
Example #33
0
 def delete(self):
     server = rcd_util.get_server_proxy()
     th = server.rcd.users.remove(self.name_get())
     th.connect("ready", self.rpc_call_ready_cb)
Example #34
0
class UsersOption(gtk.OptionMenu, red_serverlistener.ServerListener):
    def __init__(self, allow_all=0):
        gobject.GObject.__init__(self)
        red_serverlistener.ServerListener.__init__(self)

        self.__worker = None
        self.__worker_handler_id = 0
        self.__last_user = None
        self.__new_user = None
        self.__allow_all = allow_all

        self.refresh()

    def __assemble(self):
        menu = gtk.Menu()

        if self.__allow_all:
            u = User(any_user=1)
            self.__users.insert(0, u)

        for u in self.__users:
            item = gtk.MenuItem(u.name_get())
            item.show()

            item.connect("activate", lambda x, y: self.select_user(y), u)

            menu.append(item)

        menu.show()
        self.set_menu(menu)

    def users_changed(self):
        self.refresh()

    def set_users(self, users):
        list = []
        for u in users:
            user = User(u[0])
            user.privileges_set(u[1].split(", "))
            list.append(user)
        self.__users = list
        self.__assemble()

        u = self.__new_user
        if not u:
            u = self.__last_user
        if not u:
            u = self.user_name_exists(rcd_util.get_current_user())
        if not u and len(list):
            u = list[0]

        if u:
            self.select_user(u)
            self.__new_user = None

    def select_user(self, user):
        id = 0
        for u in self.__users:
            if not cmp(u, user):
                self.set_history(id)

                if cmp(self.__last_user, user):
                    self.__last_user = user
                    self.emit("selected", user)

                return
            id += 1

    def get_selected_user(self):
        return self.__last_user

    def user_name_exists(self, name):
        for u in self.__users:
            if u and u.name_get() == name:
                return u
        return 0

    def add_user(self, user):
        if user and isinstance(user, User):
            user.update()
            self.__new_user = user

    def delete_user(self, user):
        if user and isinstance(user, User):
            user.delete()
            self.__last_user = None

    def refresh(self):
        if self.__worker:
            if self.__worker_handler_id:
                self.__worker.disconnect(self.__worker_handler_id)
                self.__worker_handler_is = 0
            self.__worker.cancel()

        def got_cb(worker, this):
            if not worker.is_cancelled():
                try:
                    users = worker.get_result()
                except ximian_xmlrpclib.Fault, f:
                    rcd_util.dialog_from_fault(f)
                    return

                this.set_users(users)
                self.emit("updated")

        server = rcd_util.get_server_proxy()
        self.__worker = server.rcd.users.get_all()
        self.__worker_handler_id = self.__worker.connect("ready", got_cb, self)
Example #35
0
 def delete(self):
     server = rcd_util.get_server_proxy()
     th = server.rcd.users.remove(self.name_get())
     th.connect("ready", self.rpc_call_ready_cb)