def ok(feed): from zeroinstall.injector import reader try: feed_targets = policy.get_feed_targets(feed) if interface not in feed_targets: raise Exception( _("Not a valid feed for '%(uri)s'; this is a feed for:\n%(feed_for)s" ) % { 'uri': interface.uri, 'feed_for': '\n'.join([f.uri for f in feed_targets]) }) if interface.get_feed(feed): dialog.alert(None, _('This feed is already registered.')) else: interface.extra_feeds.append( Feed(feed, user_override=True, arch=None)) writer.save_interface(interface) chooser.destroy() reader.update_from_cache(interface) policy.recalculate() except Exception, ex: dialog.alert( None, _("Error in feed file '%(feed)s':\n\n%(exception)s") % { 'feed': feed, 'exception': str(ex) })
def monitor_download(self, dl): error_stream = dl.start() def error_ready(src, cond): got = os.read(src.fileno(), 100) if not got: error_stream.close() self.n_downloads -= 1 if self.n_downloads == 0: self.window.progress.hide() gtk.timeout_remove(self.pulse) self.pulse = None try: data = dl.error_stream_closed() self.check_signed_data(dl, data) except download.DownloadError, ex: dialog.alert( self.window, "Error downloading interface '%s':\n\n%s" % (dl.interface.uri, ex)) except InvalidInterface, ex: dialog.alert( self.window, "Syntax error in downloaded interface '%s':\n\n%s" % (dl.interface.uri, ex)) except SafeException, ex: dialog.alert( self.window, "Error updating interface '%s':\n\n%s" % (dl.interface.uri, ex))
def follow_followers(self,widget,data = None): """follow followers by id not by name""" global friendIDs,followerIDs if not self.get_friendIDs(): return #~ safety feature in case twitter f's up if len(friendIDs) < 100: print('not enough friends') return #~ load protected and pending list me = self.me.screen_name cachedir = self.get_cachedir() protfile = cachedir+me+'.prot' newprot = []; prot=[] if os.path.exists(protfile): with open(protfile) as f: prot = [int(x.strip()) for x in f.readlines()] #~ follow everyone in followerIDs for a in followerIDs: if (a not in friendIDs) and (a not in prot): try: ret = api.CreateFriendship(a) friendIDs.append(a) print('followed %s' % ret.screen_name) except TwitterError as err: print(err) if not 'follow-limits' in str(err): newprot.append(a) else: dialog.alert("You have reached Twitter's follow limit!") break #~ those we can not follow are probably protected with open(protfile,'a') as f: f.writelines([str(x)+'\n' for x in newprot])
def got_data(self, src, cond): data = os.read(src.fileno(), 100) if data: self.error += data return True else: status = self.child.wait() self.child = None if os.WIFEXITED(status) and os.WEXITSTATUS(status) == 0: self.success() else: if os.WIFEXITED(status): status = os.WEXITSTATUS(status) if status == 1 and not self.error: return False # Cancelled dialog.alert( None, _("Command failed with exit code %(status)d:\n%(error)s\n" ) % { 'status': status, 'error': self.error }) else: dialog.alert(None, _("Command failed:\n%s\n") % self.error) return False
def report_exception(self, ex, tb = None): if not isinstance(ex, SafeException): import traceback traceback.print_exception(ex, None, tb) if self.systray_icon: self.systray_icon.set_blinking(True) self.systray_icon.set_tooltip(str(ex) + '\n' + _('(click for details)')) else: dialog.alert(self.window, str(ex))
def done(self): self.watched_streams -= 1 if self.watched_streams == 0: status = self.child.wait() self.child = None if status == 0: self.success(self.stdout) else: if status == 1 and not self.error: return False # Cancelled dialog.alert(None, _("Command failed with exit code %(status)d:\n%(error)s\n") % {'status': status, 'error': self.error})
def resp(box, r): if r == gtk.RESPONSE_OK: text = "" for title, buffer in self.frames: start = buffer.get_start_iter() end = buffer.get_end_iter() text += "%s\n\n%s\n\n" % (title, buffer.get_text(start, end).strip()) title = _("Bug for %s") % iface.get_name() self.report_bug(title, text) self.destroy() dialog.alert(self, _("Your bug report has been sent. Thank you."), type=gtk.MESSAGE_INFO) else: self.destroy()
def download_and_run(self, run_button, cancelled): try: if not self.select_only: downloaded = self.driver.download_uncached_implementations() if downloaded: # We need to wait until everything is downloaded... blockers = [downloaded, cancelled] yield blockers tasks.check(blockers) if cancelled.happened: return uncached = self.driver.get_uncached_implementations() else: uncached = None # (we don't care) if uncached: missing = "\n- ".join( [ _("%(iface_name)s %(impl_version)s") % {"iface_name": iface.get_name(), "impl_version": impl.get_version()} for iface, impl in uncached ] ) dialog.alert( self.window, _("Not all downloads succeeded; cannot run program.\n\nFailed to get:") + "\n- " + missing, ) else: sels = self.driver.solver.selections doc = sels.toDOM() reply = doc.toxml("utf-8") if sys.version_info[0] > 2: stdout = sys.stdout.buffer else: stdout = sys.stdout stdout.write(("Length:%8x\n" % len(reply)).encode("utf-8") + reply) self.window.destroy() sys.exit(0) # Success except SystemExit: raise except download.DownloadAborted as ex: run_button.set_active(False) # Don't bother reporting this to the user except Exception as ex: run_button.set_active(False) self.report_exception(ex)
def download_and_run(self, run_button, cancelled): try: if not self.select_only: downloaded = self.driver.download_uncached_implementations() if downloaded: # We need to wait until everything is downloaded... blockers = [downloaded, cancelled] yield blockers tasks.check(blockers) if cancelled.happened: return uncached = self.driver.get_uncached_implementations() else: uncached = None # (we don't care) if uncached: missing = '\n- '.join([ _('%(iface_name)s %(impl_version)s') % { 'iface_name': iface.get_name(), 'impl_version': impl.get_version() } for iface, impl in uncached ]) dialog.alert( self.window, _('Not all downloads succeeded; cannot run program.\n\nFailed to get:' ) + '\n- ' + missing) else: sels = self.driver.solver.selections doc = sels.toDOM() reply = doc.toxml('utf-8') if sys.version_info[0] > 2: stdout = sys.stdout.buffer else: stdout = sys.stdout stdout.write(('Length:%8x\n' % len(reply)).encode('utf-8') + reply) self.window.destroy() sys.exit(0) # Success except SystemExit: raise except download.DownloadAborted as ex: run_button.set_active(False) # Don't bother reporting this to the user except Exception as ex: run_button.set_active(False) self.report_exception(ex)
def error_ready(src, cond): got = os.read(src.fileno(), 100) if not got: error_stream.close() self.n_downloads -= 1 try: data = dl.error_stream_closed() except download.DownloadError, ex: dialog.alert( self, "Error downloading '%s':\n\n%s" % (dl.url, ex)) try: policy.add_to_cache(dl.source, data) except SafeException, ex: dialog.alert(self, "Error unpacking '%s':\n\n%s" % (dl.url, ex))
def report_exception(self, ex, tb=None): if not isinstance(ex, SafeException): if isinstance(ex, AssertionError): # Assertions often don't say that they're errors (and are frequently # blank). ex = repr(ex) if tb is None: warn(ex, exc_info=True) else: warn(ex, exc_info=(type(ex), ex, tb)) if self.systray_icon: self.systray_icon.set_blinking(True) self.systray_icon.set_tooltip(str(ex) + "\n" + _("(click for details)")) else: dialog.alert(self.window, str(ex) or repr(ex))
def follow_clicked(self, widget, data=None): """follow all poeple in textview1 by name""" #~ iterate through the text buffer buf = self.textview1.get_buffer() (iter_first, iter_last) = buf.get_bounds() text = buf.get_text(iter_first, iter_last) #~ remove spaces and build a list to follow text = text.replace(' ', '') fol = [] #~ create fol list for x in text.split('@')[1:]: if x not in fol: fol.append(x) #~ ask if self.warn and (not dialog.ok("Follow %s people.\n" "Are you sure?" % len(fol))): return else: self.warn = False # load nofollow list if it exists me = self.me.screen_name nofol = [] cachedir = self.get_cachedir() nofollow = cachedir + me + '.nofollow' if os.path.exists(nofollow): with open(nofollow) as f: nofol = [x.strip() for x in f.readlines()] nofollen = len(nofol) #~ friend everybody unless nofol, add to nofol for a in fol: if a not in nofol: try: api.CreateFriendship(a) print('followed %s' % a) except TwitterError as err: print(err) if 'follow-limits' in str(err): dialog.alert( "You have reached Twitter's follow limit!") break nofol.append(a) #~ Write nofol to disk. These could be invalid names, #~ existing friends, or blocked accounts. #~ We don't care. We just don't follow them. if nofollen < len(nofol): with open(nofollow, 'a') as f: f.writelines([x + '\n' for x in nofol[nofollen:]])
def remove_feed(button): model, iter = self.tv.get_selection().get_selected() feed_uri = model[iter][Feeds.URI] for x in interface.extra_feeds: if x.uri == feed_uri: if x.user_override: interface.extra_feeds.remove(x) writer.save_interface(interface) import main main.recalculate() return else: dialog.alert(self.get_toplevel(), _("Can't remove '%s' as you didn't add it.") % feed_uri) return raise Exception(_("Missing feed '%s'!") % feed_uri)
def resp(box, r): if r == gtk.RESPONSE_OK: text = '' for title, buffer in self.frames: start = buffer.get_start_iter() end = buffer.get_end_iter() text += '%s\n\n%s\n\n' % (title, buffer.get_text( start, end).strip()) title = _('Bug for %s') % iface.get_name() self.report_bug(title, text) self.destroy() dialog.alert(self, _("Your bug report has been sent. Thank you."), type=gtk.MESSAGE_INFO) else: self.destroy()
def report_exception(self, ex, tb=None): if not isinstance(ex, SafeException): if isinstance(ex, AssertionError): # Assertions often don't say that they're errors (and are frequently # blank). ex = repr(ex) if tb is None: warn(ex, exc_info=True) else: warn(ex, exc_info=(type(ex), ex, tb)) if self.systray_icon: self.systray_icon.set_blinking(True) self.systray_icon.set_tooltip( str(ex) + '\n' + _('(click for details)')) else: dialog.alert(self.window, str(ex) or repr(ex))
def follow_clicked(self,widget,data = None): """follow all poeple in textview1 by name""" #~ iterate through the text buffer buf = self.textview1.get_buffer() (iter_first, iter_last) = buf.get_bounds() text = buf.get_text(iter_first, iter_last) #~ remove spaces and build a list to follow text = text.replace(' ','') fol = [] #~ create fol list for x in text.split('@')[1:]: if x not in fol: fol.append(x) #~ ask if self.warn and (not dialog.ok("Follow %s people.\n" "Are you sure?" % len(fol))): return else: self.warn=False # load nofollow list if it exists me = self.me.screen_name nofol = [] cachedir = self.get_cachedir() nofollow = cachedir+me+'.nofollow' if os.path.exists(nofollow): with open(nofollow) as f: nofol = [x.strip() for x in f.readlines()] nofollen=len(nofol) #~ friend everybody unless nofol, add to nofol for a in fol: if a not in nofol: try: api.CreateFriendship(a) print('followed %s' % a) except TwitterError as err: print(err) if 'follow-limits' in str(err): dialog.alert("You have reached Twitter's follow limit!") break nofol.append(a) #~ Write nofol to disk. These could be invalid names, #~ existing friends, or blocked accounts. #~ We don't care. We just don't follow them. if nofollen < len(nofol): with open(nofollow,'a') as f: f.writelines([x+'\n' for x in nofol[nofollen:]])
def resp(box, r): if r == gtk.RESPONSE_OK: text = '' for title, buffer in self.frames: start = buffer.get_start_iter() end = buffer.get_end_iter() text += '%s\n\n%s\n\n' % (title, buffer.get_text(start, end, include_hidden_chars = False).strip()) try: message = self.report_bug(iface, text) except Exception as ex: dialog.alert(None, _("Error sending bug report: {ex}".format(ex = ex)), type = gtk.MESSAGE_ERROR) else: dialog.alert(None, _("Success: {msg}").format(msg = message), type = gtk.MESSAGE_INFO) self.destroy() else: self.destroy()
def ok(feed): from zeroinstall.injector import reader try: feed_targets = policy.get_feed_targets(feed) if interface not in feed_targets: raise Exception(_("Not a valid feed for '%(uri)s'; this is a feed for:\n%(feed_for)s") % {'uri': interface.uri, 'feed_for': '\n'.join([f.uri for f in feed_targets])}) if feed in [f.uri for f in interface.extra_feeds]: dialog.alert(None, _('This feed is already registered.')) else: interface.extra_feeds.append(Feed(feed, user_override = True, arch = None)) writer.save_interface(interface) chooser.destroy() reader.update_from_cache(interface) import main main.recalculate() except Exception as ex: dialog.alert(None, _("Error in feed file '%(feed)s':\n\n%(exception)s") % {'feed': feed, 'exception': str(ex)})
def download_and_run(self, run_button, cancelled): try: if not self.select_only: downloaded = self.policy.download_uncached_implementations() if downloaded: # We need to wait until everything is downloaded... blockers = [downloaded, cancelled] yield blockers tasks.check(blockers) if cancelled.happened: return uncached = self.policy.get_uncached_implementations() else: uncached = None # (we don't care) if uncached: missing = '\n- '.join([_('%(iface_name)s %(impl_version)s') % {'iface_name': iface.get_name(), 'impl_version': impl.get_version()} for iface, impl in uncached]) dialog.alert(self.window, _('Not all downloads succeeded; cannot run program.\n\nFailed to get:') + '\n- ' + missing) else: from zeroinstall.injector import selections sels = selections.Selections(self.policy) doc = sels.toDOM() reply = doc.toxml('utf-8') sys.stdout.write(('Length:%8x\n' % len(reply)) + reply) self.window.destroy() sys.exit(0) # Success except SystemExit: raise except download.DownloadAborted as ex: run_button.set_active(False) # Don't bother reporting this to the user except Exception as ex: run_button.set_active(False) self.report_exception(ex)
def follow_followers(self, widget, data=None): """follow followers by id not by name""" global friendIDs, followerIDs if not self.get_friendIDs(): return #~ safety feature in case twitter f's up if len(friendIDs) < 100: print('not enough friends') return #~ load protected and pending list me = self.me.screen_name cachedir = self.get_cachedir() protfile = cachedir + me + '.prot' newprot = [] prot = [] if os.path.exists(protfile): with open(protfile) as f: prot = [int(x.strip()) for x in f.readlines()] #~ follow everyone in followerIDs for a in followerIDs: if (a not in friendIDs) and (a not in prot): try: ret = api.CreateFriendship(a) friendIDs.append(a) print('followed %s' % ret.screen_name) except TwitterError as err: print(err) if not 'follow-limits' in str(err): newprot.append(a) else: dialog.alert( "You have reached Twitter's follow limit!") break #~ those we can not follow are probably protected with open(protfile, 'a') as f: f.writelines([str(x) + '\n' for x in newprot])
def download_and_run(self, run_button, cancelled): try: downloaded = self.policy.download_uncached_implementations() if downloaded: # We need to wait until everything is downloaded... blockers = [downloaded, cancelled] yield blockers tasks.check(blockers) if cancelled.happened: return uncached = self.policy.get_uncached_implementations() if uncached: missing = '\n- '.join([ _('%s %s') % (iface.get_name(), impl.get_version()) for iface, impl in uncached ]) dialog.alert( self.window, _('Not all downloads succeeded; cannot run program.\n\nFailed to get:' ) + '\n- ' + missing) else: from zeroinstall.injector import selections sels = selections.Selections(self.policy) doc = sels.toDOM() reply = doc.toxml('utf-8') sys.stdout.write(('Length:%8x\n' % len(reply)) + reply) self.window.destroy() sys.exit(0) # Success except SystemExit: raise except Exception, ex: run_button.set_active(False) self.report_exception(ex)
def resp(box, r): if r == gtk.RESPONSE_OK: text = '' for title, buffer in self.frames: start = buffer.get_start_iter() end = buffer.get_end_iter() text += '%s\n\n%s\n\n' % ( title, buffer.get_text(start, end, include_hidden_chars=False).strip()) try: message = self.report_bug(iface, text) except Exception as ex: dialog.alert( None, _("Error sending bug report: {ex}".format(ex=ex)), type=gtk.MESSAGE_ERROR) else: dialog.alert(None, _("Success: {msg}").format(msg=message), type=gtk.MESSAGE_INFO) self.destroy() else: self.destroy()