当前位置: 首页>>代码示例>>Python>>正文


Python os.devnull方法代码示例

本文整理汇总了Python中os.devnull方法的典型用法代码示例。如果您正苦于以下问题:Python os.devnull方法的具体用法?Python os.devnull怎么用?Python os.devnull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在os的用法示例。


在下文中一共展示了os.devnull方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: gpt_device

# 需要导入模块: import os [as 别名]
# 或者: from os import devnull [as 别名]
def gpt_device(self, dev_name):
        disk_dev = self.physical_disk(dev_name)
        cmd = ['parted', disk_dev, '-s', 'print']
        with open(os.devnull) as devnull:
            p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE, stdin=devnull)
            _cmd_out, _err_out = p.communicate()
            p.wait()
        if p.returncode != 0:
            lang = os.getenv('LANG')
            encoding = lang.rsplit('.')[-1] if lang else 'utf-8'
            raise RuntimeError(str(_err_out, encoding))
        subprocess.check_call(['partprobe', disk_dev])
        if b'msdos' in _cmd_out:
            return False
        if b'gpt' in _cmd_out:
            return True
        raise RuntimeError("Disk '%s' is uninitialized and not usable." %
                           disk_dev) 
开发者ID:mbusb,项目名称:multibootusb,代码行数:21,代码来源:osdriver.py

示例2: convert_image

# 需要导入模块: import os [as 别名]
# 或者: from os import devnull [as 别名]
def convert_image(inpath, outpath, size):
    """Convert an image file using ``sips``.

    Args:
        inpath (str): Path of source file.
        outpath (str): Path to destination file.
        size (int): Width and height of destination image in pixels.

    Raises:
        RuntimeError: Raised if ``sips`` exits with non-zero status.
    """
    cmd = [
        b'sips',
        b'-z', str(size), str(size),
        inpath,
        b'--out', outpath]
    # log().debug(cmd)
    with open(os.devnull, 'w') as pipe:
        retcode = subprocess.call(cmd, stdout=pipe, stderr=subprocess.STDOUT)

    if retcode != 0:
        raise RuntimeError('sips exited with %d' % retcode) 
开发者ID:TKkk-iOSer,项目名称:wechat-alfred-workflow,代码行数:24,代码来源:notify.py

示例3: detect_missing_tools

# 需要导入模块: import os [as 别名]
# 或者: from os import devnull [as 别名]
def detect_missing_tools(distro):
    tools_dir = os.path.join('data', 'tools')
    if platform.system() == 'Windows':
        _7zip_exe = gen.resource_path(
            os.path.join(tools_dir, '7zip', '7z.exe'))
        e2fsck_exe = gen.resource_path(os.path.join(tools_dir, 'cygwin', 'e2fsck.exe'))
        resize2fs_exe = gen.resource_path(os.path.join(tools_dir, 'cygwin', 'resize2fs.exe'))
    else:
        _7zip_exe = '7z'
        e2fsck_exe = 'e2fsck'
        resize2fs_exe = 'resize2fs'
    if distro not in creator_dict or \
       creator_dict[distro][0] is not create_persistence_using_resize2fs:
        return None
    try:
        with open(os.devnull) as devnull:
            for tool in [e2fsck_exe, resize2fs_exe]:
                p = subprocess.Popen([tool], stdout=devnull, stderr=devnull)
                p.communicate()
    except FileNotFoundError:  # Windows
        return "'%s.exe' is not installed or not available for use." % tool
    except OSError:            # Linux
        return "'%s' is not installed or not available for use." % tool
    return None 
开发者ID:mbusb,项目名称:multibootusb,代码行数:26,代码来源:persistence.py

示例4: discard_stderr

# 需要导入模块: import os [as 别名]
# 或者: from os import devnull [as 别名]
def discard_stderr():
    """
    Discards error output of a routine if invoked as:

    with discard_stderr():
        ...
    """
    with open(os.devnull, 'w') as bit_bucket:
        try:
            stderr_fileno = sys.stderr.fileno()
            old_stderr = os.dup(stderr_fileno)
            try:
                os.dup2(bit_bucket.fileno(), stderr_fileno)
                yield
            finally:
                os.dup2(old_stderr, stderr_fileno)
        except AttributeError:
            # On some systems is stderr not a file descriptor but actually a virtual pipeline
            # that can not be copied
            yield 
开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:22,代码来源:test_utils.py

示例5: loadstate

# 需要导入模块: import os [as 别名]
# 或者: from os import devnull [as 别名]
def loadstate():
    global STATE, STATEFILE
    if os.getenv("HOME") is not None:
        STATEFILE = os.path.join(os.getenv("HOME"), ".epr")
        if os.path.isdir(os.path.join(os.getenv("HOME"), ".config")):
            configdir = os.path.join(os.getenv("HOME"), ".config", "epr")
            os.makedirs(configdir, exist_ok=True)
            if os.path.isfile(STATEFILE):
                if os.path.isfile(os.path.join(configdir, "config")):
                    os.remove(os.path.join(configdir, "config"))
                shutil.move(STATEFILE, os.path.join(configdir, "config"))
            STATEFILE = os.path.join(configdir, "config")
    elif os.getenv("USERPROFILE") is not None:
        STATEFILE = os.path.join(os.getenv("USERPROFILE"), ".epr")
    else:
        STATEFILE = os.devnull

    if os.path.exists(STATEFILE):
        with open(STATEFILE, "r") as f:
            STATE = json.load(f) 
开发者ID:wustho,项目名称:epr,代码行数:22,代码来源:epr.py

示例6: setUp

# 需要导入模块: import os [as 别名]
# 或者: from os import devnull [as 别名]
def setUp(self):

        self.dev_null = open(os.devnull, 'w')

        # self.spec = {"modules": {"PlanetPhysicalModel": "PlanetPhysicalModel"}}
        self.script = resource_path('test-scripts/template_minimal.json')
        with open(self.script) as f:
            self.spec = json.loads(f.read())

        modtype = getattr(EXOSIMS.Prototypes.Observatory.Observatory, '_modtype')
        pkg = EXOSIMS.Observatory
        self.allmods = [get_module(modtype)]
        for loader, module_name, is_pkg in pkgutil.walk_packages(pkg.__path__, pkg.__name__ + '.'):
            if not is_pkg:
                mod = get_module(module_name.split('.')[-1], modtype)
                self.assertTrue(mod._modtype is modtype, '_modtype mismatch for %s' % mod.__name__)
                self.allmods.append(mod) 
开发者ID:dsavransky,项目名称:EXOSIMS,代码行数:19,代码来源:test_Observatory.py

示例7: setUp

# 需要导入模块: import os [as 别名]
# 或者: from os import devnull [as 别名]
def setUp(self):

        self.dev_null = open(os.devnull, 'w')
        self.script = resource_path('test-scripts/template_minimal.json')
        with open(self.script) as f:
            self.spec = json.loads(f.read())
        
        with RedirectStreams(stdout=self.dev_null):
            self.TL = TargetList(ntargs=10,**copy.deepcopy(self.spec))
        self.TL.dist = np.random.uniform(low=0,high=100,size=self.TL.nStars)*u.pc
        
        modtype = getattr(Completeness,'_modtype')
        pkg = EXOSIMS.Completeness
        self.allmods = [get_module(modtype)]
        for loader, module_name, is_pkg in pkgutil.walk_packages(pkg.__path__, pkg.__name__+'.'):
            if (not 'starkAYO' in module_name) and not is_pkg:
                mod = get_module(module_name.split('.')[-1],modtype)
                self.assertTrue(mod._modtype is modtype,'_modtype mismatch for %s'%mod.__name__)
                self.allmods.append(mod) 
开发者ID:dsavransky,项目名称:EXOSIMS,代码行数:21,代码来源:test_Completeness.py

示例8: setUp

# 需要导入模块: import os [as 别名]
# 或者: from os import devnull [as 别名]
def setUp(self):

        self.dev_null = open(os.devnull, 'w')
        self.specs = {'modules':{'BackgroundSources':' '}}
        script = resource_path('test-scripts/template_minimal.json')
        with open(script) as f:
            spec = json.loads(f.read())
        with RedirectStreams(stdout=self.dev_null):
            self.TL = TargetList(**spec)

        modtype = getattr(EXOSIMS.Prototypes.PostProcessing.PostProcessing,'_modtype')
        pkg = EXOSIMS.PostProcessing
        self.allmods = [get_module(modtype)]
        for loader, module_name, is_pkg in pkgutil.walk_packages(pkg.__path__, pkg.__name__+'.'):
            if not is_pkg:
                mod = get_module(module_name.split('.')[-1],modtype)
                self.assertTrue(mod._modtype is modtype,'_modtype mismatch for %s'%mod.__name__)
                self.allmods.append(mod)


    #Testing some limiting cases below 
