Esempio n. 1
0
    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))
Esempio n. 2
0
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)
Esempio n. 3
0
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)
Esempio n. 4
0
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 `
Esempio n. 5
0
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))
Esempio n. 6
0
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))
Esempio n. 7
0
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))
Esempio n. 8
0
 def test_system(self):
     system('python "%s"' % self.fname)
Esempio n. 9
0
 def test_system(self):
     status = system('%s "%s"' % (python, self.fname))
     self.assertEqual(status, 0)
Esempio n. 10
0
 def test_system_quotes(self):
     status = system('%s -c "import sys"' % python)
     self.assertEqual(status, 0)
Esempio n. 11
0
def info():
	print('\nSystem volume info:')
	system('lshw -class volume,disk -short')
	print('\nMount points:')
	system('mount | grep /dev/[sm]')
	print('\n')
Esempio n. 12
0
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))
Esempio n. 13
0
def reboot():
  system('reboot')
Esempio n. 14
0
def initDrive():
    print 'Clearing the partition table on device {}...'.format(device)
    system("sgdisk -Z -o -g {}".format(device))
Esempio n. 15
0
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))
Esempio n. 16
0
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')
Esempio n. 17
0
def isEfiMounted():
    system('mountpoint /mnt/efi')
Esempio n. 18
0
 def test_system(self):
     system('python "%s"' % self.fname)
Esempio n. 19
0
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))
Esempio n. 20
0
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))
Esempio n. 21
0
def printPartTable():
    system("sgdisk -p {}".format(device))
Esempio n. 22
0
 def test_system(self):
     status = system('python "%s"' % self.fname)
     self.assertEquals(status, 0)
Esempio n. 23
0
 def test_system(self):
     status = system('%s "%s"' % (python, self.fname))
     self.assertEqual(status, 0)
Esempio n. 24
0
 def test_system_quotes(self):
     status = system('python -c "import sys"')
     self.assertEquals(status, 0)
Esempio n. 25
0
 def command():
     return system('%s -c "import time; time.sleep(5)"' % python)
Esempio n. 26
0
def poweroff():
  system('poweroff')
Esempio n. 27
0
def umount():
    system('umount ' + device + efipart)
    system('umount ' + device + syspart)
Esempio n. 28
0
 def test_system_quotes(self):
     status = system('%s -c "import sys"' % python)
     self.assertEqual(status, 0)
Esempio n. 29
0
def pack():
    print 'Archiving system into {}...'.format(folderName)
    system('mksquashfs /mnt/efi {}/efi.sfs'.format(folderName))
    system('mksquashfs /mnt/sys {}/sys.sfs'.format(folderName))
Esempio n. 30
0
 def test_system(self):
     status = system('python "%s"' % self.fname)
     self.assertEquals(status, 0)
Esempio n. 31
0
 def test_system_quotes(self):
     status = system('python -c "import sys"')
     self.assertEquals(status, 0)
Esempio n. 32
0
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')
Esempio n. 33
0
 def test_system(self):
     status = system(f'{python} "{self.fname}"')
     self.assertEqual(status, 0)