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


Python Version.parse方法代码示例

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


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

示例1: __init__

# 需要导入模块: from version import Version [as 别名]
# 或者: from version.Version import parse [as 别名]
	def __init__(self, version_string, derived=None):
		assert isinstance(version_string, basestring), "Expected string, got %s" % (type(version_string))
		self.upstream = version_string
		if derived is None:
			derived = Version.parse(version_string, coerce=True)
		assert isinstance(derived, Version)
		self.derived = derived
开发者ID:timbertson,项目名称:0downstream,代码行数:9,代码来源:composite_version.py

示例2: main

# 需要导入模块: from version import Version [as 别名]
# 或者: from version.Version import parse [as 别名]
def main():
	p = optparse.OptionParser(usage='%prog [OPTIONS] input [output]')
	p.add_option('-r', '--refresh', action='store_true')
	p.add_option('-v', '--verbose', action='store_true')
	p.add_option('-o', '--offline', action='store_true')
	p.add_option('--components', type='int', help="lock down NUM version components. If NUM is positive, it locks down NUM leading components. "
			"If NUM is negative, it locks down all but NUM trailing components. The default value is -1.\n"
			"EXAMPLES:\n"
			"    --components=2 will lock down [email protected] to >=1.2.3<1.3.0.\n"
			"    --components=-2 will lock down [email protected] to >=1.2.3<1.3.0.\n"
			"This option is ignored if --exact is used", default=-1)
	p.add_option('--exact', action='store_true', help='use exact version (takes precedence over --components)')
	p.add_option('--ignore', action='append', dest='ignore', default=[], metavar='URL', help="Don't restrict interface URL")
	p.add_option('--allow-local', action='append', dest='nonlocal', default=[], metavar='URL', help="Allow URL to be satisfied by a local feed")
	p.add_option('-c', '--command', default='run')
	opts, args = p.parse_args()
	logger.setLevel(level=logging.DEBUG if opts.verbose else logging.INFO)
	input_file = args.pop(0)
	output_file = None
	if len(args) > 0:
		assert len(args) == 1, 'too many arguments'
		output_file, = args

	assert opts.components != 0, "components must not be 0"
	
	cmd = ['0install', 'select', '--console', '--xml', input_file]
	def add_flag(arg):
		cmd.insert(2, arg)

	if opts.verbose: add_flag('--verbose')
	if opts.offline: add_flag('--offline')
	if opts.refresh: add_flag('--refresh')
	if opts.command is not None:
		add_flag('--command=' + opts.command)

	logging.debug("calling: %r" % (cmd,))
	
	selections_string = subprocess.check_output(cmd)

	selections = minidom.parseString(selections_string)
	logging.debug("Got selections:\n%s" % (selections.toprettyxml(),))

	# URI-based feed:
	root_iface = selections.documentElement.getAttribute("interface")
	is_root = lambda s: s.getAttribute("interface") == root_iface
	impl_selection = filter_one(is_root, selections.getElementsByTagName("selection"), "interface==%s" % root_iface)

	root_feed = impl_selection.getAttribute("from-feed") or root_iface
	logging.debug("root feed: %s" % (root_feed,))
	
	local_feed_path = get_local_feed_file(root_feed)
	with open(local_feed_path) as feed_file:
		feed = minidom.parse(feed_file)
	# logging.debug("feed contents: %s" % (feed.toprettyxml()))

	selected_impl_id = impl_selection.getAttribute("id")
	if local_feed_path == root_feed and os.path.isabs(selected_impl_id):
		selected_impl_id = os.path.relpath(selected_impl_id, os.path.dirname(local_feed_path))

	active_impl = isolate_implementation(feed.documentElement, selected_impl_id)

	clean_feed(feed.documentElement, command=opts.command)

	for selection in selections.getElementsByTagName('selection'):
		url = selection.getAttribute("interface")

		package = selection.getAttribute("package")
		if package:
			logging.info("Skipping distribution package %s" % (package,))
			continue
		
		if url in opts.ignore:
			logging.info("Skipping ignored URL: %s" % (url,))

		local_feed = selection.getAttribute("from-feed")
		if local_feed and not local_feed:
			msg = "Local feed %s used for %s" % (local_feed, url)
			if url in opts.nonlocal:
				logging.info(msg)
			else:
				raise RuntimeError(msg)

		version = selection.getAttribute("version")
		req = feed.createElement("requires")
		req.setAttribute("interface", url)
		ver = feed.createElement("version")
		ver.setAttribute("not-before", version)

		next_version = Version.parse(version)
		if opts.exact:
			next_version = next_version.next()
		else:
			if opts.components > 0:
				# ensure version has at least `c` components
				components = itertools.chain(next_version.components, itertools.repeat(VersionComponent(0)))
				components = list(itertools.islice(components, opts.components))
				logging.debug("Freezing components: %s" % (list(map(str, components)),))
				logging.debug("inc component %s -> %s" % (components[-1], components[-1].increment()))
				components[-1] = components[-1].increment()
				next_version = Version(components)
#.........这里部分代码省略.........
开发者ID:timbertson,项目名称:0freeze,代码行数:103,代码来源:zeroinstall_freeze.py


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