Skip to content
Browse files

Add tac template and tac.py

  • Loading branch information...
1 parent fee770c commit 492731ae3a5e6700ba9b85f02810789f76f6fb08 @iffy committed Jul 24, 2012
Showing with 74 additions and 0 deletions.
  1. +1 −0 MANIFEST.in
  2. +23 −0 grace/grace.tac
  3. +19 −0 grace/tac.py
  4. +28 −0 grace/test/test_tac.py
  5. +3 −0 setup.py
View
1 MANIFEST.in
@@ -0,0 +1 @@
+include grace/grace.tac
View
23 grace/grace.tac
@@ -0,0 +1,23 @@
+from twisted.application import service, strports
+from twisted.python.filepath import FilePath
+
+application = service.Application('grace')
+
+d = FilePath(__file__).parent()
+
+#------------------------------------------------------------------------------
+# control
+#------------------------------------------------------------------------------
+from grace.plumbing import Plumber
+plumber = Plumber()
+
+from grace.control import ServerFactory
+control_factory = ServerFactory(plumber)
+control_ep = 'unix:'+d.child('grace.socket').path
+control_service = strports.service(control_ep, control_factory)
+control_service.setServiceParent(application)
+
+#------------------------------------------------------------------------------
+# Pipes
+#------------------------------------------------------------------------------
+# plumber.addPipe(src, dst)
View
19 grace/tac.py
@@ -0,0 +1,19 @@
+from twisted.python.filepath import FilePath
+
+grace_root = FilePath(__file__).parent()
+tac_template = grace_root.child('grace.tac')
+
+
+def getTac(pipedef=None):
+ """
+ Get the content of a tac file.
+
+ @param pipedef: (optional) a tuple of strings that will be expanded and
+ passed to L{grace.plumbing.Plumber.addPipe} in the tac file.
+
+ @return: A string suitable for use as the contents of a tac file.
+ """
+ template = tac_template.getContent()
+ if pipedef:
+ template += '\nplumber.addPipe(%r, %r)\n' % pipedef
+ return template
View
28 grace/test/test_tac.py
@@ -0,0 +1,28 @@
+from twisted.trial.unittest import TestCase
+from twisted.python.filepath import FilePath
+
+grace_root = FilePath(__file__).parent().parent()
+tac_template = grace_root.child('grace.tac')
+
+from grace.tac import getTac
+
+
+class getTacTest(TestCase):
+
+
+ def test_nopipes(self):
+ """
+ You can get the tacfile without any extra Pipes.
+ """
+ s = getTac()
+ self.assertEqual(s, tac_template.getContent())
+
+
+ def test_onepipe(self):
+ """
+ You can add a pipe to the tac file
+ """
+ s = getTac(('src', 'dst'))
+ expected = tac_template.getContent()
+ expected += "\nplumber.addPipe('src', 'dst')\n"
+ self.assertEqual(s, expected)
View
3 setup.py
@@ -9,6 +9,9 @@
packages=[
'grace', 'grace.test',
],
+ package_data={
+ 'grace': ['grace.tac'],
+ },
install_requires=[
'Twisted>=10.2.0',
],

0 comments on commit 492731a

Please sign in to comment.
Something went wrong with that request. Please try again.