public inbox for gentoo-catalyst@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-catalyst] [PATCH] catalyst: add a wrapper for executing directly out of git
@ 2015-10-29  5:48 Mike Frysinger
  0 siblings, 0 replies; 4+ messages in thread
From: Mike Frysinger @ 2015-10-29  5:48 UTC (permalink / raw
  To: gentoo-catalyst

This is a smaller wrapper to set up the environment (both python and some
config options) so that all the code is used from the git repo.  This way
you don't have to install it in order to test things.
---
 bin/catalyst.git | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)
 create mode 100755 bin/catalyst.git

diff --git a/bin/catalyst.git b/bin/catalyst.git
new file mode 100755
index 0000000..eb6234b
--- /dev/null
+++ b/bin/catalyst.git
@@ -0,0 +1,52 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+# Copyright 1999-2015 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+"""Run catalyst from git using local modules/scripts."""
+
+from __future__ import print_function
+
+import os
+import sys
+import tempfile
+
+from snakeoil import process
+
+
+def main(argv):
+	"""The main entry point"""
+	source_root = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
+
+	pympath = source_root
+	pythonpath = os.environ.get('PYTHONPATH')
+	if pythonpath is None:
+		pythonpath = pympath
+	else:
+		pythonpath = pympath + ':' + pythonpath
+	os.environ['PYTHONPATH'] = pythonpath
+
+	with tempfile.NamedTemporaryFile(prefix='catalyst.conf.') as conf:
+		# Set up a config file with paths to the local tree.
+		conf.write(
+			('sharedir=%(source_root)s\n'
+			 'shdir=%(source_root)s/targets\n'
+			 'envscript=%(source_root)s/etc/catalystrc\n'
+			 % {'source_root': source_root}).encode('utf8')
+		)
+		conf.flush()
+		argv = [
+			'--config', os.path.join(source_root, 'etc', 'catalyst.conf'),
+			'--config', conf.name,
+		] + argv
+
+		cmd = [os.path.join(source_root, 'bin', 'catalyst')]
+		pid = os.fork()
+		if pid == 0:
+			os.execvp(cmd[0], cmd + argv)
+		(_pid, status) = os.waitpid(pid, 0)
+		process.exit_as_status(status)
+
+
+if __name__ == '__main__':
+	main(sys.argv[1:])
-- 
2.5.2



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [gentoo-catalyst] [PATCH] catalyst: add a wrapper for executing directly out of git
@ 2015-11-09 21:05 Mike Frysinger
  2015-11-09 21:23 ` Mike Frysinger
  2015-11-10  6:53 ` Brian Dolbec
  0 siblings, 2 replies; 4+ messages in thread
From: Mike Frysinger @ 2015-11-09 21:05 UTC (permalink / raw
  To: gentoo-catalyst

This is a smaller wrapper to set up the environment (both python and some
config options) so that all the code is used from the git repo.  This way
you don't have to install it in order to test things.
---
 bin/catalyst.git | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)
 create mode 100755 bin/catalyst.git

diff --git a/bin/catalyst.git b/bin/catalyst.git
new file mode 100755
index 0000000..eb6234b
--- /dev/null
+++ b/bin/catalyst.git
@@ -0,0 +1,52 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+# Copyright 1999-2015 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+"""Run catalyst from git using local modules/scripts."""
+
+from __future__ import print_function
+
+import os
+import sys
+import tempfile
+
+from snakeoil import process
+
+
+def main(argv):
+	"""The main entry point"""
+	source_root = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
+
+	pympath = source_root
+	pythonpath = os.environ.get('PYTHONPATH')
+	if pythonpath is None:
+		pythonpath = pympath
+	else:
+		pythonpath = pympath + ':' + pythonpath
+	os.environ['PYTHONPATH'] = pythonpath
+
+	with tempfile.NamedTemporaryFile(prefix='catalyst.conf.') as conf:
+		# Set up a config file with paths to the local tree.
+		conf.write(
+			('sharedir=%(source_root)s\n'
+			 'shdir=%(source_root)s/targets\n'
+			 'envscript=%(source_root)s/etc/catalystrc\n'
+			 % {'source_root': source_root}).encode('utf8')
+		)
+		conf.flush()
+		argv = [
+			'--config', os.path.join(source_root, 'etc', 'catalyst.conf'),
+			'--config', conf.name,
+		] + argv
+
+		cmd = [os.path.join(source_root, 'bin', 'catalyst')]
+		pid = os.fork()
+		if pid == 0:
+			os.execvp(cmd[0], cmd + argv)
+		(_pid, status) = os.waitpid(pid, 0)
+		process.exit_as_status(status)
+
+
+if __name__ == '__main__':
+	main(sys.argv[1:])
-- 
2.6.2



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [gentoo-catalyst] [PATCH] catalyst: add a wrapper for executing directly out of git
  2015-11-09 21:05 Mike Frysinger
@ 2015-11-09 21:23 ` Mike Frysinger
  2015-11-10  6:53 ` Brian Dolbec
  1 sibling, 0 replies; 4+ messages in thread
From: Mike Frysinger @ 2015-11-09 21:23 UTC (permalink / raw
  To: gentoo-catalyst

[-- Attachment #1: Type: text/plain, Size: 613 bytes --]

On 09 Nov 2015 16:05, Mike Frysinger wrote:
> +	with tempfile.NamedTemporaryFile(prefix='catalyst.conf.') as conf:
> +		# Set up a config file with paths to the local tree.
> +		conf.write(
> +			('sharedir=%(source_root)s\n'
> +			 'shdir=%(source_root)s/targets\n'
> +			 'envscript=%(source_root)s/etc/catalystrc\n'
> +			 % {'source_root': source_root}).encode('utf8')
> +		)
> +		conf.flush()

before anyone suggests using the buffering option when creating 
tempfile.NamedTemporaryFile, you should be aware that the arg
name & meaning changed between py2 & py3.  it's simpler to flush.
-mike

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [gentoo-catalyst] [PATCH] catalyst: add a wrapper for executing directly out of git
  2015-11-09 21:05 Mike Frysinger
  2015-11-09 21:23 ` Mike Frysinger
@ 2015-11-10  6:53 ` Brian Dolbec
  1 sibling, 0 replies; 4+ messages in thread
From: Brian Dolbec @ 2015-11-10  6:53 UTC (permalink / raw
  To: gentoo-catalyst

On Mon,  9 Nov 2015 16:05:45 -0500
Mike Frysinger <vapier@gentoo.org> wrote:

> This is a smaller wrapper to set up the environment (both python and
> some config options) so that all the code is used from the git repo.
> This way you don't have to install it in order to test things.
> ---
>  bin/catalyst.git | 52
> ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed,
> 52 insertions(+) create mode 100755 bin/catalyst.git
> 
> diff --git a/bin/catalyst.git b/bin/catalyst.git
> new file mode 100755
> index 0000000..eb6234b
> --- /dev/null
> +++ b/bin/catalyst.git
> @@ -0,0 +1,52 @@
> +#!/usr/bin/python
> +# -*- coding: utf-8 -*-
> +# Copyright 1999-2015 Gentoo Foundation
> +# Distributed under the terms of the GNU General Public License v2
> +
> +"""Run catalyst from git using local modules/scripts."""
> +
> +from __future__ import print_function
> +
> +import os
> +import sys
> +import tempfile
> +
> +from snakeoil import process
> +
> +
> +def main(argv):
> +	"""The main entry point"""
> +	source_root =
> os.path.dirname(os.path.dirname(os.path.realpath(__file__))) +
> +	pympath = source_root
> +	pythonpath = os.environ.get('PYTHONPATH')
> +	if pythonpath is None:
> +		pythonpath = pympath
> +	else:
> +		pythonpath = pympath + ':' + pythonpath
> +	os.environ['PYTHONPATH'] = pythonpath
> +
> +	with tempfile.NamedTemporaryFile(prefix='catalyst.conf.') as
> conf:
> +		# Set up a config file with paths to the local tree.
> +		conf.write(
> +			('sharedir=%(source_root)s\n'
> +			 'shdir=%(source_root)s/targets\n'
> +			 'envscript=%(source_root)s/etc/catalystrc\n'
> +			 % {'source_root':
> source_root}).encode('utf8')
> +		)
> +		conf.flush()
> +		argv = [
> +			'--config', os.path.join(source_root, 'etc',
> 'catalyst.conf'),
> +			'--config', conf.name,
> +		] + argv
> +
> +		cmd = [os.path.join(source_root, 'bin', 'catalyst')]
> +		pid = os.fork()
> +		if pid == 0:
> +			os.execvp(cmd[0], cmd + argv)
> +		(_pid, status) = os.waitpid(pid, 0)
> +		process.exit_as_status(status)
> +
> +
> +if __name__ == '__main__':
> +	main(sys.argv[1:])


huh, first time I looked at it, I missed seeing you were loading both
the main config and the temp config with the needed changes.

Looks good

-- 
Brian Dolbec <dolsen>



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-11-10  6:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-29  5:48 [gentoo-catalyst] [PATCH] catalyst: add a wrapper for executing directly out of git Mike Frysinger
  -- strict thread matches above, loose matches on Subject: below --
2015-11-09 21:05 Mike Frysinger
2015-11-09 21:23 ` Mike Frysinger
2015-11-10  6:53 ` Brian Dolbec

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox