summaryrefslogtreecommitdiffstats
path: root/bin/xpak-helper.py
blob: 4766d990dfed9e9b7ee32b51c3430b726727de29 (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
#!/usr/bin/python
# Copyright 2009 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

import optparse
import sys
import portage
from portage import os

def command_recompose(args):

	usage = "usage: recompose <binpkg_path> <metadata_dir>\n"

	if len(args) != 2:
		sys.stderr.write(usage)
		sys.stderr.write("2 arguments are required, got %s\n" % len(args))
		return 1

	binpkg_path, metadata_dir = args

	if not os.path.isfile(binpkg_path):
		sys.stderr.write(usage)
		sys.stderr.write("Argument 1 is not a regular file: '%s'\n" % \
			binpkg_path)
		return 1

	if not os.path.isdir(metadata_dir):
		sys.stderr.write(usage)
		sys.stderr.write("Argument 2 is not a directory: '%s'\n" % \
			metadata_dir)
		return 1

	t = portage.xpak.tbz2(binpkg_path)
	t.recompose(metadata_dir)
	return os.EX_OK

def main(argv):

	if argv and sys.hexversion < 0x3000000 and not isinstance(argv[0], unicode):
		for i, x in enumerate(argv):
			argv[i] = portage._unicode_decode(x, errors='strict')

	valid_commands = ('recompose',)
	description = "Perform metadata operations on a binary package."
	usage = "usage: %s COMMAND [args]" % \
		os.path.basename(argv[0])

	parser = optparse.OptionParser(description=description, usage=usage)
	options, args = parser.parse_args(argv[1:])

	if not args:
		parser.error("missing command argument")

	command = args[0]

	if command not in valid_commands:
		parser.error("invalid command: '%s'" % command)

	if command == 'recompose':
		rval = command_recompose(args[1:])
	else:
		raise AssertionError("invalid command: '%s'" % command)

	return rval

if __name__ == "__main__":
	rval = main(sys.argv[:])
	sys.exit(rval)