• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python posixpath.exists函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中posixpath.exists函数的典型用法代码示例。如果您正苦于以下问题:Python exists函数的具体用法?Python exists怎么用?Python exists使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: copy_license_notice_files

def copy_license_notice_files(fields, base_dir, license_notice_text_location, afp):
    lic_name = u''
    for key, value in fields:
        if key == u'license_file' or key == u'notice_file':
            lic_name = value

            from_lic_path = posixpath.join(to_posix(license_notice_text_location), lic_name)
            about_file_dir = dirname(to_posix(afp)).lstrip('/')
            to_lic_path = posixpath.join(to_posix(base_dir), about_file_dir)

            if on_windows:
                from_lic_path = add_unc(from_lic_path)
                to_lic_path = add_unc(to_lic_path)

            # Strip the white spaces
            from_lic_path = from_lic_path.strip()
            to_lic_path = to_lic_path.strip()

            # Errors will be captured when doing the validation
            if not posixpath.exists(from_lic_path):
                continue

            if not posixpath.exists(to_lic_path):
                os.makedirs(to_lic_path)
            try:
                shutil.copy2(from_lic_path, to_lic_path)
            except Exception as e:
                print(repr(e))
                print('Cannot copy file at %(from_lic_path)r.' % locals())
开发者ID:dejacode,项目名称:about-code-tool,代码行数:29,代码来源:util.py


示例2: send_head

    def send_head(self):
        path = self.translate_path(self.path)
        f = None
        if path is None:
            self.send_error(404, "File not found")
            return None
        if path is '/':
            return self.list_directory(path)
        if os.path.isdir(path):

            # not endswidth /
            if not self.path.endswith('/'):
                # redirect browser - doing basically what apache does
                self.send_response(301)
                self.send_header("Location", self.path + "/")
                self.end_headers()
                return None

            # looking for index.html or index.htm
            for index in "index.html", "index.htm":
                index = os.path.join(path, index)
                if os.path.exists(index):
                    path = index
                    break
            else:
                return self.list_directory(path)

        # If there's no extension and the file doesn't exist,
        # see if the file plus the default extension exists.
        if (SublimeServerHandler.defaultExtension and
            not posixpath.splitext(path)[1] and
            not posixpath.exists(path) and
            posixpath.exists(path + SublimeServerHandler.defaultExtension)):
            path += SublimeServerHandler.defaultExtension

        ctype = self.guess_type(path)
        try:
            # Always read in binary mode. Opening files in text mode may cause
            # newline translations, making the actual size of the content
            # transmitted *less* than the content-length!
            f = open(path, 'rb')
        except IOError:
            self.send_error(404, "File not found")
            return None
        try:
            self.send_response(200)
            self.send_header("Content-type", ctype)
            fs = os.fstat(f.fileno())
            self.send_header("Content-Length", str(fs[6]))
            self.send_header("Access-Control-Allow-Origin", "*")
            self.send_header("Cache-Control", "no-cache, no-store, must-revalidate")
            self.send_header("Pragma", "no-cache")
            self.send_header("Expires", "0")
            self.send_header(
                "Last-Modified", self.date_time_string(fs.st_mtime))
            self.end_headers()
            return f
        except:
            f.close()
            raise
开发者ID:itplanes,项目名称:SublimeServer,代码行数:60,代码来源:SublimeServer.py


示例3: compile_templates

def compile_templates(root, output, minify, input_encoding='utf-8', watch=True):
    """Compile all templates in root or root's subfolders."""
    root = posixpath.normpath(root)
    root_len = len(root)
    output = posixpath.normpath(output)
    for dirpath, dirnames, filenames in os.walk(root):
        dirpath = posixpath.normpath(dirpath)
        if posixpath.basename(dirpath).startswith('.'): continue
        filenames = [f for f in filenames if not f.startswith('.') and not f.endswith('~') and not f.endswith('.py') and not f.endswith('.pyc')]
        outdir = posixpath.join(output , dirpath[root_len:])
        if not posixpath.exists(outdir):
            os.makedirs(outdir)
        if not posixpath.exists(posixpath.join(outdir, '__init__.py')):
            out = open(posixpath.join(outdir, '__init__.py'), 'w')
            out.close()
        for f in filenames:
            path = posixpath.join(dirpath, f).replace('\\','/')
            outfile = posixpath.join(outdir, f.replace('.','_')+'.py')
            filemtime = os.stat(path)[stat.ST_MTIME]
            if not exists(outfile) or os.stat(outfile)[stat.ST_MTIME] < filemtime:
                uri = path[root_len+1:]
                print 'compiling', uri
                text = file(path).read()
                if minify:
                    text = minify_js_in_html(uri, text)
                t = mako.template.Template(text=text, filename=path, uri=uri, input_encoding=input_encoding)
                out = open(outfile, 'w')
                out.write( t.code)
                out.close()
        if watch:
            watch_folder_for_changes(dirpath, minify)
