Change-Id: I9d4758fb6428aa41305a165a076d9156e46b4e42
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/4576
Reviewed-by: Divya Thaluru <dthaluru@vmware.com>
Tested-by: gerrit-photon <photon-checkins@vmware.com>
... | ... |
@@ -12,15 +12,15 @@ class ConfirmWindow(Window): |
12 | 12 |
|
13 | 13 |
def __init__(self, height, width, maxy, maxx, menu_starty, message, info=False): |
14 | 14 |
if info: |
15 |
- items = [('OK', self.exit_function, True)] |
|
15 |
+ items = [('OK', self.exit_function, True)] |
|
16 | 16 |
else: |
17 |
- items = [ |
|
18 |
- ('Yes', self.exit_function, True), |
|
19 |
- ('No', self.exit_function, False) |
|
20 |
- ] |
|
21 |
- self.menu = Menu(menu_starty, maxx, items, can_navigate_outside = False, horizontal=True) |
|
17 |
+ items = [ |
|
18 |
+ ('Yes', self.exit_function, True), |
|
19 |
+ ('No', self.exit_function, False) |
|
20 |
+ ] |
|
21 |
+ self.menu = Menu(menu_starty, maxx, items, can_navigate_outside=False, horizontal=True) |
|
22 | 22 |
super(ConfirmWindow, self).__init__(height, width, maxy, maxx, 'Confirm', False, self.menu) |
23 |
- self.addstr(0,0, message) |
|
23 |
+ self.addstr(0, 0, message) |
|
24 | 24 |
|
25 | 25 |
def exit_function(self, yes): |
26 | 26 |
return ActionResult(True, {'yes': yes}) |
... | ... |
@@ -14,12 +14,16 @@ class Device(object): |
14 | 14 |
|
15 | 15 |
@staticmethod |
16 | 16 |
def refresh_devices(): |
17 |
- devices_list = subprocess.check_output(['lsblk', '-d', '-I', '8,259', '-n', '--output', 'NAME,SIZE,MODEL'], stderr=open(os.devnull, 'w')) |
|
17 |
+ devices_list = subprocess.check_output(['lsblk', '-d', '-I', '8,259', '-n', |
|
18 |
+ '--output', 'NAME,SIZE,MODEL'], |
|
19 |
+ stderr=open(os.devnull, 'w')) |
|
18 | 20 |
return Device.wrap_devices_from_list(devices_list) |
19 | 21 |
|
20 | 22 |
@staticmethod |
21 | 23 |
def refresh_devices_bytes(): |
22 |
- devices_list = subprocess.check_output(['lsblk', '-d', '--bytes', '-I', '8,259', '-n', '--output', 'NAME,SIZE,MODEL'], stderr=open(os.devnull, 'w')) |
|
24 |
+ devices_list = subprocess.check_output(['lsblk', '-d', '--bytes', '-I', |
|
25 |
+ '8,259', '-n', '--output', 'NAME,SIZE,MODEL'], |
|
26 |
+ stderr=open(os.devnull, 'w')) |
|
23 | 27 |
return Device.wrap_devices_from_list(devices_list) |
24 | 28 |
|
25 | 29 |
@staticmethod |
... | ... |
@@ -30,15 +34,15 @@ class Device(object): |
30 | 30 |
cols = deviceline.split(None, 2) |
31 | 31 |
#skip Virtual NVDIMM from install list |
32 | 32 |
colstr = cols[0].decode() |
33 |
- if(colstr.startswith("pmem")): |
|
33 |
+ if colstr.startswith("pmem"): |
|
34 | 34 |
continue |
35 | 35 |
model = "Unknown" |
36 |
- if(len(cols) >= 3): |
|
36 |
+ if len(cols) >= 3: |
|
37 | 37 |
model = cols[2].decode() |
38 | 38 |
devices.append( |
39 |
- Device(model #Model |
|
40 |
- , '/dev/' + cols[0].decode() #Path |
|
41 |
- , cols[1].decode() #size |
|
42 |
- )) |
|
39 |
+ Device(model #Model |
|
40 |
+ , '/dev/' + cols[0].decode() #Path |
|
41 |
+ , cols[1].decode() #size |
|
42 |
+ )) |
|
43 | 43 |
|
44 | 44 |
return devices |
... | ... |
@@ -16,8 +16,8 @@ from window import Window |
16 | 16 |
from actionresult import ActionResult |
17 | 17 |
|
18 | 18 |
class Installer(object): |
19 |
- def __init__(self, install_config, maxy = 0, maxx = 0, iso_installer = False, |
|
20 |
- rpm_path = "../stage/RPMS", log_path = "../stage/LOGS"): |
|
19 |
+ def __init__(self, install_config, maxy=0, maxx=0, iso_installer=False, |
|
20 |
+ rpm_path="../stage/RPMS", log_path="../stage/LOGS"): |
|
21 | 21 |
self.install_config = install_config |
22 | 22 |
self.iso_installer = iso_installer |
23 | 23 |
self.rpm_path = rpm_path |
... | ... |
@@ -33,7 +33,7 @@ class Installer(object): |
33 | 33 |
self.working_directory = self.install_config['working_directory'] |
34 | 34 |
else: |
35 | 35 |
self.working_directory = "/mnt/photon-root" |
36 |
- self.photon_root = self.working_directory + "/photon-chroot"; |
|
36 |
+ self.photon_root = self.working_directory + "/photon-chroot" |
|
37 | 37 |
|
38 | 38 |
self.restart_command = "shutdown" |
39 | 39 |
|
... | ... |
@@ -53,8 +53,11 @@ class Installer(object): |
53 | 53 |
self.progress_width = self.width - self.progress_padding |
54 | 54 |
self.starty = (self.maxy - self.height) // 2 |
55 | 55 |
self.startx = (self.maxx - self.width) // 2 |
56 |
- self.window = Window(self.height, self.width, self.maxy, self.maxx, 'Installing Photon', False) |
|
57 |
- self.progress_bar = ProgressBar(self.starty + 3, self.startx + self.progress_padding // 2, self.progress_width) |
|
56 |
+ self.window = Window(self.height, self.width, self.maxy, self.maxx, |
|
57 |
+ 'Installing Photon', False) |
|
58 |
+ self.progress_bar = ProgressBar(self.starty + 3, |
|
59 |
+ self.startx + self.progress_padding // 2, |
|
60 |
+ self.progress_width) |
|
58 | 61 |
|
59 | 62 |
signal.signal(signal.SIGINT, self.exit_gracefully) |
60 | 63 |
|
... | ... |
@@ -62,7 +65,8 @@ class Installer(object): |
62 | 62 |
def exit_gracefully(self, signal, frame): |
63 | 63 |
if self.iso_installer: |
64 | 64 |
self.progress_bar.hide() |
65 |
- self.window.addstr(0, 0, 'Oops, Installer got interrupted.\n\nPress any key to get to the bash...') |
|
65 |
+ self.window.addstr(0, 0, 'Oops, Installer got interrupted.\n\n' + |
|
66 |
+ 'Press any key to get to the bash...') |
|
66 | 67 |
self.window.content_window().getch() |
67 | 68 |
|
68 | 69 |
modules.commons.dump(modules.commons.LOG_FILE_NAME) |
... | ... |
@@ -86,15 +90,17 @@ class Installer(object): |
86 | 86 |
self.progress_bar.show() |
87 | 87 |
#self.rpm_path = "https://dl.bintray.com/vmware/photon_release_1.0_TP2_x86_64" |
88 | 88 |
if self.rpm_path.startswith("https://") or self.rpm_path.startswith("http://"): |
89 |
- cmdoption = 's/baseurl.*/baseurl={}/g'.format(self.rpm_path.replace('/','\/')) |
|
90 |
- process = subprocess.Popen(['sed', '-i', cmdoption,'/etc/yum.repos.d/photon-iso.repo']) |
|
89 |
+ cmdoption = 's/baseurl.*/baseurl={}/g'.format(self.rpm_path.replace('/', '\/')) |
|
90 |
+ process = subprocess.Popen(['sed', '-i', cmdoption, |
|
91 |
+ '/etc/yum.repos.d/photon-iso.repo']) |
|
91 | 92 |
retval = process.wait() |
92 | 93 |
if retval != 0: |
93 | 94 |
modules.commons.log(modules.commons.LOG_INFO, "Failed to reset repo") |
94 | 95 |
self.exit_gracefully(None, None) |
95 | 96 |
|
96 |
- cmdoption = 's/cachedir=\/var/cachedir={}/g'.format(self.photon_root.replace('/','\/')) |
|
97 |
- process = subprocess.Popen(['sed', '-i', cmdoption,'/etc/tdnf/tdnf.conf']) |
|
97 |
+ cmdoption = ('s/cachedir=\/var/cachedir={}/g' |
|
98 |
+ .format(self.photon_root.replace('/', '\/'))) |
|
99 |
+ process = subprocess.Popen(['sed', '-i', cmdoption, '/etc/tdnf/tdnf.conf']) |
|
98 | 100 |
retval = process.wait() |
99 | 101 |
if retval != 0: |
100 | 102 |
modules.commons.log(modules.commons.LOG_INFO, "Failed to reset tdnf cachedir") |
... | ... |
@@ -110,10 +116,13 @@ class Installer(object): |
110 | 110 |
packages_to_install = {} |
111 | 111 |
total_size = 0 |
112 | 112 |
with open(modules.commons.TDNF_CMDLINE_FILE_NAME, "w") as tdnf_cmdline_file: |
113 |
- tdnf_cmdline_file.write("tdnf install --installroot {0} --nogpgcheck {1}".format(self.photon_root, " ".join(selected_packages))) |
|
113 |
+ tdnf_cmdline_file.write("tdnf install --installroot {0} --nogpgcheck {1}" |
|
114 |
+ .format(self.photon_root, " ".join(selected_packages))) |
|
114 | 115 |
with open(modules.commons.TDNF_LOG_FILE_NAME, "w") as tdnf_errlog: |
115 |
- process = subprocess.Popen( |
|
116 |
- ['tdnf', 'install'] + selected_packages + ['--installroot', self.photon_root, '--nogpgcheck', '--assumeyes'], stdout=subprocess.PIPE, stderr=tdnf_errlog) |
|
116 |
+ process = subprocess.Popen(['tdnf', 'install'] + selected_packages + |
|
117 |
+ ['--installroot', self.photon_root, '--nogpgcheck', |
|
118 |
+ '--assumeyes'], stdout=subprocess.PIPE, |
|
119 |
+ stderr=tdnf_errlog) |
|
117 | 120 |
while True: |
118 | 121 |
output = process.stdout.readline().decode() |
119 | 122 |
if output == '': |
... | ... |
@@ -150,7 +159,9 @@ class Installer(object): |
150 | 150 |
self.progress_bar.update_message(output) |
151 | 151 |
# 0 : succeed; 137 : package already installed; 65 : package not found in repo. |
152 | 152 |
if retval != 0 and retval != 137: |
153 |
- modules.commons.log(modules.commons.LOG_ERROR, "Failed to install some packages, refer to {0}".format(modules.commons.TDNF_LOG_FILE_NAME)) |
|
153 |
+ modules.commons.log(modules.commons.LOG_ERROR, |
|
154 |
+ "Failed to install some packages, refer to {0}" |
|
155 |
+ .format(modules.commons.TDNF_LOG_FILE_NAME)) |
|
154 | 156 |
self.exit_gracefully(None, None) |
155 | 157 |
else: |
156 | 158 |
#install packages |
... | ... |
@@ -176,7 +187,8 @@ class Installer(object): |
176 | 176 |
# Execute post installation modules |
177 | 177 |
self.execute_modules(modules.commons.POST_INSTALL) |
178 | 178 |
if os.path.exists(modules.commons.KS_POST_INSTALL_LOG_FILE_NAME): |
179 |
- shutil.copy(modules.commons.KS_POST_INSTALL_LOG_FILE_NAME, self.photon_root + '/var/log/') |
|
179 |
+ shutil.copy(modules.commons.KS_POST_INSTALL_LOG_FILE_NAME, |
|
180 |
+ self.photon_root + '/var/log/') |
|
180 | 181 |
|
181 | 182 |
if self.iso_installer and os.path.isdir("/sys/firmware/efi"): |
182 | 183 |
self.install_config['boot'] = 'efi' |
... | ... |
@@ -187,32 +199,32 @@ class Installer(object): |
187 | 187 |
try: |
188 | 188 |
if self.install_config['boot'] == 'bios': |
189 | 189 |
process = subprocess.Popen( |
190 |
- [self.setup_grub_command, '-w', self.photon_root, |
|
191 |
- "bios", self.install_config['disk']['disk'], |
|
192 |
- self.install_config['disk']['root'], |
|
193 |
- self.install_config['disk']['boot'], |
|
194 |
- self.install_config['disk']['bootdirectory'], |
|
195 |
- str(self.install_config['disk']['boot_partition_number'])], |
|
196 |
- stdout=self.output) |
|
190 |
+ [self.setup_grub_command, '-w', self.photon_root, |
|
191 |
+ "bios", self.install_config['disk']['disk'], |
|
192 |
+ self.install_config['disk']['root'], |
|
193 |
+ self.install_config['disk']['boot'], |
|
194 |
+ self.install_config['disk']['bootdirectory'], |
|
195 |
+ str(self.install_config['disk']['boot_partition_number'])], |
|
196 |
+ stdout=self.output) |
|
197 | 197 |
elif self.install_config['boot'] == 'efi': |
198 | 198 |
process = subprocess.Popen( |
199 |
- [self.setup_grub_command, '-w', self.photon_root, |
|
200 |
- "efi", self.install_config['disk']['disk'], |
|
201 |
- self.install_config['disk']['root'], |
|
202 |
- self.install_config['disk']['boot'], |
|
203 |
- self.install_config['disk']['bootdirectory'], |
|
204 |
- str(self.install_config['disk']['boot_partition_number'])], |
|
205 |
- stdout=self.output) |
|
199 |
+ [self.setup_grub_command, '-w', self.photon_root, |
|
200 |
+ "efi", self.install_config['disk']['disk'], |
|
201 |
+ self.install_config['disk']['root'], |
|
202 |
+ self.install_config['disk']['boot'], |
|
203 |
+ self.install_config['disk']['bootdirectory'], |
|
204 |
+ str(self.install_config['disk']['boot_partition_number'])], |
|
205 |
+ stdout=self.output) |
|
206 | 206 |
except: |
207 | 207 |
#install bios if variable is not set. |
208 | 208 |
process = subprocess.Popen( |
209 |
- [self.setup_grub_command, '-w', self.photon_root, |
|
210 |
- "bios", self.install_config['disk']['disk'], |
|
211 |
- self.install_config['disk']['root'], |
|
212 |
- self.install_config['disk']['boot'], |
|
213 |
- self.install_config['disk']['bootdirectory'], |
|
214 |
- str(self.install_config['disk']['boot_partition_number'])], |
|
215 |
- stdout=self.output) |
|
209 |
+ [self.setup_grub_command, '-w', self.photon_root, |
|
210 |
+ "bios", self.install_config['disk']['disk'], |
|
211 |
+ self.install_config['disk']['root'], |
|
212 |
+ self.install_config['disk']['boot'], |
|
213 |
+ self.install_config['disk']['bootdirectory'], |
|
214 |
+ str(self.install_config['disk']['boot_partition_number'])], |
|
215 |
+ stdout=self.output) |
|
216 | 216 |
retval = process.wait() |
217 | 217 |
|
218 | 218 |
self.update_fstab() |
... | ... |
@@ -222,13 +234,15 @@ class Installer(object): |
222 | 222 |
|
223 | 223 |
command = [self.unmount_disk_command, '-w', self.photon_root] |
224 | 224 |
if not self.install_config['iso_system']: |
225 |
- command.extend(self.generate_partitions_param(reverse = True)) |
|
225 |
+ command.extend(self.generate_partitions_param(reverse=True)) |
|
226 | 226 |
process = subprocess.Popen(command, stdout=self.output) |
227 | 227 |
retval = process.wait() |
228 | 228 |
|
229 | 229 |
if self.iso_installer: |
230 | 230 |
self.progress_bar.hide() |
231 |
- self.window.addstr(0, 0, 'Congratulations, Photon has been installed in {0} secs.\n\nPress any key to continue to boot...'.format(self.progress_bar.time_elapsed)) |
|
231 |
+ self.window.addstr(0, 0, 'Congratulations, Photon has been installed in {0} secs.\n\n' + |
|
232 |
+ 'Press any key to continue to boot...' |
|
233 |
+ .format(self.progress_bar.time_elapsed)) |
|
232 | 234 |
eject_cdrom = True |
233 | 235 |
if 'ui_install' in self.install_config: |
234 | 236 |
self.window.content_window().getch() |
... | ... |
@@ -238,7 +252,7 @@ class Installer(object): |
238 | 238 |
process = subprocess.Popen(['eject', '-r'], stdout=self.output) |
239 | 239 |
process.wait() |
240 | 240 |
return ActionResult(True, None) |
241 |
- |
|
241 |
+ |
|
242 | 242 |
def copy_rpms(self): |
243 | 243 |
# prepare the RPMs list |
244 | 244 |
json_pkg_to_rpm_map = JsonWrapper(self.install_config["pkg_to_rpm_map_file"]) |
... | ... |
@@ -247,12 +261,13 @@ class Installer(object): |
247 | 247 |
self.rpms_tobeinstalled = [] |
248 | 248 |
selected_packages = self.install_config['packages'] |
249 | 249 |
|
250 |
- for pkg in selected_packages: |
|
250 |
+ for pkg in selected_packages: |
|
251 | 251 |
if pkg in pkg_to_rpm_map: |
252 | 252 |
if not pkg_to_rpm_map[pkg]['rpm'] is None: |
253 | 253 |
name = pkg_to_rpm_map[pkg]['rpm'] |
254 | 254 |
basename = os.path.basename(name) |
255 |
- self.rpms_tobeinstalled.append({'filename': basename, 'path': name, 'package' : pkg}) |
|
255 |
+ self.rpms_tobeinstalled.append({'filename': basename, 'path': name, |
|
256 |
+ 'package' : pkg}) |
|
256 | 257 |
|
257 | 258 |
# Copy the rpms |
258 | 259 |
for rpm in self.rpms_tobeinstalled: |
... | ... |
@@ -264,36 +279,45 @@ class Installer(object): |
264 | 264 |
retval = process.wait() |
265 | 265 |
|
266 | 266 |
# Copy the installer files |
267 |
- process = subprocess.Popen(['cp', '-r', "../installer", self.photon_root], stdout=self.output) |
|
267 |
+ process = subprocess.Popen(['cp', '-r', "../installer", self.photon_root], |
|
268 |
+ stdout=self.output) |
|
268 | 269 |
retval = process.wait() |
269 | 270 |
|
270 | 271 |
# Create the rpms directory |
271 |
- process = subprocess.Popen(['mkdir', '-p', self.photon_root + '/RPMS'], stdout=self.output) |
|
272 |
+ process = subprocess.Popen(['mkdir', '-p', self.photon_root + '/RPMS'], |
|
273 |
+ stdout=self.output) |
|
272 | 274 |
retval = process.wait() |
273 | 275 |
self.copy_rpms() |
274 | 276 |
|
275 | 277 |
def bind_installer(self): |
276 | 278 |
# Make the photon_root/installer directory if not exits |
277 |
- process = subprocess.Popen(['mkdir', '-p', os.path.join(self.photon_root, "installer")], stdout=self.output) |
|
279 |
+ process = subprocess.Popen(['mkdir', '-p', os.path.join(self.photon_root, "installer")], |
|
280 |
+ stdout=self.output) |
|
278 | 281 |
retval = process.wait() |
279 |
- # The function finalize_system will access the file /installer/mk-finalize-system.sh after chroot to photon_root. |
|
280 |
- # Bind the /installer folder to self.photon_root/installer, so that after chroot to photon_root, |
|
282 |
+ # The function finalize_system will access the file /installer/mk-finalize-system.sh |
|
283 |
+ # after chroot to photon_root. |
|
284 |
+ # Bind the /installer folder to self.photon_root/installer, so that after chroot |
|
285 |
+ # to photon_root, |
|
281 | 286 |
# the file can still be accessed as /installer/mk-finalize-system.sh. |
282 |
- process = subprocess.Popen(['mount', '--bind', '/installer', os.path.join(self.photon_root, "installer")], stdout=self.output) |
|
287 |
+ process = subprocess.Popen(['mount', '--bind', '/installer', |
|
288 |
+ os.path.join(self.photon_root, "installer")], |
|
289 |
+ stdout=self.output) |
|
283 | 290 |
retval = process.wait() |
284 | 291 |
|
285 | 292 |
def bind_repo_dir(self): |
286 | 293 |
rpm_cache_dir = self.photon_root + '/cache/tdnf/photon-iso/rpms' |
287 | 294 |
if self.rpm_path.startswith("https://") or self.rpm_path.startswith("http://"): |
288 | 295 |
return |
289 |
- if subprocess.call(['mkdir', '-p', rpm_cache_dir]) != 0 or subprocess.call(['mount', '--bind', self.rpm_path, rpm_cache_dir]) != 0: |
|
296 |
+ if (subprocess.call(['mkdir', '-p', rpm_cache_dir]) != 0 or |
|
297 |
+ subprocess.call(['mount', '--bind', self.rpm_path, rpm_cache_dir]) != 0): |
|
290 | 298 |
modules.commons.log(modules.commons.LOG_ERROR, "Fail to bind cache rpms") |
291 | 299 |
self.exit_gracefully(None, None) |
292 | 300 |
def unbind_repo_dir(self): |
293 | 301 |
rpm_cache_dir = self.photon_root + '/cache/tdnf/photon-iso/rpms' |
294 | 302 |
if self.rpm_path.startswith("https://") or self.rpm_path.startswith("http://"): |
295 | 303 |
return |
296 |
- if subprocess.call(['umount', rpm_cache_dir]) != 0 or subprocess.call(['rm', '-rf', rpm_cache_dir]) != 0: |
|
304 |
+ if (subprocess.call(['umount', rpm_cache_dir]) != 0 or |
|
305 |
+ subprocess.call(['rm', '-rf', rpm_cache_dir]) != 0): |
|
297 | 306 |
modules.commons.log(modules.commons.LOG_ERROR, "Fail to unbind cache rpms") |
298 | 307 |
self.exit_gracefully(None, None) |
299 | 308 |
|
... | ... |
@@ -309,7 +333,7 @@ class Installer(object): |
309 | 309 |
if 'mountpoint' in partition and partition['mountpoint'] == '/': |
310 | 310 |
options = options + ',barrier,noatime,noacl,data=ordered' |
311 | 311 |
fsck = 1 |
312 |
- |
|
312 |
+ |
|
313 | 313 |
if partition['filesystem'] == 'swap': |
314 | 314 |
mountpoint = 'swap' |
315 | 315 |
dump = 0 |
... | ... |
@@ -328,7 +352,7 @@ class Installer(object): |
328 | 328 |
# Add the cdrom entry |
329 | 329 |
fstab_file.write("/dev/cdrom\t/mnt/cdrom\tiso9660\tro,noauto\t0\t0\n") |
330 | 330 |
|
331 |
- def generate_partitions_param(self, reverse = False): |
|
331 |
+ def generate_partitions_param(self, reverse=False): |
|
332 | 332 |
if reverse: |
333 | 333 |
step = -1 |
334 | 334 |
else: |
... | ... |
@@ -343,48 +367,57 @@ class Installer(object): |
343 | 343 |
|
344 | 344 |
def initialize_system(self): |
345 | 345 |
#Setup the disk |
346 |
- if (not self.install_config['iso_system']): |
|
346 |
+ if not self.install_config['iso_system']: |
|
347 | 347 |
command = [self.mount_command, '-w', self.photon_root] |
348 | 348 |
command.extend(self.generate_partitions_param()) |
349 | 349 |
process = subprocess.Popen(command, stdout=self.output) |
350 | 350 |
retval = process.wait() |
351 |
- |
|
351 |
+ |
|
352 | 352 |
if self.iso_installer: |
353 | 353 |
self.bind_installer() |
354 | 354 |
self.bind_repo_dir() |
355 |
- process = subprocess.Popen([self.prepare_command, '-w', self.photon_root, 'install'], stdout=self.output) |
|
355 |
+ process = subprocess.Popen([self.prepare_command, '-w', self.photon_root, 'install'], |
|
356 |
+ stdout=self.output) |
|
356 | 357 |
retval = process.wait() |
357 | 358 |
else: |
358 | 359 |
self.copy_files() |
359 | 360 |
#Setup the filesystem basics |
360 |
- process = subprocess.Popen([self.prepare_command, '-w', self.photon_root], stdout=self.output) |
|
361 |
+ process = subprocess.Popen([self.prepare_command, '-w', self.photon_root], |
|
362 |
+ stdout=self.output) |
|
361 | 363 |
retval = process.wait() |
362 | 364 |
|
363 | 365 |
def finalize_system(self): |
364 | 366 |
#Setup the disk |
365 |
- process = subprocess.Popen([self.chroot_command, '-w', self.photon_root, self.finalize_command, '-w', self.photon_root], stdout=self.output) |
|
367 |
+ process = subprocess.Popen([self.chroot_command, '-w', self.photon_root, |
|
368 |
+ self.finalize_command, '-w', self.photon_root], |
|
369 |
+ stdout=self.output) |
|
366 | 370 |
retval = process.wait() |
367 | 371 |
if self.iso_installer: |
368 | 372 |
|
369 | 373 |
modules.commons.dump(modules.commons.LOG_FILE_NAME) |
370 | 374 |
shutil.copy(modules.commons.LOG_FILE_NAME, self.photon_root + '/var/log/') |
371 |
- shutil.copy(modules.commons.TDNF_LOG_FILE_NAME, self.photon_root + '/var/log/') |
|
375 |
+ shutil.copy(modules.commons.TDNF_LOG_FILE_NAME, self.photon_root + |
|
376 |
+ '/var/log/') |
|
372 | 377 |
|
373 | 378 |
# unmount the installer directory |
374 |
- process = subprocess.Popen(['umount', os.path.join(self.photon_root, "installer")], stdout=self.output) |
|
379 |
+ process = subprocess.Popen(['umount', os.path.join(self.photon_root, |
|
380 |
+ "installer")], |
|
381 |
+ stdout=self.output) |
|
375 | 382 |
retval = process.wait() |
376 | 383 |
# remove the installer directory |
377 |
- process = subprocess.Popen(['rm', '-rf', os.path.join(self.photon_root, "installer")], stdout=self.output) |
|
384 |
+ process = subprocess.Popen(['rm', '-rf', os.path.join(self.photon_root, "installer")], |
|
385 |
+ stdout=self.output) |
|
378 | 386 |
retval = process.wait() |
379 | 387 |
self.unbind_repo_dir() |
380 | 388 |
# Disable the swap file |
381 | 389 |
process = subprocess.Popen(['swapoff', '-a'], stdout=self.output) |
382 | 390 |
retval = process.wait() |
383 | 391 |
# remove the tdnf cache directory and the swapfile. |
384 |
- process = subprocess.Popen(['rm', '-rf', os.path.join(self.photon_root, "cache")], stdout=self.output) |
|
392 |
+ process = subprocess.Popen(['rm', '-rf', os.path.join(self.photon_root, "cache")], |
|
393 |
+ stdout=self.output) |
|
385 | 394 |
retval = process.wait() |
386 | 395 |
|
387 |
- def install_package(self, rpm_file_names): |
|
396 |
+ def install_package(self, rpm_file_names): |
|
388 | 397 |
|
389 | 398 |
rpms = set(rpm_file_names) |
390 | 399 |
rpm_paths = [] |
... | ... |
@@ -394,13 +427,19 @@ class Installer(object): |
394 | 394 |
rpm_paths.append(os.path.join(root, f)) |
395 | 395 |
|
396 | 396 |
# --nodeps is for hosts which do not support rich dependencies |
397 |
- rpm_params = ['--nodeps', '--root', self.photon_root, '--dbpath', '/var/lib/rpm'] |
|
397 |
+ rpm_params = ['--nodeps', '--root', self.photon_root, '--dbpath', |
|
398 |
+ '/var/lib/rpm'] |
|
398 | 399 |
|
399 |
- if ('type' in self.install_config and (self.install_config['type'] in ['micro', 'minimal'])) or self.install_config['iso_system']: |
|
400 |
+ if (('type' in self.install_config and |
|
401 |
+ (self.install_config['type'] in ['micro', 'minimal'])) or |
|
402 |
+ self.install_config['iso_system']): |
|
400 | 403 |
rpm_params.append('--excludedocs') |
401 | 404 |
|
402 |
- modules.commons.log(modules.commons.LOG_INFO, "installing packages {0}, with params {1}".format(rpm_paths, rpm_params)) |
|
403 |
- process = subprocess.Popen(['rpm', '-Uvh'] + rpm_params + rpm_paths, stderr=subprocess.STDOUT) |
|
405 |
+ modules.commons.log(modules.commons.LOG_INFO, |
|
406 |
+ "installing packages {0}, with params {1}" |
|
407 |
+ .format(rpm_paths, rpm_params)) |
|
408 |
+ process = subprocess.Popen(['rpm', '-Uvh'] + rpm_params + rpm_paths, |
|
409 |
+ stderr=subprocess.STDOUT) |
|
404 | 410 |
return process.wait() |
405 | 411 |
|
406 | 412 |
def execute_modules(self, phase): |
... | ... |
@@ -413,22 +452,27 @@ class Installer(object): |
413 | 413 |
__import__(module) |
414 | 414 |
mod = sys.modules[module] |
415 | 415 |
except ImportError: |
416 |
- modules.commons.log(modules.commons.LOG_ERROR, 'Error importing module {}'.format(module)) |
|
416 |
+ modules.commons.log(modules.commons.LOG_ERROR, |
|
417 |
+ 'Error importing module {}'.format(module)) |
|
417 | 418 |
continue |
418 |
- |
|
419 |
+ |
|
419 | 420 |
# the module default is disabled |
420 | 421 |
if not hasattr(mod, 'enabled') or mod.enabled == False: |
421 |
- modules.commons.log(modules.commons.LOG_INFO, "module {} is not enabled".format(module)) |
|
422 |
+ modules.commons.log(modules.commons.LOG_INFO, |
|
423 |
+ "module {} is not enabled".format(module)) |
|
422 | 424 |
continue |
423 | 425 |
# check for the install phase |
424 | 426 |
if not hasattr(mod, 'install_phase'): |
425 |
- modules.commons.log(modules.commons.LOG_ERROR, "Error: can not defind module {} phase".format(module)) |
|
427 |
+ modules.commons.log(modules.commons.LOG_ERROR, |
|
428 |
+ "Error: can not defind module {} phase".format(module)) |
|
426 | 429 |
continue |
427 | 430 |
if mod.install_phase != phase: |
428 |
- modules.commons.log(modules.commons.LOG_INFO, "Skipping module {0} for phase {1}".format(module, phase)) |
|
431 |
+ modules.commons.log(modules.commons.LOG_INFO, |
|
432 |
+ "Skipping module {0} for phase {1}".format(module, phase)) |
|
429 | 433 |
continue |
430 | 434 |
if not hasattr(mod, 'execute'): |
431 |
- modules.commons.log(modules.commons.LOG_ERROR, "Error: not able to execute module {}".format(module)) |
|
435 |
+ modules.commons.log(modules.commons.LOG_ERROR, |
|
436 |
+ "Error: not able to execute module {}".format(module)) |
|
432 | 437 |
continue |
433 | 438 |
|
434 | 439 |
mod.execute(module, self.install_config, self.photon_root) |
... | ... |
@@ -8,9 +8,9 @@ from ostreeinstaller import OstreeInstaller |
8 | 8 |
from ostreeserverinstaller import OstreeServerInstaller |
9 | 9 |
|
10 | 10 |
class InstallerContainer(object): |
11 |
- def __init__(self, install_config, maxy = 0, maxx = 0, |
|
12 |
- iso_installer = False, rpm_path = "../stage/RPMS", |
|
13 |
- log_path = "../stage/LOGS"): |
|
11 |
+ def __init__(self, install_config, maxy=0, maxx=0, |
|
12 |
+ iso_installer=False, rpm_path="../stage/RPMS", |
|
13 |
+ log_path="../stage/LOGS"): |
|
14 | 14 |
|
15 | 15 |
self.install_config = install_config |
16 | 16 |
self.maxy = maxy |
... | ... |
@@ -22,10 +22,14 @@ class InstallerContainer(object): |
22 | 22 |
def install(self, params): |
23 | 23 |
installer = None |
24 | 24 |
if self.install_config['type'] == "ostree_host": |
25 |
- installer = OstreeInstaller(self.install_config, self.maxy, self.maxx, self.iso_installer, self.rpm_path, self.log_path) |
|
25 |
+ installer = OstreeInstaller(self.install_config, self.maxy, self.maxx, |
|
26 |
+ self.iso_installer, self.rpm_path, self.log_path) |
|
26 | 27 |
elif self.install_config['type'] == "ostree_server": |
27 |
- installer = OstreeServerInstaller(self.install_config, self.maxy, self.maxx, self.iso_installer, self.rpm_path, self.log_path) |
|
28 |
+ installer = OstreeServerInstaller(self.install_config, self.maxy, self.maxx, |
|
29 |
+ self.iso_installer, self.rpm_path, |
|
30 |
+ self.log_path) |
|
28 | 31 |
else: |
29 |
- installer = Installer(self.install_config, self.maxy, self.maxx, self.iso_installer, self.rpm_path, self.log_path) |
|
32 |
+ installer = Installer(self.install_config, self.maxy, self.maxx, |
|
33 |
+ self.iso_installer, self.rpm_path, self.log_path) |
|
30 | 34 |
|
31 |
- return installer.install(params) |
|
32 | 35 |
\ No newline at end of file |
36 |
+ return installer.install(params) |
... | ... |
@@ -9,7 +9,7 @@ import collections |
9 | 9 |
|
10 | 10 |
class JsonWrapper(object): |
11 | 11 |
|
12 |
- def __init__(self, filename): |
|
12 |
+ def __init__(self, filename): |
|
13 | 13 |
self.filename = filename |
14 | 14 |
|
15 | 15 |
def read(self): |
... | ... |
@@ -17,7 +17,7 @@ class JsonWrapper(object): |
17 | 17 |
self.data = json.load(json_data, object_pairs_hook=collections.OrderedDict) |
18 | 18 |
return self.data |
19 | 19 |
|
20 |
- def write(self, data): |
|
20 |
+ def write(self, data): |
|
21 | 21 |
self.data = data |
22 |
- with open(self.filename, 'wb') as outfile: |
|
23 |
- json.dump(data, outfile) |
|
22 |
+ with open(self.filename, 'wb') as outfile: |
|
23 |
+ json.dump(data, outfile) |
... | ... |
@@ -8,7 +8,7 @@ from actionresult import ActionResult |
8 | 8 |
from textpane import TextPane |
9 | 9 |
|
10 | 10 |
class License(object): |
11 |
- def __init__(self, maxy, maxx): |
|
11 |
+ def __init__(self, maxy, maxx): |
|
12 | 12 |
self.maxx = maxx |
13 | 13 |
self.maxy = maxy |
14 | 14 |
self.win_width = maxx - 4 |
... | ... |
@@ -21,17 +21,17 @@ class License(object): |
21 | 21 |
self.text_height = self.win_height - 6 |
22 | 22 |
self.text_width = self.win_width - 6 |
23 | 23 |
|
24 |
- self.window = Window(self.win_height, self.win_width, self.maxy, self.maxx, 'Welcome to the Photon installer', False) |
|
24 |
+ self.window = Window(self.win_height, self.win_width, self.maxy, self.maxx, |
|
25 |
+ 'Welcome to the Photon installer', False) |
|
25 | 26 |
|
26 | 27 |
def display(self, params): |
27 |
- accept_decline_items = [ |
|
28 |
- ('<Accept>', self.accept_function), |
|
29 |
- ('<Cancel>', self.exit_function) |
|
30 |
- ] |
|
28 |
+ accept_decline_items = [('<Accept>', self.accept_function), |
|
29 |
+ ('<Cancel>', self.exit_function)] |
|
31 | 30 |
|
32 | 31 |
title = 'VMWARE 2.0 LICENSE AGREEMENT' |
33 | 32 |
self.window.addstr(0, (self.win_width - len(title)) // 2, title) |
34 |
- self.text_pane = TextPane(self.text_starty, self.maxx, self.text_width, "EULA.txt", self.text_height, accept_decline_items) |
|
33 |
+ self.text_pane = TextPane(self.text_starty, self.maxx, self.text_width, |
|
34 |
+ "EULA.txt", self.text_height, accept_decline_items) |
|
35 | 35 |
|
36 | 36 |
self.window.set_action_panel(self.text_pane) |
37 | 37 |
|
... | ... |
@@ -8,7 +8,9 @@ from actionresult import ActionResult |
8 | 8 |
from action import Action |
9 | 9 |
|
10 | 10 |
class Menu(Action): |
11 |
- def __init__(self, starty, maxx, items, height = 0, selector_menu = False, can_navigate_outside = True, horizontal = False, default_selected = 0, save_sel = False, tab_enable = True): |
|
11 |
+ def __init__(self, starty, maxx, items, height=0, selector_menu=False, |
|
12 |
+ can_navigate_outside=True, horizontal=False, default_selected=0, |
|
13 |
+ save_sel=False, tab_enable=True): |
|
12 | 14 |
self.can_navigate_outside = can_navigate_outside |
13 | 15 |
self.horizontal = horizontal |
14 | 16 |
self.horizontal_padding = 10 |
... | ... |
@@ -19,7 +21,7 @@ class Menu(Action): |
19 | 19 |
self.width = self.lengthen_items() |
20 | 20 |
self.num_items = len(self.items) |
21 | 21 |
self.save_sel = save_sel |
22 |
- self.tab_enable=tab_enable |
|
22 |
+ self.tab_enable = tab_enable |
|
23 | 23 |
if height == 0 or height > self.num_items: |
24 | 24 |
self.height = self.num_items |
25 | 25 |
else: |
... | ... |
@@ -85,9 +87,9 @@ class Menu(Action): |
85 | 85 |
elif self.position >= len(self.items): |
86 | 86 |
self.position = len(self.items)-1 |
87 | 87 |
|
88 |
- if (self.position >= self.head_position + self.height): |
|
88 |
+ if self.position >= self.head_position + self.height: |
|
89 | 89 |
self.head_position = self.position - self.height + 1 |
90 |
- if (self.position < self.head_position): |
|
90 |
+ if self.position < self.head_position: |
|
91 | 91 |
self.head_position = self.position |
92 | 92 |
|
93 | 93 |
|
... | ... |
@@ -95,7 +97,7 @@ class Menu(Action): |
95 | 95 |
if self.show_scroll: |
96 | 96 |
remaining_above = self.head_position |
97 | 97 |
remaining_down = self.num_items - self.height - self.head_position# |
98 |
- |
|
98 |
+ |
|
99 | 99 |
up = int(round(remaining_above * self.height / float(self.num_items))) |
100 | 100 |
down = self.height - up - self.filled |
101 | 101 |
|
... | ... |
@@ -119,12 +121,12 @@ class Menu(Action): |
119 | 119 |
for index in range(down): |
120 | 120 |
self.window.addch(index + up + self.filled, self.width - 2, curses.ACS_CKBOARD) |
121 | 121 |
|
122 |
- def refresh(self, highligh = True): |
|
122 |
+ def refresh(self, highligh=True): |
|
123 | 123 |
self.window.clear() |
124 | 124 |
for index, item in enumerate(self.items_strings): |
125 |
- if (index < self.head_position): |
|
125 |
+ if index < self.head_position: |
|
126 | 126 |
continue |
127 |
- elif (index > self.head_position + self.height - 1): |
|
127 |
+ elif index > self.head_position + self.height - 1: |
|
128 | 128 |
continue |
129 | 129 |
elif index == self.position: |
130 | 130 |
if highligh: |
... | ... |
@@ -189,9 +191,9 @@ class Menu(Action): |
189 | 189 |
return ActionResult(False, {'diskIndex': self.position}) |
190 | 190 |
else: |
191 | 191 |
return ActionResult(False, None) |
192 |
- |
|
192 |
+ |
|
193 | 193 |
elif key == curses.KEY_UP or key == curses.KEY_LEFT: |
194 |
- if not self.tab_enable and key==curses.KEY_LEFT: |
|
194 |
+ if not self.tab_enable and key == curses.KEY_LEFT: |
|
195 | 195 |
if self.save_sel: |
196 | 196 |
return ActionResult(False, {'diskIndex': self.position, 'direction':-1}) |
197 | 197 |
elif self.selector_menu: |
... | ... |
@@ -202,7 +204,7 @@ class Menu(Action): |
202 | 202 |
self.navigate(-1) |
203 | 203 |
|
204 | 204 |
elif key == curses.KEY_DOWN or key == curses.KEY_RIGHT: |
205 |
- if not self.tab_enable and key==curses.KEY_RIGHT: |
|
205 |
+ if not self.tab_enable and key == curses.KEY_RIGHT: |
|
206 | 206 |
if self.save_sel: |
207 | 207 |
return ActionResult(False, {'diskIndex': self.position, 'direction':1}) |
208 | 208 |
else: |
... | ... |
@@ -217,4 +219,3 @@ class Menu(Action): |
217 | 217 |
|
218 | 218 |
elif key == curses.KEY_HOME: |
219 | 219 |
self.navigate(-self.position) |
220 |
- |
... | ... |
@@ -61,9 +61,6 @@ cp EFI_$(uname -m)/BOOT/* ${BUILDROOT}/installer/EFI/BOOT/ |
61 | 61 |
# grubx64.efi is generated on Photon OS by using grub2-efi >= 2.02-7: |
62 | 62 |
# # grub2-efi-mkimage -o grubx64.efi -p /boot/grub2 -O x86_64-efi fat iso9660 part_gpt part_msdos normal boot linux configfile loopback chain efifwsetup efi_gop efi_uga ls search search_label search_fs_uuid search_fs_file gfxterm gfxterm_background gfxterm_menu test all_video loadenv exfat ext2 udf halt gfxmenu png tga lsefi help linuxefi |
63 | 63 |
|
64 |
-# grubaa64.efi is generated on Photon OS by using grub2-efi >= 2.02-7: |
|
65 |
-#grub2-mkimage -o bootaa64.efi -p /boot/grub2 -O arm64-efi fat iso9660 part_gpt part_msdos normal boot linux configfile loopback chain efifwsetup efi_gop efinet ls search search_label search_fs_uuid search_fs_file gfxterm gfxterm_background gfxterm_menu test all_video loadenv exfat ext2 udf halt gfxmenu png tga lsefi help all_video |
|
66 |
- |
|
67 | 64 |
# both bootx64.efi and grubx64.efi are signed with VMware key |
68 | 65 |
EFI_IMAGE=boot/grub2/efiboot.img |
69 | 66 |
EFI_FOLDER=`readlink -f ${STAGE_PATH}/efiboot` |
... | ... |
@@ -10,7 +10,7 @@ from window import Window |
10 | 10 |
from actionresult import ActionResult |
11 | 11 |
|
12 | 12 |
class PackageSelector(object): |
13 |
- def __init__(self, maxy, maxx, install_config, options_file): |
|
13 |
+ def __init__(self, maxy, maxx, install_config, options_file): |
|
14 | 14 |
self.install_config = install_config |
15 | 15 |
self.maxx = maxx |
16 | 16 |
self.maxy = maxy |
... | ... |
@@ -25,8 +25,8 @@ class PackageSelector(object): |
25 | 25 |
self.load_package_list(options_file) |
26 | 26 |
|
27 | 27 |
self.window = Window(self.win_height, self.win_width, self.maxy, self.maxx, |
28 |
- 'Select Installation', True, action_panel = self.package_menu, |
|
29 |
- can_go_next = True, position = 1) |
|
28 |
+ 'Select Installation', True, action_panel=self.package_menu, |
|
29 |
+ can_go_next=True, position=1) |
|
30 | 30 |
|
31 | 31 |
@staticmethod |
32 | 32 |
def get_packages_to_install(options, config_type, output_data_path): |
... | ... |
@@ -34,8 +34,12 @@ class PackageSelector(object): |
34 | 34 |
for install_option in options: |
35 | 35 |
if install_option[0] == config_type: |
36 | 36 |
for include_type in install_option[1]["include"]: |
37 |
- package_list = package_list + PackageSelector.get_packages_to_install(options, include_type, output_data_path) |
|
38 |
- json_wrapper_package_list = JsonWrapper(os.path.join(output_data_path, install_option[1]["file"])) |
|
37 |
+ package_list = (package_list + |
|
38 |
+ PackageSelector.get_packages_to_install(options, |
|
39 |
+ include_type, |
|
40 |
+ output_data_path)) |
|
41 |
+ json_wrapper_package_list = JsonWrapper(os.path.join(output_data_path, |
|
42 |
+ install_option[1]["file"])) |
|
39 | 43 |
package_list_json = json_wrapper_package_list.read() |
40 | 44 |
package_list = package_list + package_list_json["packages"] |
41 | 45 |
break |
... | ... |
@@ -64,19 +68,26 @@ class PackageSelector(object): |
64 | 64 |
visible_options_cnt = 0 |
65 | 65 |
for install_option in options_sorted: |
66 | 66 |
if install_option[1]["visible"] == True: |
67 |
- package_list = PackageSelector.get_packages_to_install(options_sorted, install_option[0], base_path) |
|
68 |
- additional_files = PackageSelector.get_additional_files_to_copy_in_iso(options_sorted, base_path, install_option[0]) |
|
69 |
- self.package_menu_items.append((install_option[1]["title"], self.exit_function, [install_option[0], package_list, additional_files] )) |
|
67 |
+ package_list = PackageSelector.get_packages_to_install(options_sorted, |
|
68 |
+ install_option[0], |
|
69 |
+ base_path) |
|
70 |
+ additional_files = PackageSelector.get_additional_files_to_copy_in_iso( |
|
71 |
+ options_sorted, base_path, install_option[0]) |
|
72 |
+ self.package_menu_items.append((install_option[1]["title"], |
|
73 |
+ self.exit_function, |
|
74 |
+ [install_option[0], |
|
75 |
+ package_list, additional_files])) |
|
70 | 76 |
if install_option[0] == 'minimal': |
71 | 77 |
default_selected = visible_options_cnt |
72 | 78 |
visible_options_cnt = visible_options_cnt + 1 |
73 | 79 |
|
74 | 80 |
|
75 |
- self.package_menu = Menu(self.menu_starty, self.maxx, self.package_menu_items, default_selected = default_selected, tab_enable=False) |
|
81 |
+ self.package_menu = Menu(self.menu_starty, self.maxx, self.package_menu_items, |
|
82 |
+ default_selected=default_selected, tab_enable=False) |
|
76 | 83 |
|
77 |
- def exit_function(self, selected_item_params): |
|
78 |
- self.install_config['type'] = selected_item_params[0]; |
|
79 |
- self.install_config['packages'] = selected_item_params[1]; |
|
84 |
+ def exit_function(self, selected_item_params): |
|
85 |
+ self.install_config['type'] = selected_item_params[0] |
|
86 |
+ self.install_config['packages'] = selected_item_params[1] |
|
80 | 87 |
self.install_config['additional-files'] = selected_item_params[2] |
81 | 88 |
return ActionResult(True, {'custom': False}) |
82 | 89 |
|
... | ... |
@@ -1,4 +1,4 @@ |
1 |
-from window import Window |
|
1 |
+from window import Window |
|
2 | 2 |
from windowstringreader import WindowStringReader |
3 | 3 |
from textpane import TextPane |
4 | 4 |
from readmultext import ReadMulText |
... | ... |
@@ -31,7 +31,8 @@ class PartitionISO(object): |
31 | 31 |
for index, device in enumerate(self.devices): |
32 | 32 |
self.disk_size.append((device.path, int(device.size) / 1048576)) |
33 | 33 |
|
34 |
- self.window = Window(self.win_height, self.win_width, self.maxy, self.maxx, 'Welcome to the Photon installer', False, can_go_next=False) |
|
34 |
+ self.window = Window(self.win_height, self.win_width, self.maxy, self.maxx, |
|
35 |
+ 'Welcome to the Photon installer', False, can_go_next=False) |
|
35 | 36 |
Device.refresh_devices() |
36 | 37 |
|
37 | 38 |
def display(self, params): |
... | ... |
@@ -40,9 +41,10 @@ class PartitionISO(object): |
40 | 40 |
return ActionResult(False, {'goBack':True}) |
41 | 41 |
if 'autopartition' in self.install_config and self.install_config['autopartition'] == True: |
42 | 42 |
return ActionResult(True, None) |
43 |
- if 'delete_partition' in self.install_config and self.install_config['delete_partition'] == True: |
|
43 |
+ if ('delete_partition' in self.install_config and |
|
44 |
+ self.install_config['delete_partition'] == True): |
|
44 | 45 |
self.delete() |
45 |
- self.install_config['delete_partition']=False |
|
46 |
+ self.install_config['delete_partition'] = False |
|
46 | 47 |
|
47 | 48 |
self.device_index = self.install_config['diskindex'] |
48 | 49 |
|
... | ... |
@@ -62,12 +64,18 @@ class PartitionISO(object): |
62 | 62 |
title = 'Current partitions:\n' |
63 | 63 |
self.window.addstr(0, (self.win_width - len(title)) // 2, title) |
64 | 64 |
|
65 |
- info = "Unpartitioned space: "+str(self.disk_size[self.device_index][1])+ " MB, Total size: "+ str(int(self.devices[self.device_index].size)/ 1048576)+" MB" |
|
65 |
+ info = ("Unpartitioned space: " + |
|
66 |
+ str(self.disk_size[self.device_index][1])+ |
|
67 |
+ " MB, Total size: "+ |
|
68 |
+ str(int(self.devices[self.device_index].size)/ 1048576) + " MB") |
|
66 | 69 |
|
67 |
- self.text_pane = TextPane(self.text_starty, self.maxx, self.text_width, |
|
68 |
- "EULA.txt", self.text_height, self.disk_buttom_items, |
|
69 |
- partition = True, popupWindow = True, install_config = self.install_config, |
|
70 |
- text_items = self.text_items, table_space=self.table_space, default_start=1, info=info, size_left=str(self.disk_size[self.device_index][1])) |
|
70 |
+ self.text_pane = TextPane(self.text_starty, self.maxx, self.text_width, |
|
71 |
+ "EULA.txt", self.text_height, self.disk_buttom_items, |
|
72 |
+ partition=True, popupWindow=True, |
|
73 |
+ install_config=self.install_config, |
|
74 |
+ text_items=self.text_items, table_space=self.table_space, |
|
75 |
+ default_start=1, info=info, |
|
76 |
+ size_left=str(self.disk_size[self.device_index][1])) |
|
71 | 77 |
|
72 | 78 |
self.window.set_action_panel(self.text_pane) |
73 | 79 |
|
... | ... |
@@ -82,19 +90,24 @@ class PartitionISO(object): |
82 | 82 |
devicedata = self.devices[self.device_index].path |
83 | 83 |
|
84 | 84 |
#no empty fields unless swap |
85 |
- if typedata == 'swap' and (len(mtdata)!=0 or len(typedata) == 0 or len(devicedata) == 0): |
|
85 |
+ if (typedata == 'swap' and |
|
86 |
+ (len(mtdata) != 0 or len(typedata) == 0 or len(devicedata) == 0)): |
|
86 | 87 |
return False, "invalid swap data " |
87 | 88 |
|
88 |
- if typedata != 'swap' and (len(sizedata) == 0 or len(mtdata) == 0 or len(typedata) == 0 or len(devicedata) == 0): |
|
89 |
- if not self.has_empty and len(mtdata) != 0 and len(typedata) != 0 and len(devicedata) != 0: |
|
89 |
+ if (typedata != 'swap' and |
|
90 |
+ (len(sizedata) == 0 or |
|
91 |
+ len(mtdata) == 0 or |
|
92 |
+ len(typedata) == 0 or |
|
93 |
+ len(devicedata) == 0)): |
|
94 |
+ if not self.has_empty and mtdata and typedata and devicedata: |
|
90 | 95 |
self.has_empty = True |
91 | 96 |
else: |
92 | 97 |
return False, "Input cannot be empty" |
93 | 98 |
|
94 |
- if typedata !='swap' and typedata!='ext3' and typedata!='ext4': |
|
99 |
+ if typedata != 'swap' and typedata != 'ext3' and typedata != 'ext4': |
|
95 | 100 |
return False, "Invalid type" |
96 | 101 |
|
97 |
- if len(mtdata)!=0 and mtdata[0] !='/': |
|
102 |
+ if len(mtdata) != 0 and mtdata[0] != '/': |
|
98 | 103 |
return False, "Invalid path" |
99 | 104 |
|
100 | 105 |
if mtdata in self.path_checker: |
... | ... |
@@ -104,7 +117,7 @@ class PartitionISO(object): |
104 | 104 |
|
105 | 105 |
#valid size: must not exceed memory limit |
106 | 106 |
curr_size = self.disk_size[i][1] |
107 |
- if len(sizedata)!=0: |
|
107 |
+ if len(sizedata) != 0: |
|
108 | 108 |
try: |
109 | 109 |
int(sizedata) |
110 | 110 |
except ValueError: |
... | ... |
@@ -114,10 +127,10 @@ class PartitionISO(object): |
114 | 114 |
return False, "invalid device size" |
115 | 115 |
#if valid, update the size and return true |
116 | 116 |
new_size = (self.disk_size[i][0], int(curr_size)- int(sizedata)) |
117 |
- self.disk_size[i] =new_size |
|
117 |
+ self.disk_size[i] = new_size |
|
118 | 118 |
|
119 |
- if mtdata=="/": |
|
120 |
- self.has_slash=True |
|
119 |
+ if mtdata == "/": |
|
120 |
+ self.has_slash = True |
|
121 | 121 |
|
122 | 122 |
self.path_checker.append(mtdata) |
123 | 123 |
return True, None |
... | ... |
@@ -127,21 +140,23 @@ class PartitionISO(object): |
127 | 127 |
|
128 | 128 |
self.install_config['partition_disk'] = self.devices[self.device_index].path |
129 | 129 |
self.partition_items = [] |
130 |
- self.partition_items.append(('Size in MB: '+str(self.disk_size[self.device_index][1])+' available')) |
|
130 |
+ self.partition_items.append(('Size in MB: ' + |
|
131 |
+ str(self.disk_size[self.device_index][1]) + |
|
132 |
+ ' available')) |
|
131 | 133 |
self.partition_items.append(('Type: (ext3, ext4, swap)')) |
132 | 134 |
self.partition_items.append(('Mountpoint:')) |
133 | 135 |
self.create_window = ReadMulText( |
134 |
- self.maxy, self.maxx, 0, |
|
135 |
- self.install_config, |
|
136 |
- str(self.install_config['partitionsnumber']) + 'partition_info', |
|
137 |
- self.partition_items, |
|
138 |
- None, |
|
139 |
- None, |
|
140 |
- None, |
|
141 |
- self.validate_partition, #validation function of the input |
|
142 |
- None, |
|
143 |
- True, |
|
144 |
- ) |
|
136 |
+ self.maxy, self.maxx, 0, |
|
137 |
+ self.install_config, |
|
138 |
+ str(self.install_config['partitionsnumber']) + 'partition_info', |
|
139 |
+ self.partition_items, |
|
140 |
+ None, |
|
141 |
+ None, |
|
142 |
+ None, |
|
143 |
+ self.validate_partition, #validation function of the input |
|
144 |
+ None, |
|
145 |
+ True, |
|
146 |
+ ) |
|
145 | 147 |
result = self.create_window.do_action() |
146 | 148 |
if result.success: |
147 | 149 |
self.install_config['partitionsnumber'] = self.install_config['partitionsnumber'] + 1 |
... | ... |
@@ -161,18 +176,23 @@ class PartitionISO(object): |
161 | 161 |
|
162 | 162 |
def next(self): |
163 | 163 |
if self.install_config['partitionsnumber'] == 0: |
164 |
- window_height=9 |
|
165 |
- window_width=40 |
|
166 |
- window_starty=(self.maxy-window_height) // 2+5 |
|
167 |
- confirm_window=ConfirmWindow(window_height,window_width,self.maxy, self.maxx, window_starty, 'Partition information cannot be empty', info=True) |
|
164 |
+ window_height = 9 |
|
165 |
+ window_width = 40 |
|
166 |
+ window_starty = (self.maxy-window_height) // 2 + 5 |
|
167 |
+ confirm_window = ConfirmWindow(window_height, window_width, self.maxy, |
|
168 |
+ self.maxx, window_starty, |
|
169 |
+ 'Partition information cannot be empty', |
|
170 |
+ info=True) |
|
168 | 171 |
confirm_window.do_action() |
169 | 172 |
return self.display(False) |
170 | 173 |
#must have / |
171 | 174 |
if not self.has_slash: |
172 |
- window_height=9 |
|
173 |
- window_width=40 |
|
174 |
- window_starty=(self.maxy-window_height) // 2 + 5 |
|
175 |
- confirm_window=ConfirmWindow(window_height,window_width,self.maxy, self.maxx, window_starty, 'Missing /', info=True) |
|
175 |
+ window_height = 9 |
|
176 |
+ window_width = 40 |
|
177 |
+ window_starty = (self.maxy - window_height) // 2 + 5 |
|
178 |
+ confirm_window = ConfirmWindow(window_height, window_width, self.maxy, |
|
179 |
+ self.maxx, window_starty, 'Missing /', |
|
180 |
+ info=True) |
|
176 | 181 |
confirm_window.do_action() |
177 | 182 |
return self.display(False) |
178 | 183 |
|
... | ... |
@@ -26,11 +26,11 @@ class ProgressBar(object): |
26 | 26 |
self.progress = 0 |
27 | 27 |
|
28 | 28 |
self.new_win = new_win |
29 |
- self.x=startx |
|
30 |
- self.y=starty |
|
29 |
+ self.x = startx |
|
30 |
+ self.y = starty |
|
31 | 31 |
|
32 | 32 |
if new_win: |
33 |
- self.contentwin = curses.newwin(7, width+2) |
|
33 |
+ self.contentwin = curses.newwin(7, width + 2) |
|
34 | 34 |
self.contentwin.bkgd(' ', curses.color_pair(2)) #Default Window color |
35 | 35 |
self.contentwin.erase() |
36 | 36 |
self.contentwin.box() |
... | ... |
@@ -59,7 +59,7 @@ class ProgressBar(object): |
59 | 59 |
self.message = message |
60 | 60 |
self.render_message() |
61 | 61 |
|
62 |
- def increment(self, step = 1): |
|
62 |
+ def increment(self, step=1): |
|
63 | 63 |
self.progress += step |
64 | 64 |
self.render_progress() |
65 | 65 |
|
... | ... |
@@ -73,7 +73,9 @@ class ProgressBar(object): |
73 | 73 |
if self.progress == 0: |
74 | 74 |
self.time_remaining = 60 |
75 | 75 |
else: |
76 |
- self.time_remaining = int(math.ceil(self.time_elapsed * self.num_items / float(self.progress))) - self.time_elapsed |
|
76 |
+ self.time_remaining = (int(math.ceil(self.time_elapsed * |
|
77 |
+ self.num_items / float(self.progress))) - |
|
78 |
+ self.time_elapsed) |
|
77 | 79 |
self.render_time() |
78 | 80 |
|
79 | 81 |
def render_message(self): |
... | ... |
@@ -120,18 +122,21 @@ class ProgressBar(object): |
120 | 120 |
def update_loading_symbol(self): |
121 | 121 |
with self.loadding_timer_lock: |
122 | 122 |
if self.loadding_timer != None: |
123 |
- self.loadding_timer = threading.Timer(self.loading_interval, self.update_loading_symbol) |
|
123 |
+ self.loadding_timer = threading.Timer(self.loading_interval, |
|
124 |
+ self.update_loading_symbol) |
|
124 | 125 |
self.loadding_timer.start() |
125 | 126 |
|
126 | 127 |
self.loading_count += 1 |
127 | 128 |
self.render_loading() |
128 | 129 |
|
129 | 130 |
def render_loading(self): |
130 |
- self.window.addstr(0, self.message_len + 1, self.loading_chars[self.loading_count % len(self.loading_chars)]) |
|
131 |
+ self.window.addstr(0, self.message_len + 1, |
|
132 |
+ self.loading_chars[self.loading_count % len(self.loading_chars)]) |
|
131 | 133 |
self.window.refresh() |
132 | 134 |
|
133 | 135 |
def show_loading(self, message): |
134 |
- self.loadding_timer = threading.Timer(self.loading_interval, self.update_loading_symbol) |
|
136 |
+ self.loadding_timer = threading.Timer(self.loading_interval, |
|
137 |
+ self.update_loading_symbol) |
|
135 | 138 |
self.loadding_timer.start() |
136 | 139 |
self.update_loading_message(message) |
137 | 140 |
|
... | ... |
@@ -169,18 +174,17 @@ class ProgressBar(object): |
169 | 169 |
completed_spaces = '' |
170 | 170 |
remaining_spaces = '' |
171 | 171 |
for i in range(completed_width): |
172 |
- if (i in range(start, end)): |
|
172 |
+ if i in range(start, end): |
|
173 | 173 |
completed_spaces += per[index] |
174 | 174 |
index += 1 |
175 | 175 |
else: |
176 | 176 |
completed_spaces += ' ' |
177 | 177 |
|
178 | 178 |
for i in range(completed_width, total_width): |
179 |
- if (i in range(start, end)): |
|
179 |
+ if i in range(start, end): |
|
180 | 180 |
remaining_spaces += per[index] |
181 | 181 |
index += 1 |
182 | 182 |
else: |
183 | 183 |
remaining_spaces += ' ' |
184 | 184 |
|
185 | 185 |
return completed_spaces, remaining_spaces |
186 |
- |
... | ... |
@@ -11,8 +11,10 @@ from window import Window |
11 | 11 |
from confirmwindow import ConfirmWindow |
12 | 12 |
|
13 | 13 |
class ReadMulText(Action): |
14 |
- def __init__(self, maxy, maxx, y, install_config, field, display_string, confirmation_error_msg, |
|
15 |
- echo_char, accepted_chars, validation_fn, conversion_fn, can_cancel, default_string = None): |
|
14 |
+ def __init__(self, maxy, maxx, y, install_config, field, |
|
15 |
+ display_string, confirmation_error_msg, |
|
16 |
+ echo_char, accepted_chars, validation_fn, conversion_fn, |
|
17 |
+ can_cancel, default_string=None): |
|
16 | 18 |
self.maxy = maxy |
17 | 19 |
self.maxx = maxx |
18 | 20 |
self.y = y |
... | ... |
@@ -32,8 +34,8 @@ class ReadMulText(Action): |
32 | 32 |
self.position = 0 |
33 | 33 |
self.height = len(self.display_string) * 4 + 2 |
34 | 34 |
self.menu_pos = 0 |
35 |
- |
|
36 |
- self.textwin = curses.newwin(self.height, self.textwin_width + 2)#self.textwin_width) |
|
35 |
+ #self.textwin_width) |
|
36 |
+ self.textwin = curses.newwin(self.height, self.textwin_width + 2) |
|
37 | 37 |
self.textwin.bkgd(' ', curses.color_pair(2)) |
38 | 38 |
self.textwin.keypad(1) |
39 | 39 |
|
... | ... |
@@ -60,20 +62,20 @@ class ReadMulText(Action): |
60 | 60 |
|
61 | 61 |
def hide(self): |
62 | 62 |
return |
63 |
- |
|
63 |
+ |
|
64 | 64 |
def init_text(self): |
65 | 65 |
self.shadowpanel.show() |
66 | 66 |
curses.panel.update_panels() |
67 | 67 |
|
68 |
- self.x = 0; |
|
68 |
+ self.x = 0 |
|
69 | 69 |
#initialize the ---- |
70 |
- dashes = '_' * self.textwin_width |
|
71 |
- cury = self.y+1 |
|
70 |
+ dashes = '_' * self.textwin_width |
|
71 |
+ cury = self.y + 1 |
|
72 | 72 |
self.str = [] |
73 | 73 |
|
74 | 74 |
for string in self.display_string: |
75 | 75 |
self.textwin.addstr(cury, 1, string) |
76 |
- self.textwin.addstr(cury+1, 1, dashes) |
|
76 |
+ self.textwin.addstr(cury + 1, 1, dashes) |
|
77 | 77 |
cury = cury + 4 |
78 | 78 |
self.str.append('') |
79 | 79 |
|
... | ... |
@@ -95,11 +97,11 @@ class ReadMulText(Action): |
95 | 95 |
curs_loc = self.visible_text_width + 1 |
96 | 96 |
else: |
97 | 97 |
curs_loc = len(self.str[self.position]) +1 |
98 |
- ch = self.textwin.getch(self.y+2+self.position*4, curs_loc) |
|
98 |
+ ch = self.textwin.getch(self.y + 2 + self.position * 4, curs_loc) |
|
99 | 99 |
|
100 | 100 |
update_text = False |
101 | 101 |
if ch in [curses.KEY_ENTER, ord('\n')]: |
102 |
- if self.menu_pos==1: |
|
102 |
+ if self.menu_pos == 1: |
|
103 | 103 |
curses.curs_set(0) |
104 | 104 |
self.shadowpanel.hide() |
105 | 105 |
return ActionResult(False, None) |
... | ... |
@@ -108,8 +110,10 @@ class ReadMulText(Action): |
108 | 108 |
curses.curs_set(0) |
109 | 109 |
conf_message_height = 8 |
110 | 110 |
conf_message_width = 48 |
111 |
- conf_message_button_y = (self.maxy - conf_message_height) / 2 + 5 |
|
112 |
- confrim_window = ConfirmWindow(conf_message_height, conf_message_width, self.maxy, self.maxx, conf_message_button_y, self.confirmation_error_msg, True) |
|
111 |
+ conf_message_button_y = (self.maxy - conf_message_height) // 2 + 5 |
|
112 |
+ confrim_window = ConfirmWindow(conf_message_height, conf_message_width, |
|
113 |
+ self.maxy, self.maxx, conf_message_button_y, |
|
114 |
+ self.confirmation_error_msg, True) |
|
113 | 115 |
confrim_window.do_action() |
114 | 116 |
return ActionResult(False, {'goBack': True}) |
115 | 117 |
self.set_field() |
... | ... |
@@ -129,7 +133,7 @@ class ReadMulText(Action): |
129 | 129 |
elif ch in [ord('\t')]: |
130 | 130 |
self.refresh(1, reset=True) |
131 | 131 |
|
132 |
- elif ch ==curses.KEY_LEFT: |
|
132 |
+ elif ch == curses.KEY_LEFT: |
|
133 | 133 |
self.menu_refresh(1) |
134 | 134 |
|
135 | 135 |
elif ch == curses.KEY_RIGHT: |
... | ... |
@@ -148,22 +152,24 @@ class ReadMulText(Action): |
148 | 148 |
self.update_text() |
149 | 149 |
|
150 | 150 |
def menu_refresh(self, n): |
151 |
- self.menu_pos+=n |
|
152 |
- if self.menu_pos<0: |
|
153 |
- self.menu_pos=0 |
|
154 |
- elif self.menu_pos>=1: |
|
155 |
- self.menu_pos=1 |
|
151 |
+ self.menu_pos += n |
|
152 |
+ if self.menu_pos < 0: |
|
153 |
+ self.menu_pos = 0 |
|
154 |
+ elif self.menu_pos >= 1: |
|
155 |
+ self.menu_pos = 1 |
|
156 | 156 |
self.update_menu() |
157 | 157 |
|
158 | 158 |
def update_menu(self): |
159 |
- if self.menu_pos==1: |
|
159 |
+ if self.menu_pos == 1: |
|
160 | 160 |
self.textwin.addstr(self.height-2, 5, '<Cancel>', curses.color_pair(3)) |
161 | 161 |
else: |
162 | 162 |
self.textwin.addstr(self.height-2, 5, '<Cancel>') |
163 |
- if self.menu_pos==0: |
|
164 |
- self.textwin.addstr(self.height-2, self.textwin_width-len('<OK>')-5, '<OK>',curses.color_pair(3)) |
|
163 |
+ if self.menu_pos == 0: |
|
164 |
+ self.textwin.addstr(self.height-2, self.textwin_width-len('<OK>')-5, '<OK>', |
|
165 |
+ curses.color_pair(3)) |
|
165 | 166 |
else: |
166 |
- self.textwin.addstr(self.height-2, self.textwin_width-len('<OK>')-5, '<OK>') |
|
167 |
+ self.textwin.addstr(self.height-2, self.textwin_width-len('<OK>')-5, |
|
168 |
+ '<OK>') |
|
167 | 169 |
|
168 | 170 |
|
169 | 171 |
|
... | ... |
@@ -176,15 +182,15 @@ class ReadMulText(Action): |
176 | 176 |
text = self.echo_char * len(text) |
177 | 177 |
|
178 | 178 |
text = text + '_' * (self.visible_text_width - len(self.str[self.position])) |
179 |
- self.textwin.addstr(self.y+2+self.position*4, 1, text) |
|
179 |
+ self.textwin.addstr(self.y + 2 + self.position * 4, 1, text) |
|
180 | 180 |
|
181 | 181 |
def refresh(self, n, reset=False): |
182 |
- self.position += n |
|
182 |
+ self.position += n |
|
183 | 183 |
if self.position < 0: |
184 | 184 |
self.position = 0 |
185 | 185 |
elif self.position >= len(self.display_string): |
186 | 186 |
if reset: |
187 |
- self.position=0 |
|
187 |
+ self.position = 0 |
|
188 | 188 |
else: |
189 | 189 |
self.position = len(self.display_string)-1 |
190 | 190 |
|
... | ... |
@@ -203,8 +209,8 @@ class ReadMulText(Action): |
203 | 203 |
if not success: |
204 | 204 |
spaces = ' ' * (int(self.textwin_width) - len(self.display_string[0])) |
205 | 205 |
self.textwin.addstr(self.y + 1, len(self.display_string[0]), spaces) |
206 |
- self.textwin.addstr(self.y + 1, len(self.display_string[0]), err, curses.color_pair(4)) |
|
206 |
+ self.textwin.addstr(self.y + 1, len(self.display_string[0]), err, |
|
207 |
+ curses.color_pair(4)) |
|
207 | 208 |
return success |
208 | 209 |
else: |
209 | 210 |
return True |
210 |
- |
... | ... |
@@ -10,7 +10,9 @@ from action import Action |
10 | 10 |
from confirmwindow import ConfirmWindow |
11 | 11 |
|
12 | 12 |
class ReadText(Action): |
13 |
- def __init__(self, maxy, maxx, textwin, y, install_config, field, confirmation_error_msg, echo_char, accepted_chars, validation_fn, conversion_fn, default_string = None, tab_enabled=True): |
|
13 |
+ def __init__(self, maxy, maxx, textwin, y, install_config, field, |
|
14 |
+ confirmation_error_msg, echo_char, accepted_chars, validation_fn, |
|
15 |
+ conversion_fn, default_string=None, tab_enabled=True): |
|
14 | 16 |
self.textwin = textwin |
15 | 17 |
self.maxy = maxy |
16 | 18 |
self.maxx = maxx |
... | ... |
@@ -25,7 +27,7 @@ class ReadText(Action): |
25 | 25 |
self.default_string = default_string |
26 | 26 |
self.textwin_width = self.textwin.getmaxyx()[1] - 1 |
27 | 27 |
self.visible_text_width = self.textwin_width - 1 |
28 |
- self.tab_enabled=tab_enabled |
|
28 |
+ self.tab_enabled = tab_enabled |
|
29 | 29 |
|
30 | 30 |
self.init_text() |
31 | 31 |
self.maxlength = 255 |
... | ... |
@@ -41,9 +43,9 @@ class ReadText(Action): |
41 | 41 |
|
42 | 42 |
def hide(self): |
43 | 43 |
return |
44 |
- |
|
44 |
+ |
|
45 | 45 |
def init_text(self): |
46 |
- self.x = 0; |
|
46 |
+ self.x = 0 |
|
47 | 47 |
#initialize the ---- |
48 | 48 |
dashes = '_' * self.textwin_width |
49 | 49 |
self.textwin.addstr(self.y, 0, dashes) |
... | ... |
@@ -88,7 +90,10 @@ class ReadText(Action): |
88 | 88 |
conf_message_height = 8 |
89 | 89 |
conf_message_width = 48 |
90 | 90 |
conf_message_button_y = (self.maxy - conf_message_height) // 2 + 5 |
91 |
- confrim_window = ConfirmWindow(conf_message_height, conf_message_width, self.maxy, self.maxx, conf_message_button_y, self.confirmation_error_msg, True) |
|
91 |
+ confrim_window = ConfirmWindow(conf_message_height, conf_message_width, |
|
92 |
+ self.maxy, |
|
93 |
+ self.maxx, conf_message_button_y, |
|
94 |
+ self.confirmation_error_msg, True) |
|
92 | 95 |
confrim_window.do_action() |
93 | 96 |
return ActionResult(False, {'goBack': True}) |
94 | 97 |
self.set_field() |
... | ... |
@@ -98,9 +103,9 @@ class ReadText(Action): |
98 | 98 |
self.set_field() |
99 | 99 |
curses.curs_set(0) |
100 | 100 |
return ActionResult(True, None) |
101 |
- elif ch ==curses.KEY_LEFT and not self.tab_enabled: |
|
101 |
+ elif ch == curses.KEY_LEFT and not self.tab_enabled: |
|
102 | 102 |
return ActionResult(False, {'direction': -1}) |
103 |
- elif ch ==curses.KEY_RIGHT and not self.tab_enabled: |
|
103 |
+ elif ch == curses.KEY_RIGHT and not self.tab_enabled: |
|
104 | 104 |
return ActionResult(False, {'direction': 1}) |
105 | 105 |
elif ch in [ord('\t')]: |
106 | 106 |
curses.curs_set(0) |
... | ... |
@@ -142,4 +147,3 @@ class ReadText(Action): |
142 | 142 |
return success |
143 | 143 |
else: |
144 | 144 |
return True |
145 |
- |
... | ... |
@@ -12,7 +12,7 @@ import modules.commons |
12 | 12 |
from progressbar import ProgressBar |
13 | 13 |
|
14 | 14 |
class SelectDisk(object): |
15 |
- def __init__(self, maxy, maxx, install_config): |
|
15 |
+ def __init__(self, maxy, maxx, install_config): |
|
16 | 16 |
self.install_config = install_config |
17 | 17 |
self.menu_items = [] |
18 | 18 |
|
... | ... |
@@ -28,19 +28,25 @@ class SelectDisk(object): |
28 | 28 |
self.menu_height = 5 |
29 | 29 |
self.progress_padding = 5 |
30 | 30 |
self.progress_width = self.win_width - self.progress_padding |
31 |
- self.progress_bar = ProgressBar(self.win_starty + 6, self.win_startx + (self.progress_padding // 2), self.progress_width, new_win=True) |
|
31 |
+ self.progress_bar = ProgressBar(self.win_starty + 6, |
|
32 |
+ self.win_startx + (self.progress_padding // 2), |
|
33 |
+ self.progress_width, new_win=True) |
|
32 | 34 |
|
33 | 35 |
self.disk_buttom_items = [] |
34 | 36 |
self.disk_buttom_items.append(('<Custom>', self.custom_function, False)) |
35 | 37 |
self.disk_buttom_items.append(('<Auto>', self.auto_function, False)) |
36 | 38 |
|
37 |
- self.window = Window(self.win_height, self.win_width, self.maxy, self.maxx, 'Select a disk', True, items = self.disk_buttom_items, menu_helper = self.save_index, position = 2, tab_enabled=False) |
|
38 |
- self.partition_window = Window(self.win_height, self.win_width, self.maxy, self.maxx, 'Partition', True) |
|
39 |
+ self.window = Window(self.win_height, self.win_width, self.maxy, self.maxx, |
|
40 |
+ 'Select a disk', True, |
|
41 |
+ items=self.disk_buttom_items, menu_helper=self.save_index, |
|
42 |
+ position=2, tab_enabled=False) |
|
43 |
+ self.partition_window = Window(self.win_height, self.win_width, self.maxy, |
|
44 |
+ self.maxx, 'Partition', True) |
|
39 | 45 |
self.devices = Device.refresh_devices() |
40 | 46 |
|
41 | 47 |
def guided_partitions(self, params): |
42 | 48 |
if not 'diskindex' in self.install_config: |
43 |
- return ActionResult(False, None); |
|
49 |
+ return ActionResult(False, None) |
|
44 | 50 |
|
45 | 51 |
device_index = self.install_config['diskindex'] |
46 | 52 |
|
... | ... |
@@ -48,7 +54,9 @@ class SelectDisk(object): |
48 | 48 |
menu_width = 40 |
49 | 49 |
menu_starty = (self.maxy - menu_height) // 2 + 5 |
50 | 50 |
self.install_config['delete_partition'] = True |
51 |
- confrim_window = ConfirmWindow(menu_height, menu_width, self.maxy, self.maxx, menu_starty, 'This will erase the disk.\nAre you sure?') |
|
51 |
+ confrim_window = ConfirmWindow(menu_height, menu_width, self.maxy, |
|
52 |
+ self.maxx, menu_starty, |
|
53 |
+ 'This will erase the disk.\nAre you sure?') |
|
52 | 54 |
confirmed = confrim_window.do_action().result['yes'] |
53 | 55 |
|
54 | 56 |
if confirmed == False: |
... | ... |
@@ -62,24 +70,27 @@ class SelectDisk(object): |
62 | 62 |
|
63 | 63 |
# Do the partitioning |
64 | 64 |
if 'partitionsnumber' in self.install_config: |
65 |
- if (int(self.install_config['partitionsnumber']) == 0): |
|
66 |
- partitions_data = modules.commons.partition_disk(self.devices[device_index].path, modules.commons.default_partitions) |
|
67 |
- else: |
|
68 |
- partitions = [] |
|
69 |
- for i in range (int (self.install_config['partitionsnumber'])): |
|
70 |
- if len(self.install_config[str(i)+'partition_info'+str(0)])==0: |
|
71 |
- sizedata=0 |
|
72 |
- else: |
|
73 |
- sizedata = int(self.install_config[str(i)+'partition_info'+str(0)]) |
|
74 |
- mtdata = self.install_config[str(i)+'partition_info'+str(2)] |
|
75 |
- typedata = self.install_config[str(i)+'partition_info'+str(1)] |
|
76 |
- |
|
77 |
- partitions = partitions + [ |
|
78 |
- {"mountpoint": mtdata, "size": sizedata, "filesystem": typedata}, |
|
79 |
- ] |
|
80 |
- partitions_data = modules.commons.partition_disk(self.devices[device_index].path, partitions) |
|
81 |
- else: |
|
82 |
- partitions_data = modules.commons.partition_disk(self.devices[device_index].path, modules.commons.default_partitions) |
|
65 |
+ if int(self.install_config['partitionsnumber']) == 0: |
|
66 |
+ partitions_data = modules.commons.partition_disk( |
|
67 |
+ self.devices[device_index].path, modules.commons.default_partitions) |
|
68 |
+ else: |
|
69 |
+ partitions = [] |
|
70 |
+ for i in range(int(self.install_config['partitionsnumber'])): |
|
71 |
+ if len(self.install_config[str(i)+'partition_info'+str(0)]) == 0: |
|
72 |
+ sizedata = 0 |
|
73 |
+ else: |
|
74 |
+ sizedata = int(self.install_config[str(i) + 'partition_info' + str(0)]) |
|
75 |
+ mtdata = self.install_config[str(i) + 'partition_info' + str(2)] |
|
76 |
+ typedata = self.install_config[str(i) + 'partition_info'+str(1)] |
|
77 |
+ |
|
78 |
+ partitions = partitions + [{"mountpoint": mtdata, |
|
79 |
+ "size": sizedata, |
|
80 |
+ "filesystem": typedata},] |
|
81 |
+ partitions_data = modules.commons.partition_disk( |
|
82 |
+ self.devices[device_index].path, partitions) |
|
83 |
+ else: |
|
84 |
+ partitions_data = modules.commons.partition_disk( |
|
85 |
+ self.devices[device_index].path, modules.commons.default_partitions) |
|
83 | 86 |
|
84 | 87 |
if partitions_data == None: |
85 | 88 |
self.partition_window.adderror('Partitioning failed, you may try again') |
... | ... |
@@ -92,22 +103,24 @@ class SelectDisk(object): |
92 | 92 |
def display(self, params): |
93 | 93 |
if 'skipPrevs' in self.install_config: |
94 | 94 |
self.install_config['skipPrevs'] = False |
95 |
- self.window.addstr(0, 0, 'Please select a disk and a method how to partition it:\nAuto - single partition for /, no swap partition.\nCustom - for customized partitioning') |
|
95 |
+ self.window.addstr(0, 0, 'Please select a disk and a method how to partition it:\n' + |
|
96 |
+ 'Auto - single partition for /, no swap partition.\n' + |
|
97 |
+ 'Custom - for customized partitioning') |
|
96 | 98 |
|
97 | 99 |
self.disk_menu_items = [] |
98 | 100 |
|
99 | 101 |
# Fill in the menu items |
100 | 102 |
for index, device in enumerate(self.devices): |
101 | 103 |
#if index > 0: |
102 |
- self.disk_menu_items.append( |
|
103 |
- ( |
|
104 |
- '{2} - {1} @ {0}'.format(device.path, device.size, device.model), |
|
105 |
- self.save_index, |
|
106 |
- index |
|
107 |
- ) |
|
108 |
- ) |
|
109 |
- |
|
110 |
- self.disk_menu = Menu(self.menu_starty, self.maxx, self.disk_menu_items, self.menu_height, tab_enable=False) |
|
104 |
+ self.disk_menu_items.append( |
|
105 |
+ ( |
|
106 |
+ '{2} - {1} @ {0}'.format(device.path, device.size, device.model), |
|
107 |
+ self.save_index, |
|
108 |
+ index |
|
109 |
+ )) |
|
110 |
+ |
|
111 |
+ self.disk_menu = Menu(self.menu_starty, self.maxx, self.disk_menu_items, |
|
112 |
+ self.menu_height, tab_enable=False) |
|
111 | 113 |
self.disk_menu.can_save_sel(True) |
112 | 114 |
|
113 | 115 |
self.window.set_action_panel(self.disk_menu) |
... | ... |
@@ -125,4 +138,3 @@ class SelectDisk(object): |
125 | 125 |
def custom_function(self, params): #custom minimize partition number is 1 |
126 | 126 |
self.install_config['autopartition'] = False |
127 | 127 |
return ActionResult(True, None) |
128 |
- |
... | ... |
@@ -6,24 +6,27 @@ from actionresult import ActionResult |
6 | 6 |
from action import Action |
7 | 7 |
|
8 | 8 |
class TextPane(Action): |
9 |
- def __init__(self, starty, maxx, width, text_file_path, height, menu_items, partition = False, popupWindow = False, install_config = {}, text_items = [], table_space = 0, default_start = 0, info=[], size_left=[]): |
|
9 |
+ def __init__(self, starty, maxx, width, text_file_path, height, |
|
10 |
+ menu_items, partition=False, popupWindow=False, |
|
11 |
+ install_config={}, text_items=[], table_space=0, |
|
12 |
+ default_start=0, info=[], size_left=[]): |
|
10 | 13 |
self.head_position = 0 #This is the start of showing |
11 | 14 |
self.menu_position = default_start |
12 | 15 |
self.lines = [] |
13 | 16 |
self.menu_items = menu_items |
14 | 17 |
self.text_items = text_items |
15 | 18 |
self.table_space = table_space |
16 |
- self.info=info |
|
17 |
- self.size_left=size_left |
|
19 |
+ self.info = info |
|
20 |
+ self.size_left = size_left |
|
18 | 21 |
|
19 | 22 |
self.width = width |
20 |
- |
|
23 |
+ |
|
21 | 24 |
if partition == False: |
22 |
- self.read_file(text_file_path, self.width - 3); |
|
25 |
+ self.read_file(text_file_path, self.width - 3) |
|
23 | 26 |
else: |
24 |
- self.install_config=install_config |
|
25 |
- self.partition(); |
|
26 |
- |
|
27 |
+ self.install_config = install_config |
|
28 |
+ self.partition() |
|
29 |
+ |
|
27 | 30 |
self.num_items = len(self.lines) |
28 | 31 |
if self.info: |
29 | 32 |
self.text_height = height - 4 |
... | ... |
@@ -37,14 +40,15 @@ class TextPane(Action): |
37 | 37 |
self.show_scroll = False |
38 | 38 |
|
39 | 39 |
# Some calculation to detitmine the size of the scroll filled portion |
40 |
- if (self.num_items == 0): |
|
40 |
+ if self.num_items == 0: |
|
41 | 41 |
self.filled = 0 |
42 | 42 |
else: |
43 | 43 |
self.filled = int(round(self.text_height * self.text_height / float(self.num_items))) |
44 | 44 |
if self.filled == 0: |
45 | 45 |
self.filled += 1 |
46 | 46 |
for i in [1, 2]: |
47 |
- if (self.num_items - self.text_height) >= i and (self.text_height - self.filled) == (i - 1): |
|
47 |
+ if ((self.num_items - self.text_height) >= i and |
|
48 |
+ (self.text_height - self.filled) == (i - 1)): |
|
48 | 49 |
self.filled -= 1 |
49 | 50 |
|
50 | 51 |
self.window = curses.newwin(height, self.width) |
... | ... |
@@ -69,26 +73,29 @@ class TextPane(Action): |
69 | 69 |
|
70 | 70 |
self.lines.append(tstring) |
71 | 71 |
#draw the table |
72 |
- for i in range (int (self.install_config['partitionsnumber'])): |
|
72 |
+ for i in range(int(self.install_config['partitionsnumber'])): |
|
73 | 73 |
pdisk = self.install_config['partition_disk'] |
74 | 74 |
if len(pdisk) > self.text_items[0][1]: |
75 | 75 |
pdisk = pdisk[-self.text_items[0][1]:] |
76 | 76 |
psize = self.install_config[str(i)+'partition_info'+str(0)] |
77 | 77 |
if len(psize) > self.text_items[1][1]: |
78 | 78 |
psize = psize[-self.text_items[1][1]:] |
79 |
- if len(psize)==0: |
|
80 |
- psize='<'+self.size_left+'>' |
|
81 |
- ptype = self.install_config[str(i)+'partition_info'+str(1)] |
|
79 |
+ if len(psize) == 0: |
|
80 |
+ psize = '<' + self.size_left + '>' |
|
81 |
+ ptype = self.install_config[str(i) + 'partition_info' + str(1)] |
|
82 | 82 |
if len(ptype) > self.text_items[2][1]: |
83 | 83 |
ptype = ptype[-self.text_items[2][1]:] |
84 |
- pmountpoint = self.install_config[str(i)+'partition_info'+str(2)] |
|
84 |
+ pmountpoint = self.install_config[str(i) + 'partition_info' + str(2)] |
|
85 | 85 |
if len(pmountpoint) > self.text_items[3][1]: |
86 | 86 |
pmountpoint = pmountpoint[-self.text_items[3][1]:] |
87 |
- pstring = pdisk + ' '*(self.text_items[0][1] - len(pdisk)) + ' ' * self.table_space + psize + ' '*(self.text_items[1][1] - len(psize)) + ' ' * self.table_space + ptype + ' '*(self.text_items[2][1] - len(ptype) + self.table_space) + pmountpoint |
|
87 |
+ pstring = (pdisk + ' '*(self.text_items[0][1] - len(pdisk)) + |
|
88 |
+ ' ' * self.table_space + psize + |
|
89 |
+ ' '*(self.text_items[1][1] - len(psize)) + |
|
90 |
+ ' ' * self.table_space + ptype + |
|
91 |
+ ' '*(self.text_items[2][1] - len(ptype) + |
|
92 |
+ self.table_space) + pmountpoint) |
|
88 | 93 |
self.lines.append(pstring) |
89 | 94 |
|
90 |
- |
|
91 |
- |
|
92 | 95 |
def read_file(self, text_file_path, line_width): |
93 | 96 |
with open(text_file_path, "rb") as f: |
94 | 97 |
for line in f: |
... | ... |
@@ -108,7 +115,7 @@ class TextPane(Action): |
108 | 108 |
while sep_index > 0 and line[sep_index-1] != ' ' and line[sep_index] != ' ': |
109 | 109 |
sep_index = sep_index - 1 |
110 | 110 |
|
111 |
- current_line_width=sep_index |
|
111 |
+ current_line_width = sep_index |
|
112 | 112 |
if sep_index == 0: |
113 | 113 |
current_line_width = actual_line_width |
114 | 114 |
currLine = line[:current_line_width] |
... | ... |
@@ -116,7 +123,8 @@ class TextPane(Action): |
116 | 116 |
line = line.strip() |
117 | 117 |
|
118 | 118 |
# Lengthen the line with spaces |
119 |
- self.lines.append(' ' * indent + currLine + ' ' *(actual_line_width - len(currLine))) |
|
119 |
+ self.lines.append(' ' * indent + currLine + |
|
120 |
+ ' ' *(actual_line_width - len(currLine))) |
|
120 | 121 |
|
121 | 122 |
# lengthen the line with spaces |
122 | 123 |
self.lines.append(' ' * indent + line + ' ' *(actual_line_width - len(line))) |
... | ... |
@@ -141,7 +149,7 @@ class TextPane(Action): |
141 | 141 |
if self.show_scroll: |
142 | 142 |
remaining_above = self.head_position |
143 | 143 |
remaining_down = self.num_items - self.text_height - self.head_position# |
144 |
- |
|
144 |
+ |
|
145 | 145 |
up = int(round(remaining_above * self.text_height / float(self.num_items))) |
146 | 146 |
down = self.text_height - up - self.filled |
147 | 147 |
|
... | ... |
@@ -168,9 +176,9 @@ class TextPane(Action): |
168 | 168 |
def refresh(self): |
169 | 169 |
self.window.clear() |
170 | 170 |
for index, line in enumerate(self.lines): |
171 |
- if (index < self.head_position): |
|
171 |
+ if index < self.head_position: |
|
172 | 172 |
continue |
173 |
- elif (index > self.head_position + self.text_height - 1): |
|
173 |
+ elif index > self.head_position + self.text_height - 1: |
|
174 | 174 |
continue |
175 | 175 |
|
176 | 176 |
x = 0 |
... | ... |
@@ -233,4 +241,3 @@ class TextPane(Action): |
233 | 233 |
|
234 | 234 |
elif key == curses.KEY_HOME: |
235 | 235 |
self.head_position = 0 |
236 |
- |
... | ... |
@@ -9,21 +9,23 @@ from action import Action |
9 | 9 |
|
10 | 10 |
class Window(Action): |
11 | 11 |
|
12 |
- def __init__(self, height, width, maxy, maxx, title, can_go_back, action_panel = None, items = None, menu_helper = None, position = 0, tab_enabled = True, can_go_next = False, read_text=False): |
|
12 |
+ def __init__(self, height, width, maxy, maxx, title, can_go_back, |
|
13 |
+ action_panel=None, items=None, menu_helper=None, position=0, |
|
14 |
+ tab_enabled=True, can_go_next=False, read_text=False): |
|
13 | 15 |
self.can_go_back = can_go_back |
14 | 16 |
self.can_go_next = can_go_next |
15 | 17 |
self.height = height |
16 |
- self.width = width; |
|
18 |
+ self.width = width |
|
17 | 19 |
self.y = (maxy - height) // 2 |
18 |
- self.x = (maxx - width ) // 2 |
|
20 |
+ self.x = (maxx - width) // 2 |
|
19 | 21 |
title = ' ' + title + ' ' |
20 | 22 |
|
21 | 23 |
self.contentwin = curses.newwin(height - 1, width -1) |
22 | 24 |
self.contentwin.bkgd(' ', curses.color_pair(2)) #Default Window color |
23 | 25 |
self.contentwin.erase() |
24 | 26 |
self.contentwin.box() |
25 |
- self.tab_enabled=tab_enabled |
|
26 |
- self.read_text=read_text |
|
27 |
+ self.tab_enabled = tab_enabled |
|
28 |
+ self.read_text = read_text |
|
27 | 29 |
|
28 | 30 |
self.position = position |
29 | 31 |
if items: |
... | ... |
@@ -31,8 +33,8 @@ class Window(Action): |
31 | 31 |
else: |
32 | 32 |
self.items = [] |
33 | 33 |
self.menu_helper = menu_helper |
34 |
- self.contentwin.addstr(0, (width - 1 - len(title)) // 2 , title)# |
|
35 |
- newy = 5; |
|
34 |
+ self.contentwin.addstr(0, (width - 1 - len(title)) // 2, title)# |
|
35 |
+ newy = 5 |
|
36 | 36 |
|
37 | 37 |
if self.can_go_back: |
38 | 38 |
self.contentwin.addstr(height - 3, 5, '<Go Back>') |
... | ... |
@@ -44,13 +46,13 @@ class Window(Action): |
44 | 44 |
if len(self.items) > 0: |
45 | 45 |
#To select items, we need to identify up left right keys |
46 | 46 |
|
47 |
- self.dist=self.width-11 |
|
48 |
- self.dist-=len('<Go Back>') |
|
49 |
- count=0 |
|
47 |
+ self.dist = self.width-11 |
|
48 |
+ self.dist -= len('<Go Back>') |
|
49 |
+ count = 0 |
|
50 | 50 |
for item in self.items: |
51 |
- self.dist-=len(item[0]) |
|
52 |
- count+=1 |
|
53 |
- self.dist=self.dist//count |
|
51 |
+ self.dist -= len(item[0]) |
|
52 |
+ count += 1 |
|
53 |
+ self.dist = self.dist // count |
|
54 | 54 |
self.contentwin.keypad(1) |
55 | 55 |
newy += len('<Go Back>') |
56 | 56 |
newy += self.dist |
... | ... |
@@ -74,9 +76,9 @@ class Window(Action): |
74 | 74 |
self.hide_window() |
75 | 75 |
|
76 | 76 |
def update_next_item(self): |
77 |
- self.position=1 |
|
77 |
+ self.position = 1 |
|
78 | 78 |
self.items.append(('<Next>', self.next_function, False)) |
79 |
- self.tab_enabled=False |
|
79 |
+ self.tab_enabled = False |
|
80 | 80 |
|
81 | 81 |
|
82 | 82 |
def next_function(self, params): |
... | ... |
@@ -85,8 +87,10 @@ class Window(Action): |
85 | 85 |
def set_action_panel(self, action_panel): |
86 | 86 |
self.action_panel = action_panel |
87 | 87 |
|
88 |
- def update_menu(self,action_result): |
|
89 |
- if action_result.result and 'goNext' in action_result.result and action_result.result['goNext']: |
|
88 |
+ def update_menu(self, action_result): |
|
89 |
+ if (action_result.result and |
|
90 |
+ 'goNext' in action_result.result and |
|
91 |
+ action_result.result['goNext']): |
|
90 | 92 |
return ActionResult(True, None) |
91 | 93 |
if self.position == 0: |
92 | 94 |
self.contentwin.addstr(self.height - 3, 5, '<Go Back>') |
... | ... |
@@ -95,7 +99,8 @@ class Window(Action): |
95 | 95 |
self.action_panel.hide() |
96 | 96 |
return ActionResult(False, None) |
97 | 97 |
else: |
98 |
- if (action_result.result != None and 'diskIndex' in action_result.result): |
|
98 |
+ if (action_result.result != None and |
|
99 |
+ 'diskIndex' in action_result.result): |
|
99 | 100 |
params = action_result.result['diskIndex'] |
100 | 101 |
if self.menu_helper: |
101 | 102 |
self.menu_helper(params) |
... | ... |
@@ -121,18 +126,24 @@ class Window(Action): |
121 | 121 |
action_result = self.action_panel.do_action() |
122 | 122 |
|
123 | 123 |
if action_result.success: |
124 |
- if action_result.result and 'goNext' in action_result.result and action_result.result['goNext']: |
|
124 |
+ if (action_result.result and |
|
125 |
+ 'goNext' in action_result.result and |
|
126 |
+ action_result.result['goNext']): |
|
125 | 127 |
return ActionResult(True, None) |
126 |
- if self.position!=0: #saving the disk index |
|
128 |
+ if self.position != 0: #saving the disk index |
|
127 | 129 |
self.items[self.position-1][1](None) |
128 | 130 |
if self.items: |
129 | 131 |
return self.update_menu(action_result) |
130 | 132 |
self.hide_window() |
131 | 133 |
return action_result |
132 | 134 |
else: |
133 |
- if not self.tab_enabled and action_result.result !=None and 'direction' in action_result.result: |
|
135 |
+ if (not self.tab_enabled and |
|
136 |
+ action_result.result != None and |
|
137 |
+ 'direction' in action_result.result): |
|
134 | 138 |
self.refresh(action_result.result['direction'], True) |
135 |
- if (action_result.result != None and 'goBack' in action_result.result and action_result.result['goBack']): |
|
139 |
+ if (action_result.result != None and |
|
140 |
+ 'goBack' in action_result.result |
|
141 |
+ and action_result.result['goBack']): |
|
136 | 142 |
self.hide_window() |
137 | 143 |
self.action_panel.hide() |
138 | 144 |
return action_result |
... | ... |
@@ -142,7 +153,7 @@ class Window(Action): |
142 | 142 |
|
143 | 143 |
while action_result.success == False: |
144 | 144 |
if self.read_text: |
145 |
- is_go_back= self.position==0 |
|
145 |
+ is_go_back = self.position == 0 |
|
146 | 146 |
action_result = self.action_panel.do_action(returned=True, go_back=is_go_back) |
147 | 147 |
if action_result.success: |
148 | 148 |
if self.items: |
... | ... |
@@ -150,7 +161,9 @@ class Window(Action): |
150 | 150 |
self.hide_window() |
151 | 151 |
return action_result |
152 | 152 |
else: |
153 |
- if (action_result.result != None and 'goBack' in action_result.result and action_result.result['goBack']): |
|
153 |
+ if (action_result.result != None and |
|
154 |
+ 'goBack' in action_result.result and |
|
155 |
+ action_result.result['goBack']): |
|
154 | 156 |
self.hide_window() |
155 | 157 |
self.action_panel.hide() |
156 | 158 |
return action_result |
... | ... |
@@ -167,7 +180,8 @@ class Window(Action): |
167 | 167 |
self.action_panel.hide() |
168 | 168 |
return ActionResult(False, None) |
169 | 169 |
else: |
170 |
- if (action_result.result != None and 'diskIndex' in action_result.result): |
|
170 |
+ if (action_result.result != None and |
|
171 |
+ 'diskIndex' in action_result.result): |
|
171 | 172 |
params = action_result.result['diskIndex'] |
172 | 173 |
if self.menu_helper: |
173 | 174 |
self.menu_helper(params) |
... | ... |
@@ -184,7 +198,7 @@ class Window(Action): |
184 | 184 |
return ActionResult(False, None) |
185 | 185 |
elif key in [ord('\t')]: |
186 | 186 |
if not self.tab_enabled: |
187 |
- continue; |
|
187 |
+ continue |
|
188 | 188 |
#remove highlight from Go Back |
189 | 189 |
self.refresh(0, False) |
190 | 190 |
# go do the action inside the panel |
... | ... |
@@ -196,7 +210,7 @@ class Window(Action): |
196 | 196 |
#highlight the GoBack and keep going |
197 | 197 |
self.refresh(0, True) |
198 | 198 |
elif key == curses.KEY_UP or key == curses.KEY_LEFT: |
199 |
- if key == curses.KEY_UP and self.tab_enabled==False: |
|
199 |
+ if key == curses.KEY_UP and self.tab_enabled == False: |
|
200 | 200 |
self.action_panel.navigate(-1) |
201 | 201 |
action_result = self.action_panel.do_action() |
202 | 202 |
if action_result.success: |
... | ... |
@@ -212,7 +226,7 @@ class Window(Action): |
212 | 212 |
self.refresh(-1, True) |
213 | 213 |
|
214 | 214 |
elif key == curses.KEY_DOWN or key == curses.KEY_RIGHT: |
215 |
- if key == curses.KEY_DOWN and self.tab_enabled==False: |
|
215 |
+ if key == curses.KEY_DOWN and self.tab_enabled == False: |
|
216 | 216 |
self.action_panel.navigate(1) |
217 | 217 |
action_result = self.action_panel.do_action() |
218 | 218 |
if action_result.success: |
... | ... |
@@ -240,7 +254,7 @@ class Window(Action): |
240 | 240 |
if not self.items and not self.can_go_next: |
241 | 241 |
self.position = 0 |
242 | 242 |
#add the highlight |
243 |
- newy = 5; |
|
243 |
+ newy = 5 |
|
244 | 244 |
if self.position == 0: #go back |
245 | 245 |
if select: |
246 | 246 |
self.contentwin.addstr(self.height - 3, 5, '<Go Back>', curses.color_pair(3)) |
... | ... |
@@ -276,7 +290,7 @@ class Window(Action): |
276 | 276 |
newy += self.dist |
277 | 277 |
index += 1 |
278 | 278 |
|
279 |
- self.contentwin.refresh() |
|
279 |
+ self.contentwin.refresh() |
|
280 | 280 |
|
281 | 281 |
def show_window(self): |
282 | 282 |
y = self.y |
... | ... |
@@ -306,7 +320,7 @@ class Window(Action): |
306 | 306 |
curses.panel.update_panels() |
307 | 307 |
curses.doupdate() |
308 | 308 |
|
309 |
- def addstr(self, y, x, str, mode = 0): |
|
309 |
+ def addstr(self, y, x, str, mode=0): |
|
310 | 310 |
self.textwin.addstr(y, x, str, mode) |
311 | 311 |
|
312 | 312 |
def adderror(self, str): |
... | ... |
@@ -320,4 +334,3 @@ class Window(Action): |
320 | 320 |
|
321 | 321 |
def content_window(self): |
322 | 322 |
return self.textwin |
323 |
- |
... | ... |
@@ -3,12 +3,14 @@ |
3 | 3 |
# |
4 | 4 |
# Author: Mahmoud Bassiouny <mbassiouny@vmware.com> |
5 | 5 |
|
6 |
-import curses |
|
7 | 6 |
from window import Window |
8 | 7 |
from readtext import ReadText |
9 | 8 |
|
10 | 9 |
class WindowStringReader(object): |
11 |
- def __init__(self, maxy, maxx, height, width, field, confirmation_err_msg, echo_char, accepted_chars, validation_fn, conversion_fn, title, display_string, inputy, install_config, default_string = None, tab_enabled=False): |
|
10 |
+ def __init__(self, maxy, maxx, height, width, field, confirmation_err_msg, |
|
11 |
+ echo_char, accepted_chars, validation_fn, conversion_fn, title, |
|
12 |
+ display_string, inputy, install_config, default_string=None, |
|
13 |
+ tab_enabled=False): |
|
12 | 14 |
self.title = title |
13 | 15 |
self.display_string = display_string |
14 | 16 |
self.install_config = install_config |
... | ... |
@@ -21,11 +23,17 @@ class WindowStringReader(object): |
21 | 21 |
|
22 | 22 |
self.startx = (self.maxx - self.width) // 2 |
23 | 23 |
self.starty = (self.maxy - self.height) // 2 |
24 |
- self.tab_enabled=False |
|
25 |
- self.can_go_next=True |
|
24 |
+ self.tab_enabled = False |
|
25 |
+ self.can_go_next = True |
|
26 | 26 |
|
27 |
- self.window = Window(self.height, self.width, self.maxy, self.maxx, self.title, True, tab_enabled=self.tab_enabled, position=1, can_go_next=self.can_go_next, read_text=self.can_go_next) |
|
28 |
- self.read_text = ReadText(maxy, maxx, self.window.content_window(), self.inputy, install_config, field, confirmation_err_msg, echo_char, accepted_chars, validation_fn, conversion_fn, default_string, tab_enabled=self.tab_enabled) |
|
27 |
+ self.window = Window(self.height, self.width, self.maxy, self.maxx, self.title, |
|
28 |
+ True, tab_enabled=self.tab_enabled, |
|
29 |
+ position=1, can_go_next=self.can_go_next, read_text=self.can_go_next) |
|
30 |
+ self.read_text = ReadText(maxy, maxx, self.window.content_window(), self.inputy, |
|
31 |
+ install_config, |
|
32 |
+ field, confirmation_err_msg, echo_char, accepted_chars, |
|
33 |
+ validation_fn, |
|
34 |
+ conversion_fn, default_string, tab_enabled=self.tab_enabled) |
|
29 | 35 |
self.window.set_action_panel(self.read_text) |
30 | 36 |
self.window.addstr(0, 0, self.display_string) |
31 | 37 |
|