From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lists.gentoo.org ([140.105.134.102] helo=robin.gentoo.org) by nuthatch.gentoo.org with esmtp (Exim 4.43) id 1E35C8-0002Ht-02 for garchives@archives.gentoo.org; Thu, 11 Aug 2005 05:01:32 +0000 Received: from robin.gentoo.org (localhost [127.0.0.1]) by robin.gentoo.org (8.13.4/8.13.4) with SMTP id j7B504s5009594; Thu, 11 Aug 2005 05:00:04 GMT Received: from rproxy.gmail.com (rproxy.gmail.com [64.233.170.206]) by robin.gentoo.org (8.13.4/8.13.4) with ESMTP id j7B5031e020521 for ; Thu, 11 Aug 2005 05:00:03 GMT Received: by rproxy.gmail.com with SMTP id a41so236636rng for ; Wed, 10 Aug 2005 22:00:50 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:user-agent:x-accept-language:mime-version:to:subject:content-type; b=Gc45VxpKaLyCuG4nSo3yuCdy9gPBdC8TxJ4ZInDoNpavfaEOdbpaayUtB2ZOOXLjEZLWwpiDtao3zgcRr9rN/kf/28lxhhPnUnTehw1LEHK0na/rI2fsD2v+zfdcJRHTUHeJRQbBm1CUvVsNGGfz1kCRfSygNVtABz0c0w5COMA= Received: by 10.38.207.47 with SMTP id e47mr510239rng; Wed, 10 Aug 2005 22:00:50 -0700 (PDT) Received: from ?192.168.1.104? ([24.30.171.44]) by mx.gmail.com with ESMTP id c3sm1077549rne.2005.08.10.22.00.49; Wed, 10 Aug 2005 22:00:50 -0700 (PDT) Message-ID: <42FADD3A.7020103@gmail.com> Date: Wed, 10 Aug 2005 22:08:10 -0700 From: Zac Medico User-Agent: Mozilla Thunderbird 1.0.6 (X11/20050804) X-Accept-Language: en-us, en Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-portage-dev@gentoo.org Reply-to: gentoo-portage-dev@lists.gentoo.org MIME-Version: 1.0 To: gentoo-portage-dev@lists.gentoo.org Subject: [gentoo-portage-dev] PATCH: refactor emerge spinner (#102073) Content-Type: multipart/mixed; boundary="------------060504000305090908030101" X-Archives-Salt: b71c4cd1-b913-4e83-9333-4c53b001263d X-Archives-Hash: 2a1ec1854abf087a638235085968f537 This is a multi-part message in MIME format. --------------060504000305090908030101 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit http://bugs.gentoo.org/show_bug.cgi?id=102073 Author: Zac Medico Some refactoring could help make the emerge code more maintainable. I have written a trivial patch that encapsulates the spinner code into an object. This patch only reorganizes code and should not cause any regressions or changes in functionality. Comments? Zac --------------060504000305090908030101 Content-Type: text/x-patch; name="refactor-emerge-spinner.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="refactor-emerge-spinner.patch" Index: portage-2.0.51.22/bin/emerge =================================================================== --- portage-2.0.51.22.orig/bin/emerge +++ portage-2.0.51.22/bin/emerge @@ -17,61 +17,60 @@ import portage_util import portage_locks import portage_exception +class stdout_spinner: + def __init__(self): + spinner_msgs = ["Gentoo Rocks ("+os.uname()[0]+")", + "Thank you for using Gentoo. :)", + "Are you actually trying to read this?", + "How many times have you stared at this?", + "We are generating the cache right now", + "You are paying too much attention.", + "A theory is better than its explanation.", + "Phasers locked on target, Captain.", + "Thrashing is just virtual crashing.", + "To be is to program.", + "Real Users hate Real Programmers.", + "When all else fails, read the instructions.", + "Functionality breeds Contempt.", + "The future lies ahead.", + "3.1415926535897932384626433832795028841971694", + "Sometimes insanity is the only alternative.", + "Inaccuracy saves a world of explanation.", + ] + + self.spinpos = 0 + self.spinner = "/-\\|/-\\|/-\\|/-\\|\\-/|\\-/|\\-/|\\-/|" + self.update_spinner = self.update_twirl_spinner + + if "candy" in portage.settings.features: + self.spinner = spinner_msgs[int(time.time()*100)%len(spinner_msgs)] + self.update_spinner = self.update_scroll_spinner + if not sys.stdout.isatty() or ("--nospinner" in sys.argv): + self.update_spinner = self.update_basic_spinner + + def update_basic_spinner(self): + self.spinpos = (self.spinpos+1) % 500 + if (self.spinpos % 100) == 0: + if self.spinpos == 0: + sys.stdout.write(". ") + else: + sys.stdout.write(".") + sys.stdout.flush() + + def update_scroll_spinner(self): + if(self.spinpos >= len(self.spinner)): + sys.stdout.write(darkgreen(" \b\b\b"+self.spinner[len(self.spinner)-1-(self.spinpos%len(self.spinner))])) + else: + sys.stdout.write(green("\b "+self.spinner[self.spinpos])) + sys.stdout.flush() + self.spinpos = (self.spinpos+1) % (2*len(self.spinner)) + + def update_twirl_spinner(self): + self.spinpos = (self.spinpos+1) % len(self.spinner) + sys.stdout.write("\b\b "+self.spinner[self.spinpos]) + sys.stdout.flush() -spinner_msgs = ["Gentoo Rocks ("+os.uname()[0]+")", - "Thank you for using Gentoo. :)", - "Are you actually trying to read this?", - "How many times have you stared at this?", - "We are generating the cache right now", - "You are paying too much attention.", - "A theory is better than its explanation.", - "Phasers locked on target, Captain.", - "Thrashing is just virtual crashing.", - "To be is to program.", - "Real Users hate Real Programmers.", - "When all else fails, read the instructions.", - "Functionality breeds Contempt.", - "The future lies ahead.", - "3.1415926535897932384626433832795028841971694", - "Sometimes insanity is the only alternative.", - "Inaccuracy saves a world of explanation.", - ] - - -def update_basic_spinner(): - global spinner, spinpos - spinpos = (spinpos+1) % 500 - if (spinpos % 100) == 0: - if spinpos == 0: - sys.stdout.write(". ") - else: - sys.stdout.write(".") - sys.stdout.flush() - -def update_scroll_spinner(): - global spinner, spinpos - if(spinpos >= len(spinner)): - sys.stdout.write(darkgreen(" \b\b\b"+spinner[len(spinner)-1-(spinpos%len(spinner))])) - else: - sys.stdout.write(green("\b "+spinner[spinpos])) - sys.stdout.flush() - spinpos = (spinpos+1) % (2*len(spinner)) - -def update_twirl_spinner(): - global spinner, spinpos - spinpos = (spinpos+1) % len(spinner) - sys.stdout.write("\b\b "+spinner[spinpos]) - sys.stdout.flush() - -spinpos = 0 -spinner = "/-\\|/-\\|/-\\|/-\\|\\-/|\\-/|\\-/|\\-/|" -update_spinner = update_twirl_spinner -if "candy" in portage.settings.features: - spinner = spinner_msgs[int(time.time()*100)%len(spinner_msgs)] - update_spinner = update_scroll_spinner -if not sys.stdout.isatty() or ("--nospinner" in sys.argv): - update_spinner = update_basic_spinner - +spinner=stdout_spinner() if (not sys.stdout.isatty()) or (portage.settings["NOCOLOR"] in ["yes","true"]): nocolor() @@ -713,7 +712,7 @@ class search: self.searchkey=re.sub("\+\+","\+\+",self.searchkey) self.searchre=re.compile(self.searchkey.lower(),re.I) for package in portage.portdb.cp_all(): - update_spinner() + spinner.update_spinner() if match_category: match_string = package[:] @@ -915,7 +914,7 @@ class depgraph: #this conditional is needed to prevent infinite recursion on already-processed deps return 1 - update_spinner() + spinner.update_spinner() mytype,myroot,mykey=mybigkey # select the correct /var database that we'll be checking against --------------060504000305090908030101-- -- gentoo-portage-dev@gentoo.org mailing list