本文整理汇总了Python中os.path.insert函数的典型用法代码示例。如果您正苦于以下问题:Python insert函数的具体用法?Python insert怎么用?Python insert使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了insert函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, setting, widgetname = None, root = None,
maxlevels = -1):
"""Take the setting given, and propagate it to other widgets,
according to the parameters here.
If widgetname is given then only propagate it to widgets with
the name given.
widgets are located from the widget given (root if not set)
Up to maxlevels levels of widgets are changed (<0 means infinite)
"""
self.val = setting.val
self.widgetname = widgetname
if root:
self.rootpath = root.path
else:
self.rootpath = None
self.maxlevels = maxlevels
# work out path of setting relative to widget
path = []
s = setting
while not s.isWidget():
path.insert(0, s.name)
s = s.parent
self.setpath = path[1:]
self.widgettype = s.typename
开发者ID:grahambell,项目名称:veusz,代码行数:30,代码来源:operations.py
示例2: xmlPath
def xmlPath(element):
'''Return a simple, unambiguous path for an XML element'''
path = []
while True:
parent = element.getparent()
name = element.tag
if name.startswith(POM_NS_PREFIX):
name = name[len(POM_NS_PREFIX):]
if parent is None:
path.insert(0, '/%s' % name)
break
expr = etree.ETXPath(element.tag)
children = expr(parent)
#print 'xmlPath',element.tag,children
index = children.index(element)
if len(children) == 1:
item = '/%s' % name
else:
item = '/%s[%d]' % (name, index)
path.insert(0, item)
element = parent
return ''.join(path)
开发者ID:digulla,项目名称:org.eclipse.dash.m4e.tools,代码行数:29,代码来源:pom.py
示例3: use
def use(self):
from r2.lib.template_helpers import static
path = [g.static_path, self.name]
if g.uncompressedJS:
path.insert(1, "js")
return script_tag.format(src=static(os.path.join(*path)))
开发者ID:GreatChenR,项目名称:reddit,代码行数:7,代码来源:js.py
示例4: path
def path(self):
path = [self.name]
parent = self.parent
while parent:
path.insert(0, parent.name)
parent = parent.parent
return '/'.join(path)
开发者ID:idmond,项目名称:dcc2014,代码行数:7,代码来源:system.py
示例5: url
def url(self, absolute=False, mangle_name=False):
from r2.lib.template_helpers import static
path = [g.static_path, self.name]
if g.uncompressedJS:
path.insert(1, "js")
return static(os.path.join(*path), absolute, mangle_name)
开发者ID:ActivateServices,项目名称:reddit,代码行数:7,代码来源:js.py
示例6: get_path
def get_path(tag):
path = []
cur = tag
while cur != None:
path.insert(0, cur.name)
cur = cur.parent
return "root" + ".".join(path)
开发者ID:Riddler76,项目名称:scripts,代码行数:7,代码来源:checkworld.py
示例7: _process_path
def _process_path(self, path):
""" Take a path and set the space and parent """
path = normalize_path(self.path).split("/")
if not self.has_space():
spacePath = path.pop(0)
try:
self.space = Space.objects.get(path=spacePath)
except ObjectDoesNotExist:
# Space might not be included in path, add it back to path
path.insert(0, spacePath)
parentPath = path[0:-1]
if len(path) >= 1:
self.path = path[-1]
else:
self.path = ""
parentPath = filter(len, parentPath) # remove empty path sections
if parentPath:
self.parent = Document.objects.get_by_path(
parentPath,
space=self.space,
create=True)
开发者ID:jgillick,项目名称:Spaces,代码行数:25,代码来源:models.py
示例8: generate
def generate():
db.init_db()
@db.transactionnal
def generate_urls():
urls = []
for fct in web.static_pages_fcts:
urls = urls + fct()
return urls
urls = generate_urls()
print urls
print "Generation of the static content"
for url in urls:
with web.app.test_request_context(url, method="GET"):
print "Generating", url
x = web.app.dispatch_request()
path = []
parent = url
while parent != '/':
tmp = os.path.split(parent)
path.insert(0, tmp[1])
parent = tmp[0]
path = os.path.join(*path)
path = os.path.join(config.dist_folder, path)
if not os.path.exists(os.path.dirname(path)):
os.makedirs(os.path.dirname(path))
with open(path, "w") as f:
if type(x) == str or type(x) == unicode:
f.write(x)
else:
f.write(x.data)
开发者ID:nicolas-van,项目名称:protocms,代码行数:31,代码来源:cmd.py
示例9: chain_wires
def chain_wires(wires):
assert wires.num_vertices > 0
visited = np.zeros(wires.num_vertices, dtype=bool)
path = [0]
visited[0] = True
while not np.all(visited):
front = path[0]
front_neighbors = wires.get_vertex_neighbors(int(front))
for v in front_neighbors:
if visited[v]:
continue
path.insert(0, v)
visited[v] = True
break
end = path[-1]
end_neighbors = wires.get_vertex_neighbors(int(end))
for v in end_neighbors:
if visited[v]:
continue
visited[v] = True
path.append(v)
break
first_neighbors = wires.get_vertex_neighbors(int(path[0])).squeeze()
if len(path) > 2 and path[-1] in first_neighbors:
# Close the loop.
path.append(path[0])
path = wires.vertices[path]
return path
开发者ID:mortezah,项目名称:PyMesh,代码行数:30,代码来源:minkowski_sum.py
示例10: _backport_which
def _backport_which(cmd, mode=os.F_OK | os.X_OK, path=None):
"""Given a command, mode, and a PATH string, return the path which
conforms to the given mode on the PATH, or None if there is no such
file.
`mode` defaults to os.F_OK | os.X_OK. `path` defaults to the result
of os.environ.get("PATH"), or can be overridden with a custom search
path.
"""
# Check that a given file can be accessed with the correct mode.
# Additionally check that `file` is not a directory, as on Windows
# directories pass the os.access check.
def _access_check(fn, mode):
return (os.path.exists(fn) and os.access(fn, mode)
and not os.path.isdir(fn))
# If we're given a path with a directory part, look it up directly rather
# than referring to PATH directories. This includes checking relative to the
# current directory, e.g. ./script
if os.path.dirname(cmd):
if _access_check(cmd, mode):
return cmd
return None
if path is None:
path = os.environ.get("PATH", os.defpath)
if not path:
return None
path = path.split(os.pathsep)
if sys.platform == "win32":
# The current directory takes precedence on Windows.
if not os.curdir in path:
path.insert(0, os.curdir)
# PATHEXT is necessary to check on Windows.
pathext = os.environ.get("PATHEXT", "").split(os.pathsep)
# See if the given file matches any of the expected path extensions.
# This will allow us to short circuit when given "python.exe".
# If it does match, only test that one, otherwise we have to try
# others.
if any(cmd.lower().endswith(ext.lower()) for ext in pathext):
files = [cmd]
else:
files = [cmd + ext for ext in pathext]
else:
# On other platforms you don't have things like PATHEXT to tell you
# what file suffixes are executable, so just pass on cmd as-is.
files = [cmd]
seen = set()
for dir in path:
normdir = os.path.normcase(dir)
if not normdir in seen:
seen.add(normdir)
for thefile in files:
name = os.path.join(dir, thefile)
if _access_check(name, mode):
return name
return None
开发者ID:shailesh17,项目名称:aws-cli,代码行数:59,代码来源:compat.py
示例11: _get_default_search_path
def _get_default_search_path():
path = sys.path
# The first element of sys.path is the current directory of this
# script, not the user's current directory. So, insert the empty
# string (standing in for the current directory) at the start of
# the list.
path.insert(0, '')
return path
开发者ID:rth7680,项目名称:systemtap,代码行数:8,代码来源:stap-resolve-module-function.py
示例12: retracePath
def retracePath(self, n):
node = self.getNodeAt(n.index)
path.insert(0,node)
if n.parent == None:
return path
retracePath(self, n.parent)
return path
开发者ID:kit-ipe,项目名称:katrinTankViewer,代码行数:8,代码来源:main.py
示例13: _path_from
def _path_from(parent, child):
if os.path.split(parent)[1] == '':
parent = os.path.split(parent)[0]
path = []
while parent != child:
child, dirname = os.path.split(child)
path.insert(0, dirname)
assert os.path.split(child)[0] != child
return path
开发者ID:AlexSnet,项目名称:polyglot,代码行数:9,代码来源:downloader.py
示例14: which
def which(cmd, mode=os.F_OK | os.X_OK, env=None):
"""Given a command, mode, and a PATH string, return the path which
conforms to the given mode on the PATH, or None if there is no such
file.
`mode` defaults to os.F_OK | os.X_OK. `env` defaults to os.environ,
if not supplied.
"""
# Check that a given file can be accessed with the correct mode.
# Additionally check that `file` is not a directory, as on Windows
# directories pass the os.access check.
def _access_check(fn, mode):
return (os.path.exists(fn) and os.access(fn, mode)
and not os.path.isdir(fn))
# Short circuit. If we're given a full path which matches the mode
# and it exists, we're done here.
if _access_check(cmd, mode):
return cmd
if env is None:
env = os.environ
path = env.get("PATH", os.defpath).split(os.pathsep)
if sys.platform == "win32":
# The current directory takes precedence on Windows.
if not os.curdir in path:
path.insert(0, os.curdir)
# PATHEXT is necessary to check on Windows.
pathext = env.get("PATHEXT", "").split(os.pathsep)
# See if the given file matches any of the expected path extensions.
# This will allow us to short circuit when given "python.exe".
matches = [cmd for ext in pathext if cmd.lower().endswith(ext.lower())]
# If it does match, only test that one, otherwise we have to try
# others.
files = [cmd] if matches else [cmd + ext.lower() for ext in pathext]
else:
# On other platforms you don't have things like PATHEXT to tell you
# what file suffixes are executable, so just pass on cmd as-is.
files = [cmd]
seen = set()
for dir in path:
dir = os.path.normcase(dir)
if not dir in seen:
seen.add(dir)
for thefile in files:
name = os.path.join(dir, thefile)
if _access_check(name, mode):
return name
return None
开发者ID:RovioAnimation,项目名称:rez,代码行数:53,代码来源:shutilwhich.py
示例15: list_paths
def list_paths(self):
''''''
self.connect()
device = self.dmd.Devices.findDevice(self.options.device)
if device is None:
DEFAULTLOG.error("Device '{}' not found.".format(self.options.device))
return
from Acquisition import aq_chain
from Products.ZenRelations.RelationshipBase import RelationshipBase
all_paths = set()
included_paths = set()
class_summary = collections.defaultdict(set)
for component in device.getDeviceComponents():
for facet in component.get_facets(recurse_all=True):
path = []
for obj in aq_chain(facet):
if obj == component:
break
if isinstance(obj, RelationshipBase):
path.insert(0, obj.id)
all_paths.add(component.meta_type + ":" + "/".join(path) + ":" + facet.meta_type)
for facet in component.get_facets():
path = []
for obj in aq_chain(facet):
if obj == component:
break
if isinstance(obj, RelationshipBase):
path.insert(0, obj.id)
all_paths.add(component.meta_type + ":" + "/".join(path) + ":" + facet.meta_type)
included_paths.add(component.meta_type + ":" + "/".join(path) + ":" + facet.meta_type)
class_summary[component.meta_type].add(facet.meta_type)
print "Paths\n-----\n"
for path in sorted(all_paths):
if path in included_paths:
if "/" not in path:
# normally all direct relationships are included
print "DIRECT " + path
else:
# sometimes extra paths are pulled in due to extra_paths
# configuration.
print "EXTRA " + path
else:
print "EXCLUDE " + path
print "\nClass Summary\n-------------\n"
for source_class in sorted(class_summary.keys()):
print "{} is reachable from {}".format(source_class, ", ".join(sorted(class_summary[source_class])))
开发者ID:zenoss,项目名称:zenpacklib,代码行数:52,代码来源:ZPLCommand.py
示例16: _search_data
def _search_data(data, search):
for field in search:
path = field.split('.')
if len(path) == 1:
continue
path.insert(0, 'models')
v = data
for key in path:
if key in v:
v = v[key]
if v != search[field]:
return False
return True
开发者ID:mrakitin,项目名称:sirepo,代码行数:13,代码来源:simulation_db.py
示例17: path
def path(self):
"""
Return list of endpoints in the path up to this one.
"""
path = []
ep = self
while ep.table:
path.insert(0, ep)
ep = ep.parent
return path
开发者ID:ponycloud,项目名称:sparkle,代码行数:13,代码来源:schema.py
示例18: _add_venv
def _add_venv(path, filename):
"""Add the virtualenv's bin directory, if in a virtualenv"""
filename = os.path.realpath(filename) # Resolve symlinks
filepath = os.path.dirname(filename)
parts = filepath.split(os.path.sep)
for index in range(1, len(parts) - 1):
root = os.path.join(*parts[:-index])
activate = os.path.sep + os.path.join(root, 'bin', 'activate')
if os.path.exists(activate):
path.insert(0, os.path.sep + os.path.join(root, 'bin'))
break
开发者ID:xuanhan863,项目名称:lintswitch,代码行数:14,代码来源:checkers.py
示例19: _search_data
def _search_data(data, search):
for field, expect in search.items():
path = field.split('.')
if len(path) == 1:
#TODO(robnagler) is this a bug? Why would you supply a search path
# value that didn't want to be searched.
continue
path.insert(0, 'models')
v = data
for key in path:
if key in v:
v = v[key]
if v != expect:
return False
return True
开发者ID:e-carlin,项目名称:sirepo,代码行数:15,代码来源:simulation_db.py
示例20: OptimizePathSlide
def OptimizePathSlide(self, path, frict = Sf):
'''
Optimize by sliding WP along segments
'''
i = 0
while i+2 < len(path):
temp = self.SlideMove(path[i],path[i+1],path[i+2],frict=frict)
if temp == None:
# remove path[i+1]
path.remove(path[i+1])
# Keep i unchanged
else:
index = path.index(path[i+1])
path.insert(index, temp)
i = i + 1
return path
开发者ID:hsoula,项目名称:opcon,代码行数:16,代码来源:sandbox_map.py
注:本文中的os.path.insert函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论