From: Zac Medico <zmedico@gmail.com>
To: gentoo-portage-dev@lists.gentoo.org
Subject: [gentoo-portage-dev] PATCH: refactor emerge spinner (#102073)
Date: Wed, 10 Aug 2005 22:08:10 -0700 [thread overview]
Message-ID: <42FADD3A.7020103@gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 334 bytes --]
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
[-- Attachment #2: refactor-emerge-spinner.patch --]
[-- Type: text/x-patch, Size: 5199 bytes --]
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
next reply other threads:[~2005-08-11 5:01 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-08-11 5:08 Zac Medico [this message]
2005-08-11 12:14 ` [gentoo-portage-dev] PATCH: refactor emerge spinner (#102073) Alec Warner
2005-08-11 14:06 ` Jason Stubbs
2005-08-12 5:19 ` [gentoo-portage-dev] the refactoring of emerge, continued... (was PATCH: refactor emerge spinner (#102073)) Zac Medico
2005-08-12 12:36 ` Alec Warner
2005-08-12 20:57 ` Zac Medico
2005-08-12 21:48 ` warnera6
2005-08-12 22:10 ` Marius Mauch
2005-08-12 22:12 ` warnera6
2005-08-12 22:49 ` Zac Medico
2005-08-13 1:06 ` Jason Stubbs
2005-08-13 17:34 ` Zac Medico
2005-08-13 22:25 ` Zac Medico
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=42FADD3A.7020103@gmail.com \
--to=zmedico@gmail.com \
--cc=gentoo-portage-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox