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
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