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


Python posixpath.normpath函数代码示例

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


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

示例1: _converter

    def _converter(self, url):
        if url.startswith(('#', 'data:')):
            return url
        elif url.startswith(SCHEMES):
            return self.add_suffix(url)
        full_url = posixpath.normpath('/'.join([str(self.directory_name),
                                                url]))

        # custom
        partial_url = full_url[len(self.url) + 1:]
        if not os.path.isfile(
                os.path.join(
                    django_settings.STATIC_ROOT, partial_url)):
            dir_name = '/'.join((
                self.url,
                os.path.dirname(self.path)[len('/'.join([
                    django_settings.PIMPMYTHEME_FOLDER_NAME,
                    django_settings.SETTINGS_MODULE.split('.')[0]])) + 1:]))
            full_url = posixpath.normpath('/'.join([str(dir_name), url]))
        # end custom

        if self.has_scheme:
            full_url = "%s%s" % (self.protocol, full_url)
        full_url = self.add_suffix(full_url)
        return self.post_process_url(full_url)
开发者ID:novafloss,项目名称:django-pimpmytheme,代码行数:25,代码来源:filters.py

示例2: open_how_to

def open_how_to():
    failed_list = []
    bash = ''
    if (get_os_name() == "Windows"):
      bash = 'bash ';

    for lang in languages:     
        path = _base_path + lang['lang']
        how_to_list = glob.glob((path + '//' + "HowTo*"))
        for how_to in how_to_list:
            print "*" * 70
            build_sh = posixpath.normpath("%s/build.sh" % how_to)
            build_sh = build_sh.replace("\\", "/")
            run_sh = posixpath.normpath("%s/run.sh" % how_to)
            run_sh = run_sh.replace("\\", "/")
            print " - Building %s" % build_sh #os.path.basename(how_to)
            if subprocess.call("%s./%s" % (bash, build_sh)) == 0:
                print "     - Build succeeded"
                # print " - Running %s " % run_sh #os.path.basename(how_to)
                # print "     - ", "%s./%s" % (bash, run_sh)
                # subprocess.call("%s./%s" % (bash, run_sh))
            else:
                print "     - Build failed."
                print "     - Removing %s" %how_to
                failed_list.append((os.path.basename(how_to), lang['lang']))
                shutil.rmtree(how_to)
    print '*' * 70
    print ' - Failed builds:'
    for name, lang in failed_list:
        print '     - %s : %s' %(lang, name)
    print '*' * 70
开发者ID:Aloz1,项目名称:swingame,代码行数:31,代码来源:test_how_tos.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: normalizeUrl

 def normalizeUrl(self, url, base=None):
     if url and not (url.startswith('http://') or os.path.isabs(url)):
         if base is not None and not base.startswith('http:') and '%' in url:
             url = unquote(url)
         if base:
             if base.startswith("http://"):
                 prot, sep, path = base.partition("://")
                 normedPath = prot + sep + posixpath.normpath(os.path.dirname(path) + "/" + url)
             else:
                 if '%' in base:
                     base = unquote(base)
                 normedPath = os.path.normpath(os.path.join(os.path.dirname(base),url))
         else:
             normedPath = url
         if normedPath.startswith("file://"): normedPath = normedPath[7:]
         elif normedPath.startswith("file:\\"): normedPath = normedPath[6:]
         
         # no base, not normalized, must be relative to current working directory
         if base is None and not os.path.isabs(url): 
             normedPath = os.path.abspath(normedPath)
     else:
         normedPath = url
     
     if normedPath:
         if normedPath.startswith('http://'):
             pathpart = normedPath[7:].replace('\\','/')
             endingSep = '/' if pathpart[-1] == '/' else ''  # normpath drops ending directory separator
             return "http://" + posixpath.normpath(pathpart) + endingSep
         normedPath = os.path.normpath(normedPath)
         if normedPath.startswith(self.cacheDir):
             normedPath = self.cacheFilepathToUrl(normedPath)
     return normedPath
开发者ID:fukkun,项目名称:Arelle,代码行数:32,代码来源:WebCache.py

示例5: remove_backslashes_and_dotdots

def remove_backslashes_and_dotdots(directory):
    """
    Walk a directory and rename the files if their names contain backslashes.
    Return a list of errors if any.
    """
    if on_linux:
        directory = path_to_bytes(directory)
    errors = []
    for top, _, files in os.walk(directory):
        for filename in files:
            if not (WIN_PATH_SEP in filename or DOTDOT in filename):
                continue
            try:
                new_path = fileutils.as_posixpath(filename)
                new_path = new_path.strip(POSIX_PATH_SEP)
                new_path = posixpath.normpath(new_path)
                new_path = new_path.replace(DOTDOT, POSIX_PATH_SEP)
                new_path = new_path.strip(POSIX_PATH_SEP)
                new_path = posixpath.normpath(new_path)
                segments = new_path.split(POSIX_PATH_SEP)
                directory = os.path.join(top, *segments[:-1])
                fileutils.create_dir(directory)
                shutil.move(os.path.join(top, filename), os.path.join(top, *segments))
            except Exception:
                errors.append(os.path.join(top, filename))
    return errors
开发者ID:ocabrisses,项目名称:scancode-toolkit,代码行数:26,代码来源:__init__.py

示例6: update_config_file

def update_config_file(dryrun=False):
    for site, site_config in config.sites.items():
        redis_processes = [
            (x, site_config.processes[x]) for x in site_config.processes if site_config.processes[x]["type"] == "redis"
        ]
        template_path = site_config["redis"]["template"]
        print redis_processes
        for process_name, process in redis_processes:
            working_directoy = posixpath.normpath(posixpath.join(env.path, "..", "data", "redis", process_name))
            log_directory = posixpath.normpath(posixpath.join(env.path, "..", "log", "redis"))
            run("mkdir -p " + working_directoy)
            run("mkdir -p " + log_directory)
            context_dict = site_config
            context_dict.update(
                {
                    "site": site,
                    "working_directory": working_directoy,
                    "log_directory": log_directory,
                    "process_name": process_name,
                    "socket": process["socket"],
                }
            )
            path = posixpath.abspath(
                posixpath.join(site_config["deployment"]["path"], "..", "config", process_name + ".conf")
            )
            output = render_template(template_path, context_dict)
            if dryrun:
                print path + ":"
                print output
            else:
                put(StringIO.StringIO(output), path)
开发者ID:justzx2011,项目名称:dploi-fabric,代码行数:31,代码来源:redis.py

示例7: __make_urls

 def __make_urls(self, repoline):
     """The same as above, but only for one line"""
     match = re.match(r"(?P<repo_type>deb|deb-src)\s+(?P<base_url>[\S]+?)/?\s+((?P<simple_repo>[\S]*?/)|(?P<repo>\S*?[^/\s])(?:\s+(?P<sections>[^/]+?)))\s*$", repoline)
     if not match:
         raise AptRepoException("Unable to parse: %s" % repoline)
    
     url_bins = []
     url_srcs = []
     repo_type = match.group("repo_type")
     if match.group("simple_repo"):
         if repo_type == "deb":
             __path = posixpath.normpath(posixpath.join("./" + match.group("simple_repo"), "Packages"))
             url_bins = [ (posixpath.join(match.group("base_url"), __path), match.group("simple_repo"), '') ]
         elif repo_type == "deb-src":
             __path = posixpath.normpath(posixpath.join("./" + match.group("simple_repo"), "Sources"))
             url_srcs = [ (posixpath.join(match.group("base_url"), __path), match.group("simple_repo"), '' ) ]
         else:
             raise AptRepoException("Unknown repository type: %s" % repo_type)
     else:
         if repo_type == "deb":
             for item in re.split("\s+", match.group("sections")):
                 for arch in self._arch:
                     url_bins.append( (posixpath.join(match.group("base_url"), "dists", match.group("repo"), item, "binary-%s/Packages" % arch), match.group("repo"), item))
         elif repo_type == "deb-src":
             for item in match.group("sections").split():
                 url_srcs.append( (posixpath.join(match.group("base_url"), "dists", match.group("repo"), item, "source/Sources"), match.group("repo"), item))
         else:
             raise AptRepoException("Unknown repository type: %s" % repo_type)
     return (match.group("base_url"), url_srcs, url_bins)
开发者ID:excid3,项目名称:python-minideblib,代码行数:29,代码来源:AptRepoClient.py

示例8: download_hash_list

def download_hash_list(config, config_filename, server):
    """
	Downloads file with indexes of file found in remote vault and return this list
	@param config: configparser object
	@param server: easywebdav object
	"""
    config.read(config_filename)
    save_loc = "."
    rem_list = config.get("RemoteFolders", "list_dir")
    # the file should given this code be called checksums.txt, @todo: smarter
    # remote = always posix
    remote_checksumfile = posixpath.normpath(posixpath.join(rem_list, "checksums.txt"))
    local_checksumfile = path.join(save_loc, "checksums.txt")
    # local can be 'nt' or 'posix', let's normalise stuff
    if myos == "nt":
        local_checksumfile = ntpath.normpath(local_checksumfile)
    elif myos == "posix":
        local_checksumfile = posixpath.normpath(local_checksumfile)
    server.download(remote_checksumfile, local_checksumfile)
    # curr_file = open(path.join(save_loc,'hashlist.txt'))
    with open(local_checksumfile, "r") as curr_file:
        download_list = curr_file.readlines()
        if DEBUG:
            print(download_list)
    download_list = [i.split() for i in download_list if not i[0] == "#"]  # remove comments from list and split string
    md5_list = [i for i in download_list if "md" in i[0]]
    sha256_list = [i for i in download_list if "sha" in i[0]]
    return download_list, md5_list, sha256_list
开发者ID:UtrechtUniversity,项目名称:Labdata_cleanup,代码行数:28,代码来源:clean_data.py

示例9: handle

	def handle(self):
		self.data = self.request.recv(1024).strip()
		request_list = self.data.split()
		path=posixpath.normpath(request_list[1])
		path=path[1:];
		if path == '':
			path = 'index.html'
		if os.path.isdir(path):
			path = path + '/index.html'
		path=posixpath.normpath(path)
		print path
		if  os.access(path, os.R_OK) is False:
			self.request.sendall("HTTP/1.1 404 NOT FOUND\r\n")
			self.send_header('Date', self.date_time_string())
			self.send_header('Content-Type',"text/plain; charset=UTF-8")
			self.send_header('Connection','closed')
			self.end_header()
			self.request.sendall(DEFAULT_ERROR_MESSAGE)
		if os.access(path, os.R_OK) is True:
			name,extend = os.path.splitext(path)
			try:
				with open(path,'r') as f:
					buffer = f.read()
					self.request.sendall("HTTP/1.1 200 OK\r\n")
					self.send_header('Date', self.date_time_string())
					self.send_header('Content-Type',"text/%s"%(extend[1:]))
					self.send_header('Connection','closed')
					self.end_header()
					self.request.sendall(buffer)
			except IOError as e:
				print "I/O error({0}): {1}".format(e.errno, e.strerror)
		print("Got a request of: %s\n" % self.data)
开发者ID:dyf102,项目名称:CMPUT404-assignment-webserver,代码行数:32,代码来源:server.py

示例10: locate_imported_file

    def locate_imported_file(self, source_dir, import_path):
        """ Locate the imported file in the source directory.
            Return the path to the imported file relative to STATIC_ROOT

        :param source_dir: source directory
        :type source_dir: str
        :param import_path: path to the imported file
        :type import_path: str
        :returns: str

        """
        if not import_path.endswith(self.EXTENSION):
            import_path += self.EXTENSION
        path = posixpath.normpath(posixpath.join(source_dir, import_path))

        try:
            self.get_full_source_path(path)
            return path
        except ValueError:
            pass

        filename = posixpath.basename(import_path)
        if filename[0] != "_":
            path = posixpath.normpath(posixpath.join(
                source_dir,
                posixpath.dirname(import_path),
                "_" + filename,
            ))

        try:
            self.get_full_source_path(path)
            return path
        except ValueError:
            pass
开发者ID:artas90,项目名称:django-static-precompiler,代码行数:34,代码来源:scss.py

示例11: update_config_file

def update_config_file(dryrun=False):
    for site, site_config in config.sites.items():
        redis_processes = [(x, site_config.processes[x]) for x in site_config.processes if site_config.processes[x]["type"] == "redis"]
        template_path = site_config['redis']['template']
        print redis_processes
        for process_name, process in redis_processes:
            working_directoy = posixpath.normpath(posixpath.join(env.path, '..', 'data', 'redis', process_name))
            log_directory = posixpath.normpath(posixpath.join(site_config['deployment']['logdir'], 'log', 'redis'))
            run('mkdir -p ' + working_directoy)
            run('mkdir -p ' + log_directory)
            context_dict = site_config
            context_dict.update({
                'site': site,
                'working_directory': working_directoy,
                'log_directory': log_directory,
                'process_name': process_name,
                'socket': process['socket'],
            })
            path = posixpath.abspath(posixpath.join(site_config['deployment']['path'], '..', 'config', process_name + '.conf'))
            output = render_template(template_path, context_dict)
            if dryrun:
                print path + ":"
                print output
            else:
                put(StringIO.StringIO(output), path)
开发者ID:baiyunping333,项目名称:dploi-fabric,代码行数:25,代码来源:redis.py

示例12: execute

    def execute(self):
        productionLocation = self.productionDetails[indexer.INDEX_PRODUCTION_LOCATION]
        fileLocation = self.fileDetails[indexer.INDEX_FILE_LOCATION]
        fileLocation = os.path.join(productionLocation, fileLocation)
        subDirs = fileLocation.replace(self.sourceDirectory, self.targetDirectory, 1)
        fileLocationDir = os.path.dirname(subDirs)
        absRefLoc = os.path.normcase(posixpath.normpath(os.path.join(self.productionDetails[2], subDirs)))
        
        absNewLoc = os.path.normcase(posixpath.normpath(os.path.join(self.productionDetails[2], self.referenceFileDetails[indexer.INDEX_FILE_LOCATION])))
        newpath = "//"+_relpath(absNewLoc, fileLocationDir)
        handle = blendfile.openBlendFile(fileLocation, 'r+b')
        for libraryblock in handle.FindBlendFileBlocksWithCode("LI"):
            
            relPath = libraryblock.Get("name").split("\0")[0].replace("\\", "/")
            absPath = blendfile.blendPath2AbsolutePath(fileLocation, relPath)
            normPath = os.path.normpath(absPath)
            if normPath==absNewLoc:
                libraryblock.Set("name", newpath)

        for imageblock in handle.FindBlendFileBlocksWithCode("IM"):
            
            relPath = imageblock.Get("name").split("\0")[0].replace("\\", "/")
            absPath = blendfile.blendPath2AbsolutePath(fileLocation, relPath)
            normPath = os.path.normpath(absPath)
            if normPath==absNewLoc:
                imageblock.Set("name", newpath)
            
        handle.close()
开发者ID:JenevanStudios,项目名称:blender-aid,代码行数:28,代码来源:servicerefactor.py

示例13: translate_path

    def translate_path(self, path):
        """Translate a /-separated PATH to the local filename syntax.

        Components that mean special things to the local file system
        (e.g. drive or directory names) are ignored.  (XXX They should
        probably be diagnosed.)

        """
        try:
            path = posixpath.normpath(urllib.unquote(path))
            words = path.split('/')
            words = filter(None, words)
            path = os.getcwd()
            for word in words:
                drive, word = os.path.splitdrive(word)
                head, word = os.path.split(word)
                if word in (os.curdir, os.pardir): continue
                path = os.path.join(path, word)
            return path
        except Exception, e:
           self.send_error(403, e)
           path = posixpath.normpath(urllib.unquote(path))
           words = path.split('/')
           words = filter(None, words)
           path = os.getcwd()
           for word in words:
               drive, word = os.path.splitdrive(word)
               head, word = os.path.split(word)
               if word in (os.curdir, os.pardir): continue
               path = os.path.join(path, word)
           return path.encode("utf-8")
开发者ID:AmarKalabic,项目名称:Xplorer,代码行数:31,代码来源:main.py

示例14: __call__

    def __call__(self, req):
        #if os.path.normpath("/" + req.path_info) == "/":
        #    return(base.ec2_md_print(base.VERSIONS + ["latest"]))

        path = req.path_info
        if path == "" or path[0] != "/":
            path = posixpath.normpath("/" + path)
        else:
            path = posixpath.normpath(path)

        path_tokens = path.split('/')[1:]

        if path_tokens[0] not in ("ip", "help"):
            if path_tokens[0] == "":
                # request for /
                #path_tokens = ["ip"]
                #TODO
                raise webob.exc.HTTPNotFound()
        elif path_tokens[0] == u'ip' and path_tokens[1]:
            data = self.check_ipv4(path_tokens[1])
        else:
            #TODO
            raise webob.exc.HTTPNotFound()

        return Response(json.dumps(data), content_type='application/json')
开发者ID:brk0v,项目名称:nova-viper,代码行数:25,代码来源:handler.py

示例15: _abssource

def _abssource(repo, push=False, abort=True):
    """return pull/push path of repo - either based on parent repo .hgsub info
    or on the top repo config. Abort or return None if no source found."""
    if hasattr(repo, '_subparent'):
        source = repo._subsource
        if source.startswith('/') or '://' in source:
            return source
        parent = _abssource(repo._subparent, push, abort=False)
        if parent:
            if '://' in parent:
                if parent[-1] == '/':
                    parent = parent[:-1]
                r = urlparse.urlparse(parent + '/' + source)
                r = urlparse.urlunparse((r[0], r[1],
                                         posixpath.normpath(r[2]),
                                         r[3], r[4], r[5]))
                return r
            else: # plain file system path
                return posixpath.normpath(os.path.join(parent, repo._subsource))
    else: # recursion reached top repo
        if hasattr(repo, '_subtoppath'):
            return repo._subtoppath
        if push and repo.ui.config('paths', 'default-push'):
            return repo.ui.config('paths', 'default-push')
        if repo.ui.config('paths', 'default'):
            return repo.ui.config('paths', 'default')
    if abort:
        raise util.Abort(_("default path for subrepository %s not found") %
            reporelpath(repo))
开发者ID:helloandre,项目名称:cr48,代码行数:29,代码来源:subrepo.py


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