Пример #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))
Пример #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)
Пример #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)
Пример #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 `
Пример #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))
Пример #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))
Пример #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))
Пример #8
0
 def test_system(self):
     system('python "%s"' % self.fname)
Пример #9
0
 def test_system(self):
     status = system('%s "%s"' % (python, self.fname))
     self.assertEqual(status, 0)
Пример #10
0
 def test_system_quotes(self):
     status = system('%s -c "import sys"' % python)
     self.assertEqual(status, 0)
Пример #11
0
def info():
	print('\nSystem volume info:')
	system('lshw -class volume,disk -short')
	print('\nMount points:')
	system('mount | grep /dev/[sm]')
	print('\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))
Пример #13
0
def reboot():
  system('reboot')
Пример #14
0
def initDrive():
    print 'Clearing the partition table on device {}...'.format(device)
    system("sgdisk -Z -o -g {}".format(device))
Пример #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))
Пример #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')
Пример #17
0
def isEfiMounted():
    system('mountpoint /mnt/efi')
Пример #18
0
 def test_system(self):
     system('python "%s"' % self.fname)
Пример #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))
Пример #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))
Пример #21
0
def printPartTable():
    system("sgdisk -p {}".format(device))
Пример #22
0
 def test_system(self):
     status = system('python "%s"' % self.fname)
     self.assertEquals(status, 0)
Пример #23
0
 def test_system(self):
     status = system('%s "%s"' % (python, self.fname))
     self.assertEqual(status, 0)
Пример #24
0
 def test_system_quotes(self):
     status = system('python -c "import sys"')
     self.assertEquals(status, 0)
Пример #25
0
 def command():
     return system('%s -c "import time; time.sleep(5)"' % python)
Пример #26
0
def poweroff():
  system('poweroff')
Пример #27
0
def umount():
    system('umount ' + device + efipart)
    system('umount ' + device + syspart)
Пример #28
0
 def test_system_quotes(self):
     status = system('%s -c "import sys"' % python)
     self.assertEqual(status, 0)
Пример #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))
Пример #30
0
 def test_system(self):
     status = system('python "%s"' % self.fname)
     self.assertEquals(status, 0)
Пример #31
0
 def test_system_quotes(self):
     status = system('python -c "import sys"')
     self.assertEquals(status, 0)
Пример #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')
Пример #33
0
 def test_system(self):
     status = system(f'{python} "{self.fname}"')
     self.assertEqual(status, 0)