<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>No Huddle Offense</title>
	<atom:link href="http://www.nohuddleoffense.de/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.nohuddleoffense.de</link>
	<description>&#34;Individual commitment to a group effort-that is what makes a team work, a company work, a society work, a civilization work.&#34;</description>
	<lastBuildDate>Sat, 04 Feb 2012 06:55:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Fun with OpenShift</title>
		<link>http://www.nohuddleoffense.de/2012/02/03/fun-with-openshift/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=fun-with-openshift</link>
		<comments>http://www.nohuddleoffense.de/2012/02/03/fun-with-openshift/#comments</comments>
		<pubDate>Fri, 03 Feb 2012 19:57:04 +0000</pubDate>
		<dc:creator>coach</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[OCCI]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.nohuddleoffense.de/?p=844</guid>
		<description><![CDATA[I&#8217;ve been playing around with OpenShift for the past hour. More specifically OpenShift Express which allows you to quickly develop apps Java, Ruby, PHP, Perl and Python and run them in the &#8216;Cloud&#8217;. As a first exercise I wanted to check that I was able to get a simple Task board up and running. A [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been playing around with <a href="https://openshift.redhat.com/">OpenShift</a> for the past hour. More specifically OpenShift Express which allows you to quickly develop apps Java, Ruby, PHP, Perl and Python and run them in the &#8216;Cloud&#8217;.</p>
<p>As a first exercise I wanted to check that I was able to get a simple Task board up and running. A good tutorial to create such a simple application with <a href="http://docs.pylonsproject.org/projects/pyramid_tutorials/en/latest/index.html">Pyramid</a> can be found <a href="http://docs.pylonsproject.org/projects/pyramid_tutorials/en/latest/single_file_tasks/single_file_tasks.html">here</a>.</p>
<p>After signing into OpenShift you can create a new application in the dashboard. Make sure that before doing so you have your <em>namespace</em> setup and your <em>public ssh</em> key configured in OpenShift. After creating the application a <a href="http://git-scm.com/">git</a> repository is created for you. Simple clone this so you have a local working copy on your machine.</p>
<p>Now have a look inside you local working copy. You will find the directories <em>data</em>, <em>libs</em>, <em>wsgi</em> and some files like a <em>README</em> and the python setuptools related <em>setup.py</em>. Let&#8217;s start with editing the <em>setup.py</em> file:</p>
<pre class="brush: python; title: ; notranslate">
from setuptools import setup

setup(name='A simple TODO Application to test OpenShift Features.',
      version='1.0',
      description='An OpenShift App',
      author='Thijs Metsch',
      author_email='thijs.metsch@opensolaris.org',
      install_requires=['pyramid'],
      classifiers=[
                     'Operating System :: OS Independent',
                     'Programming Language :: Python',
                    ],
     )
</pre>
<p>Please note the install_required parameter. Using this parameter will ensure that during deployment of you app the necessary requirements get installed &#8211; in this case Pyramid.</p>
<p>The following steps are pretty straight forward. The file application in the <em>wsgi</em> directory is as the name states a simple <a href="http://www.wsgi.org">WSGI</a> app. What we need to do is edit this file and let it call the todo app:</p>
<pre class="brush: python; title: ; notranslate">
#!/usr/bin/python

import os

virtenv = os.environ['APPDIR'] + '/virtenv/'
os.environ['PYTHON_EGG_CACHE'] = os.path.join(virtenv, 'lib/python2.6/site-packages')
virtualenv = os.path.join(virtenv, 'bin/activate_this.py')
try:
    execfile(virtualenv, dict(__file__=virtualenv))
except IOError:
    pass

from todo import application
</pre>
<p>Please note that the file has no &#8216;.py&#8217; extension. </p>
<p>Now we are ready to create the finally application. Please have a look at this <a href="http://docs.pylonsproject.org/projects/pyramid_tutorials/en/latest/single_file_tasks/single_file_tasks.html">tutorial</a> as the code will almost be identical.</p>
<p>Create a file todo.py and follow the tutorial as described. Make sure you application runs locally. Put the &#8216;*.mako&#8217; files in the subdirectory <em>static </em>under the <em>wsgi </em>directory. You can place the schema.sql file in the data directory. We will be using a sqlite database which will also be place in there.</p>
<p>The final step is to alter the <em>todo.py</em> file and remove the <em>__main__</em> part. Instead we will introduce the following application function:</p>
<pre class="brush: python; title: ; notranslate">
here = os.environ['OPENSHIFT_APP_DIR']

def application(environ, start_response):
    '''
    A WSGI application.

    Configure pyramid, add routes and finally serve the app.

    environ -- the environment.
    start_response -- the response object.
    '''
    settings = {}
    settings['reload_all'] = True
    settings['debug_all'] = True
    settings['mako.directories'] = os.path.join(here, 'static')
    settings['db'] = os.path.join(here, '..', 'data', 'tasks.db')

    session_factory = UnencryptedCookieSessionFactoryConfig('itsaseekreet')

    config = Configurator(settings=settings, session_factory=session_factory)

    config.add_route('list', '/')
    config.add_route('new', '/new')
    config.add_route('close', '/close/{id}')

    config.add_static_view('static', os.path.join(here, 'static'))

    config.scan()

    return config.make_wsgi_app()(environ, start_response)
</pre>
<p>When done we can push the code to the repository. When done you can visit you application at the given URL.</p>
<p>With this I&#8217;ve been able to create the app <a href="http://todo-sample.rhcloud.com/">http://todo-sample.rhcloud.com/</a> and I also deployed my <a href="http://www.occi-wg.org">OCCI</a> example service: <a href="http://occi-sample.rhcloud.com/">http://occi-sample.rhcloud.com/</a>. As you can see pretty straight forward &#038; fast and of course fun!</p>
<p>What would be fun is to create a simple unittesting framework for OpenShift. For now you can find the code pieces at <a href="https://github.com/tmetsch/openshift-todo">github</a>. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.nohuddleoffense.de/2012/02/03/fun-with-openshift/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Forget static callgraphs &#8211; Use Python &amp; DTrace!</title>
		<link>http://www.nohuddleoffense.de/2011/10/20/forget-static-callgraphs-use-dtrace/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=forget-static-callgraphs-use-dtrace</link>
		<comments>http://www.nohuddleoffense.de/2011/10/20/forget-static-callgraphs-use-dtrace/#comments</comments>
		<pubDate>Thu, 20 Oct 2011 09:11:00 +0000</pubDate>
		<dc:creator>coach</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[DTrace]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.nohuddleoffense.de/?p=826</guid>
		<description><![CDATA[Forget about static analyzed callgrahs! No more running the code closing it and then looking at the callgraph. With DTrace you can attach yourself to any (running) process on the (running/production) system and get life up to date information about what the programm is doing. No need to restart the application or anything. This works [...]]]></description>
			<content:encoded><![CDATA[<p>Forget about static analyzed callgrahs! No more running the code closing it and then looking at the callgraph. With <a href="http://www.dtrace.org">DTrace</a> you can attach yourself to any (running) process on the (running/production) system and get life up to date information about what the programm is doing. No need to restart the application or anything. This works for most programming languages which have DTrace providers (like C, Java and Python <img src='http://www.nohuddleoffense.de/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> ). All you need to know is the pid.</p>
<p>Based on the information you get from DTrace (using the <a href="http://www.nohuddleoffense.de/2011/10/07/python-as-a-dtrace-consumer-using-libdtrace/" title="Python as a DTrace consumer using libdtrace">Python consumer</a>) you can draw life updating callgraphs of what is currently happening in the program. Not only is it possible to look at the callgraph but you can also look at the time it took to reach a certain piece of code to analyze bottle necks and the flow of the program:</p>
<pre class="brush: bash; title: ; notranslate">
$ pgrep python # get the pid of the process you want to trace
123456
$ ./callgraph.py 123456 # trace the program and create a callgraph
</pre>
<p>So if you would have the following Python code:</p>
<pre class="brush: python; title: ; notranslate">
class A(object):

    def sayHello(self):
        return 'I am A'

class B(object):

    def __init__(self):
        self.a = A()

    def sayHello(self):
        return self.a.sayHello()

if __name__ == '__main__':
    print B().sayHello()
</pre>
<p>You would get the following life generated callgraph &#8211; the GUI can start, stop and restart tracing and get live updates as the DTrace probes fires:</p>
<div id="attachment_840" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.nohuddleoffense.de/wp-content/uploads/2011/10/Screenshot-Python-DTrace-Call-graph-1.png"><img src="http://www.nohuddleoffense.de/wp-content/uploads/2011/10/Screenshot-Python-DTrace-Call-graph-1-300x120.png" alt="" title="Screenshot-Python DTrace - Call graph-1" width="300" height="120" class="size-medium wp-image-840" /></a><p class="wp-caption-text">Click to enlarge</p></div>
<p>The following screenshot was taken while looking into the printer manager:</p>
<div id="attachment_841" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.nohuddleoffense.de/wp-content/uploads/2011/10/Screenshot-Python-DTrace-Call-graph-2.png"><img src="http://www.nohuddleoffense.de/wp-content/uploads/2011/10/Screenshot-Python-DTrace-Call-graph-2-300x295.png" alt="" title="Screenshot-Python DTrace - Call graph-2" width="300" height="295" class="size-medium wp-image-841" /></a><p class="wp-caption-text">Click to enlarge</p></div>
<p>DTrace for the win!</p>
<p>[Updated] Updated the screenshots.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nohuddleoffense.de/2011/10/20/forget-static-callgraphs-use-dtrace/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python traces Python using DTrace</title>
		<link>http://www.nohuddleoffense.de/2011/10/19/python-traces-python-using-dtrace/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=python-traces-python-using-dtrace</link>
		<comments>http://www.nohuddleoffense.de/2011/10/19/python-traces-python-using-dtrace/#comments</comments>
		<pubDate>Wed, 19 Oct 2011 10:16:20 +0000</pubDate>
		<dc:creator>coach</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[DTrace]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.nohuddleoffense.de/?p=815</guid>
		<description><![CDATA[Another example of how to use Python as a DTrace consumer. This little program traces a Python program while is runs and shows you the flow of the code. The output is displayed in a Treeview (An indent mean that python called another function &#8211; Stepping back means that the function returned) and when double [...]]]></description>
			<content:encoded><![CDATA[<p>Another example of how to use <a title="Python as a DTrace consumer using libdtrace" href="http://www.nohuddleoffense.de/2011/10/07/python-as-a-dtrace-consumer-using-libdtrace/">Python as a DTrace consumer</a>. This little program traces a Python program while is runs and shows you the flow of the code. The output is displayed in a Treeview (An indent mean that python called another function &#8211; Stepping back means that the function returned) and when double clicking the source code is displayed (Would be nice to open <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=305336">pydev</a> as well).</p>
<div id="attachment_816" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.nohuddleoffense.de/wp-content/uploads/2011/10/Screenshot-Python-Flow-Tracer.png"><img class="size-medium wp-image-816" title="Screenshot-Python Flow Tracer" src="http://www.nohuddleoffense.de/wp-content/uploads/2011/10/Screenshot-Python-Flow-Tracer-300x165.png" alt="" width="300" height="165" /></a><p class="wp-caption-text">Click to enlarge</p></div>
<p>Another example of Python as a DTrace consumer: This small GUI gives an up to date view of the number of syscalls made by an executable. Since this GUI is a live up to date view you can watch the circles appear, grow and become smaller again <img src='http://www.nohuddleoffense.de/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<div id="attachment_820" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.nohuddleoffense.de/wp-content/uploads/2011/10/screenshot.png"><img class="size-medium wp-image-820" title="screenshot" src="http://www.nohuddleoffense.de/wp-content/uploads/2011/10/screenshot-300x197.png" alt="" width="300" height="197" /></a><p class="wp-caption-text">Click to enlarge</p></div>
<p style="text-align: center;">
<p>Now on to other things&#8230;maybe creating live animated callgraphs as your program runs? <img src='http://www.nohuddleoffense.de/wp-includes/images/smilies/icon_razz.gif' alt=':-P' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.nohuddleoffense.de/2011/10/19/python-traces-python-using-dtrace/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python as a DTrace consumer &#8211; Part 2 walk the aggregate</title>
		<link>http://www.nohuddleoffense.de/2011/10/08/python-as-a-dtrace-consumer-part-2-walk-the-aggregate/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=python-as-a-dtrace-consumer-part-2-walk-the-aggregate</link>
		<comments>http://www.nohuddleoffense.de/2011/10/08/python-as-a-dtrace-consumer-part-2-walk-the-aggregate/#comments</comments>
		<pubDate>Sat, 08 Oct 2011 13:12:34 +0000</pubDate>
		<dc:creator>coach</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[DTrace]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.nohuddleoffense.de/?p=805</guid>
		<description><![CDATA[Yesterday I blogged about how to use Python as a DTrace consumer with the help of ctypes. The examples in there are very rudimentary and only captured the normal output of DTrace &#8211; not the aggregates. The examples in the last post have been altered and now we let DTrace work for a few seconds [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I <a href="http://www.nohuddleoffense.de/2011/10/07/python-as-a-dtrace-consumer-using-libdtrace/" title="Python as a DTrace consumer using libdtrace">blogged</a> about how to use Python as a DTrace consumer with the help of ctypes. The examples in there are very rudimentary and only captured the normal output of DTrace &#8211; not the aggregates. </p>
<p>The examples in the last post have been altered and now we let DTrace work for a few seconds and then walk the aggregate:</p>
<pre class="brush: python; title: ; notranslate">
    # aggregate data for a few sec...
    i = 0
    chew = CHEW_FUNC(chew_func)
    chew_rec = CHEWREC_FUNC(chewrec_func)
    while i &lt; 2:
        LIBRARY.dtrace_sleep(handle)
        LIBRARY.dtrace_work(handle, None, chew, chew_rec, None)

        time.sleep(1)
        i += 1

    LIBRARY.dtrace_stop(handle)

    walk_func = WALK_FUNC(walk)
    # sorting instead of dtrace_aggregate_walk
    if LIBRARY.dtrace_aggregate_walk_valsorted(handle, walk_func, None) != 0:
        txt = LIBRARY.dtrace_errmsg(handle, LIBRARY.dtrace_errno(handle))
        raise Exception(c_char_p(txt).value)
</pre>
<p>The walk function is right now very simple but does work &#8211; please note the TODO <img src='http://www.nohuddleoffense.de/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<pre class="brush: python; title: ; notranslate">
def walk(data, arg):
    '''
    Aggregate walker.
    '''
    # TODO: pickup the 16 and 272 from offset in dtrace_aggdesc struct...

    tmp = data.contents.dtada_data
    name = cast(tmp + 16, c_char_p).value
    instance = deref(tmp + 272, c_int).value

    print '+--&gt; walking', name, instance

    return 0
</pre>
<p>When run the Python script will output (Would be fun to run <a href="http://www.nohuddleoffense.de/2011/07/01/python-and-dtrace/" title="Python &#038; DTrace">this DTrace script</a> with the help of Python &#8211; Python as a DTrace consumer tracing Python as DTrace provider <img src='http://www.nohuddleoffense.de/wp-includes/images/smilies/icon_razz.gif' alt=':-P' class='wp-smiley' /> ):</p>
<pre class="brush: bash; title: ; notranslate">
./dtrace.py
+--&gt; In chew: cpu : 0
  +--&gt; In out:  Hello World
+--&gt; walking updatemanagernot 2
+--&gt; walking mixer_applet2 4
+--&gt; walking gnome-netstatus- 135
+--&gt; walking firefox-bin 139
+--&gt; walking gnome-terminal 299
+--&gt; walking python2.7 545
Error 0
</pre>
<p>Overall this works pretty smoothly &#8211; but needs a lot of updating before it is production ready &#8211; Still it gives an rough overview that Python can be a simple DTrace consumer while using ctypes. So now Python can be consumer and provider for DTrace *happy days* <img src='http://www.nohuddleoffense.de/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>The code (examples) have been updated on <a href="https://github.com/tmetsch/python-dtrace">github</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nohuddleoffense.de/2011/10/08/python-as-a-dtrace-consumer-part-2-walk-the-aggregate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python as a DTrace consumer using libdtrace</title>
		<link>http://www.nohuddleoffense.de/2011/10/07/python-as-a-dtrace-consumer-using-libdtrace/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=python-as-a-dtrace-consumer-using-libdtrace</link>
		<comments>http://www.nohuddleoffense.de/2011/10/07/python-as-a-dtrace-consumer-using-libdtrace/#comments</comments>
		<pubDate>Fri, 07 Oct 2011 11:23:33 +0000</pubDate>
		<dc:creator>coach</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[DTrace]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.nohuddleoffense.de/?p=775</guid>
		<description><![CDATA[So DTrace is awesome &#8211; You can create nice analytics with it like Joyent does. But what I wanted is to access the output/aggregations from DTrace using Python to be able to parse the output as it comes. Using DTrace to Monitor Python or zones is already easy Doing so it might be able to [...]]]></description>
			<content:encoded><![CDATA[<p>So <a href="http://www.dtrace.org">DTrace</a> is awesome &#8211; You can create nice analytics with it like <a href="http://www.joyentcloud.com">Joyent</a> does. But what I wanted is to access the output/aggregations from DTrace using Python to be able to parse the output as it comes. Using DTrace to Monitor <a title="Python &amp; DTrace" href="http://www.nohuddleoffense.de/2011/07/01/python-and-dtrace/">Python</a> or <a title="OpenIndiana zones &amp; DTrace" href="http://www.nohuddleoffense.de/2011/07/06/openindiana-zones-dtrace/">zones</a> is already easy <img src='http://www.nohuddleoffense.de/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  Doing so it might be able to express up to date information to a (Cloud)Client (using of course sth. like <a href="http://www.occi-wg.org">OCCI</a>)</p>
<p>So all I need is a Python based DTrace consumer which uses the dtrace library. To start with let&#8217;s reading the comments in the file <em>/usr/include/dtrace.h</em> &#8211; most notable is:</p>
<blockquote><p>Note: The contents of this file are private to the implementation of the Solaris system and DTrace subsystem and are subject to change at any time without notice.</p></blockquote>
<p>So we are already on our own &#8211; Next to that there is very limited documentation on writing DTrace consumers. A few quick searches might help you find some information. Probably the most up to date is to look into Bryan Cantrill&#8217;s consumer for node.js: <a href="https://github.com/bcantrill/node-libdtrace">https://github.com/bcantrill/node-libdtrace</a>. And as mentioned a Python based consumer for libdtrace should be the goal of all this &#8211; so peeking to how others do it is probably a good idea <img src='http://www.nohuddleoffense.de/wp-includes/images/smilies/icon_razz.gif' alt=':-P' class='wp-smiley' /> . For now let we will focus on a simple <strong>Hello World</strong> example.</p>
<p>First we need to understand how to use <em>libdtrace</em> &#8211; So let&#8217;s take a look at this diagram:</p>
<div id="attachment_782" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.nohuddleoffense.de/wp-content/uploads/2011/10/drace_life_cycle.jpg"><img class="size-medium wp-image-782" title="drace_life_cycle" src="http://www.nohuddleoffense.de/wp-content/uploads/2011/10/drace_life_cycle-300x252.jpg" alt="" width="300" height="252" /></a><p class="wp-caption-text">Source: http://www.macosinternals.com/images/stories/DTrace/drace_life_cycle.jpg</p></div>
<p>Following this life-cycle we can easily create some <a href="https://github.com/tmetsch/python-dtrace/blob/master/attic/main.c">C code</a> which will interface nicely with <em>libdtrace</em>. But since we can use it in C we can also use <a href="http://www.python.org">Python</a> and <a href="http://docs.python.org/library/ctypes.html">ctypes</a> to access the library. Here it is where we start the fun part.</p>
<p>To start with we will try to execute the following D script. It does nothing more than printing <strong>Hello World</strong> when executed using the dtrace command. But the output of this trace should now be received in Python code &#8211; so the output could be evaluated later on:</p>
<pre class="brush: bash; title: ; notranslate">
dtrace:::BEGIN {trace(&quot;Hello World&quot;);}
</pre>
<p>Now let&#8217;s write some python code &#8211; first we need to wrap some Structures which are defined in the <em>dtrace.h</em> file. Namely we will need <em>dtrace_bufdata</em>, <em>dtrace_probedesc</em>, <em>dtrace_probedata</em> and <em>dtrace_recdesc</em>. Since this is a blog post please refer to the source code at <a href="https://github.com/tmetsch/python-dtrace">github</a> for more details. We also need to define some types for callback functions &#8211; since we need a <em>buffered</em> writer, <em>chew</em> and <em>chewrec</em> functions as shown in the previous diagram:</p>
<pre class="brush: python; title: ; notranslate">
CHEW_FUNC = CFUNCTYPE(c_int,
                      POINTER(dtrace_probedata),
                      POINTER(c_void_p))
CHEWREC_FUNC = CFUNCTYPE(c_int,
                         POINTER(dtrace_probedata),
                         POINTER(dtrace_recdesc),
                         POINTER(c_void_p))
BUFFERED_FUNC = CFUNCTYPE(c_int,
                          POINTER(dtrace_bufdata),
                          POINTER(c_void_p))

def chew_func(data, arg):
    '''
    Callback for chew.
    '''
    print 'cpu :', c_int(data.contents.dtpda_cpu).value
    return 0

def chewrec_func(data, rec, arg):
    '''
    Callback for record chewing.
    '''
    if rec == None:
        return 1
    return 0

def buffered(bufdata, arg):
    '''
    In case dtrace_work is given None as filename - this one is called.
    '''
    print c_char_p(bufdata.contents.dtbda_buffered).value.strip()
    return 0
</pre>
<p>The function called <em>buffered</em> will eventually write the <strong>Hello World</strong> string later on &#8211; The <em>chew</em> function will print out the CPU id.</p>
<p>With the basic stuff available new can load the libdtrace library and start doing some magic with it:</p>
<pre class="brush: python; title: ; notranslate">
cdll.LoadLibrary(&quot;libdtrace.so&quot;)

LIBRARY = CDLL(&quot;libdtrace.so&quot;)
</pre>
<p>Now all there is left to do is follow the steps described in the diagram. First step is to get an <em>handle</em> an set some options:</p>
<pre class="brush: python; title: ; notranslate">
    # get dtrace handle
    handle = LIBRARY.dtrace_open(3, 0, byref(c_int(0)))

    # options
    if LIBRARY.dtrace_setopt(handle, &quot;bufsize&quot;, &quot;4m&quot;) != 0:
        txt = LIBRARY.dtrace_errmsg(handle, LIBRARY.dtrace_errno(handle))
        raise Exception(c_char_p(txt).value)
</pre>
<p>Setting the <em>bufsize</em> option is important &#8211; otherwise DTrace will report an error. Now we&#8217;ll register the buffered function which we wrote in Python and for which we have a <em>ctypes</em> type:</p>
<pre class="brush: python; title: ; notranslate">
    buf_func = BUFFERED_FUNC(buffered)
    LIBRARY.dtrace_handle_buffered(handle, buf_func, None)
</pre>
<p>Now we will compile the D script and run it:</p>
<pre class="brush: python; title: ; notranslate">
    prg = LIBRARY.dtrace_program_strcompile(handle, SCRIPT, 3, 4, 0, None)

    # run
    LIBRARY.dtrace_program_exec(handle, prg, None)
    LIBRARY.dtrace_go(handle)
    LIBRARY.dtrace_stop(handle)
</pre>
<p>If this exists correctly (The C file in the github repository has all the checks for the return codes in it) we can try to get the <strong>Hello World</strong>. The <em>chew</em> and <em>chewrec</em> functions are also implemented in Python and can now be registered.</p>
<p>If the second argument on the <em>dtrace_work</em> function is <strong>None</strong> DTrace will automatically use the buffered callback function described two steps ago. Otherwise a filename needs to be provided &#8211; but we wanted to get the <strong>Hello World</strong> into our Python code:</p>
<pre class="brush: python; title: ; notranslate">
    # do work
    LIBRARY.dtrace_sleep(handle)
    chew = CHEW_FUNC(chew_func)
    chew_rec = CHEWREC_FUNC(chewrec_func)
    LIBRARY.dtrace_work(handle, None, chew, chew_rec, None)
</pre>
<p>And last but not least we will print out any errors close the handle on DTrace:</p>
<pre class="brush: python; title: ; notranslate">
    # Get errors if any...
    txt = LIBRARY.dtrace_errmsg(handle, LIBRARY.dtrace_errno(handle))
    print c_char_p(txt).value

    # Last: close handle!
    LIBRARY.dtrace_close(handle)
</pre>
<p>Now this all isn&#8217;t perfect and not ready at all (especially the naming of functions could be updated, a nice abstraction layer be added, etc) &#8211; but it should give a nice overview of how to write DTrace consumers. And for the simple example here both the C and Python code at the previously mentioned <a href="https://github.com/tmetsch/python-dtrace">github</a> repository do seem to work &#8211; and do in fact output:</p>
<pre class="brush: bash; title: ; notranslate">
cpu : 0
Hello World
Error 0
</pre>
<p>So maybe it&#8217;s time to combine <a href="http://pyssf.sf.net">pyssf</a> (an OCCI implementation), <a href="https://github.com/tmetsch/pyzone">pyzone</a> (Manage zones using Python) and <a href="https://github.com/tmetsch/python-dtrace">python-dtrace</a> for monitoring and create a nice &#8216;dependable&#8217; (Not my idea &#8211; these are the words of <a href="http://andy.edmonds.be">Andy</a>) <a title="The Power of Python &amp; Solaris" href="http://www.nohuddleoffense.de/2011/06/16/the-power-of-python-solaris/">something</a>&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nohuddleoffense.de/2011/10/07/python-as-a-dtrace-consumer-using-libdtrace/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>OpenIndiana zones &amp; DTrace</title>
		<link>http://www.nohuddleoffense.de/2011/07/06/openindiana-zones-dtrace/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=openindiana-zones-dtrace</link>
		<comments>http://www.nohuddleoffense.de/2011/07/06/openindiana-zones-dtrace/#comments</comments>
		<pubDate>Wed, 06 Jul 2011 08:27:51 +0000</pubDate>
		<dc:creator>coach</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[DTrace]]></category>
		<category><![CDATA[OpenSolaris]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[ZFS]]></category>

		<guid isPermaLink="false">http://www.nohuddleoffense.de/?p=733</guid>
		<description><![CDATA[Let&#8217;s assume we want to create a Solaris zone called foo on an OpenIndiana box. This post will walk you to all the steps necessary to bootstrap and configure the zone, so it&#8217;s ready to use without any user interaction. Also briefly discussed is how to limit the resources a zone can consume. 7 Steps [...]]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s assume we want to create a Solaris zone called <em>foo</em> on an <a href="http://openindiana.org/">OpenIndiana</a> box. This post will walk you to all the steps necessary to bootstrap and configure the zone, so it&#8217;s ready to use without any user interaction. Also briefly discussed is how to limit the resources a zone can consume.</p>
<p>7 Steps are included in this mini tutorial:</p>
<ol>
<li><strong>Step 1</strong> &#8211; Create the zpool for your zones</li>
<li><strong>Step 2</strong> &#8211; Configure the zone</li>
<li><strong>Step 3</strong> &#8211; Sign into the zone</li>
<li><strong>Step 4</strong> &#8211; Delete and unconfigure the zone</li>
<li><strong>Step 5</strong> &#8211; Limit memory</li>
<li><strong>Step 6</strong> &#8211; Use the fair-share scheduler</li>
<li><strong>Step 7</strong> &#8211; Some DTrace fun</li>
</ol>
<p><strong>Step 1</strong> &#8211; Create the zpool for your zones</p>
<p>First a pool is created and mounted to /zones. Deduplication is activated for this pool &amp; a quota is set &#8211; so the zone has a space limit of 10Gb.</p>
<pre class="brush: bash; title: ; notranslate">
zfs create -o compression=on rpool/export/zones
zfs set mountpoint=/zones rpool/export/zones
zfs set dedup=on rpool/export/zones

mkdir /zones/foo
chmod 700 /zones/foo

zfs set quota=10g rpool/export/zones/foo
</pre>
<p><strong>Step 2</strong> &#8211; Configure the zone</p>
<p>A zone will be configured the way that it has the IP 192.168.0.160 (Nope &#8211; DHCP doesn&#8217;t work here <img src='http://www.nohuddleoffense.de/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> ) and uses the physical device rum2. Otherwise the configuration is pretty straight forward. (<strong>TODO</strong>: use crossbow)</p>
<pre class="brush: bash; title: ; notranslate">
zonecfg -z foo &quot;create; set zonepath=/zones/foo; set autoboot=true; \
 add net; set address=192.168.0.160/24; set defrouter=192.168.0.1; set physical=rum2; end; \
 verify; commit&quot;
zoneadm -z foo verify
zoneadm -z foo install
</pre>
<p>Too ensure that when we boot the zone everything is ready to use without any additional setups, a file called <em>sysidcfg</em> is placed in the /etc of the zone. This will make sure that when we boot all necessary parameters like a root password, the network or the keyboard layout are automatically configured. Also the host&#8217;s <em>resolv.conf</em> is copied to the zone (this might not be necessary if you have a properly setup DNS server &#8211; than you can configure that DNS server in the <em>sysidcfg</em> file &#8211; mine does not know the hostname <em>foo</em> so that is why I do it this way) and the <em>nsswitch.conf</em> file is copied so it&#8217;ll use the <em>resolv.conf</em> file. Finally the zone is started&#8230;</p>
<pre class="brush: bash; title: ; notranslate">
echo &quot;
name_service=NONE
network_interface=PRIMARY {hostname=foo
                           default_route=192.168.0.1
                           ip_address=192.168.0.160
                           netmask=255.255.255.0
                           protocol_ipv6=no}
root_password=aajfMKNH1hTm2
security_policy=NONE
terminal=xterms
timezone=CET
timeserver=localhost
keyboard=German
nfs4_domain=dynamic
&quot; &amp;&gt; /zones/foo/root/etc/sysidcfg

cp /etc/resolv.conf /zones/foo/root/etc/
cp /zones/foo/root/etc/nsswitch.dns /zones/foo/root/etc/nsswitch.files

zoneadm -z foo boot
</pre>
<p>To create a password you can use the power of <a href="http://www.python.org">Python</a> &#8211; the old way of copying the passwords from <em>/etc/shadow</em> doesn&#8217;t work on newer Solaris boxes since the value of <em>CRYPT_DEFAULT</em> is set to 5 in the file <em>/etc/security/crypt.conf</em>:</p>
<pre class="brush: python; title: ; notranslate">
python -c &quot;import crypt; print crypt.crypt('password', 'aa')&quot;
</pre>
<p><strong>Step 3</strong> &#8211; Sign into the zone</p>
<p>Now <em>zlogin</em> or <em>ssh</em> can be used to access the zone &#8211; Note that the commands <em>mpstat</em> and <em>prtconf</em> will show that the zone has the same hardware configuration as the host box (<em>zfs list</em> &#8211; will show that disk space is already limited). In the next steps we want to limit those&#8230;</p>
<p><strong>Step 4</strong> &#8211; Delete and unconfigure the zone</p>
<p>First we will delete the zone <em>foo</em> again:</p>
<pre class="brush: bash; title: ; notranslate">
zoneadm -z foo halt
zoneadm -z foo uninstall
zonecfg -z foo delete
</pre>
<p><strong>Step 5</strong> &#8211; Limit memory</p>
<p>Following the steps above just change the configuration of the zone and add the <em>capped-memory</em> option. In this example it&#8217;ll limit the memory available to the zone. When running <em>prtconf</em> it&#8217;ll show that the zone only has 512Mb RAM &#8211; <em>mpstat</em> will still show all CPUs of your host box.</p>
<pre class="brush: bash; title: ; notranslate">
zonecfg -z foo &quot;create; set zonepath=/zones/foo; set autoboot=true; \
 add net; set address=192.168.0.160/24; set defrouter=192.168.0.1; set physical=rum2; end; \
 add capped-memory; set physical=512m; set swap=512m; end; \
 verify; commit&quot;
</pre>
<p><strong>Step 6</strong> &#8211; Using Resource Pools</p>
<p>While using resources pools it is possible to create a resource pool for a zone which only has one CPU assigned. Use the pooladm command to configure a pool called pool1:</p>
<pre class="brush: bash; title: ; notranslate">
poolcfg -c 'create pset pool1_set (uint pset.min=1 ; uint pset.max=1)'
poolcfg -c 'create pool pool1'
poolcfg -c 'associate pool pool1 (pset pool1_set)'

pooladm -c # writes to /etc/pooladm.conf
</pre>
<p>To restore the old pool configuration run &#8216;<em>pooladm -x</em>&#8216; and &#8216;<em>pooladm -s</em>&#8216;</p>
<p>Now just configure the zone to use and associate it with the pool:</p>
<pre class="brush: bash; title: ; notranslate">
zonecfg -z foo &quot;create; set zonepath=/zones/foo; set autoboot=true; \
 set pool=pool1; \
 add net; set address=192.168.0.160/24; set defrouter=192.168.0.1; set physical=rum2; end; \
 add capped-memory; set physical=512m; set swap=512m; end; \
 verify; commit&quot;
</pre>
<p>Running <em>mpstat</em> and <em>prtconf</em> in the zone will show only one CPU and 512Mb RAM.</p>
<p><strong>Step 6</strong> &#8211; Use the fair-share scheduler</p>
<p>Also if you have several zones running in one pool you want to modify the pool to use FSS &#8211; so a more important zone gets privileged shares:</p>
<pre class="brush: bash; title: ; notranslate">
poolcfg -c 'modify pool pool_default (string pool.scheduler=&quot;FSS&quot;)'
pooladm -c
priocntl -s -c FSS -i class TS
priocntl -s -c FSS -i pid 1
</pre>
<p>And during the zone configuration define the <em>rctl</em> option &#8211; This example will give the zone 2 shares:</p>
<pre class="brush: bash; title: ; notranslate">
zonecfg -z foo &quot;create; set zonepath=/zones/foo; set autoboot=true; \
 add net; set address=192.168.0.160/24; set defrouter=192.168.0.1; set physical=rum2; end; \
 add capped-memory; set physical=512m; set swap=512m; end; \
 add rctl; set name=zone.cpu-shares; add value (priv=privileged,limit=2,action=none); end; \
 verify; commit&quot;
</pre>
<p><strong>Step 7</strong> &#8211; Some DTrace fun</p>
<p><a href="http://www.dtrace.org">DTrace</a> can &#8216;look&#8217; into the zones &#8211; For example to let DTrace look at the files which are opened by process within the zone <em>foo</em> you can simply add the predicate &#8216;zonename == &#8220;foo&#8221;&#8216;: </p>
<pre class="brush: bash; title: ; notranslate">
pfexec dtrace -n 'syscall::open*:entry / zonename == &quot;foo&quot; / \
  { printf(&quot;%s %s&quot;,execname,copyinstr(arg0)); }'
</pre>
<p>I was researching this stuff to create a Python module to configure and bootstrap zones so I can monitor the zones &#038; their previously created SLAs. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.nohuddleoffense.de/2011/07/06/openindiana-zones-dtrace/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python &amp; DTrace</title>
		<link>http://www.nohuddleoffense.de/2011/07/01/python-and-dtrace/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=python-and-dtrace</link>
		<comments>http://www.nohuddleoffense.de/2011/07/01/python-and-dtrace/#comments</comments>
		<pubDate>Fri, 01 Jul 2011 13:28:15 +0000</pubDate>
		<dc:creator>coach</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[DTrace]]></category>
		<category><![CDATA[OpenSolaris]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.nohuddleoffense.de/?p=708</guid>
		<description><![CDATA[The following DTrace script can be used to trace Python. It will show you the file, line-number, the time it took to get from the last line to the current one and the (indented) function it is in. This helps understanding the flow of your Python code and can help finding bugs &#038; timing issues. [...]]]></description>
			<content:encoded><![CDATA[<p>
The following <a href="http://www.dtrace.org">DTrace</a> script can be used to trace <a href="http://www.python.org">Python</a>. It will show you the <strong>file</strong>, <strong>line-number</strong>, the <strong>time</strong> it took to get from the last line to the current one and the (indented) <strong>function</strong> it is in. This helps understanding the flow of your Python code and can help finding bugs &#038; timing issues. As a little extra it is setup the way that it only shows the files of your code &#8211; not the once located in <em>/usr/lib/*</em>. This helps with readability and makes the output more dense since the <em>site-packages</em> are left out.
</p>
<p>
I now have this running in the background on a second screen whenever I code python. First screen holds my IDE &#8211; and <a href="http://www.nohuddleoffense.de/2011/02/21/my-software-development-environment-for-python/">next to all the other stuff</a> I do it gives great up-to-date information on the stuff you&#8217;re coding. Again proof for the case that coding Python on <a href="http://www.opensolaris.org">Solaris</a> is a great idea (Also thanks to DTrace). I know this is simple stuff &#8211; but sometimes the simple stuff helps a lot! Now it would only be nice to create a GUI around it <img src='http://www.nohuddleoffense.de/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  First the DTrace script is shown; example output is further below&#8230;
</p>
<pre class="brush: cpp; title: ; notranslate">
#pragma D option quiet

self int depth;
self int last;

dtrace:::BEGIN
{
    printf(&quot;Tracing... Hit Ctrl-C to end.\n&quot;);
    printf(&quot; %-70s %4s %10s : %s %s\n&quot;, &quot;FILE&quot;, &quot;LINE&quot;, &quot;TIME&quot;,
           &quot;FUNCTION NAME&quot;, &quot;&quot;);
}

python*:::function-entry,
python*:::function-return
/ self-&gt;last == 0 /
{
    self-&gt;last = timestamp;
}

python*:::function-entry
/ dirname(copyinstr(arg0)) &lt;= &quot;/usr/lib/&quot; /
{
    self-&gt;delta = (timestamp - self-&gt;last) / 1000;
    printf(&quot; %-70s %4i %10i : %*s&gt; %s\n&quot;, copyinstr(arg0), arg2, self-&gt;delta,
           self-&gt;depth, &quot;&quot;, copyinstr(arg1));
    self-&gt; depth++;
    self-&gt;last = timestamp;
}

python*:::function-return
/ dirname(copyinstr(arg0)) &lt;= &quot;/usr/lib/&quot; /
{
    self-&gt;delta = (timestamp - self-&gt;last) / 1000;
    self-&gt;depth--;
    printf(&quot; %-70s %4i %10i : %*s&lt; %s\n&quot;, copyinstr(arg0), arg2, self-&gt;delta,
            self-&gt;depth, &quot;&quot;, copyinstr(arg1));
    self-&gt;last = timestamp;
}
</pre>
<p>Example output:</p>
<pre class="brush: bash; title: ; notranslate">
 $ pfexec dtrace -s misc/py_trace.d
Tracing... Hit Ctrl-C to end.
 FILE                                                                   LINE       TIME : FUNCTION NAME
[...]
 /home/tmetsch/data/workspace/pyssf/occi/service.py                      144       1380 : &gt; put
 /home/tmetsch/data/workspace/pyssf/occi/service.py                      184         13 :  &gt; parse_incoming
 /home/tmetsch/data/workspace/pyssf/occi/service.py                       47          9 :   &gt; extract_http_data
 /home/tmetsch/data/workspace/pyssf/occi/service.py                       68         39 :   &lt; extract_http_data
 /home/tmetsch/data/workspace/pyssf/occi/service.py                       70         10 :   &gt; get_parser
 /home/tmetsch/data/workspace/pyssf/occi/registry.py                      60         36 :    &gt; get_parser
 /home/tmetsch/data/workspace/pyssf/occi/registry.py                      83         12 :    &lt; get_parser
 /home/tmetsch/data/workspace/pyssf/occi/service.py                       77          8 :   &lt; get_parser
 /home/tmetsch/data/workspace/pyssf/occi/protocol/rendering.py            99         11 :   &gt; to_entity
 /home/tmetsch/data/workspace/pyssf/occi/protocol/rendering.py            81         10 :    &gt; extract_data
 /home/tmetsch/data/workspace/pyssf/occi/protocol/rendering.py            37         11 :     &gt; __init__
 /home/tmetsch/data/workspace/pyssf/occi/protocol/rendering.py            41         11 :     &lt; __init__
 /home/tmetsch/data/workspace/pyssf/occi/protocol/rendering.py            97         14 :    &lt; extract_data
[...]
</pre>
<p>This was inspired by the <em>py_flowtime.d</em> script written by <a href="http://dtrace.org/blogs/brendan/">Brendan Gregg</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nohuddleoffense.de/2011/07/01/python-and-dtrace/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Power of Python &amp; Solaris</title>
		<link>http://www.nohuddleoffense.de/2011/06/16/the-power-of-python-solaris/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=the-power-of-python-solaris</link>
		<comments>http://www.nohuddleoffense.de/2011/06/16/the-power-of-python-solaris/#comments</comments>
		<pubDate>Thu, 16 Jun 2011 22:08:17 +0000</pubDate>
		<dc:creator>coach</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[DTrace]]></category>
		<category><![CDATA[OCCI]]></category>
		<category><![CDATA[OpenSolaris]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.nohuddleoffense.de/?p=698</guid>
		<description><![CDATA[Here is a presentation I gave today to demo the power of Python and Solaris. It&#8217;s about creating a fictitious service similar to no.de or Google App Engine but with Python &#038; Solaris. Warning: contains OCCI and DTrace! Simple Service Offering with Python, Solaris, OCCI and DTrace View more presentations from befreax]]></description>
			<content:encoded><![CDATA[<p>
Here is a presentation I gave today to demo the power of <a href="http://www.python.org">Python</a> and <a href="http://www.opensolaris.org">Solaris</a>. It&#8217;s about creating a fictitious service similar to <a href="http://no.de">no.de</a> or <a href="http://code.google.com/appengine/">Google App Engine</a> but with Python &#038; Solaris. Warning: contains <a href="http://www.occi-wg.org">OCCI </a>and <a href="http://www.dtrace.org">DTrace</a>!
</p>
<div style="width:425px" id="__ss_8331626"> <strong style="display:block;margin:12px 0 4px"><a href="http://www.slideshare.net/befreax/simple-service-offering-with-python-solaris-occi-and-dtrace" title="Simple Service Offering with Python, Solaris, OCCI and DTrace">Simple Service Offering with Python, Solaris, OCCI and DTrace</a></strong> <iframe src="http://www.slideshare.net/slideshow/embed_code/8331626" width="425" height="355" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
<div style="padding:5px 0 12px"> View more <a href="http://www.slideshare.net/">presentations</a> from <a href="http://www.slideshare.net/befreax">befreax</a> </div>
</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.nohuddleoffense.de/2011/06/16/the-power-of-python-solaris/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Build Python with custom TCL/TK libs</title>
		<link>http://www.nohuddleoffense.de/2011/04/26/python_tcl_t/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=python_tcl_t</link>
		<comments>http://www.nohuddleoffense.de/2011/04/26/python_tcl_t/#comments</comments>
		<pubDate>Tue, 26 Apr 2011 14:03:47 +0000</pubDate>
		<dc:creator>coach</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.nohuddleoffense.de/?p=687</guid>
		<description><![CDATA[Issue with my Solaris installation is that it has slightly older TCK/TK libs. Since I&#8217;m currently playing around with some Tkinter stuff and python I needed a newer version to test the TreeView and Notebook widgets for example. Here is how yo can get Python 2.7.1 up and running against TCL/TK libs which are not [...]]]></description>
			<content:encoded><![CDATA[<p>Issue with my <a href="http://www.opensolaris.org">Solaris</a> installation is that it has slightly older TCK/TK libs. Since I&#8217;m currently <a href="http://www.nohuddleoffense.de/?p=673">playing</a> around with some <a href="http://docs.python.org/library/tkinter.html">Tkinter</a> stuff and python I needed a newer version to test the <a href="http://docs.python.org/library/ttk.html#treeview">TreeView</a> and <a href="http://docs.python.org/library/ttk.html#notebook">Notebook</a> widgets for example. </p>
<p>Here is how yo can get Python 2.7.1 up and running against TCL/TK libs which are not system wide installed:</p>
<pre class="brush: bash; title: ; notranslate">
# Switch to TCL directory
cd unix/
./configure --prefix=&lt;some_path&gt;
make
make install
# Switch to TK directory
cd unix/
./configure --prefix=&lt;some_path&gt; --with-tcl=&lt;some_path&gt;
make
make install
# Switch to Python source directory
export LD_LIBRARY_PATH=&lt;some_path&gt;
./configure --prefix=&lt;some_path&gt;
make
make install
</pre>
<p>Please note the following:</p>
<ul>
<li>&lt;some_path&gt; needs to be the same in all calls</li>
<li>you need to set the LD_LIBRARY_PATH before calling the configure script in the Python source directory
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.nohuddleoffense.de/2011/04/26/python_tcl_t/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generating Tkinter GUIs from JSON</title>
		<link>http://www.nohuddleoffense.de/2011/04/21/generating-tkinter-guis-from-json/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=generating-tkinter-guis-from-json</link>
		<comments>http://www.nohuddleoffense.de/2011/04/21/generating-tkinter-guis-from-json/#comments</comments>
		<pubDate>Thu, 21 Apr 2011 09:12:26 +0000</pubDate>
		<dc:creator>coach</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.nohuddleoffense.de/?p=673</guid>
		<description><![CDATA[Source available on GitHub&#8230; Yesterday I posted something about creating Tkinter based GUIs via an XML. Thanks to python and all its build in features (like JSON support) it was a piece of cake to rewrite it an now you can create Tkinter GUIs from a JSON definition. Just a few lines (ca 25 lines [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Source</strong> available on <a href="https://github.com/tmetsch/pytkgen">GitHub</a>&#8230;</p>
<p>Yesterday <a href="http://www.nohuddleoffense.de/?p=655">I posted</a> something about creating <a href="http://docs.python.org/library/tkinter.html">Tkinter</a> based GUIs via an XML. Thanks to python and all its build in features (like <a href="http://docs.python.org/library/json.html">JSON</a> support) it was a piece of cake to rewrite it an now you can create Tkinter GUIs from a JSON definition. Just a few lines (ca 25 lines needed to be changed) later and this request was fulfilled: </p>
<p><a href="http://www.nohuddleoffense.de/wp-content/uploads/2011/04/tkinter_json_tweet.png"><img src="http://www.nohuddleoffense.de/wp-content/uploads/2011/04/tkinter_json_tweet-300x121.png" alt="" title="tkinter_json_tweet" width="300" height="121" class="aligncenter size-medium wp-image-676" /></a></p>
<p>To create the same GUI as in the last post the JSON file should look like:</p>
<pre class="brush: bash; title: ; notranslate">
{
    &quot;Frame&quot;:{
        &quot;LabelFrame&quot;:{
            &quot;text&quot;:&quot;Hello World&quot;,
            &quot;column&quot;: 0,
            &quot;columnspan&quot;: 2,
            &quot;row&quot;: 0,
            &quot;Label&quot;:{
                &quot;text&quot;:&quot;Entry:&quot;,
                &quot;column&quot;: 0,
                &quot;row&quot;: 0
            },
            &quot;Checkbutton&quot;:{
                &quot;name&quot;:&quot;check&quot;,
                &quot;text&quot;:&quot;checkbutton&quot;,
                &quot;column&quot;: 1,
                &quot;row&quot;: 0
            },
            &quot;Entry&quot;:{
                &quot;name&quot;:&quot;entry&quot;,
                &quot;text&quot;:&quot;checkbutton&quot;,
                &quot;width&quot;:&quot;30&quot;,
                &quot;bg&quot;:&quot;gold&quot;,
                &quot;column&quot;: 0,
                &quot;row&quot;: 1,
                &quot;columnspan&quot;: 2
            }
        },
        &quot;Button&quot;:[
            {
                &quot;name&quot;:&quot;ok&quot;,
                &quot;text&quot;:&quot;OK&quot;,
                &quot;column&quot;: 0,
                &quot;row&quot;: 1
            },
            {
                &quot;name&quot;:&quot;cancel&quot;,
                &quot;text&quot;:&quot;Cancel&quot;,
                &quot;column&quot;: 1,
                &quot;row&quot;: 1
            }
        ]
    }
}
</pre>
<p>And for sure: the sample code from yesterday &#8211; didn&#8217;t change <img src='http://www.nohuddleoffense.de/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  Again: you gotta love <a href="http://www.python.org">python</a>! And right now the JSON UI definitions are nicer so I might follow this approach for the future.</p>
<p>Also nice about this approach is that within the JSON or XML file you define everything for the Tkinter widgets. Every value of the configuration of an Tkinter widget can be defined in the files. For example all <a href="http://effbot.org/tkinterbook/entry.htm#Tkinter.Entry.config-method">these</a> values could be put in the file for the &#8216;Entry&#8217; Tkinter widget. Nice ain&#8217;t it?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nohuddleoffense.de/2011/04/21/generating-tkinter-guis-from-json/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

