summaryrefslogtreecommitdiff
path: root/DysonInstaller
diff options
context:
space:
mode:
Diffstat (limited to 'DysonInstaller')
-rw-r--r--DysonInstaller/snack/__init__.py83
1 files changed, 83 insertions, 0 deletions
diff --git a/DysonInstaller/snack/__init__.py b/DysonInstaller/snack/__init__.py
index 31cb0f2..580aaba 100644
--- a/DysonInstaller/snack/__init__.py
+++ b/DysonInstaller/snack/__init__.py
@@ -11,6 +11,8 @@ without prior consent from anybody.
from snack import *
import math
+import apt.progress.base
+import os
class ProgressMessage(object):
_text = None
@@ -118,3 +120,84 @@ class ProgressBar(object):
def __del__(self):
self._screen.popWindow()
+
+
+class BaseProgress(object):
+ _progressbar = None
+ _screen = None
+ _title = None
+ _text = ''
+
+ def __init__(self, screen, title, text=''):
+ self._screen = screen
+ self._title = title
+ self._text = text
+
+ def _create_progressbar(self):
+ self._progressbar = ProgressBar(self._screen,
+ title=self._title, text=self._text)
+
+ def _destroy_progressbar(self):
+ del self._progressbar
+ self._progressbar = None
+
+
+class DownloadProgress(apt.progress.base.AcquireProgress, BaseProgress):
+ def pulse(self, acquire):
+ self._progressbar.progress = (
+ ((self.current_bytes + self.current_items) * 100.0) /
+ float(self.total_bytes + self.total_items))
+ return True
+
+ def start(self):
+ self._create_progressbar()
+
+ def stop(self):
+ self._destroy_progressbar()
+
+class OpenProgress(apt.progress.base.OpProgress, BaseProgress):
+ def __init__(self, screen, title, text=''):
+ BaseProgress.__init__(self, screen, title, text)
+
+ def update(self, percent=None):
+ if not self._progressbar:
+ self._create_progressbar()
+ if percent:
+ self._progressbar.progress = percent
+
+ def done(self):
+ self._destroy_progressbar()
+
+class InstallProgress(apt.progress.base.InstallProgress, BaseProgress):
+ _logfile = '/dev/null'
+
+ def __init__(self, screen, title, text='', logfile=None):
+ apt.progress.base.InstallProgress.__init__(self)
+ BaseProgress.__init__(self, screen, title, text)
+ if logfile:
+ self._logfile = logfile
+
+
+ def start_update(self):
+ self._create_progressbar()
+
+ def finish_update(self):
+ self._destroy_progressbar()
+
+ def status_change(self, pkg, percent, status):
+ self._progressbar.progress = percent
+ self._progressbar.text = status
+
+ def dpkg_status_change(self, pkg, status):
+ self._progressbar.progress = percent
+ self._progressbar.text = status + ' ' + pkg
+
+ def fork(self):
+ """ Shut up dpkg """
+ pid = os.fork()
+ if pid == 0:
+ log = os.open(self._logfile, os.O_WRONLY + os.O_CREAT)
+ os.dup2(log, 1)
+ os.dup2(log, 2)
+ return pid
+