1. Miki Tebeka
  2. canvas2dot

Commits

Miki Tebeka  committed 12e897d

starting

  • Participants
  • Branches default

Comments (0)

Files changed (8)

File .hgignore

View file
  • Ignore whitespace
+syntax: glob
+
+dots/*.png

File canvas2dot.py

View file
  • Ignore whitespace
+from itertools import tee, izip
+
+__version__ = '0.1.0'
+
+
+# http://docs.python.org/2/library/itertools.html#recipes
+def pairwise(iterable):
+    's -> (s0,s1), (s1,s2), (s2, s3), ...'
+    a, b = tee(iterable)
+    next(b, None)
+    return izip(a, b)
+
+
+def chain2dot(chn, fo):
+    for head, tail in pairwise(reversed(chn.tasks)):
+        fo.write('{} -> {}'.format(head.task, tail.task))
+
+
+def chord2dot(chrd, fo):
+    tail = chrd.body.task
+    fo.write('subgraph {

File dots/Makefile

View file
  • Ignore whitespace
+%.png : %.dot
+	dot -Tpng -o $@ $<
+
+
+dots = $(wildcard *.dot)
+png=$(dots:.dot=.png)
+
+all: $(png)
+
+clean:
+	rm -f $(png)

File dots/chain.dot

View file
  • Ignore whitespace
+digraph G {
+    add -> mul;
+    mul -> div;
+}

File dots/chord.dot

View file
  • Ignore whitespace
+digraph G {
+    subgraph cluster_1 {
+        color=blue;
+        mul;
+        add;
+    }
+
+    mul -> div;
+    add -> div;
+}

File dots/x.dot

View file
  • Ignore whitespace
+digraph G {
+
+/*
+	subgraph cluster_0 {
+		style=filled;
+		color=lightgrey;
+		node [style=filled,color=white];
+		a0 -> a1 -> a2 -> a3;
+		label = "process #1";
+	}
+*/
+
+	subgraph cluster_1 {
+//		node [style=filled];
+		b0 -> b1 -> b2 -> b3;
+//		label = "process #2";
+		color=blue
+	}
+	start -> a0;
+	start -> b0;
+	a1 -> b3;
+	b2 -> a3;
+	a3 -> a0;
+	a3 -> end;
+	b3 -> end;
+
+	start [shape=Mdiamond];
+	end [shape=Msquare];
+}

File setup.py

View file
  • Ignore whitespace
+from setuptools import setup
+import canvas2dot
+
+setup(
+    name='canvas2dot',
+    version=canvas2dot.__version__,
+    description='Celery canvas object to dot files',
+    author='Miki Tebeka',
+    author_email='miki.tebeka@gmail.com',
+    license='MIT',
+    url='https://bitbucket.org/tebeka/canvas2dot',
+    py_modules=['canvas2dot'],
+    classifiers=[
+        'Development Status :: 4 - Beta',
+        'Intended Audience :: Developers',
+        'License :: OSI Approved :: MIT License',
+        'Programming Language :: Python',
+        'Programming Language :: Python :: 2',
+        'Topic :: Software Development :: Libraries',
+        'Topic :: Software Development :: Libraries :: Python Modules',
+    ],
+    install_requires=['celery'],
+)

File test_canvas2dot.py

View file
  • Ignore whitespace
+from celery import Celery, chain
+celery = Celery()
+
+@celery.task
+def add(x, y):
+    return x + y
+
+
+@celery.task
+def mul(x, y):
+    return x + y
+
+
+def test_chain():
+    chn = chain(add.s(4, 4), mul.s(5))