def mount_target(self): """mount selected partitions on /target .""" # stderr.write ('PuntosDeMontaje: ' + str (self.mountpoints) + '\n') if not os.path.isdir(self.target) and not os.path.isfile(self.target): os.mkdir(self.target) misc.ex('mount', self.mountpoints.keys()[self.mountpoints.values().index('/')], self.target) for device, path in self.mountpoints.items(): if ( path == '/' ): continue elif ( path == 'swap' ): os.system('swapon %s' % device) continue path = os.path.join(self.target, path[1:]) if not os.path.isdir(path) and not os.path.isfile(path): os.mkdir(path) else: misc.pre_log('error', 'Problemas al crear %s' % path) if not misc.ex ('mount', '-t', 'ext3', device, path): misc.ex('mkfs.ext3',device) misc.ex('mount', device, path) # if ( 'swap' not in self.mountpoints.values() ): # # If swap partition isn't defined, we create a swapfile # os.system("dd if=/dev/zero of=%s/swapfile bs=1024 count=%d" % (self.target, MINIMAL_PARTITION_SCHEME ['swap'] * 1024) ) # os.system("mkswap %s/swapfile" % self.target) # os.system("swapon %s/swapfile" % self.target) return True
def copy_logs(self): try: misc.ex('cp', '-a', '/var/log/installer', os.path.join(self.target, '/var/log/installer')) except IOError, error: misc.pre_log('error', error) return False
def mount_target(self): """mount selected partitions on /target .""" # stderr.write ('PuntosDeMontaje: ' + str (self.mountpoints) + '\n') if not os.path.isdir(self.target) and not os.path.isfile(self.target): os.mkdir(self.target) misc.ex('mount', self.mountpoints.keys()[self.mountpoints.values().index('/')], self.target) for device, path in self.mountpoints.items(): if ( path == '/' ): continue elif ( path == 'swap' ): os.system('swapon %s' % device) continue path = os.path.join(self.target, path[1:]) if not os.path.isdir(path) and not os.path.isfile(path): os.mkdir(path) else: misc.pre_log('error', 'Problemas al crear %s' % path) if not misc.ex ('mount', '-t', 'ext3', device, path): misc.ex('mkfs.ext3',device) misc.ex('mount', device, path) if ( 'swap' not in self.mountpoints.values() ): # If swap partition isn't defined, we create a swapfile os.system("dd if=/dev/zero of=%s/swapfile bs=1024 count=%d" % (self.target, MINIMAL_PARTITION_SCHEME ['swap'] * 1024) ) os.system("mkswap %s/swapfile" % self.target) os.system("swapon %s/swapfile" % self.target) return True
def unmount_source(self): if not misc.pre_log('info', 'umount ' + self.source): return False sleep(1) if not misc.pre_log('info', 'losetup -d ' + self.dev): return False sleep(1) return True
def copy_logs(self): try: misc.pre_log('info','cp -a /var/log/installer ' + os.path.join(self.target,'/var/log/installer')) sleep(1) except IOError, error: misc.pre_log('error', error) return False
def unmount_source(self): if not misc.pre_log('info','umount ' + self.source): return False sleep(1) if not misc.pre_log('info','losetup -d ' + self.dev): return False sleep(1) return True
def copy_logs(self): try: misc.pre_log( 'info', 'cp -a /var/log/installer ' + os.path.join(self.target, '/var/log/installer')) sleep(1) except IOError, error: misc.pre_log('error', error) return False
def copy_logs(self): """copy logs files into installed system.""" distro = open ('/etc/lsb-release').readline ().strip ().split ('=') [1].lower () log_file = '/var/log/' + distro + '-express' if not misc.ex('cp', '-a', log_file, os.path.join(self.target, log_file[1:])): misc.pre_log('error', 'No se pudieron copiar los registros de instalación') return True
def copy_all(self): files = [] total_size = 0 misc.pre_log('info','Recolecting files to copy') for dirpath, dirnames, filenames in os.walk(self.source): sourcepath = dirpath[len(self.source)+1:] if sourcepath.startswith('etc'): print 7 elif sourcepath.startswith('home'): print 8 elif sourcepath.startswith('media'): print 10 elif sourcepath.startswith('usr/doc'): print 11 elif sourcepath.startswith('usr/local'): print 13 elif sourcepath.startswith('usr/src'): print 15 elif sourcepath.startswith('var/backups'): print 16 elif sourcepath.startswith('var/tmp'): print 17 for name in dirnames + filenames: relpath = os.path.join(sourcepath, name) fqpath = os.path.join(self.source, dirpath, name) if os.path.isfile(fqpath): size = os.path.getsize(fqpath) total_size += size files.append((relpath, size)) else: files.append((relpath, None)) misc.pre_log('info','About to start copying') copy = subprocess.Popen(['cpio', '-d0mp', self.target], cwd=self.source, stdin=subprocess.PIPE) copied_bytes = 0 for path, size in files: copy.stdin.write(path + '\0') if size is not None: copied_bytes += size per = (copied_bytes * 100) / total_size # Adjusting the percentage per = (per*73/100)+17 print per copy.stdin.close() copy.wait() return True
def mount_source(self): """mounting loop system from cloop or squashfs system.""" from os import path self.dev = '' if not os.path.isdir(self.source): try: os.mkdir(self.source) except Exception, e: print e misc.pre_log('info', 'mkdir %s' % self.source)
def copy_all(self): files = [] total_size = 0 misc.pre_log("info", "Recolecting files to copy") for dirpath, dirnames, filenames in os.walk(self.source): sourcepath = dirpath[len(self.source) + 1 :] if sourcepath.startswith("etc"): print 7 elif sourcepath.startswith("home"): print 8 elif sourcepath.startswith("media"): print 10 elif sourcepath.startswith("usr/doc"): print 11 elif sourcepath.startswith("usr/local"): print 13 elif sourcepath.startswith("usr/src"): print 15 elif sourcepath.startswith("var/backups"): print 16 elif sourcepath.startswith("var/tmp"): print 17 for name in dirnames + filenames: relpath = os.path.join(sourcepath, name) fqpath = os.path.join(self.source, dirpath, name) if os.path.isfile(fqpath): size = os.path.getsize(fqpath) total_size += size files.append((relpath, size)) else: files.append((relpath, None)) misc.pre_log("info", "About to start copying") copy = subprocess.Popen(["cpio", "-d0mp", self.target], cwd=self.source, stdin=subprocess.PIPE) copied_bytes = 0 for path, size in files: copy.stdin.write(path + "\0") if size is not None: copied_bytes += size per = (copied_bytes * 100) / total_size # Adjusting the percentage per = (per * 73 / 100) + 17 print per copy.stdin.close() copy.wait() return True
def mount_target(self): misc.pre_log('info','mount %s %s' % (self.mountpoints['/'], self.target)) sleep(1) for path, device in self.mountpoints.items(): if path in ('/', 'swap'): continue path = os.path.join(self.target, path[1:]) sleep(1) if not misc.pre_log('info','mount', device, path): return False sleep(1) return True
def mount_target(self): misc.pre_log('info', 'mount %s %s' % (self.mountpoints['/'], self.target)) sleep(1) for path, device in self.mountpoints.items(): if path in ('/', 'swap'): continue path = os.path.join(self.target, path[1:]) sleep(1) if not misc.pre_log('info', 'mount', device, path): return False sleep(1) return True
def copy_all(self): files = [] total_size = 0 misc.pre_log('info','Recolecting files to copy') for dirpath, dirnames, filenames in os.walk(self.source): sourcepath = dirpath[len(self.source)+1:] if sourcepath.startswith('etc'): print 7 elif sourcepath.startswith('home'): print 8 elif sourcepath.startswith('media'): print 10 elif sourcepath.startswith('usr/doc'): print 11 elif sourcepath.startswith('usr/local'): print 13 elif sourcepath.startswith('usr/src'): print 15 elif sourcepath.startswith('var/backups'): print 16 elif sourcepath.startswith('var/tmp'): print 17 for name in dirnames + filenames: relpath = os.path.join(sourcepath, name) fqpath = os.path.join(self.source, dirpath, name) if os.path.isfile(fqpath): size = os.path.getsize(fqpath) total_size += size files.append((relpath, size)) else: files.append((relpath, None)) misc.pre_log('info','About to start copying') copied_bytes = 0 for path, size in files: sleep(1) if size is not None: copied_bytes += size per = (copied_bytes * 100) / total_size # Adjusting the percentage per = (per*73/100)+17 print per return True
def format_target(mountpoints): '''format_target(mountpoints) -> bool From mountpoints extract the devices to partition and do it. The method return true or false depends the result of this operation. ''' for path, device in mountpoints.items(): if path in ['/']: print "0 Preparing the disc" misc.pre_log('info','mkfs.ext3' + device) sleep(2) print "2 Preparing the disc" elif path == 'swap': misc.pre_log('info', 'mkswap' + device) sleep(2) print "3 Preparing the disc" return True
def format_target(mountpoints): '''format_target(mountpoints) -> bool From mountpoints extract the devices to partition and do it. The method return true or false depends the result of this operation. ''' for path, device in mountpoints.items(): if path in ['/']: print "0 Preparing the disc" misc.pre_log('info', 'mkfs.ext3' + device) sleep(2) print "2 Preparing the disc" elif path == 'swap': misc.pre_log('info', 'mkswap' + device) sleep(2) print "3 Preparing the disc" return True
def mount_source(self): from os import path self.dev = '' files = ['/cdrom/casper/filesystem.cloop', '/cdrom/META/META.squashfs'] for f in files: if path.isfile(f) and path.splitext(f)[1] == '.cloop': file = f self.dev = '/dev/cloop1' elif path.isfile(f) and path.splitext(f)[1] == '.squashfs': file = f self.dev = '/dev/loop3' if self.dev == '': return False misc.ex('losetup', self.dev, file) if not os.path.isdir(self.source): os.mkdir(self.source) misc.pre_log('info', 'mkdir %s' % self.source) misc.ex('mount', self.dev, self.source) return True
def mount_source(self): from os import path self.dev = "" files = ["/cdrom/casper/filesystem.cloop", "/cdrom/META/META.squashfs"] for f in files: if path.isfile(f) and path.splitext(f)[1] == ".cloop": file = f self.dev = "/dev/cloop1" elif path.isfile(f) and path.splitext(f)[1] == ".squashfs": file = f self.dev = "/dev/loop3" if self.dev == "": return False misc.ex("losetup", self.dev, file) if not os.path.isdir(self.source): os.mkdir(self.source) misc.pre_log("info", "mkdir %s" % self.source) misc.ex("mount", self.dev, self.source) return True
def mount_source(self): from os import path self.dev = '' files = ['/cdrom/casper/filesystem.cloop','/cdrom/META/META.squashfs'] for f in files: if path.isfile(f) and path.splitext(f)[1] == '.cloop': file = f self.dev = '/dev/cloop1' elif path.isfile(f) and path.splitext(f)[1] == '.squashfs': file = f self.dev = '/dev/loop3' if self.dev == '': return False misc.pre_log('info','losetup %s %s' % (self.dev, file)) sleep(1) if not os.path.isdir(self.source): misc.pre_log('info','mkdir %s' % self.source) misc.pre_log('info','mount %s %s' % (self.dev, self.source)) sleep(1) return True
def run(self, queue): """Run the copy stage. This is the second step from the installation process.""" queue.put( '3 Preparando el directorio de instalación') misc.pre_log('info', 'Mounting target') if self.mount_target(): queue.put( '3 Directorio de instalación listo') misc.pre_log('info', 'Mounted target') else: misc.pre_log('error', 'Mounting target') return False queue.put( '4 Obteniendo la distribución a copiar') misc.pre_log('info', 'Mounting source') if self.mount_source(): queue.put( '5 Distribución obtenida') misc.pre_log('info', 'Mounted source') else: misc.pre_log('error', 'Mounting source') return False queue.put( '6 Preparando la copia a disco') misc.pre_log('info', 'Copying distro') if self.copy_all(queue): queue.put( '90 Ficheros copiados') misc.pre_log('info', 'Copied distro') else: misc.pre_log('error', 'Copying distro') return False queue.put( '91 Copiando registros de instalación al disco') misc.pre_log('info', 'Copying logs files') if self.copy_logs(): queue.put( '92 Registros de instalación listos') misc.post_log('info', 'Copied logs files') else: misc.pre_log('error', 'Copying logs files') return False queue.put( '93 Desmontando la imagen original de la copia') misc.post_log('info', 'Umounting source') if self.umount_source(): queue.put( '94 Imagen de la copia desmontada') misc.post_log('info', 'Umounted source') else: misc.post_log('error', 'Umounting source') return False
def copy_logs(self): try: misc.ex("cp", "-a", "/var/log/installer", os.path.join(self.target, "/var/log/installer")) except IOError, error: misc.pre_log("error", error) return False
def copy_all(self, queue): """Core copy process. This is the most important step of this stage. It clones live filesystem into a local partition in the selected hard disk.""" files = [] total_size = 0 oldsourcepath = '' misc.pre_log('info','Recolecting files to copy') for dirpath, dirnames, filenames in os.walk(self.source): sourcepath = dirpath[len(self.source)+1:] if ( oldsourcepath.split('/')[0] != sourcepath.split('/')[0] ): if sourcepath.startswith('etc'): queue.put( '7 Recorriendo /etc' ) elif sourcepath.startswith('home'): queue.put( '8 Recorriendo /home' ) elif sourcepath.startswith('media'): queue.put( '10 Recorriendo /media' ) elif sourcepath.startswith('usr/doc'): queue.put( '11 Recorriendo /usr/doc' ) elif sourcepath.startswith('usr/local'): queue.put( '13 Recorriendo /usr/local' ) elif sourcepath.startswith('usr/src'): queue.put( '15 Recorriendo /usr/src' ) elif sourcepath.startswith('var/backups'): queue.put( '16 Recorriendo /var/backups' ) elif sourcepath.startswith('var/tmp'): queue.put( '17 Recorriendo /var/tmp' ) oldsourcepath = sourcepath for name in dirnames + filenames: relpath = os.path.join(sourcepath, name) fqpath = os.path.join(self.source, dirpath, name) if os.path.isfile(fqpath): size = os.path.getsize(fqpath) total_size += size files.append((relpath, size)) else: files.append((relpath, None)) misc.pre_log('info','About to start copying') copy = subprocess.Popen(['cpio', '-d0mp', self.target], cwd = self.source, stdin = subprocess.PIPE) copied_bytes, counter = 0, 0 for path, size in files: copy.stdin.write(path + '\0') misc.pre_log('info', path) if ( size != None ): copied_bytes += size per = (copied_bytes * 100) / total_size # Adjusting the percentage per = (per*73/100)+17 if ( counter != per and per < 34 ): # We start the counter until 33 time_start = time.time() counter = per queue.put("%s Copiando %s%% - [%s]" % (per, per, path)) elif ( counter != per and per >= 40 ): counter = per time_left = (time.time()-time_start)*57/(counter - 33) - (time.time()-time_start) minutes, seconds = time_left/60, time_left - int(time_left/60)*60 queue.put("%s Copiando %s%% - Queda %02d:%02d - [%s]" % (per, per, minutes, seconds, path)) elif ( counter != per ): counter = per queue.put("%s Copiando %s%% - [%s]" % (per, per, path)) copy.stdin.close() copy.wait() return True
def run(self): print '0 Preparing the target in the disc' if self.mount_target(): print '5 Prepared the target in the disc' misc.pre_log('info', 'Mounting target') else: misc.pre_log('error', 'Mounting target') return False print '7 Getting the distro to copy' if self.mount_source(): print '10 Got the distro to copy' misc.pre_log('info', 'Mounting source') else: misc.pre_log('error', 'Mounting source') return False print '12 Copying the distro files to the disc' if self.copy_all(): print '85 Copied the distro files to the disc' misc.pre_log('info', 'Copying distro') else: misc.pre_log('error', 'Copying distro') return False print '86 Copying the logs files to the disc' if self.copy_logs(): print '90 Copied the logs files to the disc' misc.post_log('info', 'Copying logs files') else: misc.pre_log('error', 'Copying logs files') return False print '91 Releasing the copied distro image' if self.mount_source(): print '92 Released the copied distro image' misc.post_log('info', 'Umounting source') else: misc.post_log('error', 'Umounting source') return False
def run(self): print "3 Preparing the target in the disc" misc.pre_log("info", "Mounting target") if self.mount_target(): print "3 Prepared the target in the disc" misc.pre_log("info", "Mounted target") else: misc.pre_log("error", "Mounting target") return False print "4 Getting the distro to copy" misc.pre_log("info", "Mounting source") if self.mount_source(): print "5 Got the distro to copy" misc.pre_log("info", "Mounted source") else: misc.pre_log("error", "Mounting source") return False print "6 Copying the distro files to the disc" misc.pre_log("info", "Copying distro") if self.copy_all(): print "90 Copied the distro files to the disc" misc.pre_log("info", "Copied distro") else: misc.pre_log("error", "Copying distro") return False print "91 Copying the logs files to the disc" misc.pre_log("info", "Copying logs files") if self.copy_logs(): print "92 Copied the logs files to the disc" misc.post_log("info", "Copied logs files") else: misc.pre_log("error", "Copying logs files") return False print "93 Releasing the copied distro image" misc.post_log("info", "Umounting source") if self.unmount_source(): print "94 Released the copied distro image" misc.post_log("info", "Umounted source") else: misc.post_log("error", "Umounting source") return False
def copy_all(self, queue): """Core copy process. This is the most important step of this stage. It clones live filesystem into a local partition in the selected hard disk.""" files = [] total_size = 0 oldsourcepath = '' misc.pre_log('info', 'Recolecting files to copy') for dirpath, dirnames, filenames in os.walk(self.source): sourcepath = dirpath[len(self.source) + 1:] if (oldsourcepath.split('/')[0] != sourcepath.split('/')[0]): if sourcepath.startswith('etc'): queue.put('7 Recorriendo /etc') elif sourcepath.startswith('home'): queue.put('8 Recorriendo /home') elif sourcepath.startswith('media'): queue.put('10 Recorriendo /media') elif sourcepath.startswith('usr/doc'): queue.put('11 Recorriendo /usr/doc') elif sourcepath.startswith('usr/local'): queue.put('13 Recorriendo /usr/local') elif sourcepath.startswith('usr/src'): queue.put('15 Recorriendo /usr/src') elif sourcepath.startswith('var/backups'): queue.put('16 Recorriendo /var/backups') elif sourcepath.startswith('var/tmp'): queue.put('17 Recorriendo /var/tmp') oldsourcepath = sourcepath for name in dirnames + filenames: relpath = os.path.join(sourcepath, name) fqpath = os.path.join(self.source, dirpath, name) if os.path.isfile(fqpath): size = os.path.getsize(fqpath) total_size += size files.append((relpath, size)) else: files.append((relpath, None)) misc.pre_log('info', 'About to start copying') copy = subprocess.Popen(['cpio', '-d0mp', self.target], cwd=self.source, stdin=subprocess.PIPE) copied_bytes, counter = 0, 0 for path, size in files: copy.stdin.write(path + '\0') misc.pre_log('info', path) if (size != None): copied_bytes += size per = (copied_bytes * 100) / total_size # Adjusting the percentage per = (per * 73 / 100) + 17 if (counter != per and per < 34): # We start the counter until 33 time_start = time.time() counter = per queue.put("%s Copiando %s%% - [%s]" % (per, per, path)) elif (counter != per and per >= 40): counter = per time_left = (time.time() - time_start) * 57 / ( counter - 33) - (time.time() - time_start) minutes, seconds = time_left / 60, time_left - int( time_left / 60) * 60 queue.put("%s Copiando %s%% - Queda %02d:%02d - [%s]" % (per, per, minutes, seconds, path)) elif (counter != per): counter = per queue.put("%s Copiando %s%% - [%s]" % (per, per, path)) copy.stdin.close() copy.wait() return True
def get_empty_space(drive): # As sector size is supossed to be 512 the ratio MB/Sec is 1/2048 conv_value = 2048 import os os.putenv('LANG', 'C') out = Popen(['/sbin/cfdisk', '-P', 's', drive], stdin=PIPE, stdout=PIPE, close_fds=True) cont = out.stdout.readlines() cont = cont[5:] if extend(drive): extended = None frees = [] list = [] logics = 0 for i in cont: j = i[3:] j = j.replace('*', ' ') line = j.split() if line[5] == 'Extended': extended = cont.index(i) elif line[5] == 'Free': frees.append(cont.index(i)) elif line[0] == 'Logical': logics += 1 begin, end, length = int(line[1]), int(line[2]), int(line[4]) list.append([begin, end, length]) # If there is more than 12 logic partitions(4 primaries plus 8 logicals) exit if logics > 8: print "Too much logical partitions" misc.pre_log('error', "Too much logical partitions") return (None, None) sizes = [] indexs = [] for i in list: if list[extended] != i and i[-1] < list[extended][1] and i[ 1] > list[extended][0] and list.index(i) in frees: sizes.append(i[2]) indexs.append(list.index(i)) if not sizes: print "No freespace has enough room" misc.pre_log('error', "No freespace has enough room") return (None, None) bigger = max(sizes) index = sizes.index(bigger) i = indexs[index] tam = sizes[index] / conv_value scheme = calc_sizes(tam) begin = list[i][0] / conv_value end = list[i][1] / conv_value if not scheme: print "Not enough space" misc.pre_log('error', "Not enough space") return (None, None) limits = limits_for_scheme(begin, end, scheme) logic_dev = logics + 4 partitions = { "%s%d" % (drive, logic_dev + 1): '/', "%s%d" % (drive, logic_dev + 2): '/home', "%s%d" % (drive, logic_dev + 3): 'swap' } else: nonfrees = 0 list = [] for i in cont: i = i.replace('*', ' ') line = i.split() # If there is not any number in the first value, it's not a # partition, but it's a free space if not line[0].isdigit(): begin, end, length = int(line[1]), int(line[2]), int(line[4]) list.append([begin, end, length]) else: nonfrees += 1 if nonfrees > 3: print "Too many primary partitions" misc.pre_log('error', "Too many primary partitions") return (None, None) sizes = [] for i in list: sizes.append(i[2]) if not sizes: print "No freespace has enough room" misc.pre_log('error', "No freespace has enough room") return (None, None) bigger = max(sizes) index = sizes.index(bigger) tam = sizes[index] / conv_value scheme = calc_sizes(tam) begin = (list[index][0] / conv_value) + 2 end = (list[index][1] / conv_value) - 2 if not scheme: print "Not enough space" misc.pre_log('error', "Not enough space") return (None, None) limits = limits_for_scheme(begin, end, scheme) limits['extended'] = [begin, end] partitions = { "%s%d" % (drive, 5): '/', "%s%d" % (drive, 6): '/home', "%s%d" % (drive, 7): 'swap' } print >> sys.stderr, "Limits: ", limits, "\nMountpoints: ", partitions return (limits, partitions)
def run(self, queue): """Run the copy stage. This is the second step from the installation process.""" queue.put('3 Preparando el directorio de instalación') misc.pre_log('info', 'Mounting target') if self.mount_target(): queue.put('3 Directorio de instalación listo') misc.pre_log('info', 'Mounted target') else: misc.pre_log('error', 'Mounting target') return False queue.put('4 Obteniendo la distribución a copiar') misc.pre_log('info', 'Mounting source') if self.mount_source(): queue.put('5 Distribución obtenida') misc.pre_log('info', 'Mounted source') else: misc.pre_log('error', 'Mounting source') return False queue.put('6 Preparando la copia a disco') misc.pre_log('info', 'Copying distro') if self.copy_all(queue): queue.put('90 Ficheros copiados') misc.pre_log('info', 'Copied distro') else: misc.pre_log('error', 'Copying distro') return False queue.put('91 Copiando registros de instalación al disco') misc.pre_log('info', 'Copying logs files') if self.copy_logs(): queue.put('92 Registros de instalación listos') misc.post_log('info', 'Copied logs files') else: misc.pre_log('error', 'Copying logs files') return False queue.put('93 Desmontando la imagen original de la copia') misc.post_log('info', 'Umounting source') if self.umount_source(): queue.put('94 Imagen de la copia desmontada') misc.post_log('info', 'Umounted source') else: misc.post_log('error', 'Umounting source') return False
def get_empty_space(drive): # As sector size is supossed to be 512 the ratio MB/Sec is 1/2048 conv_value = 2048 import os os.putenv('LANG','C') out = Popen(['/sbin/cfdisk', '-P', 's', drive], stdin=PIPE, stdout=PIPE, close_fds=True) cont = out.stdout.readlines() cont = cont[5:] if extend(drive): extended = None frees = [] list = [] logics = 0 for i in cont: j = i[3:] j = j.replace('*',' ') line = j.split() if line[5] == 'Extended': extended = cont.index(i) elif line[5] == 'Free': frees.append(cont.index(i)) elif line[0] == 'Logical': logics += 1 begin, end, length = int(line[1]), int(line[2]), int(line[4]) list.append([begin, end, length]) # If there is more than 12 logic partitions(4 primaries plus 8 logicals) exit if logics > 8: print "Too much logical partitions" misc.pre_log('error', "Too much logical partitions") return (None,None) sizes = [] indexs = [] for i in list: if list[extended] != i and i[-1] < list[extended][1] and i[1] > list[extended][0] and list.index(i) in frees: sizes.append(i[2]) indexs.append(list.index(i)) if not sizes: print "No freespace has enough room" misc.pre_log('error', "No freespace has enough room") return (None,None) bigger = max(sizes) index = sizes.index(bigger) i = indexs[index] tam = sizes[index]/conv_value scheme = calc_sizes(tam) begin = list[i][0]/conv_value end = list[i][1]/conv_value if not scheme: print "Not enough space" misc.pre_log('error', "Not enough space") return (None,None) limits = limits_for_scheme(begin, end, scheme) logic_dev = logics + 4 partitions = { "%s%d" % (drive,logic_dev+1) : '/' , "%s%d" % (drive,logic_dev+2) : '/home', "%s%d" % (drive,logic_dev+3) : 'swap' } else: nonfrees = 0 list = [] for i in cont: i = i.replace('*',' ') line = i.split() # If there is not any number in the first value, it's not a # partition, but it's a free space if not line[0].isdigit(): begin, end, length = int(line[1]), int(line[2]), int(line[4]) list.append([begin, end, length]) else: nonfrees += 1 if nonfrees > 3: print "Too many primary partitions" misc.pre_log('error', "Too many primary partitions") return (None,None) sizes = [] for i in list: sizes.append(i[2]) if not sizes: print "No freespace has enough room" misc.pre_log('error', "No freespace has enough room") return (None,None) bigger = max(sizes) index = sizes.index(bigger) tam = sizes[index]/conv_value scheme = calc_sizes(tam) begin = (list[index][0]/conv_value)+2 end = (list[index][1]/conv_value)-2 if not scheme: print "Not enough space" misc.pre_log('error', "Not enough space") return (None,None) limits = limits_for_scheme(begin, end, scheme) limits['extended'] = [begin, end] partitions = { "%s%d" % (drive,5) : '/' , "%s%d" % (drive,6) : '/home', "%s%d" % (drive,7) : 'swap' } print >>sys.stderr, "Limits: ", limits, "\nMountpoints: ", partitions return (limits,partitions)
def copy_logs(self): try: misc.ex('cp', '-a', '/var/log/installer', os.path.join(self.target,'/var/log/installer')) except IOError, error: misc.pre_log('error', error) return False
def run(self): print '3 Preparing the target in the disc' misc.pre_log('info', 'Mounting target') if self.mount_target(): print '3 Prepared the target in the disc' misc.pre_log('info', 'Mounted target') else: misc.pre_log('error', 'Mounting target') return False print '4 Getting the distro to copy' misc.pre_log('info', 'Mounting source') if self.mount_source(): print '5 Got the distro to copy' misc.pre_log('info', 'Mounted source') else: misc.pre_log('error', 'Mounting source') return False print '6 Copying the distro files to the disc' misc.pre_log('info', 'Copying distro') if self.copy_all(): print '90 Copied the distro files to the disc' misc.pre_log('info', 'Copied distro') else: misc.pre_log('error', 'Copying distro') return False print '91 Copying the logs files to the disc' misc.pre_log('info', 'Copying logs files') if self.copy_logs(): print '92 Copied the logs files to the disc' misc.post_log('info', 'Copied logs files') else: misc.pre_log('error', 'Copying logs files') return False print '93 Releasing the copied distro image' misc.post_log('info', 'Umounting source') if self.unmount_source(): print '94 Released the copied distro image' misc.post_log('info', 'Umounted source') else: misc.post_log('error', 'Umounting source') return False
def mount_target(self): """mount selected partitions on /target .""" # stderr.write ('PuntosDeMontaje: ' + str (self.mountpoints) + '\n') if not os.path.isdir(self.target) and not os.path.isfile(self.target): os.mkdir(self.target) misc.ex('mount', self.mountpoints.keys()[self.mountpoints.values().index('/')], self.target) for device, path in self.mountpoints.items(): if ( path == '/' ): continue elif ( path == 'swap' ): os.system('swapon %s' % device) continue elif ( path == '/home' ): path = os.path.join(self.target, path[1:]) if not os.path.isdir(path) and not os.path.isfile(path): os.makedirs(path) else: misc.pre_log('error', 'Problemas al crear %s' % path) # If we cannot mount home partition, we format it if not misc.ex ('mount', '-t', 'ext3', device, path): misc.pre_log('info','%s is not able to be mounted in /home as ext3 filesystem' % device) misc.pre_log('info','%s is going to be formated as ext3 filesystem' % device) misc.ex('mkfs.ext3', device) misc.ex('e2fsck -fy', device) misc.ex('mount', device, path) else: path = os.path.join(self.target, path[1:]) if not os.path.isdir(path) and not os.path.isfile(path): os.makedirs(path) else: misc.pre_log('error', 'Problemas al crear %s' % path) # If we cannot mount the rest of user defined partition, we leave them # as they are (without formatting), just for security if not misc.ex ('mount', '-t', 'auto', device, path): misc.pre_log('info','%s cannot be mounted ' % device) misc.pre_log('info','%s will not be formatted ' % device) return True