开发者ID:dound,项目名称:CraigNotes,代码行数:31,代码来源:manage.py


示例4: safe_rename

def safe_rename(old, new):
    if old != new:
        if not posixpath.exists(old):
            raise Exception, "Old path does not exist: %s" % old
        if posixpath.exists(new):
            raise Exception, "New path exists already: %s" % new

        os.rename(old, new)
开发者ID:Alberto-Beralix,项目名称:Beralix,代码行数:8,代码来源:safe.py


示例5: test_exists

    def test_exists(self):
        self.assertIs(posixpath.exists(test_support.TESTFN), False)
        f = open(test_support.TESTFN, "wb")
        try:
            f.write("foo")
            f.close()
            self.assertIs(posixpath.exists(test_support.TESTFN), True)
            self.assertIs(posixpath.lexists(test_support.TESTFN), True)
        finally:
            if not f.close():
                f.close()

        self.assertRaises(TypeError, posixpath.exists)
开发者ID:CaoYouXin,项目名称:myfirstapicloudapp,代码行数:13,代码来源:test_posixpath.py


示例6: safe_make_fifo

def safe_make_fifo(path, mode=0666):
    if posixpath.exists(path):
        mode = os.stat(path)[ST_MODE]
        if not S_ISFIFO(mode):
            raise Exception, "Path is not a FIFO: %s" % path
    else:
        os.mkfifo(path, mode)
开发者ID:Alberto-Beralix,项目名称:Beralix,代码行数:7,代码来源:safe.py


示例7: safe_change_mode

def safe_change_mode(path, mode):
    if not posixpath.exists(path):
        raise Exception, "Path does not exist: %s" % path

    old_mode = os.stat(path)[ST_MODE]
    if mode != S_IMODE(old_mode):
        os.chmod(path, mode)
开发者ID:Alberto-Beralix,项目名称:Beralix,代码行数:7,代码来源:safe.py


示例8: test_islink

    def test_islink(self):
        self.assertIs(posixpath.islink(test_support.TESTFN + "1"), False)
        f = open(test_support.TESTFN + "1", "wb")
        try:
            f.write("foo")
            f.close()
            self.assertIs(posixpath.islink(test_support.TESTFN + "1"), False)
            if hasattr(os, "symlink"):
                os.symlink(test_support.TESTFN + "1", test_support.TESTFN + "2")
                self.assertIs(posixpath.islink(test_support.TESTFN + "2"), True)
                os.remove(test_support.TESTFN + "1")
                self.assertIs(posixpath.islink(test_support.TESTFN + "2"), True)
                self.assertIs(posixpath.exists(test_support.TESTFN + "2"), False)
                self.assertIs(posixpath.lexists(test_support.TESTFN + "2"), True)
        finally:
            if not f.close():
                f.close()
            try:
                os.remove(test_support.TESTFN + "1")
            except os.error:
                pass
            try:
                os.remove(test_support.TESTFN + "2")
            except os.error:
                pass

        self.assertRaises(TypeError, posixpath.islink)
开发者ID:Alex-CS,项目名称:sonify,代码行数:27,代码来源:test_posixpath.py


示例9: write

	def write(self):
		import posixpath
		if os.environ.has_key('CDDB_WRITE_DIR'):
			dir = os.environ['CDDB_WRITE_DIR']
		else:
			dir = os.environ['HOME'] + '/' + _cddbrc
		file = dir + '/' + self.id + '.rdb'
		if posixpath.exists(file):
			# make backup copy
			posix.rename(file, file + '~')
		f = open(file, 'w')
		f.write('album.title:\t' + self.title + '\n')
		f.write('album.artist:\t' + self.artist + '\n')
		f.write('album.toc:\t' + self.toc + '\n')
		for note in self.notes:
			f.write('album.notes:\t' + note + '\n')
		prevpref = None
		for i in range(1, len(self.track)):
			if self.trackartist[i]:
				f.write('track'+`i`+'.artist:\t'+self.trackartist[i]+'\n')
			track = self.track[i]
			try:
				off = string.index(track, ',')
			except string.index_error:
				prevpref = None
			else:
				if prevpref and track[:off] == prevpref:
					track = track[off:]
				else:
					prevpref = track[:off]
			f.write('track' + `i` + '.title:\t' + track + '\n')
		f.close()
