moksha.spec | 1
moksha/commands/cli.py | 81 ++++++++++++++++++++++++++++++++++++++++++++++
moksha/lib/paver_tasks.py | 26 +++++++++++---
setup.py | 1
4 files changed, 104 insertions(+), 5 deletions(-)
New commits:
commit b0a6bf9e8c039d17983a0abbad68a87e7d05f8a9
Author: Luke Macken <lmacken(a)redhat.com>
Date: Sun Sep 12 00:38:11 2010 -0400
Get the appropriate RPM top dir from rpm instead of guessing
diff --git a/moksha/lib/paver_tasks.py b/moksha/lib/paver_tasks.py
index ff7c6cc..1a0213c 100644
--- a/moksha/lib/paver_tasks.py
+++ b/moksha/lib/paver_tasks.py
@@ -1,6 +1,10 @@
import os
from paver.easy import *
+def rpm_topdir():
+ """ Return the RPM top dir """
+ return sh("rpm --eval='%{_topdir}'", capture=True).strip()
+
@task
def rpm():
specfile = '%s.spec' % options.rpm_name
@@ -53,17 +57,29 @@ paver install -O1 --skip-build --root %%{buildroot} --record INSTALLED_FILES
'url': options.url, 'rpm_name': options.rpm_name})
spec_file.close()
+ topdir = rpm_topdir()
+ if not topdir:
+ print "Error: No RPM build directory found. Try installing the "
+ print "fedora-packager package and running `rpmdev-setuptree`?"
+ sys.exit(-1)
+
sh('paver sdist --format=bztar')
- sh('mv dist/* ~/rpmbuild/SOURCES/')
- sh('cp %s.spec ~/rpmbuild/SPECS/' % options.rpm_name)
- sh('rpmbuild -ba ~/rpmbuild/SPECS/%s.spec' % options.rpm_name)
+ sh('mv dist/* %s/SOURCES/' % topdir)
+ sh('cp %s.spec %s/SPECS/' % (options.rpm_name, topdir))
+ sh('rpmbuild -ba %s/SPECS/%s.spec' % (topdir, options.rpm_name))
@task
@needs(['rpm'])
def reinstall():
+ topdir = rpm_topdir()
+ if not topdir:
+ print "Error: No RPM build directory found. Try installing the "
+ print "fedora-packager package and running `rpmdev-setuptree`?"
+ sys.exit(-1)
+
sh('sudo rpm -e %s' % options.rpm_name, ignore_error=True)
- sh('sudo rpm -ivh ~/rpmbuild/RPMS/noarch/%s-%s-%s.*noarch.rpm' % (
- options.rpm_name, options.version, options.release))
+ sh('sudo rpm -ivh %s/RPMS/noarch/%s-%s-%s.*noarch.rpm' % (
+ topdir, options.rpm_name, options.version, options.release))
@task
@needs('setuptools.command.install')
commit 90fc06ad7ad14a68060d902c84bcd597447274fa
Author: Luke Macken <lmacken(a)redhat.com>
Date: Sun Sep 12 00:37:40 2010 -0400
Add the beginning of a `moksha` command-line tool.
Currently, only `moksha start` is implemented.
diff --git a/moksha.spec b/moksha.spec
index aa13e45..67c6fe5 100644
--- a/moksha.spec
+++ b/moksha.spec
@@ -127,6 +127,7 @@ restorecon -Rv /var/cache/moksha
%files
%defattr(-,root,root,-)
%doc README AUTHORS LICENSE COPYING
+%{_bindir}/moksha
%{python_sitelib}/%{name}/
%{python_sitelib}/%{name}-%{version}-py%{pyver}.egg-info/
%attr(-,apache,apache) %dir %{_localstatedir}/lib/%{name}
diff --git a/moksha/commands/cli.py b/moksha/commands/cli.py
new file mode 100644
index 0000000..23b3a1f
--- /dev/null
+++ b/moksha/commands/cli.py
@@ -0,0 +1,81 @@
+#!/usr/bin/env python
+""" The Moksha Command-line Interface """
+
+import os
+import sys
+import signal
+
+from subprocess import Popen, PIPE
+from twisted.internet import protocol
+from twisted.internet import reactor
+
+pids = []
+
+class MokshaProcessProtocol(protocol.ProcessProtocol):
+ def __init__(self, name):
+ self.name = name
+ def connectionMade(self):
+ pass
+ def outReceived(self, data):
+ sys.stdout.write(data)
+ def errReceived(self, data):
+ sys.stderr.write(data)
+ def inConnectionLost(self):
+ pass
+ def outConnectionLost(self):
+ pass
+ def errConnectionLost(self):
+ pass
+ def processEnded(self, status_object):
+ print "Process %r quit with status %d" % (
+ self.name, status_object.value.exitCode)
+ reactor.stop()
+ for pid in pids:
+ try:
+ os.kill(pid, signal.SIGTERM)
+ except OSError:
+ pass
+
+
+class MokshaCLI(object):
+
+ def _exec(self, process, *args, **kw):
+ args = args and [process] + list(args) or [process]
+ print "Running %s %s" % (process, ' '.join(args))
+ pp = MokshaProcessProtocol(name=process)
+ orbited = reactor.spawnProcess(pp, process, args, **kw)
+ pids.append(orbited.pid)
+
+ def start(self):
+ """ Start all of the Moksha components """
+ # Try to import moksha. If you can, move on.
+ # If not, setup a virtualenv if one doesn't already exist
+
+ self._exec('orbited')
+ self._exec('paster', 'serve', 'development.ini')
+ self._exec('moksha-hub')
+
+ def list(self):
+ """ List all available apps, widgets, producers and consumers """
+
+ def install(self):
+ """ Install a Moksha component """
+
+ def uninstall(self):
+ """ Uninstall a Moksha component """
+
+ def quickstart(self):
+ """ Create a new Moksha component """
+ # If no arguments given, run `paster moksha --help`
+
+
+def main():
+ moksha = MokshaCLI()
+ if sys.argv[1] == 'start':
+ print "Starting Moksha..."
+ moksha.start()
+ try:
+ reactor.run()
+ except Exception, e:
+ print "Caught exception: %s" % str(e)
+ moksha.stop()
diff --git a/setup.py b/setup.py
index e4b6e94..8d474ef 100644
--- a/setup.py
+++ b/setup.py
@@ -70,6 +70,7 @@ setup(
entry_points="""
[console_scripts]
moksha-hub = moksha.hub.hub:main
+ moksha = moksha.commands.cli:main
[paste.app_factory]
main = moksha.config.middleware:make_app