def system_piped(self, cmd): """Call the given cmd in a subprocess, piping stdout/err Parameters ---------- cmd : str Command to execute (can not end in '&', as background processes are not supported. Should not be a command that expects input other than simple text. """ if cmd.rstrip().endswith('&'): # this is *far* from a rigorous test # We do not support backgrounding processes because we either use # pexpect or pipes to read from. Users can always just call # os.system() or use ip.system=ip.system_raw # if they really want a background process. raise OSError("Background processes not supported.") # we explicitly do NOT return the subprocess status code, because # a non-None value would trigger :func:`sys.displayhook` calls. # Instead, we store the exit_code in user_ns. # Also, protect system call from UNC paths on Windows here too # as is done in InteractiveShell.system_raw if sys.platform == 'win32': cmd = self.var_expand(cmd, depth=1) from IPython.utils._process_win32 import AvoidUNCPath with AvoidUNCPath() as path: if path is not None: cmd = 'pushd %s &&%s' % (path, cmd) self.user_ns['_exit_code'] = system(cmd) else: self.user_ns['_exit_code'] = system(self.var_expand(cmd, depth=1))
def target_update(target,deps,cmd): """Update a target with a given command given a list of dependencies. target_update(target,deps,cmd) -> runs cmd if target is outdated. This is just a wrapper around target_outdated() which calls the given command if target is outdated.""" if target_outdated(target,deps): system(cmd)
def page_file(fname, start=0, pager_cmd=None): """Page a file, using an optional pager command and starting line. """ pager_cmd = get_pager_cmd(pager_cmd) pager_cmd += " " + get_pager_start(pager_cmd, start) try: if os.environ["TERM"] in ["emacs", "dumb"]: raise EnvironmentError system(pager_cmd + " " + fname) except: try: if start > 0: start -= 1 page(open(fname).read(), start) except: print "Unable to show file", ` fname `
def page_file(fname, start=0, pager_cmd=None): """Page a file, using an optional pager command and starting line. """ pager_cmd = get_pager_cmd(pager_cmd) pager_cmd += " " + get_pager_start(pager_cmd, start) try: if os.environ["TERM"] in ["emacs", "dumb"]: raise EnvironmentError system(pager_cmd + " " + fname) except: try: if start > 0: start -= 1 page(open(fname).read(), start) except: print("Unable to show file", repr(fname))
def page_file(fname, start=0, pager_cmd=None): """Page a file, using an optional pager command and starting line. """ pager_cmd = get_pager_cmd(pager_cmd) pager_cmd += ' ' + get_pager_start(pager_cmd,start) try: if os.environ['TERM'] in ['emacs','dumb']: raise EnvironmentError system(pager_cmd + ' ' + fname) except: try: if start > 0: start -= 1 page(open(fname).read(),start) except: print('Unable to show file',repr(fname))
def page_file(fname, start=0, pager_cmd=None): """Page a file, using an optional pager command and starting line. """ pager_cmd = get_pager_cmd(pager_cmd) pager_cmd += ' ' + get_pager_start(pager_cmd, start) try: if os.environ['TERM'] in ['emacs', 'dumb']: raise EnvironmentError system(pager_cmd + ' ' + fname) except: try: if start > 0: start -= 1 page(open(fname).read(), start) except: print('Unable to show file', repr(fname))
def test_system(self): system('python "%s"' % self.fname)
def test_system(self): status = system('%s "%s"' % (python, self.fname)) self.assertEqual(status, 0)
def test_system_quotes(self): status = system('%s -c "import sys"' % python) self.assertEqual(status, 0)
def info(): print('\nSystem volume info:') system('lshw -class volume,disk -short') print('\nMount points:') system('mount | grep /dev/[sm]') print('\n')
def mount(readOnly): if readOnly: arg = '-r ' else: arg = '' system('mount {} /mnt/efi'.format(arg + device + efipart)) system('mount {} /mnt/sys'.format(arg + device + syspart))
def reboot(): system('reboot')
def initDrive(): print 'Clearing the partition table on device {}...'.format(device) system("sgdisk -Z -o -g {}".format(device))
def unpack(): print 'Unpacking system from folder {}...'.format(folderName) system('unsquashfs -f -d /mnt/efi {}/efi.sfs'.format(folderName)) system('unsquashfs -f -d /mnt/sys {}/sys.sfs'.format(folderName))
def checkEfi(): system('mount -r {} /mnt/efi'.format(folderName + '/efi.sfs')) if not os.path.exists('/mnt/efi/EFI'): raise RuntimeError('Invalid archive file "{}"'.format(folderName + '/efi.sfs')) system('umount /mnt/efi')
def isEfiMounted(): system('mountpoint /mnt/efi')
def setupSys(): print 'Setting up system partition as {}...'.format(device + syspart) system("sgdisk -n 2:: {}".format(device)) print ' Formatting...' system("mkfs.ext4 -F {}".format(device + syspart))
def setupEfi(): print 'Setting up UEFI boot partition as {}...'.format(device + efipart) system("sgdisk -n 1::+512M {}".format(device)) system("sgdisk -t 1:ef00 {}".format(device)) print ' Formatting...' system("mkfs.fat -F32 {}".format(device + efipart))
def printPartTable(): system("sgdisk -p {}".format(device))
def test_system(self): status = system('python "%s"' % self.fname) self.assertEquals(status, 0)
def test_system_quotes(self): status = system('python -c "import sys"') self.assertEquals(status, 0)
def command(): return system('%s -c "import time; time.sleep(5)"' % python)
def poweroff(): system('poweroff')
def umount(): system('umount ' + device + efipart) system('umount ' + device + syspart)
def pack(): print 'Archiving system into {}...'.format(folderName) system('mksquashfs /mnt/efi {}/efi.sfs'.format(folderName)) system('mksquashfs /mnt/sys {}/sys.sfs'.format(folderName))
def checkSys(): system('mount -r {} /mnt/sys'.format(folderName + '/sys.sfs')) if not os.path.exists('/mnt/sys/etc'): raise RuntimeError('Invalid archive file "{}"'.format(folderName + '/sys.sfs')) system('umount /mnt/sys')
def test_system(self): status = system(f'{python} "{self.fname}"') self.assertEqual(status, 0)