开发者ID:dsavransky,项目名称:EXOSIMS,代码行数:23,代码来源:test_PostProcessing.py

示例9: setUp

# 需要导入模块: import os [as 别名]
# 或者: from os import devnull [as 别名]
def setUp(self):
        self.dev_null = open(os.devnull, 'w')
        self.script = resource_path('test-scripts/template_prototype_testing.json')
        with open(self.script) as f:
            self.spec = json.loads(f.read())

        with RedirectStreams(stdout=self.dev_null):
            self.sim = MissionSim.MissionSim(self.script)
        self.TL = self.sim.TargetList
        self.nStars = self.TL.nStars
        self.star_index = np.array(range(0, self.nStars))
        self.Obs = self.sim.Observatory
        self.mode = self.sim.OpticalSystem.observingModes[0]
        self.TK = self.sim.TimeKeeping
        assert self.nStars > 10, "Need at least 10 stars in the target list for the unit test."
        self.unit = 1./u.arcsec**2

        modtype = getattr(EXOSIMS.Prototypes.ZodiacalLight.ZodiacalLight, '_modtype')
        pkg = EXOSIMS.ZodiacalLight
        self.allmods = [get_module(modtype)]
        for loader, module_name, is_pkg in pkgutil.walk_packages(pkg.__path__, pkg.__name__ + '.'):
            if not is_pkg:
                mod = get_module(module_name.split('.')[-1], modtype)
                self.assertTrue(mod._modtype is modtype, '_modtype mismatch for %s' % mod.__name__)
                self.allmods.append(mod) 
开发者ID:dsavransky,项目名称:EXOSIMS,代码行数:27,代码来源:test_ZodiacalLight.py

示例10: setUp

# 需要导入模块: import os [as 别名]
# 或者: from os import devnull [as 别名]
def setUp(self):

        self.dev_null = open(os.devnull, 'w')
        self.script = resource_path('test-scripts/template_minimal.json')
        with open(self.script) as f:
            self.spec = json.loads(f.read())
        
        with RedirectStreams(stdout=self.dev_null):
            self.TL = TargetList(ntargs=10,**copy.deepcopy(self.spec))
        self.TL.dist = np.random.uniform(low=0,high=100,size=self.TL.nStars)*u.pc
        
        modtype = getattr(SimulatedUniverse,'_modtype')
        pkg = EXOSIMS.SimulatedUniverse
        self.allmods = [get_module(modtype)]
        for loader, module_name, is_pkg in pkgutil.walk_packages(pkg.__path__, pkg.__name__+'.'):
            if not is_pkg:
                mod = get_module(module_name.split('.')[-1],modtype)
                self.assertTrue(mod._modtype is modtype,'_modtype mismatch for %s'%mod.__name__)
                self.allmods.append(mod) 
开发者ID:dsavransky,项目名称:EXOSIMS,代码行数:21,代码来源:test_SimulatedUniverse.py

示例11: setUp

# 需要导入模块: import os [as 别名]
# 或者: from os import devnull [as 别名]
def setUp(self):

        self.dev_null = open(os.devnull, 'w')
        self.script = resource_path('test-scripts/template_minimal.json')
        with open(self.script) as f:
            self.spec = json.loads(f.read())
        
        with RedirectStreams(stdout=self.dev_null):
            self.TL = TargetList(ntargs=10,**copy.deepcopy(self.spec))
        
        modtype = getattr(OpticalSystem,'_modtype')
        pkg = EXOSIMS.OpticalSystem
        self.allmods = [get_module(modtype)]
        for loader, module_name, is_pkg in pkgutil.walk_packages(pkg.__path__, pkg.__name__+'.'):
            if not is_pkg:
                mod = get_module(module_name.split('.')[-1],modtype)
                self.assertTrue(mod._modtype is modtype,'_modtype mismatch for %s'%mod.__name__)
                self.allmods.append(mod) 
开发者ID:dsavransky,项目名称:EXOSIMS,代码行数:20,代码来源:test_OpticalSystem.py

示例12: setUp

# 需要导入模块: import os [as 别名]
# 或者: from os import devnull [as 别名]
def setUp(self):
        self.dev_null = open(os.devnull, 'w')
        modtype = getattr(EXOSIMS.Prototypes.BackgroundSources.BackgroundSources,'_modtype')
        pkg = EXOSIMS.BackgroundSources
        self.allmods = [get_module(modtype)]
        for loader, module_name, is_pkg in pkgutil.walk_packages(pkg.__path__, pkg.__name__+'.'):
            if not is_pkg:
                mod = get_module(module_name.split('.')[-1],modtype)
                self.assertTrue(mod._modtype is modtype,'_modtype mismatch for %s'%mod.__name__)
                self.allmods.append(mod)
        # need a TargetList object for testing
        script = resource_path('test-scripts/template_prototype_testing.json')
        with open(script) as f:
            spec = json.loads(f.read())
        with RedirectStreams(stdout=self.dev_null):
            self.TL = TargetList(**spec) 
开发者ID:dsavransky,项目名称:EXOSIMS,代码行数:18,代码来源:test_BackgroundSources.py

示例13: delete_runtime

# 需要导入模块: import os [as 别名]
# 或者: from os import devnull [as 别名]
def delete_runtime(self, docker_image_name, memory):
        """
        Deletes a runtime
        """
        if docker_image_name == 'default':
            docker_image_name = self._get_default_runtime_image_name()

        logger.debug('Deleting {} runtime'.format(docker_image_name))
        name = self._format_runtime_name(docker_image_name)
        if self._is_localhost:
            if self.docker_client:
                self.docker_client.containers.stop(name, force=True)
            else:
                cmd = 'docker rm -f {}'.format(name)
                if not self.log_level:
                    cmd = cmd + " >{} 2>&1".format(os.devnull)
                os.system(cmd)
        else:
            cmd = 'docker rm -f {}'.format(name)
            self._ssh_run_remote_command(cmd) 
开发者ID:pywren,项目名称:pywren-ibm-cloud,代码行数:22,代码来源:docker.py

示例14: delete_all_runtimes

# 需要导入模块: import os [as 别名]
# 或者: from os import devnull [as 别名]
def delete_all_runtimes(self):
        """
        Delete all created runtimes
        """
        if self._is_localhost:
            if self.docker_client:
                running_containers = self.docker_client.containers.list(filters={'name': 'pywren'})
                for runtime in running_containers:
                    logger.debug('Deleting {} runtime'.format(runtime.name))
                    runtime.stop()
            else:
                list_runtimes_cmd = "docker ps -a -f name=pywren | awk '{print $NF}' | tail -n +2"
                running_containers = subprocess.check_output(list_runtimes_cmd, shell=True).decode().strip()
                for name in running_containers.splitlines():
                    cmd = 'docker rm -f {}'.format(name)
                    if not self.log_level:
                        cmd = cmd + " >{} 2>&1".format(os.devnull)
                    os.system(cmd)
        else:
            list_runtimes_cmd = "docker ps -a -f name=pywren | awk '{print $NF}' | tail -n +2"
            running_containers = self._ssh_run_remote_command(list_runtimes_cmd)
            for name in running_containers.splitlines():
                cmd = 'docker rm -f {}'.format(name)
                self._ssh_run_remote_command(cmd) 
开发者ID:pywren,项目名称:pywren-ibm-cloud,代码行数:26,代码来源:docker.py

示例15: _build_default_runtime

# 需要导入模块: import os [as 别名]
# 或者: from os import devnull [as 别名]
def _build_default_runtime(self, default_runtime_img_name):
        """
        Builds the default runtime
        """
        if os.system('docker --version >{} 2>&1'.format(os.devnull)) == 0:
            # Build default runtime using local dokcer
            python_version = version_str(sys.version_info).replace('.', '')
            location = 'https://raw.githubusercontent.com/pywren/pywren-ibm-cloud/master/runtime/knative'
            resp = requests.get('{}/Dockerfile.python{}'.format(location, python_version))
            dockerfile = "Dockefile.default-kantive-runtime"
            if resp.status_code == 200:
                with open(dockerfile, 'w') as f:
                    f.write(resp.text)
                self.build_runtime(default_runtime_img_name, dockerfile)
                os.remove(dockerfile)
            else:
                msg = 'There was an error fetching the default runitme Dockerfile: {}'.format(resp.text)
                logger.error(msg)
                exit()
        else:
            # Build default runtime using Tekton
            self._build_default_runtime_from_git(default_runtime_img_name) 
开发者ID:pywren,项目名称:pywren-ibm-cloud,代码行数:24,代码来源:knative.py


注:本文中的os.devnull方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。