aboutsummaryrefslogtreecommitdiff
blob: e1abbe412407fac13636be996b2a8fc59ccd0f4b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/python

from pkgcore.config import load_config
from pkgcore.resolver import plan
from pkgcore.package.atom import atom
from pkgcore.util.lists import flatten, stable_unique


def pop_paired_args(args, arg, msg):
	rets = []
	if not isinstance(arg, (tuple, list)):
		arg = [arg]
	for a in arg:
		try:
			while True:
				i = args.index(a)
				args.pop(i)
				if len(args) == i:
					raise Exception("%s needs to be followed by an arg: %s" % (a, msg))
				rets.append(args.pop(i))
		except ValueError:
			pass
	return rets

def pop_arg(args, *arg):

	ret = False
	for a in arg:
		try:
			while True:
				args.remove(a)
				ret = True
		except ValueError:
			pass
	return ret
	

if __name__ == "__main__":
	import sys
	args = sys.argv[1:]

	if pop_arg(args, "-h", "--help"):
		print "args supported, [-D || --deep], [[-u || --upgrade] | [-m || --max-upgrade]] and -s (system|world) [-d || --debug]"
		print "can specify additional atoms when specifying -s, no atoms/sets available, defaults to sys-apps/portage"
		sys.exit(1)
	if pop_arg(args, "-d", "--debug"):
		plan.limiters.add(None)
	trigger_pdb = pop_arg(args, "-p", "--pdb")
	empty_vdb = pop_arg(args, "-e", "--empty")
	upgrade = pop_arg(args, "-u", "--upgrade")
	max = pop_arg(args, "-m", "--max-upgrade")
	if max and max == upgrade:
		print "can only choose max, or upgrade"
		sys.exit(1)
	if max:
		strategy = plan.merge_plan.force_max_version_strategy
	elif upgrade:
		strategy = plan.merge_plan.prefer_highest_version_strategy
	else:
		strategy = plan.merge_plan.prefer_reuse_strategy

	deep = bool(pop_arg(args, "-D", "--deep"))

	conf = load_config()

	set_targets = pop_paired_args(args, ["--set", "-s"], "pkg sets to enable")
	if set_targets:
		print "using pkgset(s): %s" % (", ".join("'%s'" % x.strip() for x in set_targets))
	set_targets = [a for t in set_targets for a in conf.pkgset[t]]
	#map(atom, conf.pkgset[l]) for l in set_targets], restriction.base)
	
	if not args:
		if set_targets:
			atoms = set_targets
		else:
			print "resolving sys-apps/portage since no atom supplied"
			atoms = [atom("sys-apps/portage")]
	else:
		atoms = [atom(x) for x in args] + set_targets
	atoms = stable_unique(atoms)

	domain = conf.domain["livefs domain"]
	vdb, repo = domain.vdb[0], domain.repos[0]
	resolver = plan.merge_plan(vdb, repo, pkg_selection_strategy=strategy, verify_vdb=deep)
	ret = True
	import time
	start_time = time.time()
	for x in atoms:
		print "\ncalling resolve for %s..." % x
		ret = resolver.add_atom(x)
		if ret:
			print "ret was",ret
			print "resolution failed"
			sys.exit(2)
	print "\nbuildplan"
	for x in resolver.state.iter_pkg_ops():
		print "%s %s" % (x[0].ljust(8), x[1])
	print "result was successfull, 'parently- took %.2f seconds" % (time.time() - start_time)