开发者ID:asottile,项目名称:ancient-pythons,代码行数:32,代码来源:cddb.py


示例10: renderArea

    def renderArea(self, width, height, srs, xmin, ymin, xmax, ymax, zoom):
        """
        """
        if self.mapnik is None:
            self.mapnik = mapnik.Map(0, 0)

            if exists(self.mapfile):
                mapnik.load_map(self.mapnik, str(self.mapfile))

            else:
                handle, filename = mkstemp()
                os.write(handle, urlopen(self.mapfile).read())
                os.close(handle)

                mapnik.load_map(self.mapnik, filename)
                os.unlink(filename)

        self.mapnik.width = width
        self.mapnik.height = height
        self.mapnik.zoom_to_box(mapnik.Envelope(xmin, ymin, xmax, ymax))

        img = mapnik.Image(width, height)
        mapnik.render(self.mapnik, img)

        img = Image.fromstring("RGBA", (width, height), img.tostring())

        return img
开发者ID:ricebeans,项目名称:TileStache,代码行数:27,代码来源:Providers.py


示例11: test

def test():
#----------------------------------------------------------------------------
    ##TODO: a more serious test with distinct processes !

    print('Testing glock.py...')

    # unfortunately can't test inter-process lock here!
    lockName = 'myFirstLock'
    l = GlobalLock(lockName)
    if not _windows:
        assert posixpath.exists(lockName)
    l.acquire()
    l.acquire() # reentrant lock, must not block
    l.release()
    l.release()

    try: l.release()
    except NotOwner: pass
    else: raise Exception('should have raised a NotOwner exception')

    # Check that <> threads of same process do block:
    import threading, time
    thread = threading.Thread(target=threadMain, args=(l,))
    print('main: locking...', end=' ')
    l.acquire()
    print(' done.')
    thread.start()
    time.sleep(3)
    print('\nmain: unlocking...', end=' ')
    l.release()
    print(' done.')
    time.sleep(0.1)

    print('=> Test of glock.py passed.')
    return l
开发者ID:bladernr,项目名称:checkbox,代码行数:35,代码来源:glock.py


示例12: __init__

    def __init__(self, fpath, lockInitially=False, logger=None):
        ''' Creates (or opens) a global lock.

            @param fpath: Path of the file used as lock target. This is also
                          the global id of the lock. The file will be created
                          if non existent.
            @param lockInitially: if True locks initially.
            @param logger: an optional logger object.
        '''
        self.logger = logger
        self.fpath = fpath
        if posixpath.exists(fpath):
            self.previous_lockfile_present = True
        else:
            self.previous_lockfile_present = False
        if _windows:
            self.name = string.replace(fpath, '\\', '_')
            self.mutex = win32event.CreateMutex(None, lockInitially, self.name)
        else: # Unix
            self.name = fpath
            self.flock = open(fpath, 'w')
            self.fdlock = self.flock.fileno()
            self.threadLock = threading.RLock()
        if lockInitially:
            self.acquire()
开发者ID:bladernr,项目名称:checkbox,代码行数:25,代码来源:glock.py


示例13: main

def main(args):
    sections = SplitArgsIntoSections(args[1:])
    assert len(sections) == 3
    command = sections[0]
    outputs = sections[1]
    inputs = sections[2]
    assert len(inputs) == len(outputs)
#    print 'command: %s' % command
#    print 'inputs: %s' % inputs
#    print 'outputs: %s' % outputs
  
    for i in range(0, len(inputs)):
      # make sure output directory exists
      out_dir = posixpath.dirname(outputs[i])
      if not posixpath.exists(out_dir):
        posixpath.makedirs(out_dir)
      # redirect stdout to the output file
      out_file = open(outputs[i], 'w')
      
      # build up the command
      subproc_cmd = [command[0]]
      subproc_cmd.append(inputs[i])
      subproc_cmd += command[1:]

      # fork and exec
      returnCode = subprocess.call(subproc_cmd, stdout=out_file)
      # clean up output file
      out_file.close()

      # make sure it worked
      assert returnCode == 0
    
    return 0
开发者ID:EQ4,项目名称:h5vcc,代码行数:33,代码来源:action_iterate_over_args.py


示例14: printindex

