Python exceptions 模块,OSError() 实例源码

我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用exceptions.OSError()

项目:core-framework    作者:RedhawkSDR    | 项目源码 | 文件源码
def setFile(self, filename):
    self.filename = filename
    if self.filename.count('/') > 0:
        aggregate = os.path.join('/')
        if self.filename.startswith('/') == False :
            aggregate = os.path.join(os.getcwd()+'/')
        dirs = self.filename.split('/')
        for _dir in dirs[:-1]:
            if _dir == '':
                continue
            aggregate = os.path.join(aggregate,_dir)
            try: 
                os.mkdir(aggregate)
            except Exception, e:
                if type(e) == exceptions.OSError and e.errno == 13:
                    print e
                pass

    self.baseFilename = os.path.abspath(filename)
    self.log4pyProps['filename'] = filename
项目:picosdk-python-examples    作者:picotech    | 项目源码 | 文件源码
def psloadlib(name):
    """ Loads driver library
    :param name: driver name
    :type name: str
    :returns: ctypes reference to the library
    :rtype: object
    """
    result = None
    try:
        if sys.platform == 'win32':
            result = ctypes.WinDLL(find_library(name))
        else:
            result = cdll.LoadLibrary(find_library(name))
    except OSError as ex:
        print name, "import(%d): Library not found" % sys.exc_info()[-1].tb_lineno
    return result
项目:som    作者:vsoch    | 项目源码 | 文件源码
def run_command(cmd,error_message=None,sudopw=None,suppress=False):
    '''run_command uses subprocess to send a command to the terminal.
    :param cmd: the command to send, should be a list for subprocess
    :param error_message: the error message to give to user if fails, 
    if none specified, will alert that command failed.
    :param execute: if True, will add `` around command (default is False)
    :param sudopw: if specified (not None) command will be run asking for sudo
    '''
    if sudopw == None:
        sudopw = os.environ.get('pancakes',None)

    if sudopw != None:
        cmd = ' '.join(["echo", sudopw,"|","sudo","-S"] + cmd)
        if suppress == False:
            output = os.popen(cmd).read().strip('\n')
        else:
            output = cmd
            os.system(cmd)
    else:
        try:
            process = subprocess.Popen(cmd,stdout=subprocess.PIPE)
            output, err = process.communicate()
        except OSError as error: 
            if error.errno == os.errno.ENOENT:
                bot.error(error_message)
            else:
                bot.error(err)
            return None

    return output
项目:node-dcm    作者:pydicom    | 项目源码 | 文件源码
def run_command(cmd,error_message=None,sudopw=None,suppress=False):
    '''run_command uses subprocess to send a command to the terminal.
    :param cmd: the command to send, should be a list for subprocess
    :param error_message: the error message to give to user if fails, 
    if none specified, will alert that command failed.
    :param execute: if True, will add `` around command (default is False)
    :param sudopw: if specified (not None) command will be run asking for sudo
    '''
    if sudopw == None:
        sudopw = os.environ.get('pancakes',None)

    if sudopw is not None:
        cmd = ' '.join(["echo", sudopw,"|","sudo","-S"] + cmd)
        if suppress == False:
            output = os.popen(cmd).read().strip('\n')
        else:
            output = cmd
            os.system(cmd)
    else:
        try:
            process = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
            output, err = process.communicate()
        except OSError as error: 
            if error.errno == os.errno.ENOENT:
                bot.logger.error(error_message)
            else:
                bot.logger.error(error)
            return None

    return output


############################################################################
## FILE OPERATIONS #########################################################
############################################################################
项目:sardana    作者:sardana-org    | 项目源码 | 文件源码
def startPool_PopenStyle(self):
        """Starts the Device pool"""

        try:
            self.pool_process = subprocess.Popen([self.pool_exec,
                                                  self.pool_ds_instance],
                                                 stdout=subprocess.PIPE,
                                                 stderr=subprocess.STDOUT)
        except exceptions.OSError, e:
            if e.strerror == PoolTestCase.PoolExecNotFound:
                self.assert_(
                    False, "Could not find Pool executable. Make sure it is in the PATH")
            else:
                raise

        self.failIf(self.pool_process.stdout is None,
                    "Was not able to grab Pool output")

        self.pool_start_time = time.time()
        while True:
            delta_time = time.time() - self.pool_start_time

            self.failIf(delta_time >= PoolTestCase.PoolMaxStartupTime,
                        "Pool startup time exceeded")

            line = self.pool_process.stdout.readline()

            if line.count(PoolTestCase.PoolReadyMsg) > 0:
                break

            self.failIfEqual(line, PoolTestCase.PoolAlreadyRunning,
                             PoolTestCase.PoolAlreadyRunning)
项目:AnonID_OP    作者:UCL-InfoSec    | 项目源码 | 文件源码
def css(environ, start_response, logger):
    try:
        info = open(environ["PATH_INFO"]).read()
        resp = Response(info)
    except (OSError, IOError):
        resp = NotFound(environ["PATH_INFO"])

    return resp(environ, start_response)


# ----------------------------------------------------------------------------


#noinspection PyUnusedLocal
项目:AnonID_OP    作者:UCL-InfoSec    | 项目源码 | 文件源码
def static_file(path):
    try:
        os.stat(path)
        return True
    except OSError:
        return False


#noinspection PyUnresolvedReferences