diff options
Diffstat (limited to 'setup')
-rwxr-xr-x | setup | 107 |
1 files changed, 62 insertions, 45 deletions
@@ -11,42 +11,43 @@ from lib.hdd import Disk d = dialog.Dialog(dialog='whiptail') d.setBackgroundTitle('Dyson Installer') - -HDD = {} -RPOOL = 'rpool' - -def read_hdd(): - global HDD - pat = re.compile('\d+\.\s+(\S+)\s+<(\S+)\s*.+>') - out = subprocess.Popen('format </dev/null', shell=True, stdout=subprocess.PIPE).stdout +class Installer(object): HDD = {} - for line in out: - m = pat.search(line) - if m: - name = m.group(1) - HDD[name] = Disk(name, m.group(2)) - if len(HDD) == 0: - d.msgbox(width=50, title='Error: no disks found', - text='\nSorry, no hard disks found on your system. Installation is not possible.') - sys.exit(1) - + RPOOL = 'rpool' + RHDD = None + # method: (if true, if false) + flow = {} + + def _read_hdd(self): + pat = re.compile('\d+\.\s+(\S+)\s+<(\S+)\s*.+>') + out = subprocess.Popen('format </dev/null', shell=True, stdout=subprocess.PIPE).stdout + self.HDD = {} + for line in out: + m = pat.search(line) + if m: + name = m.group(1) + self.HDD[name] = Disk(name, m.group(2)) + if len(self.HDD) == 0: + d.msgbox(width=50, title='Error: no disks found', + text='\nSorry, no hard disks found on your system. Installation is not possible.') + return False + else: + return True -def choose_hdd(): - while True: + def choose_hdd(self): choices = [] - for hdd in sorted(HDD): - choices.append((hdd, HDD[hdd].cap + ' ' + HDD[hdd].desc)) + for hdd in sorted(self.HDD): + choices.append((hdd, self.HDD[hdd].cap + ' ' + self.HDD[hdd].desc)) - cancel, disk = d.menu(choices=choices, width=70, height=20, + cancel, self.RHDD = d.menu(choices=choices, width=70, height=20, title='Choose a disk for ZFS root pool', text='') - if cancel: - return False + return not cancel -def welcome(): - no = d.yesno(width=60, height=20, title='Welcome to Dyson installer', - text=''' + def welcome(self): + return not d.yesno(width=60, height=20, title='Welcome to Dyson installer', + text=''' Dyson is an operating system derived from Debian and based on Illumos core. \ It uses Illumos unix kernel and libc, ZFS file system and SMF to manage system startup. \ To learn more visit http://osdyson.org @@ -58,24 +59,40 @@ Please note, this system IS VERY EXPERIMENTAL. \ You can LOOSE ALL YOUR DATA which this system can reach ;-) Whould you like to continue?''') - if no: - sys.exit(1) -def choose_rpool_name(): - global RPOOL # Holy cow! - while True: - (cancel, pool) = d.inputbox(width=40, title='ZFS root pool', + def choose_rpool_name(self): + cancel, pool = d.inputbox(width=40, title='ZFS root pool', text='\nPlease, enter a name for ZFS root pool. Default is "rpool":', - init=RPOOL) + init=self.RPOOL) if cancel: - break + return False + else: + self.RPOOL = pool + return True + + def __init__(self): + self._read_hdd() + self.flow['welcome'] = ('choose_hdd', 'cancel') + pass + + def run(self, method='welcome'): + rc = getattr(self, method)() + if method in self.flow: + t, f = self.flow[method] + if rc: + self.run(t) + else: + self.run(f) else: - # TODO: check for valid name, if valid - break - RPOOL = pool - break - -welcome() -choose_rpool_name() -read_hdd() -choose_hdd() -#pprint.pprint(p) + self.done() + + def done(self, code=0): + sys.exit(0) + + def cancel(self): + self.done(1) + + + +i = Installer() +i.run() |