def printindex(outfilename,headfilename,levels,titles,tables):
      # Read in the header file
      headbuf = ''
      if posixpath.exists(headfilename) :
            try:
                  fd = open(headfilename,'r')
            except:
                  print 'Error reading file',headfilename
                  exit()
            headbuf = fd.read()
            fd.close()
      else:
            print 'Header file \'' + headfilename + '\' does not exist'

      # Now open the output file.
      try:
            fd = open(outfilename,'w')
      except:
            print 'Error writing to file',outfilename
            exit()

      # Add the HTML Header info here.
      fd.write(headbuf)
      # Add some HTML separators
      fd.write('\n<P>\n')
      fd.write('<TABLE>\n')
      for i in range(len(levels)):
            level = levels[i]
            title = titles[i]

            if len(tables[i]) == 0:
                  # If no functions in 'None' category, then don't print
                  # this category.
                  if level == 'none':
                        continue
                  else:
                        # If no functions in any other category, then print
                        # the header saying no functions in this cagetory.
                        fd.write('</TR><TD WIDTH=250 COLSPAN="3">')
                        fd.write('<B>' + 'No ' + level +' routines' + '</B>')
                        fd.write('</TD></TR>\n')
                        continue
                  
            fd.write('</TR><TD WIDTH=250 COLSPAN="3">')
            #fd.write('<B>' + upper(title[0])+title[1:] + '</B>')
            fd.write('<B>' + title + '</B>')
            fd.write('</TD></TR>\n')
            # Now make the entries in the table column oriented
            tables[i] = maketranspose(tables[i],3)
            for filename in tables[i]:
                  path,name     = posixpath.split(filename)
                  func_name,ext = posixpath.splitext(name)
                  mesg          = ' <TD WIDTH=250><A HREF="'+ './' + name + '">' + \
                                  func_name + '</A></TD>\n'
                  fd.write(mesg)
                  if tables[i].index(filename) % 3 == 2 : fd.write('<TR>\n')
      fd.write('</TABLE>\n')
      # Add HTML tail info here
      fd.write('<BR><A HREF="../index.html"><IMG SRC="../up.gif">Table of Contents</A>\n')
      fd.close()
开发者ID:fuentesdt,项目名称:tao-1.10.1-p3,代码行数:60,代码来源:wwwindex.py


示例15: __init__

 def __init__(self, filename=None, name=None, robot=None, brain=None, echo=1, mode="w"):
     """
   Pass in robot and brain so that we can query them (and maybe make
   copies and query them on occation).
   If echo is True, then it will echo the log file to the terminal
   """
     self.open = 1
     timestamp = self.timestamp()
     if filename == None:
         filename = timestamp + ".log"
         while posixpath.exists(filename):
             timestamp = self.timestamp()
             filename = timestamp + ".log"
     self.filename = filename
     self.file = open(filename, mode)
     self.echo = echo
     if mode == "a":
         self.writeln("... Continuing log at " + timestamp)
     else:
         self.writeln("Log opened: " + timestamp)
     if name != None:
         self.writeln("Experiment name: " + name)
     if robot != None:
         self.writeln("Robot: " + robot.type)
     if brain != None:
         self.writeln("Brain: " + brain.name)
     if os.environ.has_key("HOSTNAME"):
         self.writeln("Hostname: " + os.environ["HOSTNAME"])
     if os.environ.has_key("USER"):
         self.writeln("User: " + os.environ["USER"])
开发者ID:pfcoperez,项目名称:tecnicasiarobotica,代码行数:30,代码来源:log.py


示例16: __setitem__

    def __setitem__(self, key, value):
        if key == "includes":
            if isinstance(value, list):
                value = value[0]
            for path in split(value):
                path = self._parser._interpolate("DEFAULT", None, path, self)
                path = posixpath.expanduser(path)
                if not posixpath.exists(path):
                    raise Exception, "No such configuration file: %s" % path
                if posixpath.isdir(path):
                    logging.info("Parsing config filenames from directory: %s",
                        path)
                    def walk_func(arg, directory, names):
                        for name in names:
                            path = posixpath.join(directory, name)
                            if not posixpath.isdir(path):
                                arg._parser.read(path)

                    posixpath.walk(path, walk_func, self)
                else:
                    logging.info("Parsing config filename: %s", path)
                    self._parser.read(path)

        # Environment has precedence over configuration
        elif not key.startswith("CHECKBOX") or key.upper() not in os.environ:
            super(IncludeDict, self).__setitem__(key, value)
开发者ID:Alberto-Beralix,项目名称:Beralix,代码行数:26,代码来源:config.py


示例17: renames

