diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2013-04-14 17:29:26 +0000 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2013-04-14 17:29:26 +0000 |
commit | 1e59b39800eefe750aa86c4e5aa354cad4aa7e52 (patch) | |
tree | a834e01e569d0b43a579b15f6f64d1d135280bc4 /DysonInstaller | |
parent | 2f6f7f75ac9ed518d806f07f9f45b0c9363429f2 (diff) | |
download | live-1e59b39800eefe750aa86c4e5aa354cad4aa7e52.tar.gz |
Renamed
Diffstat (limited to 'DysonInstaller')
-rw-r--r-- | DysonInstaller/__init__.py | 0 | ||||
-rw-r--r-- | DysonInstaller/hdd/__init__.py | 120 | ||||
-rw-r--r-- | DysonInstaller/snack/__init__.py | 116 |
3 files changed, 236 insertions, 0 deletions
diff --git a/DysonInstaller/__init__.py b/DysonInstaller/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/DysonInstaller/__init__.py diff --git a/DysonInstaller/hdd/__init__.py b/DysonInstaller/hdd/__init__.py new file mode 100644 index 0000000..fb0c8ab --- /dev/null +++ b/DysonInstaller/hdd/__init__.py @@ -0,0 +1,120 @@ +#!/usr/bin/python + +""" +Written by Igor Pashev <pashev.igor@gmail.com> + +The author has placed this work in the Public Domain, +thereby relinquishing all copyrights. Everyone is free +to use, modify, republish, sell or give away this work +without prior consent from anybody. +""" + +from subprocess import Popen, PIPE +import re +import sys + +def human_capacity(b): + b = float(b) + G = ['%.0f B', '%.2f KiB', '%.2f MiB', '%.2f GiB', '%.2f TiB'] + for p in G: + if b < 1024: + return p % b + else: + b /= 1024 + raise Exception('Too large hard drive ;-)') + +class Partition(object): + blocks = 0 + boot = False + bytes = 0 + capacity = None + end = 0 + id = 0 + logical = False + start = 0 + system = None + +class HDD(object): + bytes = 0 + capacity = None + description = None + geometry = [] + name = None + partitions = [] + raw_device = None + + # fdisk -G /dev/rdsk/c0t0d0p0 + # * Physical geometry for device /dev/rdsk/c0t0d0p0 + # * PCYL NCYL ACYL BCYL NHEAD NSECT SECSIZ + # 2088 2088 0 0 255 63 512 + _fdiskG = re.compile('\s*(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s*') + + # fdisk.ul -l /dev/rdsk/c0t4d0p0 + # XXX note a bug: p0p1, must be p1. + # Device Boot Start End Blocks Id System + # /dev/rdsk/c0t4d0p0p1 63 15631244 7815591 bf Solaris + # /dev/rdsk/c0t4d0p0p2 15631245 33543719 8956237+ 5 Extended + # /dev/rdsk/c0t4d0p0p5 15631308 23438834 3903763+ 82 Linux swap / Solaris + # /dev/rdsk/c0t4d0p0p6 33479523 33543719 32098+ 83 Linux + + + def reread_partitions(self): + # boot? start end blocks id system + fdisk_ul = re.compile('^/dev/rdsk/{}\S+\s+(\*|\s)\s+(\d+)\s+(\d+)\s+(\d+)\+?\s+([a-f0-9]+)\s(.+)\s*$'.format(self.name)) + fdisk_ul_cmd = Popen(['fdisk.ul', '-l', self.raw_device], stdout=PIPE, stderr=PIPE) + self.partitions = [] + for line in fdisk_ul_cmd.stdout: + m = fdisk_ul.match(line) + if m: + p = Partition() + p.boot = m.group(1) == '*' + p.start = int(m.group(2)) + p.end = int(m.group(3)) + p.blocks = int(m.group(4)) + p.id = int(m.group(5), 16) + p.system = m.group(6) + p.logical = False # Update in the second pass + p.bytes = (p.end - p.start) * self.geometry['secsiz'] + p.capacity = human_capacity(p.bytes) + self.partitions.append(p) + + ext= None + for p in self.partitions: + if p.id == 0x05: + ext= p + break + if ext: + for p in self.partitions: + if p.id != 0x05 and p.start >= ext.start and p.end <= ext.end: + p.logical = True + + def __init_capacity(self): + fdisk_cmd = Popen(['fdisk', '-G', self.raw_device], stdout=PIPE) + for line in fdisk_cmd.stdout: + m = self._fdiskG.match(line) + if m: + self.geometry = { + 'pcyl' : int(m.group(1)), + 'ncyl' : int(m.group(2)), + 'acyl' : int(m.group(3)), + 'bcyl' : int(m.group(4)), + 'nhead' : int(m.group(5)), + 'nsect' : int(m.group(6)), + 'secsiz' : int(m.group(7)), + } + + + self.bytes = ( self.geometry['ncyl'] * self.geometry['nhead'] * + self.geometry['nsect'] * self.geometry['secsiz'] ) + self.capacity = human_capacity(self.bytes) + + + + def __init__(self, name, description): + self.name = name + self.raw_device = '/dev/rdsk/{}p0'.format(name) + self.description = description + self.__init_capacity() + self.reread_partitions() + + diff --git a/DysonInstaller/snack/__init__.py b/DysonInstaller/snack/__init__.py new file mode 100644 index 0000000..31794ee --- /dev/null +++ b/DysonInstaller/snack/__init__.py @@ -0,0 +1,116 @@ +#!/usr/bin/python + +""" +Written by Igor Pashev <pashev.igor@gmail.com> + +The author has placed this work in the Public Domain, +thereby relinquishing all copyrights. Everyone is free +to use, modify, republish, sell or give away this work +without prior consent from anybody. +""" + +from snack import * +import math + +class ProgressMessage(object): + _text = None + + @property + def text(self): + return self._text + @text.setter + def text(self, text): + self._text = text + self._textbox.setText(self._text) + self._refresh() + + def _refresh(self): + self._form.draw() + self._screen.refresh() + + def __init__(self, screen, width=40, title=' ', text=' '): + self._screen = screen + + self._textbox = TextboxReflowed(width, text) + + self._grid = Grid(1, 1) + self._grid.setField(self._textbox, 0, 0) + + self._screen.gridWrappedWindow(self._grid, title) + + self._form = Form() + self._form.add(self._textbox) + self._refresh() + + def __del__(self): + self._screen.popWindow() + +class ProgressBar(object): + _progress = 0 + _top = 0 + _text = None + _textbox = None + _screen = None + _form = None + _scale = None + _grid = None + _allow_back = False + + @property + def text(self): + return self._text + @text.setter + def text(self, text): + self._text = text + self._textbox.setText(self._text) + self._refresh() + + @property + def progress(self): + return self._progress + @text.setter + def progress(self, i): + if type(i) == 'str': + i = float(i) + if type(i) == 'float': + i = math.ceil(i) + if i > self._top: + i = self._top + i = int(i) + if i > self._progress or self._allow_back: + self._progress = int(i) + self._scale.set(self._progress) + self._refresh() + + def advance(self, i=1): + self.progress = self._progress + i + + def _refresh(self): + self._form.draw() + self._screen.refresh() + + + def __init__(self, screen, width=40, title='', text=' ', top=100, allow_back=False): + self._allow_back = allow_back + self._screen = screen + self._top = top + + self._textbox = TextboxReflowed(width, text) + + self._scale = Scale(width, self._top) + self._scale.set(0) + + self._grid = Grid(1, 2) + self._grid.setField(self._textbox, 0, 0) + self._grid.setField(self._scale, 0, 1) + + self._screen.gridWrappedWindow(self._grid, title) + + self._form = Form() + self._form.add(self._textbox) + self._form.add(self._scale) + self._refresh() + + + def __del__(self): + self._screen.popWindow() |