Gentoo Archives: gentoo-catalyst

From: Mike Frysinger <vapier@g.o>
To: gentoo-catalyst@l.g.o
Subject: [gentoo-catalyst] [PATCH] catalyst: add a wrapper for executing directly out of git
Date: Thu, 29 Oct 2015 05:49:09
Message-Id: 1446097738-24624-1-git-send-email-vapier@gentoo.org
1 This is a smaller wrapper to set up the environment (both python and some
2 config options) so that all the code is used from the git repo. This way
3 you don't have to install it in order to test things.
4 ---
5 bin/catalyst.git | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
6 1 file changed, 52 insertions(+)
7 create mode 100755 bin/catalyst.git
8
9 diff --git a/bin/catalyst.git b/bin/catalyst.git
10 new file mode 100755
11 index 0000000..eb6234b
12 --- /dev/null
13 +++ b/bin/catalyst.git
14 @@ -0,0 +1,52 @@
15 +#!/usr/bin/python
16 +# -*- coding: utf-8 -*-
17 +# Copyright 1999-2015 Gentoo Foundation
18 +# Distributed under the terms of the GNU General Public License v2
19 +
20 +"""Run catalyst from git using local modules/scripts."""
21 +
22 +from __future__ import print_function
23 +
24 +import os
25 +import sys
26 +import tempfile
27 +
28 +from snakeoil import process
29 +
30 +
31 +def main(argv):
32 + """The main entry point"""
33 + source_root = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
34 +
35 + pympath = source_root
36 + pythonpath = os.environ.get('PYTHONPATH')
37 + if pythonpath is None:
38 + pythonpath = pympath
39 + else:
40 + pythonpath = pympath + ':' + pythonpath
41 + os.environ['PYTHONPATH'] = pythonpath
42 +
43 + with tempfile.NamedTemporaryFile(prefix='catalyst.conf.') as conf:
44 + # Set up a config file with paths to the local tree.
45 + conf.write(
46 + ('sharedir=%(source_root)s\n'
47 + 'shdir=%(source_root)s/targets\n'
48 + 'envscript=%(source_root)s/etc/catalystrc\n'
49 + % {'source_root': source_root}).encode('utf8')
50 + )
51 + conf.flush()
52 + argv = [
53 + '--config', os.path.join(source_root, 'etc', 'catalyst.conf'),
54 + '--config', conf.name,
55 + ] + argv
56 +
57 + cmd = [os.path.join(source_root, 'bin', 'catalyst')]
58 + pid = os.fork()
59 + if pid == 0:
60 + os.execvp(cmd[0], cmd + argv)
61 + (_pid, status) = os.waitpid(pid, 0)
62 + process.exit_as_status(status)
63 +
64 +
65 +if __name__ == '__main__':
66 + main(sys.argv[1:])
67 --
68 2.5.2