def renames(old, new):
    """renames(old, new)

    Super-rename; create directories as necessary and delete any left
    empty.  Works like rename, except creation of any intermediate
    directories needed to make the new pathname good is attempted
    first.  After the rename, directories corresponding to rightmost
    path segments of the old name will be pruned way until either the
    whole path is consumed or a nonempty directory is found.

    Note: this function can fail with the new directory structure made
    if you lack permissions needed to unlink the leaf directory or
    file.

    """
    head, tail = path.split(new)
    if head and tail and not path.exists(head):
        makedirs(head)
    rename(old, new)
    head, tail = path.split(old)
    if head and tail:
        try:
            removedirs(head)
        except error:
            pass
开发者ID:develersrl,项目名称:dspython,代码行数:25,代码来源:os.py


示例18: makeDimensionLBNList

def makeDimensionLBNList(dimname):
    command = "sam translate constraints -a --dim='%s' | grep -v ':'  " %(dimname) 

    result = os.popen(command).readlines()
    result.sort()
    n = 0
    l = 0
    s = 0
    for file in result:
	  filename = string.strip(file)
	  if(len(filename)<2):
	      continue
	  if(string.find(filename,':') >= 0):
	      continue
	  
	  if(exists(filename+".parentage")):
	      s = s+1
	      continue
	  result=makeFileParentageList(filename)
	  if result[0] == "OK":
	      n = n + 1
	      if(len(result[1]) < 1):
		  print " strange problem, no lbns"
		  continue
	      f = open(filename+".parentage","w")
	      i = 0
	      while i < len(result[1]):
		  f.write("%d %d %s %s %s %s\n"%(result[1][i][0],result[1][i][1],result[1][i][2],result[1][i][3],result[1][i][4],result[1][i][5]))
		  i = i + 1
		  l = l + 1
	      f.close
	  else:
	      sys.stderr.write( result[0])
    
    return [n,l,s]
开发者ID:complexbits,项目名称:HEP-archive,代码行数:35,代码来源:makeDimensionParentageList.py


示例19: makedirs

def makedirs(name, mode=0o777, exist_ok=False):
    """makedirs(path [, mode=0o777][, exist_ok=False])

    Super-mkdir; create a leaf directory and all intermediate ones.
    Works like mkdir, except that any intermediate path segment (not
    just the rightmost) will be created if it does not exist. If the
    target directory with the same mode as we specified already exists,
    raises an OSError if exist_ok is False, otherwise no exception is
    raised.  This is recursive.

    """
    head, tail = path.split(name)
    if not tail:
        head, tail = path.split(head)
    if head and tail and not path.exists(head):
        try:
            makedirs(head, mode, exist_ok)
        except OSError as e:
            # be happy if someone already created the path
            if e.errno != errno.EEXIST:
                raise
        if tail == curdir:           # xxx/newdir/. exists if xxx/newdir exists
            return
    try:
        mkdir(name, mode)
    except OSError as e:
        import stat as st
        if not (e.errno == errno.EEXIST and exist_ok and path.isdir(name) and
                st.S_IMODE(lstat(name).st_mode) == _get_masked_mode(mode)):
            raise
开发者ID:AndyPanda95,项目名称:python-for-android,代码行数:30,代码来源:os.py


示例20: makedirs

def makedirs(name, mode=0o777, exist_ok=False):
    """makedirs(name [, mode=0o777][, exist_ok=False])

    Super-mkdir; create a leaf directory and all intermediate ones.  Works like
    mkdir, except that any intermediate path segment (not just the rightmost)
    will be created if it does not exist. If the target directory already
    exists, raise an OSError if exist_ok is False. Otherwise no exception is
    raised.  This is recursive.

    """
    head, tail = path.split(name)
    if not tail:
        head, tail = path.split(head)
    if head and tail and not path.exists(head):
        try:
            makedirs(head, exist_ok=exist_ok)
        except FileExistsError:
            # Defeats race condition when another thread created the path
            pass
        cdir = curdir
        if isinstance(tail, bytes):
            cdir = bytes(curdir, 'ASCII')
        if tail == cdir:           # xxx/newdir/. exists if xxx/newdir exists
            return
    try:
        mkdir(name, mode)
    except OSError:
        # Cannot rely on checking for EEXIST, since the operating system
        # could give priority to other errors like EACCES or EROFS
        if not exist_ok or not path.isdir(name):
            raise
开发者ID:Daetalus,项目名称:cpython,代码行数:31,代码来源:os.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python posixpath.expanduser函数代码示例发布时间:2022-05-25
下一篇:
Python posixpath.dirname函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap