Author: ks156
Date: 2009-03-11 15:25:40 +0100 (Wed, 11 Mar 2009)
New Revision: 3954
Modified:
software_suite_v2/tuxware/installers/unix/branches/refactoring/misc/progressBar.py
software_suite_v2/tuxware/installers/unix/branches/refactoring/tux_software_updater.py
Log:
* The progress bar is now a class.
* The size is dynamically calculated, and always fit the TTY size.
Modified:
software_suite_v2/tuxware/installers/unix/branches/refactoring/misc/progressBar.py
===================================================================
---
software_suite_v2/tuxware/installers/unix/branches/refactoring/misc/progressBar.py
2009-03-11 13:05:42 UTC (rev 3953)
+++
software_suite_v2/tuxware/installers/unix/branches/refactoring/misc/progressBar.py
2009-03-11 14:25:40 UTC (rev 3954)
@@ -1,45 +1,91 @@
#!/usr/bin/python
-__steps = 0
-__progress = 0.0
-__title = ""
-__unit = ""
-__prog_size = 0
-def initProgressBar(steps, title, unit):
- global __steps
- global __progress
- global __title
- global __unit
- global __prog_size
+import commands
+class progressBar(object):
- # TTY - TITLE - UNIT - MINIMIM SIZE
- __prog_size = 80 - len(title) - len(unit) - 12
- __title = title
- __unit = unit
- __steps = __prog_size / float(steps)
- __progress = 0
+ def init(self, steps, title, unit):
+ # Init variables
+ self.PAYLOAD = 12
+ self.__step = 0.0
+ self.__steps_orig = 0.0
+ self.__progress = 0.0
+ self.__prog_size = 0.0
+ self.__prog_size_bak = 0.0
+ self.__title = ""
+ self.__unit = ""
+ # Find the tty size
+ try:
+ tty = int(commands.getoutput("/bin/stty size").split(" ")[1])
+ except:
+ tty = 80
+ # Compute the progress bar size
+ self.__prog_size = tty - len(title) - len(unit) - self.PAYLOAD
+ # Store the value
+ self.__prog_size_bak = float(self.__prog_size)
+ # Set the title
+ self.__title = title
+ # Set the unit
+ self.__unit = unit
+ # Store the initial steps
+ self.__steps_orig = steps
+ # Compute the size of a step
+ self.__step = float(self.__prog_size) / float(steps)
+ # Init the progression
+ self.__progress = 0
-def setProgressBar(percent):
- global __progress
- global __prog_size
- progress = ((float(percent) * __prog_size) / 100.0)
+ def setProgressBar(self, percent):
+ # Set a value
+ self.__progress = ((float(percent) * float(self.__prog_size)) / 100.0)
-def getProgressBar():
- global __progress
- global __prog_size
- return ((float (__progress) * 100.0) / __prog_size)
+ def getProgressBar(self):
+ # Get the actual percentage
+ return ((float (self.__progress) * 100.0) / float(self.__prog_size))
-def incProgressBar():
- global __steps
- global __progress
- __progress = __progress + __steps
- percent = getProgressBar()
- __strokeProgressBar(percent, __progress)
+ def incProgressBar(self):
+ # Increment the progress bar
-def __strokeProgressBar(percent, progress):
- global __title
- global __unit
- global __prog_size
- print "%s : [\033[s"%__title \
- +"#"*int(progress)+"\033[u\033[%dC] "%__prog_size \
- +"%.0f"%percent+"%s\033[1A"%__unit
+ # Get the TTY size
+ try:
+ tty = int(commands.getoutput("/bin/stty size").split(" ")[1])
+ except:
+ tty = 80
+
+ # Get the actual progression
+ percent = self.getProgressBar()
+
+ # Get the progression bar size
+ self.__prog_size = tty - len(self.__title) - len(self.__unit) -
self.PAYLOAD
+ # If the progressbar size has changed, compute again all the values
+ if self.__prog_size != self.__prog_size_bak:
+ # Compute the step size
+ self.__step = float(self.__prog_size) / float(self.__steps_orig)
+ # Store this new value of the progressbar size
+ self.__prog_size_bak = float(self.__prog_size)
+ # Set the new progression value
+ self.setProgressBar(percent)
+ # Clear the line
+ print '\033[K\033[1A'
+ # Increment the progression
+ self.__progress = float(self.__progress) + float(self.__step)
+ # Get the new percentage value
+ percent = self.getProgressBar()
+ # Redraw the progress bar
+ self.__strokeProgressBar(percent, self.__progress)
+
+ def __strokeProgressBar(self, percent, progress):
+ # This is a bit tricky :
+ # int(9.75) == 9, so sometimes, the progress bar end with a missing
dash
+ # [####### ] 100%
+ # So, the progression is always higher than the real value. A test
+ # control the overflow.
+ p = int(progress + 1)
+ if p > self.__prog_size:
+ p = self.__prog_size
+ # Print the progressbar
+ # \033[s -> store the cursor context
+ # \033[u -> restore the cursor context
+ # \033[<N>C -> move the cursor backward of N
+ # \033[<N>A -> move the cursor up
+ print "%s : [\033[s"%self.__title \
+ +"#"*p+"\033[u\033[%dC] "%self.__prog_size \
+ +"%.0f"%percent+"%s\033[1A"%self.__unit
Modified:
software_suite_v2/tuxware/installers/unix/branches/refactoring/tux_software_updater.py
===================================================================
---
software_suite_v2/tuxware/installers/unix/branches/refactoring/tux_software_updater.py
2009-03-11 13:05:42 UTC (rev 3953)
+++
software_suite_v2/tuxware/installers/unix/branches/refactoring/tux_software_updater.py
2009-03-11 14:25:40 UTC (rev 3954)
@@ -5,7 +5,7 @@
from misc.tuxPaths import *
from misc.URLTools import *
from misc.DirectoriesAndFilesTools import *
-from misc.progressBar import *
+from misc.progressBar import progressBar
import getopt
import sys
import os
@@ -13,6 +13,9 @@
DEBUG = 0
def __usage():
+ """__usage()
+ Give the help to know how to use tux_software_updater
+ """
print "-"*80
print "Tux Software Updater"
print "-"*80
@@ -37,6 +40,15 @@
sys.exit(0)
def __retrieveRules(data):
+ """__retrieveRules :
+ This function check if the database exists, and create two lists :
+ - toInstall : list containing all the stuff to install
+ - toRemove : list containing the stuff to remove
+
+ @param data : an array containing the server rules
+ #return: toInstall, toRemove
+ """
+
# Retrieve the DB file
if isInstalledDb():
toInstall, toRemove = parseDb(data)
@@ -46,6 +58,11 @@
return toInstall, toRemove
def __isSomethingToUpdate(toInstall):
+ """__isSomethingToUpdate
+ Check if a new file has to be updated.
+ @param toInstall A list containing the rules of the software to install
+ @return True if something has to be updated
+ """
# Check if new updates are available
proceed = False
if len(toInstall) == 0:
@@ -63,7 +80,7 @@
print "New update available"
print "Total downloading size : %.2f Mb"% \
float(float(totalSize) / (1048576.0))
- answer = raw_input("Proceed ? [Y/N] : ")
+ answer = raw_input("Proceed ? [y/n] : ")
if answer.startswith("Y") or answer.startswith("y"):
proceed = True
else:
@@ -72,49 +89,58 @@
return proceed
def __updateSystem(data, toInstall, toRemove, processToKillList):
- # Kill the services
- for service in processToKillList:
- os.system("pkill -f %s"%service)
+ """__updateSystem
+ This function install, update or remove the applications from the server.
+ It also kill the process specified before updating the system.
+ @param data : The complete list retrieved from the server
+ @param toInstall : A list containing the files to install
+ @param toRemove : A list containing the files to uninstall
+ @param processToKillList : The list of the process to kill before uptdating
+ """
+ # Kill the services
+ for service in processToKillList:
+ os.system("pkill -f %s"%service)
- initProgressBar(len(toInstall), 'Download', '%')
- # Install or update the new software
- for item in toInstall:
- incProgressBar()
- # Copy the new files
- if item['command'] == "COPY":
- dest = item['destination'].replace("$PREFIX", TUXDROID_PREFIX)
- path, filename = os.path.split(dest)
- if not os.path.isdir(path):
- os.system("mkdir -p %s"%path)
-
- URLDownloadToFile(item['source'], dest)
- # Install a meta-package
- elif item['command'] == "INST":
- os.system("mkdir -p /tmp/tuxdroid_upd")
- dest = item['destination'].replace("$PREFIX", TUXDROID_PREFIX)
- path = os.path.split(dest)[0]
- filename = os.path.split(item['source'])[1]
-
- URLDownloadToFile(item['source'],
"/tmp/tuxdroid_upd/%s"%filename)
-
- os.system("tar -xf /tmp/tuxdroid_upd/%s -C /tmp/tuxdroid_upd/
&&\
- cd /tmp/tuxdroid_upd/%s && /bin/bash install.sh %s &&\
- rm -rf /tmp/tuxdroid_upd/" \
- %(filename, filename.split("-")[0], dest))
- print ''
- writeDb(data)
-
- # Uninstall the ununsed stuff
- for item in toRemove:
+ pb = progressBar()
+ pb.init(len(toInstall), 'Download', '%')
+ # Install or update the new software
+ for item in toInstall:
+ pb.incProgressBar()
+ # Copy the new files
+ if item['command'] == "COPY":
dest = item['destination'].replace("$PREFIX", TUXDROID_PREFIX)
- if item['command'] == "COPY":
- if os.path.isfile(dest):
- os.system("rm %s"%dest)
- elif item['command'] == "INST":
+ path, filename = os.path.split(dest)
+ if not os.path.isdir(path):
+ os.system("mkdir -p %s"%path)
+
+ URLDownloadToFile(item['source'], dest)
+ # Install a meta-package
+ elif item['command'] == "INST":
+ os.system("mkdir -p /tmp/tuxdroid_upd")
+ dest = item['destination'].replace("$PREFIX", TUXDROID_PREFIX)
+ path = os.path.split(dest)[0]
+ filename = os.path.split(item['source'])[1]
+
+ URLDownloadToFile(item['source'], "/tmp/tuxdroid_upd/%s"%filename)
+
+ os.system("tar -xf /tmp/tuxdroid_upd/%s -C /tmp/tuxdroid_upd/ &&\
+ cd /tmp/tuxdroid_upd/%s && /bin/bash install.sh %s &&\
+ rm -rf /tmp/tuxdroid_upd/" \
+ %(filename, filename.split("-")[0], dest))
+ print ''
+ writeDb(data)
+
+ # Uninstall the ununsed stuff
+ for item in toRemove:
+ dest = item['destination'].replace("$PREFIX", TUXDROID_PREFIX)
+ if item['command'] == "COPY":
+ if os.path.isfile(dest):
+ os.system("rm %s"%dest)
+ elif item['command'] == "INST":
+ if os.path.isdir(dest):
+ os.system("cd %s && /bin/bash uninstall.sh"%dest)
if os.path.isdir(dest):
- os.system("cd %s && /bin/bash uninstall.sh"%dest)
- if os.path.isdir(dest):
- RMDirs(dest)
+ RMDirs(dest)
def main():
global DEBUG
------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn