def switch_page_cb(self, page, num): page_box = self.get_nth_page(num) if not page_box.initialized and not self.block_builds: server = rcd_util.get_server() contents = page_box.page.build_widget(self.package, rcd_util.get_server()) page_box.add(contents) #print "Built page %d: '%s'" % (num, page_box.page.name()) contents.show() page_box.initialized = 1
def build(self): self.item_id_list = [] menu = gtk.Menu() server = rcd_util.get_server() services = server.rcd.service.list_types() services.sort(lambda x,y:cmp(string.lower(x["alias"]), string.lower(y["alias"]))) for s in services: self.item_id_list.append(s["alias"]) item = gtk.MenuItem(s["name"]) item.show() def activate_cb(item, id, opt): if id != self.__last_id: opt.__last_id = id opt.emit("selected", id) item.connect("activate", activate_cb, s["alias"], self) menu.append(item) menu.show() self.set_menu(menu) ## Let's try to advertise zenworks. for id in self.item_id_list: if id == "zenworks": self.set_service_by_id(id) break
def apply_prefs(self): server = rcd_util.get_server() for n in self.queued_sets: server.rcd.prefs.set_pref(n, self.prefs[n]["value"]) self.queued_sets = [] self.queued_id = 0 return 0
def view_server_info_cb(app): # We only allow one server info window at a time if getattr(app, "server_info_window", None): destroy_server_info(app) server = rcd_util.get_server() try: results = server.rcd.system.ping() except: results = None if results: dialog_type = gtk.MESSAGE_INFO messages = [_("The daemon identified itself as:"), ""] if results.has_key("name"): messages.append("%s" % results["name"]) if results.has_key("copyright"): messages.append(results["copyright"]) messages.append("") if results.has_key("distro_info"): messages.append(_("System type") + ": " + results["distro_info"]) if results.has_key("server_url"): messages.append(_("Server URL") + ": " + results["server_url"]) if results.get("server_premium", 0): messages.append(_("Server supports enhanced features.")) else: # couldn't ping the server dialog_type = gtk.MESSAGE_WARNING messages = [_("Unable to contact the daemon.")] dialog = gtk.MessageDialog(app, 0, dialog_type, gtk.BUTTONS_CLOSE, string.join(messages, "\n")) dialog.set_default_response(gtk.RESPONSE_OK) if results: bbox = gtk.HButtonBox() dialog.vbox.pack_start(bbox, expand=0, fill=0, padding=6) button = gtk.Button(_("Dump daemon info to XML file")) button.connect("clicked", lambda x,y:select_and_dump(y), dialog) bbox.add(button) def destroy_cb(x, y, z): destroy_server_info(z) dialog.connect("response", destroy_cb, app) dialog.show_all() app.server_info_window = dialog
def wait_for_server_cb(dialog): try: server = rcd_util.get_server() ping = server.rcd.system.ping() if ping: dialog.destroy() show_server_is_alive_dialog() return 0 except: # FIXME: don't just mindlessly catch all exceptions print "waiting for server..." return 1
def fetch_package(self): proto, rest = urllib.splittype(self.url) if not proto: return None name = "open_" + proto if "-" in name: # replace - with _ name = string.join(string.split(name, "-"), "_") if not hasattr(urllib.URLopener, name): return None try: u = urllib.URLopener().open(self.url) except IOError: return None if self.cancelled: u.close() return None data = "" while 1: d = u.read(1024) if not d: break data += d if self.cancelled: u.close() return None pdata = ximian_xmlrpclib.Binary(data) server = rcd_util.get_server() try: p = server.rcd.packsys.query_file(pdata) except ximian_xmlrpclib.Fault, f: if f.faultCode == rcd_util.fault.package_not_found \ or f.faultCode == rcd_util.fault.invalid_package_file: return None else: raise
def cancelled(self): PendingView.cancelled(self) if self.download_id == -1 or self.download_complete: print "Can't abort transaction" return serv = rcd_util.get_server() try: ret = serv.rcd.packsys.abort_download(self.download_id) except ximian_xmlrpclib.Fault, f: ## FIXME: This is really ugly hack, but otherwise ui will be ## unresponsive if connection with rcd is lost (even if rcd ## comes back). rcd_util.dialog_from_fault(f) ret = 1
def check(self): if not self.curr_seqnos: return global last_seqnos global last_server global poll_count, working_polls poll_lock.acquire() server = rcd_util.get_server() # This lets us do the right thing if the server changes # out from under us. if id(server) != last_server: last_seqnos = {} last_server = id(server) s = self.curr_seqnos if s.get("channels") != last_seqnos.get("channels") or \ s.get("subscriptions") != last_seqnos.get("subscriptions"): rcd_util.reset_services() rcd_util.reset_channels() if s.get("users") != last_seqnos.get("users"): rcd_util.reset_server_permissions() # Ignore any problems on the first poll, since we know we # don't have valid server information before that point. if poll_count != 0: # We signal the listeners in an idle function so that # it will always happen in the main thread. gtk.idle_add(signal_listeners, last_seqnos, s) last_seqnos = s poll_count += 1 working_polls -= 1 poll_lock.release()
def install_files(files, parent=None): server = rcd_util.get_server() err = 0 plist = [] try: # We need to do the stat check because if we select something in # the filesel and then unselect it (with control-click), we'll # get the parent directory for that file, not the file itself. def is_valid(x): try: return stat.S_ISDIR(os.stat(x).st_mode) except OSError, e: # File probably doesn't exist. return 0 def query_file(x): is_local = rcd_util.get_server_local() if is_local: pdata = os.path.abspath(x) else: pdata = ximian_xmlrpclib.Binary(open(x).read()) p = server.rcd.packsys.query_file(pdata) if is_local: p["package_filename"] = pdata else: p["package_data"] = pdata return p plist = [query_file(x) \ for x in files \ if not is_valid(x)]