<?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>moosechips</title>
	<atom:link href="http://www.moosechips.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.moosechips.com</link>
	<description>leaving my mark on the internet</description>
	<lastBuildDate>Wed, 18 Jul 2012 17:34:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>View Django Project Settings</title>
		<link>http://www.moosechips.com/2011/07/view-django-project-settings/</link>
		<comments>http://www.moosechips.com/2011/07/view-django-project-settings/#comments</comments>
		<pubDate>Mon, 25 Jul 2011 08:05:38 +0000</pubDate>
		<dc:creator>moosechips</dc:creator>
				<category><![CDATA[<code>]]></category>

		<guid isPermaLink="false">http://www.moosechips.com/?p=794</guid>
		<description><![CDATA[Start a Python shell and import settings to view your Django project settings python manage.py shell &#62;&#62;&#62; import settings &#62;&#62;&#62; settings.ROOT_URLCONF 'myproject.urls']]></description>
			<content:encoded><![CDATA[<p>Start a Python shell and import settings to view your Django project settings</p>

<div class="wp_syntax"><div class="code"><pre class="python geshicode" id="geshiid" style="font-family:monospace;">python manage.<span style="color: #35CECE;">py</span> shell
<span style=" color: #053163;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;color: #729FCF;">import</span> settings
<span style=" color: #053163;">&gt;&gt;&gt;</span> settings.<span style="color: #35CECE;">ROOT_URLCONF</span>
<span style="color: #483d8b;color: #AD7FA8;">'myproject.urls'</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.moosechips.com/2011/07/view-django-project-settings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Short Django Tutorial Notes</title>
		<link>http://www.moosechips.com/2011/07/short-django-tutorial-notes/</link>
		<comments>http://www.moosechips.com/2011/07/short-django-tutorial-notes/#comments</comments>
		<pubDate>Mon, 25 Jul 2011 05:58:57 +0000</pubDate>
		<dc:creator>moosechips</dc:creator>
				<category><![CDATA[<code>]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[notes]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.moosechips.com/?p=760</guid>
		<description><![CDATA[Some condensed notes on the Django tutorial (Django 1.3) This is just a short self-reference (or maybe a 2-minute overview), not an actual tutorial. Database Create / update database python manage.py syncdb Models Models define how data is stored. Create a model by inheriting from django.db.models.Model from django.db import models &#160; class Choice&#40;models.Model&#41;: poll = [...]]]></description>
			<content:encoded><![CDATA[<p>Some condensed notes on the <a href="https://docs.djangoproject.com/en/dev/intro/tutorial01/">Django tutorial</a>  (Django 1.3) This is just a short self-reference (or maybe a 2-minute overview), not an actual tutorial.</p>
<h2>Database</h2>
<p>Create / update database</p>

<div class="wp_syntax"><div class="code"><pre class="python geshicode" id="geshiid" style="font-family:monospace;">python manage.<span style="color: #35CECE;">py</span> syncdb</pre></div></div>

<h2>Models</h2>
<p>Models define how data is stored. Create a model by inheriting from <code>django.db.models.Model</code></p>

<div class="wp_syntax"><div class="code"><pre class="python geshicode" id="geshiid" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;color: #729FCF;">from</span> django.<span style="color: #35CECE;">db</span> <span style="color: #ff7700;font-weight:bold;color: #729FCF;">import</span> models
&nbsp;
<span style="color: #ff7700;font-weight:bold;color: #729FCF;">class</span> Choice<span style=" color: #053163;">&#40;</span>models.<span style="color: #35CECE;">Model</span><span style=" color: #053163;">&#41;</span>:
    poll = models.<span style="color: #35CECE;">ForeignKey</span><span style=" color: #053163;">&#40;</span>Poll<span style=" color: #053163;">&#41;</span>
    choice = models.<span style="color: #35CECE;">CharField</span><span style=" color: #053163;">&#40;</span>max_length=<span style="color: #ff4500;color: red;">200</span><span style=" color: #053163;">&#41;</span>
    votes = models.<span style="color: #35CECE;">IntegerField</span><span style=" color: #053163;">&#40;</span><span style=" color: #053163;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;color: #729FCF;">def</span> <span style="color: #35CECE;">__unicode__</span><span style=" color: #053163;">&#40;</span><span style="color: #008000;color: #729FCF;">self</span><span style=" color: #053163;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;color: #729FCF;">return</span> <span style="color: #008000;color: #729FCF;">self</span>.<span style="color: #35CECE;">choice</span></pre></div></div>

<h2>App</h2>
<p>An &#8220;app&#8221; is simply a directory with an <code>__init__.py</code> file and other python files. (An &#8220;app&#8221; is more commonly known in other languages as a &#8220;package&#8221;.)  </p>
<p>The <code>INSTALLED_APPS</code> variable in <code>settings.py</code> tells Django which apps to use.</p>

<div class="wp_syntax"><div class="code"><pre class="python geshicode" id="geshiid" style="font-family:monospace;">INSTALLED_APPS = <span style=" color: #053163;">&#40;</span>
    <span style="color: #483d8b;color: #AD7FA8;">'django.contrib.auth'</span>,
    <span style="color: #483d8b;color: #AD7FA8;">'django.contrib.contenttypes'</span>,
    <span style="color: #483d8b;color: #AD7FA8;">'django.contrib.sessions'</span>,
    <span style="color: #483d8b;color: #AD7FA8;">'django.contrib.sites'</span>,
    <span style="color: #483d8b;color: #AD7FA8;">'polls'</span>
<span style=" color: #053163;">&#41;</span></pre></div></div>

<p>Make sure your app directory is on your Python path.</p>
<p>Re-run <code>python manage.py syncdb</code> after making changes to the <code>INSTALLED_APPS</code>.</p>
<h2>URLs</h2>
<p>The variable <code>urlpatterns</code> tells Django which Python code to run (which view to use) based on the url path.</p>

<div class="wp_syntax"><div class="code"><pre class="python geshicode" id="geshiid" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;color: #729FCF;">from</span> django.<span style="color: #35CECE;">conf</span>.<span style="color: #35CECE;">urls</span>.<span style="color: #35CECE;">defaults</span> <span style="color: #ff7700;font-weight:bold;color: #729FCF;">import</span> patterns, include, url
<span style="color: #ff7700;font-weight:bold;color: #729FCF;">from</span> django.<span style="color: #35CECE;">contrib</span> <span style="color: #ff7700;font-weight:bold;color: #729FCF;">import</span> admin
admin.<span style="color: #35CECE;">autodiscover</span><span style=" color: #053163;">&#40;</span><span style=" color: #053163;">&#41;</span>
&nbsp;
urlpatterns = patterns<span style=" color: #053163;">&#40;</span><span style="color: #483d8b;color: #AD7FA8;">''</span>,
   <span style=" color: #053163;">&#40;</span>r<span style="color: #483d8b;color: #AD7FA8;">'^polls/$'</span>, <span style="color: #483d8b;color: #AD7FA8;">'polls.views.index'</span><span style=" color: #053163;">&#41;</span>,
   <span style=" color: #053163;">&#40;</span>r<span style="color: #483d8b;color: #AD7FA8;">'^polls/(?P
&lt;poll_id&gt;<span style="color: #000099; font-weight: bold;">\d</span>+)/$'</span>, <span style="color: #483d8b;color: #AD7FA8;">'polls.views.detail'</span><span style=" color: #053163;">&#41;</span>,
   url<span style=" color: #053163;">&#40;</span>r<span style="color: #483d8b;color: #AD7FA8;">'^admin/'</span>, include<span style=" color: #053163;">&#40;</span>admin.<span style="color: #dc143c;color: #729FCF;">site</span>.<span style="color: #35CECE;">urls</span><span style=" color: #053163;">&#41;</span><span style=" color: #053163;">&#41;</span>,
<span style=" color: #053163;">&#41;</span></pre></div></div>

<p>The <code>ROOT_URLCONF</code> variable in <code>settings.py</code> tells Django where to find the module-level variable <code>urlpatterns</code>.  E.g. if <code>urlpatterns</code> is defined in <code>mysite/urls.py</code>, the <code>settings.py</code> file should have</p>

<div class="wp_syntax"><div class="code"><pre class="python geshicode" id="geshiid" style="font-family:monospace;">ROOT_URLCONF = <span style="color: #483d8b;color: #AD7FA8;">'mysite.urls'</span></pre></div></div>

<h2>View</h2>
<p>The code used to generate a page is called a view. A view is a Python function which returns a web page.  Example <code>index()</code> view in <code>polls/views.py</code></p>

<div class="wp_syntax"><div class="code"><pre class="python geshicode" id="geshiid" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;color: #729FCF;">from</span> django.<span style="color: #35CECE;">template</span> <span style="color: #ff7700;font-weight:bold;color: #729FCF;">import</span> Context, loader
<span style="color: #ff7700;font-weight:bold;color: #729FCF;">from</span> polls.<span style="color: #35CECE;">models</span> <span style="color: #ff7700;font-weight:bold;color: #729FCF;">import</span> Poll
<span style="color: #ff7700;font-weight:bold;color: #729FCF;">from</span> django.<span style="color: #35CECE;">http</span> <span style="color: #ff7700;font-weight:bold;color: #729FCF;">import</span> HttpResponse
&nbsp;
<span style="color: #ff7700;font-weight:bold;color: #729FCF;">def</span> index<span style=" color: #053163;">&#40;</span>request<span style=" color: #053163;">&#41;</span>:
    latest_poll_list = Poll.<span style="color: #35CECE;">objects</span>.<span style="color: #008000;color: #729FCF;">all</span><span style=" color: #053163;">&#40;</span><span style=" color: #053163;">&#41;</span>.<span style="color: #35CECE;">order_by</span><span style=" color: #053163;">&#40;</span><span style="color: #483d8b;color: #AD7FA8;">'-pub_date'</span><span style=" color: #053163;">&#41;</span><span style=" color: #053163;">&#91;</span>:<span style="color: #ff4500;color: red;">5</span><span style=" color: #053163;">&#93;</span>
    t = loader.<span style="color: #35CECE;">get_template</span><span style=" color: #053163;">&#40;</span><span style="color: #483d8b;color: #AD7FA8;">'polls/index.html'</span><span style=" color: #053163;">&#41;</span>
    c = Context<span style=" color: #053163;">&#40;</span><span style=" color: #053163;">&#123;</span>
        <span style="color: #483d8b;color: #AD7FA8;">'latest_poll_list'</span>: latest_poll_list,
    <span style=" color: #053163;">&#125;</span><span style=" color: #053163;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;color: #729FCF;">return</span> HttpResponse<span style=" color: #053163;">&#40;</span>t.<span style="color: #35CECE;">render</span><span style=" color: #053163;">&#40;</span>c<span style=" color: #053163;">&#41;</span><span style=" color: #053163;">&#41;</span></pre></div></div>

<p>The <code>urlpatterns</code> tells Django which view to use based on the url.  For example, the <code>urlpatterns</code> line</p>

<div class="wp_syntax"><div class="code"><pre class="python geshicode" id="geshiid" style="font-family:monospace;">   <span style=" color: #053163;">&#40;</span>r<span style="color: #483d8b;color: #AD7FA8;">'^polls/$'</span>, <span style="color: #483d8b;color: #AD7FA8;">'polls.views.index'</span><span style=" color: #053163;">&#41;</span>,</pre></div></div>

<p>tells Django that the url <b>http://site.com/polls</b> is created by the <code>index()</code> function in <code>polls/views.py</code>.</p>
<p><code>render_to_response</code> is a common shortcut for creating views.  Equivalent view using <code>render_to_response</code></p>

<div class="wp_syntax"><div class="code"><pre class="python geshicode" id="geshiid" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;color: #729FCF;">from</span> django.<span style="color: #35CECE;">shortcuts</span> <span style="color: #ff7700;font-weight:bold;color: #729FCF;">import</span> render_to_response
<span style="color: #ff7700;font-weight:bold;color: #729FCF;">from</span> polls.<span style="color: #35CECE;">models</span> <span style="color: #ff7700;font-weight:bold;color: #729FCF;">import</span> Poll
&nbsp;
<span style="color: #ff7700;font-weight:bold;color: #729FCF;">def</span> index<span style=" color: #053163;">&#40;</span>request<span style=" color: #053163;">&#41;</span>:
    latest_poll_list = Poll.<span style="color: #35CECE;">objects</span>.<span style="color: #008000;color: #729FCF;">all</span><span style=" color: #053163;">&#40;</span><span style=" color: #053163;">&#41;</span>.<span style="color: #35CECE;">order_by</span><span style=" color: #053163;">&#40;</span><span style="color: #483d8b;color: #AD7FA8;">'-pub_date'</span><span style=" color: #053163;">&#41;</span><span style=" color: #053163;">&#91;</span>:<span style="color: #ff4500;color: red;">5</span><span style=" color: #053163;">&#93;</span>
    <span style="color: #ff7700;font-weight:bold;color: #729FCF;">return</span> render_to_response<span style=" color: #053163;">&#40;</span><span style="color: #483d8b;color: #AD7FA8;">'polls/index.html'</span>, <span style=" color: #053163;">&#123;</span><span style="color: #483d8b;color: #AD7FA8;">'latest_poll_list'</span>: latest_poll_list<span style=" color: #053163;">&#125;</span><span style=" color: #053163;">&#41;</span></pre></div></div>

<p>Often views need to respond to a request.  Templates use the <code>{% csrf_token %}</code> to prevent &#8220;Cross Site Request Forgeries&#8221;, and the view uses a <code>django.template.RequestContext</code></p>

<div class="wp_syntax"><div class="code"><pre class="python geshicode" id="geshiid" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;color: #729FCF;">from</span> django.<span style="color: #35CECE;">template</span> <span style="color: #ff7700;font-weight:bold;color: #729FCF;">import</span> RequestContext
<span style="color: #808080; font-style: italic; color: #81D962;"># ...</span>
<span style="color: #ff7700;font-weight:bold;color: #729FCF;">def</span> detail<span style=" color: #053163;">&#40;</span>request, poll_id<span style=" color: #053163;">&#41;</span>:
    p = get_object_or_404<span style=" color: #053163;">&#40;</span>Poll, pk=poll_id<span style=" color: #053163;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;color: #729FCF;">return</span> render_to_response<span style=" color: #053163;">&#40;</span><span style="color: #483d8b;color: #AD7FA8;">'polls/detail.html'</span>, <span style=" color: #053163;">&#123;</span><span style="color: #483d8b;color: #AD7FA8;">'poll'</span>: p<span style=" color: #053163;">&#125;</span>,
                               context_instance=RequestContext<span style=" color: #053163;">&#40;</span>request<span style=" color: #053163;">&#41;</span><span style=" color: #053163;">&#41;</span></pre></div></div>

<h2>Template</h2>
<p>A Django template is a HTML skeleton with special Django tags which tell the Django view where to fill in data.  Example template <code>polls/index.html</code></p>

<div class="wp_syntax"><div class="code"><pre class="python geshicode" id="geshiid" style="font-family:monospace;"><span style=" color: #053163;">&#123;</span><span style=" color: #053163;">%</span> <span style="color: #ff7700;font-weight:bold;color: #729FCF;">if</span> latest_poll_list <span style=" color: #053163;">%</span><span style=" color: #053163;">&#125;</span>
<span style=" color: #053163;">&lt;</span>ul<span style=" color: #053163;">&gt;</span>
    <span style=" color: #053163;">&#123;</span><span style=" color: #053163;">%</span> <span style="color: #ff7700;font-weight:bold;color: #729FCF;">for</span> poll <span style="color: #ff7700;font-weight:bold;color: #729FCF;">in</span> latest_poll_list <span style=" color: #053163;">%</span><span style=" color: #053163;">&#125;</span>
<span style=" color: #053163;">&lt;</span>li<span style=" color: #053163;">&gt;&lt;</span>a href=<span style="color: #483d8b;color: #AD7FA8;">&quot;/polls/{{ poll.id }}/&quot;</span><span style=" color: #053163;">&gt;</span><span style=" color: #053163;">&#123;</span><span style=" color: #053163;">&#123;</span> poll.<span style="color: #35CECE;">question</span> <span style=" color: #053163;">&#125;</span><span style=" color: #053163;">&#125;</span><span style=" color: #053163;">&lt;</span>/a<span style=" color: #053163;">&gt;&lt;</span>/li<span style=" color: #053163;">&gt;</span>
&nbsp;
    <span style=" color: #053163;">&#123;</span><span style=" color: #053163;">%</span> endfor <span style=" color: #053163;">%</span><span style=" color: #053163;">&#125;</span>
    <span style=" color: #053163;">&lt;</span>/ul<span style=" color: #053163;">&gt;</span>
&nbsp;
<span style=" color: #053163;">&#123;</span><span style=" color: #053163;">%</span> <span style="color: #ff7700;font-weight:bold;color: #729FCF;">else</span> <span style=" color: #053163;">%</span><span style=" color: #053163;">&#125;</span>
    <span style=" color: #053163;">&lt;</span>p<span style=" color: #053163;">&gt;</span>No polls are available.<span style=" color: #053163;">&lt;</span>/p<span style=" color: #053163;">&gt;</span>
<span style=" color: #053163;">&#123;</span><span style=" color: #053163;">%</span> endif <span style=" color: #053163;">%</span><span style=" color: #053163;">&#125;</span></pre></div></div>

<h2>Admin Interface</h2>
<p>Register apps with Django&#8217;s admin interface</p>

<div class="wp_syntax"><div class="code"><pre class="python geshicode" id="geshiid" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;color: #729FCF;">from</span> polls.<span style="color: #35CECE;">models</span> <span style="color: #ff7700;font-weight:bold;color: #729FCF;">import</span> Poll
<span style="color: #ff7700;font-weight:bold;color: #729FCF;">from</span> django.<span style="color: #35CECE;">contrib</span> <span style="color: #ff7700;font-weight:bold;color: #729FCF;">import</span> admin
&nbsp;
<span style="color: #ff7700;font-weight:bold;color: #729FCF;">class</span> PollAdmin<span style=" color: #053163;">&#40;</span>admin.<span style="color: #35CECE;">ModelAdmin</span><span style=" color: #053163;">&#41;</span>:
    fields = <span style=" color: #053163;">&#91;</span><span style="color: #483d8b;color: #AD7FA8;">'pub_date'</span>, <span style="color: #483d8b;color: #AD7FA8;">'question'</span><span style=" color: #053163;">&#93;</span>
&nbsp;
admin.<span style="color: #dc143c;color: #729FCF;">site</span>.<span style="color: #35CECE;">register</span><span style=" color: #053163;">&#40;</span>Poll, PollAdmin<span style=" color: #053163;">&#41;</span></pre></div></div>

<h2>Generic Views</h2>
<p>There&#8217;s generic views which means that you don&#8217;t have to write a view function; you use django.views.generic to generate a simple view.</p>

<div class="wp_syntax"><div class="code"><pre class="python geshicode" id="geshiid" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;color: #729FCF;">from</span> django.<span style="color: #35CECE;">conf</span>.<span style="color: #35CECE;">urls</span>.<span style="color: #35CECE;">defaults</span> <span style="color: #ff7700;font-weight:bold;color: #729FCF;">import</span> patterns, include, url
<span style="color: #ff7700;font-weight:bold;color: #729FCF;">from</span> django.<span style="color: #35CECE;">views</span>.<span style="color: #35CECE;">generic</span> <span style="color: #ff7700;font-weight:bold;color: #729FCF;">import</span> DetailView, ListView
<span style="color: #ff7700;font-weight:bold;color: #729FCF;">from</span> polls.<span style="color: #35CECE;">models</span> <span style="color: #ff7700;font-weight:bold;color: #729FCF;">import</span> Poll
&nbsp;
urlpatterns = patterns<span style=" color: #053163;">&#40;</span><span style="color: #483d8b;color: #AD7FA8;">''</span>,
    <span style=" color: #053163;">&#40;</span>r<span style="color: #483d8b;color: #AD7FA8;">'^$'</span>,
        ListView.<span style="color: #35CECE;">as_view</span><span style=" color: #053163;">&#40;</span>
            queryset=Poll.<span style="color: #35CECE;">objects</span>.<span style="color: #35CECE;">order_by</span><span style=" color: #053163;">&#40;</span><span style="color: #483d8b;color: #AD7FA8;">'-pub_date'</span><span style=" color: #053163;">&#41;</span><span style=" color: #053163;">&#91;</span>:<span style="color: #ff4500;color: red;">5</span><span style=" color: #053163;">&#93;</span>,
            context_object_name=<span style="color: #483d8b;color: #AD7FA8;">'latest_poll_list'</span>,
            template_name=<span style="color: #483d8b;color: #AD7FA8;">'polls/index.html'</span><span style=" color: #053163;">&#41;</span><span style=" color: #053163;">&#41;</span>,
    <span style=" color: #053163;">&#40;</span>r<span style="color: #483d8b;color: #AD7FA8;">'^(?P
&lt;pk&gt;<span style="color: #000099; font-weight: bold;">\d</span>+)/$'</span>,
        DetailView.<span style="color: #35CECE;">as_view</span><span style=" color: #053163;">&#40;</span>
            model=Poll,
            template_name=<span style="color: #483d8b;color: #AD7FA8;">'polls/detail.html'</span><span style=" color: #053163;">&#41;</span><span style=" color: #053163;">&#41;</span>,
    url<span style=" color: #053163;">&#40;</span>r<span style="color: #483d8b;color: #AD7FA8;">'^(?P
&lt;pk&gt;<span style="color: #000099; font-weight: bold;">\d</span>+)/results/$'</span>,
        DetailView.<span style="color: #35CECE;">as_view</span><span style=" color: #053163;">&#40;</span>
            model=Poll,
            template_name=<span style="color: #483d8b;color: #AD7FA8;">'polls/results.html'</span><span style=" color: #053163;">&#41;</span>,
        name=<span style="color: #483d8b;color: #AD7FA8;">'poll_results'</span><span style=" color: #053163;">&#41;</span>,
    <span style=" color: #053163;">&#40;</span>r<span style="color: #483d8b;color: #AD7FA8;">'^(?P
&lt;poll_id&gt;<span style="color: #000099; font-weight: bold;">\d</span>+)/vote/$'</span>, <span style="color: #483d8b;color: #AD7FA8;">'polls.views.vote'</span><span style=" color: #053163;">&#41;</span>,
<span style=" color: #053163;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.moosechips.com/2011/07/short-django-tutorial-notes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Installing Mezzanine (Django based CMS) on Dreamhost via virtualenv</title>
		<link>http://www.moosechips.com/2011/07/installing-mezzanine-django-based-cms-on-dreamhost/</link>
		<comments>http://www.moosechips.com/2011/07/installing-mezzanine-django-based-cms-on-dreamhost/#comments</comments>
		<pubDate>Wed, 20 Jul 2011 19:08:12 +0000</pubDate>
		<dc:creator>moosechips</dc:creator>
				<category><![CDATA[<code>]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[dreamhost]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[help]]></category>
		<category><![CDATA[install]]></category>
		<category><![CDATA[mezzanine]]></category>
		<category><![CDATA[passenger]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[virtualenv]]></category>

		<guid isPermaLink="false">http://www.moosechips.com/?p=750</guid>
		<description><![CDATA[Here&#8217;s some notes for installing Mezzanine on Dreamhost using virtualenv. This can be useful for installing on any server where you don&#8217;t have permissions to install python packages normally. There&#8217;s also notes here for how to set up Passenger to serve your site via Apache. In Dreamhost panel, setup site for use with Passenger &#038; [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s some notes for installing Mezzanine on Dreamhost using virtualenv.  This can be useful for installing on any server where you don&#8217;t have permissions to install python packages normally.  There&#8217;s also notes here for how to set up Passenger to serve your site via Apache.</p>
<p>In Dreamhost panel, setup site for use with Passenger &#038; ssh</p>
<p>Ssh into your Dreamhost server</p>
<p>Setup a Python virtualenv so you can install your own Python packages.  Check the <a href="http://pypi.python.org/pypi/virtualenv#downloads">virtualenv pypi page</a> for the latest virtualenv version (currently 1.6.3).</p>

<div class="wp_syntax"><div class="code"><pre class="bash geshicode" id="geshiid" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;color: #729FCF;">wget</span> http:<span style=" color: #053163;">//</span>pypi.python.org<span style=" color: #053163;">/</span>packages<span style=" color: #053163;">/</span>source<span style=" color: #053163;">/</span>v<span style=" color: #053163;">/</span>virtualenv<span style=" color: #053163;">/</span>virtualenv-1.6.3.tar.gz
<span style="color: #c20cb9; font-weight: bold;color: #729FCF;">tar</span> xzf virtualenv-1.6.3.tar.gz
python virtualenv-1.6.3<span style=" color: #053163;">/</span>virtualenv.py <span style="color: #007800;color: #35CECF;">$HOME</span><span style=" color: #053163;">/</span><span style="color: #7a0874; font-weight: bold;color: #729FCF;">local</span>
<span style="color: #c20cb9; font-weight: bold;color: #729FCF;">rm</span> <span style="color: #660033;color: #35CECF;">-rf</span> virtualenv<span style=" color: #053163;">*</span>
<span style="color: #7a0874; font-weight: bold;color: #729FCF;">export</span> <span style="color: #007800;color: #35CECF;">PATH</span>=<span style="color: #007800;color: #35CECF;">$HOME</span><span style=" color: #053163;">/</span>local<span style=" color: #053163;">/</span>bin:<span style="color: #007800;color: #35CECF;">$PATH</span></pre></div></div>

<p>You probably want to add <code>$HOME/local/bin</code> to your path permanently.  Add the export line to your <code>~/.bashrc</code> file:</p>

<div class="wp_syntax"><div class="code"><pre class="bash geshicode" id="geshiid" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;color: #729FCF;">export</span> <span style="color: #007800;color: #35CECF;">PATH</span>=<span style="color: #007800;color: #35CECF;">$HOME</span><span style=" color: #053163;">/</span>local<span style=" color: #053163;">/</span>bin:<span style="color: #007800;color: #35CECF;">$PATH</span></pre></div></div>

<p>To make sure that you are using the virtualenv python, check that <code>which python</code> returns <code>/home/youruser/local/bin/python</code> and NOT <code>/usr/bin/python</code>.</p>
<p>Now you can install some Python packages</p>

<div class="wp_syntax"><div class="code"><pre class="bash geshicode" id="geshiid" style="font-family:monospace;">pip <span style="color: #c20cb9; font-weight: bold;color: #729FCF;">install</span> <span style="color: #660033;color: #35CECF;">--upgrade</span> django mezzanine south paste</pre></div></div>

<p>Create a mezzanine project</p>

<div class="wp_syntax"><div class="code"><pre class="bash geshicode" id="geshiid" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;color: #729FCF;">cd</span> ~<span style=" color: #053163;">/</span>site.com
<span style="color: #666666; font-style: italic; color: #81D962;"># Name this project whatever you like.  I will use &quot;mez&quot;</span>
mezzanine-project mez</pre></div></div>

<p>Edit your settings in <code>mez/local_settings.py</code>.  I will leave the sqlite database for testing.  You could should probably create a mysql database for a real site though.  Add these lines so Django knows where files are.</p>

<div class="wp_syntax"><div class="code"><pre class="python geshicode" id="geshiid" style="font-family:monospace;">TIME_ZONE = <span style="color: #483d8b;color: #AD7FA8;">'America/Los_Angeles'</span>
APP_URL = <span style="color: #483d8b;color: #AD7FA8;">'http://site.com'</span>
<span style="color: #808080; font-style: italic; color: #81D962;">## Note the leading and trailing slash here</span>
<span style="color: #808080; font-style: italic; color: #81D962;">#ADMIN_MEDIA_PREFIX = '/admin_media/'</span>
<span style="color: #808080; font-style: italic; color: #81D962;">#MEDIA_ROOT= '/home/youruser/site.com/mez/site_media/'</span>
<span style="color: #808080; font-style: italic; color: #81D962;">#MEDIA_URL = 'http://site.com/site_media'</span></pre></div></div>

<p>Setup your site with Passenger by creating a <code>~/site.com/passenger_wsgi.py</code> file with the following:</p>

<div class="wp_syntax"><div class="code"><pre class="python geshicode" id="geshiid" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;color: #729FCF;">import</span> <span style="color: #dc143c;color: #729FCF;">sys</span>,<span style="color: #dc143c;color: #729FCF;">os</span>
<span style="color: #808080; font-style: italic; color: #81D962;"># Force Passenger to run our virtualenv python</span>
INTERP = <span style="color: #483d8b;color: #AD7FA8;">&quot;/home/youruser/local/bin/python&quot;</span>
<span style="color: #ff7700;font-weight:bold;color: #729FCF;">if</span> <span style="color: #dc143c;color: #729FCF;">sys</span>.<span style="color: #35CECE;">executable</span> <span style=" color: #053163;">!</span>= INTERP: <span style="color: #dc143c;color: #729FCF;">os</span>.<span style="color: #35CECE;">execl</span><span style=" color: #053163;">&#40;</span>INTERP, INTERP, <span style=" color: #053163;">*</span><span style="color: #dc143c;color: #729FCF;">sys</span>.<span style="color: #35CECE;">argv</span><span style=" color: #053163;">&#41;</span>
<span style="color: #808080; font-style: italic; color: #81D962;"># Setup paths and environment variables</span>
<span style="color: #dc143c;color: #729FCF;">sys</span>.<span style="color: #35CECE;">path</span>.<span style="color: #35CECE;">append</span><span style=" color: #053163;">&#40;</span><span style="color: #483d8b;color: #AD7FA8;">&quot;/home/youruser/site.com&quot;</span><span style=" color: #053163;">&#41;</span>
<span style="color: #dc143c;color: #729FCF;">sys</span>.<span style="color: #35CECE;">path</span>.<span style="color: #35CECE;">append</span><span style=" color: #053163;">&#40;</span><span style="color: #483d8b;color: #AD7FA8;">&quot;/home/youruser/site.com/mez&quot;</span><span style=" color: #053163;">&#41;</span>
<span style="color: #dc143c;color: #729FCF;">os</span>.<span style="color: #35CECE;">environ</span><span style=" color: #053163;">&#91;</span><span style="color: #483d8b;color: #AD7FA8;">'DJANGO_SETTINGS_MODULE'</span><span style=" color: #053163;">&#93;</span> = <span style="color: #483d8b;color: #AD7FA8;">'mez.settings'</span>
<span style="color: #808080; font-style: italic; color: #81D962;"># Set the application</span>
<span style="color: #ff7700;font-weight:bold;color: #729FCF;">import</span> django.<span style="color: #35CECE;">core</span>.<span style="color: #35CECE;">handlers</span>.<span style="color: #35CECE;">wsgi</span>
<span style="color: #ff7700;font-weight:bold;color: #729FCF;">from</span> paste.<span style="color: #dc143c;color: #729FCF;">exceptions</span>.<span style="color: #35CECE;">errormiddleware</span> <span style="color: #ff7700;font-weight:bold;color: #729FCF;">import</span> ErrorMiddleware
application = django.<span style="color: #35CECE;">core</span>.<span style="color: #35CECE;">handlers</span>.<span style="color: #35CECE;">wsgi</span>.<span style="color: #35CECE;">WSGIHandler</span><span style=" color: #053163;">&#40;</span><span style=" color: #053163;">&#41;</span>
<span style="color: #808080; font-style: italic; color: #81D962;"># Use paste to display errors</span>
application = ErrorMiddleware<span style=" color: #053163;">&#40;</span>application, debug=<span style="color: #008000;color: #729FCF;">True</span><span style=" color: #053163;">&#41;</span></pre></div></div>

<p>Now setup the static files</p>

<div class="wp_syntax"><div class="code"><pre class="bash geshicode" id="geshiid" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;color: #729FCF;">ln</span> <span style="color: #660033;color: #35CECF;">-s</span> ~<span style=" color: #053163;">/</span>site.com<span style=" color: #053163;">/</span>mez<span style=" color: #053163;">/</span>site_media ~<span style=" color: #053163;">/</span>site.com<span style=" color: #053163;">/</span>public<span style=" color: #053163;">/</span>site_media</pre></div></div>

<p>Setup the database</p>

<div class="wp_syntax"><div class="code"><pre class="bash geshicode" id="geshiid" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;color: #729FCF;">cd</span> ~<span style=" color: #053163;">/</span>site.com<span style=" color: #053163;">/</span>mez
python manage.py syncdb
<span style="color: #666666; font-style: italic; color: #81D962;"># I think I initially had some errors running migrate, </span>
<span style="color: #666666; font-style: italic; color: #81D962;"># but it worked the second time running migrate</span>
python manage.py migrate</pre></div></div>

<p>Restart the web server.  Ordinarily you might do <code>sudo /etc/init.d/apache2 restart</code>.  On Dreamhost you do this by touching <code>tmp/restart.txt</code>. (If the tmp directory doesn&#8217;t exist, <code>mkdir ~/site.com/tmp</code>)</p>

<div class="wp_syntax"><div class="code"><pre class="bash geshicode" id="geshiid" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;color: #729FCF;">touch</span> ~<span style=" color: #053163;">/</span>site.com<span style=" color: #053163;">/</span>tmp<span style=" color: #053163;">/</span>restart.txt</pre></div></div>

<p>That should be it.  Check to see if your site is up and running.</p>
<p>TODO&#8217;s: setup mysql, customize theme, etc</p>
<p>There&#8217;s alternative ways to handle the static files.  The package <a href="http://pypi.python.org/pypi/django-staticfiles">django-staticfiles</a> might be better?  I haven&#8217;t tried it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.moosechips.com/2011/07/installing-mezzanine-django-based-cms-on-dreamhost/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Notes on installing Gitorious on Ubuntu 10.10</title>
		<link>http://www.moosechips.com/2011/06/notes-on-installing-gitorious-on-ubuntu-10-10/</link>
		<comments>http://www.moosechips.com/2011/06/notes-on-installing-gitorious-on-ubuntu-10-10/#comments</comments>
		<pubDate>Sat, 04 Jun 2011 23:32:22 +0000</pubDate>
		<dc:creator>moosechips</dc:creator>
				<category><![CDATA[<linux>]]></category>

		<guid isPermaLink="false">http://www.moosechips.com/?p=740</guid>
		<description><![CDATA[A few notes from my experience installing Gitorious on Ubuntu Maverick 10.10. I used soundmaster&#8217;s fork of the gitorious-ubuntu-sprinkle script. I used ruby 1.8 and rubygems from the Ubuntu repository. Edit Config Files The sprinkle readme doesn&#8217;t mention it, but you need to edit the config files before running. Add your mysql password to config/database.yml [...]]]></description>
			<content:encoded><![CDATA[<p>A few notes from my experience installing Gitorious on Ubuntu Maverick 10.10.  I used <a href="https://github.com/soundmonster/gitorious-ubuntu-sprinkle">soundmaster&#8217;s fork of the gitorious-ubuntu-sprinkle</a> script.  I used ruby 1.8 and rubygems from the Ubuntu repository.</p>
<h3>Edit Config Files</h3>
<p>The sprinkle readme doesn&#8217;t mention it, but you need to edit the config files before running. Add your <strong>mysql password</strong> to <code>config/database.yml</code> and change your <strong>hostname and email</strong> in <code>config/gitorious.yml</code>.  <br />
Beware that if the script already installed the files to <code>/var/www/gitorious/config</code> it won&#8217;t overwrite the existing files, so you will need to make your changes to the files at <code>/var/www/gitorious/config</code> (or delete the files and re-run the sprinkle script).</p>
<h3>Sprinkle Script Overview</h3>
<p>The sprinkle script will</p>
<ul>
<li>Install required gems</li>
<li>Download and configure gitorious</li>
<li>Install and start startup scripts (stomp, git-poller, git-daemon)</li>
<li>Setup gitorious mysql database</li>
<li>Create a user named &#8220;git&#8221; (whose home dir is /var/www/gitorious)</li>
<li>Setup apache for use with gitorious</li>
</ul>
<h3>Deciphering Errors</h3>
<p>I had a bunch of problems running </p>

<div class="wp_syntax"><div class="code"><pre class="bash geshicode" id="geshiid" style="font-family:monospace;">bundle <span style="color: #7a0874; font-weight: bold;color: #729FCF;">exec</span> sprinkle <span style="color: #660033;color: #35CECF;">-s</span> gitorious.rb</pre></div></div>

<p>Ruby/capistrano spits out some long error messages, which you have to decipher to figure out which line in <code>gitorious.rb</code> failed to run.</p>
<p>Bundle couldn&#8217;t install the latest version of echoe (0.4.6) because Ubuntu&#8217;s rubygems (1.3.7) isn&#8217;t recent enough, so I installed an older version of echoe.</p>

<div class="wp_syntax"><div class="code"><pre class="bash geshicode" id="geshiid" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;color: #729FCF;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;color: #729FCF;">install</span> echoe <span style="color: #660033;color: #35CECF;">-v</span>=<span style="color: #ff0000;color: #AD7FA8;">&quot;0.4.5&quot;</span></pre></div></div>

<p>I then removed echoe from the list of gitorious_dependencies in <code>gitorious.rb</code>.  In hindsight, I think I could have added an entry to <code>Gemfile</code> specifying the echoe version, but I&#8217;m a Ruby noob, and just hacked the script to get it to work.</p>
<p>Then Rake couldn&#8217;t setup my database (some error about having activated rake 1.9.1 but the script required rake 1.8.7).  Turns out I need to call <code>bundle exec rake</code> instead of <code>/var/lib/gems/1.8/bin/rake</code>.  I modified the lines in <code>gitorious.rb</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash geshicode" id="geshiid" style="font-family:monospace;">    <span style="color: #666666; font-style: italic; color: #81D962;">#post :install, 'su - git -c &quot;/var/lib/gems/1.8/bin/rake db:setup RAILS_ENV=production&quot;'</span>
    post :<span style="color: #c20cb9; font-weight: bold;color: #729FCF;">install</span>, <span style="color: #ff0000;">'su - git -c &quot;bundle exec rake db:setup RAILS_ENV=production&quot;'</span></pre></div></div>

<h3>Miscellaneous notes</h3>
<p>Make sure your server is getting ports 80 and 443 (for ssl).</p>
<p>I also had to set up my server to properly route email so that Gitorious could send emails (e.g. registration confirmation).  I used <a href="http://www.cpuug.org/index.php?topic=231.0">this guide</a> to setup <code>postfix</code> to route mail through Gmail&#8217;s smtp.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.moosechips.com/2011/06/notes-on-installing-gitorious-on-ubuntu-10-10/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gps Navigators</title>
		<link>http://www.moosechips.com/2011/03/gps-navigators/</link>
		<comments>http://www.moosechips.com/2011/03/gps-navigators/#comments</comments>
		<pubDate>Mon, 28 Mar 2011 00:40:59 +0000</pubDate>
		<dc:creator>moosechips</dc:creator>
				<category><![CDATA[<uncategorized>]]></category>

		<guid isPermaLink="false">http://www.moosechips.com/?p=716</guid>
		<description><![CDATA[I wish there was an Android Garmin Nuvi. C&#8217;mon Google!]]></description>
			<content:encoded><![CDATA[<p>I wish there was an Android Garmin Nuvi.  C&#8217;mon Google!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.moosechips.com/2011/03/gps-navigators/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bedtools-python install in Windows</title>
		<link>http://www.moosechips.com/2011/02/bedtools-python-install-in-windows/</link>
		<comments>http://www.moosechips.com/2011/02/bedtools-python-install-in-windows/#comments</comments>
		<pubDate>Fri, 18 Feb 2011 01:21:57 +0000</pubDate>
		<dc:creator>moosechips</dc:creator>
				<category><![CDATA[<code>]]></category>

		<guid isPermaLink="false">http://www.moosechips.com/?p=726</guid>
		<description><![CDATA[Compiling applications from source may be the MO in Linux, but it is really tedious in Windows. This is not for the faint of heart. Dependencies Python (I have the 32-bit Python 2.7.1 installed. I&#8217;m not sure if bedtools-python is 3.x compliant) Be sure that you&#8217;ve added C:/Python27/bin to your PATH environment variable so you [...]]]></description>
			<content:encoded><![CDATA[<p>Compiling applications from source may be the MO in Linux, but it is really tedious in Windows.  This is not for the faint of heart.  </p>
<p><span id="more-726"></span></p>
<p>Dependencies</p>
<ul>
<li><code>Python</code> (I have the 32-bit Python 2.7.1 installed.  I&#8217;m not sure if bedtools-python is 3.x compliant)  Be sure that you&#8217;ve added <code>C:/Python27/bin</code> to your <code>PATH</code> environment variable so you can run python from the command line.</li>
<li><code>easy_install</code> (not technically required, but makes installing many Python modules easy)</li>
</ul>
<p>1. Install <a href="http://sourceforge.net/projects/mingw/files/">MinGW32</a> for your compiler.  This is as close to GCC as you get for Windows and will be much easier to compile than trying to use Visual Studio.  Download the suggested file (currently <code>mingw-get-inst-20110211.exe</code>).</p>
<p>2. Install the cython package</p>

<div class="wp_syntax"><div class="code"><pre class="bash geshicode" id="geshiid" style="font-family:monospace;">easy_install cython</pre></div></div>

<p>3. Download <a href="https://github.com/arq5x/bedtools-python">bedtools-python</a> and extract the folder into <code>C:/MinGW/msys/1.0/home/USERNAME</code></p>
<p>The hairy part #1: try to compile</p>
<p>4. Open the MinGW shell.  You should see the bedtools directory you extracted.  Go to the folder and try to build bedtools-python.</p>

<div class="wp_syntax"><div class="code"><pre class="bash geshicode" id="geshiid" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;color: #729FCF;">ls</span>
<span style="color: #7a0874; font-weight: bold;color: #729FCF;">cd</span> arq5x-bedtools-python-<span style="color: #000000;color: red;">6671082</span>
python setup.py build <span style="color: #660033;color: #35CECF;">--compiler</span>=mingw32</pre></div></div>

<p>I get an error &#8220;src/gzstream.h:35:18: fatal error: zlib.h: No such file or directory&#8221;</p>
<p>  You need to install <a href="http://www.zlib.net/">zlib</a>.  Download the <a href="http://prdownloads.sourceforge.net/libpng/zlib125-dll.zip?download">precompiled DLL</a> and unzip into the bedtools-python folder (or install it permanently into the c:/Mingw folder).</p>
<p>Change the name of lib/zdll.lib to lib/libzdll.a</p>
<p>Edit setup.py to tell it about zlib.  You will need to modify the libraries and include_dirs line, and add a library_dirs line in the Extension section.  It should look like this</p>

<div class="wp_syntax"><div class="code"><pre class="none geshicode" id="geshiid" style="font-family:monospace;">    Extension(&quot;bedtools.cbedtools&quot;,
              sources=[&quot;bedtools/cbedtools.pyx&quot;] + glob.glob(&quot;src/*.cpp&quot;),
              libraries=[&quot;stdc++&quot;, &quot;zdll&quot;],
              library_dirs=[&quot;lib/&quot;],
              include_dirs=[&quot;src/&quot;, &quot;include/&quot;],
              depends = glob.glob(&quot;src/*.h&quot;),
              language=&quot;c++&quot;),</pre></div></div>

<p>Hopefully you can build bedtools-python now (ignore the ugly stream of compiler commands and warning messages).  Now install bedtools-python.</p>

<div class="wp_syntax"><div class="code"><pre class="bash geshicode" id="geshiid" style="font-family:monospace;">python setup.py <span style="color: #c20cb9; font-weight: bold;color: #729FCF;">install</span></pre></div></div>

<p>Hairy part #2:</p>
<p>Now see if you can use bedtools.</p>

<div class="wp_syntax"><div class="code"><pre class="bash geshicode" id="geshiid" style="font-family:monospace;">python
<span style=" color: #053163;">&gt;&gt;&gt;</span> import bedtools</pre></div></div>

<p>If you get errors like </p>

<div class="wp_syntax"><div class="code"><pre class="bash geshicode" id="geshiid" style="font-family:monospace;">from cbedtools import IntervalFile
ImportError: DLL load failed: The specified procedure could not be found.</pre></div></div>

<p>then bedtools can&#8217;t find some dlls that it needs on python&#8217;s path.  To figure out what dll files it&#8217;s looking for, run depends.exe from <a href="http://www.dependencywalker.com/">dependencywalker.com</a> and open up <code>build/lib.win32-2.7/bedtools/cbedtools.pyd</code>.  This hopefully gives you a list of DLL files that it&#8217;s looking for.  You will need to either find and copy these files to <code>C:/Windows/system32</code>.  I was missing <code>libgcc_s_dw2-1.dll</code> and <code>libstdc++-6.dll</code> (found in <code>C:/Ming32/bin</code>) and <code>MSVCR90.DLL</code>.</p>
<p>Now use bedtools.</p>

<div class="wp_syntax"><div class="code"><pre class="bash geshicode" id="geshiid" style="font-family:monospace;">python
<span style=" color: #053163;">&gt;&gt;&gt;</span> import bedtools</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.moosechips.com/2011/02/bedtools-python-install-in-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple python printing</title>
		<link>http://www.moosechips.com/2011/02/simple-python-printing/</link>
		<comments>http://www.moosechips.com/2011/02/simple-python-printing/#comments</comments>
		<pubDate>Thu, 17 Feb 2011 18:54:54 +0000</pubDate>
		<dc:creator>moosechips</dc:creator>
				<category><![CDATA[<code>]]></category>

		<guid isPermaLink="false">http://www.moosechips.com/?p=722</guid>
		<description><![CDATA[Simplify python string formatting using locals() or vars(). In python 2 style print keyword usage. Use print( string ) for python 3k. name = 'moose' adjective = 'squishy' &#160; print '{name} is {adjective}'.format&#40;**locals&#40;&#41;&#41; # moose is squishy &#160; # vars() with no args is same as locals() print '{name} is {adjective}'.format&#40;**vars&#40;&#41;&#41; # moose is squishy [...]]]></description>
			<content:encoded><![CDATA[<p>Simplify python string formatting using <code>locals()</code> or <code>vars()</code>.  In python 2 style <code>print</code> keyword usage.  Use <code>print( string )</code> for python 3k.</p>

<div class="wp_syntax"><div class="code"><pre class="python geshicode" id="geshiid" style="font-family:monospace;">name = <span style="color: #483d8b;color: #AD7FA8;">'moose'</span>
adjective = <span style="color: #483d8b;color: #AD7FA8;">'squishy'</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;color: #729FCF;">print</span> <span style="color: #483d8b;color: #AD7FA8;">'{name} is {adjective}'</span>.<span style="color: #35CECE;">format</span><span style=" color: #053163;">&#40;</span><span style=" color: #053163;">**</span><span style="color: #008000;color: #729FCF;">locals</span><span style=" color: #053163;">&#40;</span><span style=" color: #053163;">&#41;</span><span style=" color: #053163;">&#41;</span>
<span style="color: #808080; font-style: italic; color: #81D962;"># moose is squishy</span>
&nbsp;
<span style="color: #808080; font-style: italic; color: #81D962;"># vars() with no args is same as locals()</span>
<span style="color: #ff7700;font-weight:bold;color: #729FCF;">print</span> <span style="color: #483d8b;color: #AD7FA8;">'{name} is {adjective}'</span>.<span style="color: #35CECE;">format</span><span style=" color: #053163;">&#40;</span><span style=" color: #053163;">**</span><span style="color: #008000;color: #729FCF;">vars</span><span style=" color: #053163;">&#40;</span><span style=" color: #053163;">&#41;</span><span style=" color: #053163;">&#41;</span>
<span style="color: #808080; font-style: italic; color: #81D962;"># moose is squishy</span></pre></div></div>

<p>Using vars to access object properties</p>

<div class="wp_syntax"><div class="code"><pre class="python geshicode" id="geshiid" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;color: #729FCF;">class</span> Cat:
    <span style="color: #ff7700;font-weight:bold;color: #729FCF;">def</span> <span style="color: #35CECE;">__init__</span><span style=" color: #053163;">&#40;</span><span style="color: #008000;color: #729FCF;">self</span>, name, adj<span style=" color: #053163;">&#41;</span>:
        <span style="color: #008000;color: #729FCF;">self</span>.<span style="color: #35CECE;">name</span> = name
        <span style="color: #008000;color: #729FCF;">self</span>.<span style="color: #35CECE;">adjective</span> = adj
&nbsp;
kitty = Cat<span style=" color: #053163;">&#40;</span><span style="color: #483d8b;color: #AD7FA8;">'Garfield'</span>, <span style="color: #483d8b;color: #AD7FA8;">'hungry'</span><span style=" color: #053163;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;color: #729FCF;">print</span> <span style="color: #483d8b;color: #AD7FA8;">'{name} is {adjective}'</span>.<span style="color: #35CECE;">format</span><span style=" color: #053163;">&#40;</span><span style=" color: #053163;">**</span><span style="color: #008000;color: #729FCF;">vars</span><span style=" color: #053163;">&#40;</span>kitty<span style=" color: #053163;">&#41;</span><span style=" color: #053163;">&#41;</span>
<span style="color: #808080; font-style: italic; color: #81D962;"># Garfield is hungry</span></pre></div></div>

<p>Now do some <a href="http://stackoverflow.com/questions/2201867/capturing-vars-pattern-in-string-formatting">hacks</a> to get rid of that <code>.format(**locals())</code></p>

<div class="wp_syntax"><div class="code"><pre class="python geshicode" id="geshiid" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;color: #729FCF;">import</span> <span style="color: #dc143c;color: #729FCF;">inspect</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;color: #729FCF;">def</span> printhack<span style=" color: #053163;">&#40;</span>s<span style=" color: #053163;">&#41;</span>:
    caller = <span style="color: #dc143c;color: #729FCF;">inspect</span>.<span style="color: #35CECE;">currentframe</span><span style=" color: #053163;">&#40;</span><span style=" color: #053163;">&#41;</span>.<span style="color: #35CECE;">f_back</span>
    <span style="color: #ff7700;font-weight:bold;color: #729FCF;">print</span> s.<span style="color: #35CECE;">format</span><span style=" color: #053163;">&#40;</span><span style=" color: #053163;">**</span>caller.<span style="color: #35CECE;">f_locals</span><span style=" color: #053163;">&#41;</span>
&nbsp;
applecolor = <span style="color: #483d8b;color: #AD7FA8;">'red'</span>
&nbsp;
printhack<span style=" color: #053163;">&#40;</span><span style="color: #483d8b;color: #AD7FA8;">'apples are {applecolor}'</span><span style=" color: #053163;">&#41;</span>
<span style="color: #808080; font-style: italic; color: #81D962;"># apples are red</span>
&nbsp;
&nbsp;
<span style="color: #ff7700;font-weight:bold;color: #729FCF;">def</span> dbgvar<span style=" color: #053163;">&#40;</span>varname<span style=" color: #053163;">&#41;</span>:
    caller = <span style="color: #dc143c;color: #729FCF;">inspect</span>.<span style="color: #35CECE;">currentframe</span><span style=" color: #053163;">&#40;</span><span style=" color: #053163;">&#41;</span>.<span style="color: #35CECE;">f_back</span>
    <span style="color: #ff7700;font-weight:bold;color: #729FCF;">print</span> <span style="color: #483d8b;color: #AD7FA8;">'variable &quot;{varname}&quot; is {value}'</span>.<span style="color: #35CECE;">format</span><span style=" color: #053163;">&#40;</span>varname=varname, value=caller.<span style="color: #35CECE;">f_locals</span><span style=" color: #053163;">&#91;</span>varname<span style=" color: #053163;">&#93;</span><span style=" color: #053163;">&#41;</span>
&nbsp;
duck = <span style="color: #483d8b;color: #AD7FA8;">'soup'</span>
&nbsp;
dbgvar<span style=" color: #053163;">&#40;</span><span style="color: #483d8b;color: #AD7FA8;">'duck'</span><span style=" color: #053163;">&#41;</span>
<span style="color: #808080; font-style: italic; color: #81D962;"># variable &quot;duck&quot; is soup</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.moosechips.com/2011/02/simple-python-printing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>explicit is not better than implicit</title>
		<link>http://www.moosechips.com/2011/02/explicit-is-not-better-than-implicit/</link>
		<comments>http://www.moosechips.com/2011/02/explicit-is-not-better-than-implicit/#comments</comments>
		<pubDate>Thu, 17 Feb 2011 13:56:52 +0000</pubDate>
		<dc:creator>moosechips</dc:creator>
				<category><![CDATA[<code>]]></category>

		<guid isPermaLink="false">http://www.moosechips.com/?p=719</guid>
		<description><![CDATA[I&#8217;m sick of all the python fangeeks always using the argument that &#8220;explicit is better than implicit&#8221; to justify python behaviors. I think it&#8217;s a good design principle to consider, but it is not a overarching commandment that good code should always be explicit. Convenience and readability is sometimes better than explicit. Use your brain, [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m sick of all the python fangeeks always using the argument that &#8220;explicit is better than implicit&#8221; to justify python behaviors.  I think it&#8217;s a good design principle to consider, but it is not a overarching commandment that good code should always be explicit.  Convenience and readability is sometimes better than explicit.  Use your brain, don&#8217;t be a eibti zombie.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.moosechips.com/2011/02/explicit-is-not-better-than-implicit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python call easy_install within a Python session</title>
		<link>http://www.moosechips.com/2011/02/python-call-easy_install-within-a-python-session/</link>
		<comments>http://www.moosechips.com/2011/02/python-call-easy_install-within-a-python-session/#comments</comments>
		<pubDate>Thu, 17 Feb 2011 12:34:56 +0000</pubDate>
		<dc:creator>moosechips</dc:creator>
				<category><![CDATA[<code>]]></category>
		<category><![CDATA[easy_install]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.moosechips.com/?p=717</guid>
		<description><![CDATA[Thanks stack overflow from setuptools.command import easy_install easy_install.main&#40; &#91;&#34;-U&#34;,&#34;py2app&#34;&#93; &#41;]]></description>
			<content:encoded><![CDATA[<p>Thanks <a href="http://stackoverflow.com/questions/935111/using-easy-install-inside-a-python-script">stack overflow</a></p>

<div class="wp_syntax"><div class="code"><pre class="python geshicode" id="geshiid" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;color: #729FCF;">from</span> setuptools.<span style="color: #35CECE;">command</span> <span style="color: #ff7700;font-weight:bold;color: #729FCF;">import</span> easy_install
easy_install.<span style="color: #35CECE;">main</span><span style=" color: #053163;">&#40;</span> <span style=" color: #053163;">&#91;</span><span style="color: #483d8b;color: #AD7FA8;">&quot;-U&quot;</span>,<span style="color: #483d8b;color: #AD7FA8;">&quot;py2app&quot;</span><span style=" color: #053163;">&#93;</span> <span style=" color: #053163;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.moosechips.com/2011/02/python-call-easy_install-within-a-python-session/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Redmine on Ubuntu Maverick</title>
		<link>http://www.moosechips.com/2011/02/redmine-on-ubuntu-maverick/</link>
		<comments>http://www.moosechips.com/2011/02/redmine-on-ubuntu-maverick/#comments</comments>
		<pubDate>Sat, 05 Feb 2011 03:36:23 +0000</pubDate>
		<dc:creator>moosechips</dc:creator>
				<category><![CDATA[<linux>]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[maverick]]></category>
		<category><![CDATA[redmine]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.moosechips.com/?p=701</guid>
		<description><![CDATA[Redmine is a project management software. There&#8217;s existing documentation on the web about installing Redmine on Ubuntu, but much of it is out of date and confusing. Redmine is in the Ubuntu repos now so the installation is really quite simple. sudo tasksel install lamp-server sudo apt-get install redmine Select sqlite for the database (redmine-sqlite [...]]]></description>
			<content:encoded><![CDATA[<p>Redmine is a project management software.  There&#8217;s existing <a href="http://www.redmine.org/projects/redmine/wiki/howto_install_redmine_in_ubuntu">documentation</a> <a href="http://wiki.ousli.org/index.php/RedmineUbuntu">on the web</a> about <a href="http://drinkingbird.net/blog/articles/2008/02/27/setting-up-a-redmine-site-on-ubuntu">installing Redmine on Ubuntu</a>, but much of it is out of date and confusing.  Redmine is in the Ubuntu repos now so the installation is really quite simple.</p>

<div class="wp_syntax"><div class="code"><pre class="bash geshicode" id="geshiid" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;color: #729FCF;">sudo</span> tasksel <span style="color: #c20cb9; font-weight: bold;color: #729FCF;">install</span> lamp-server
<span style="color: #c20cb9; font-weight: bold;color: #729FCF;">sudo</span> <span style="color: #c20cb9; font-weight: bold;color: #729FCF;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;color: #729FCF;">install</span> redmine</pre></div></div>

<p>Select <code>sqlite</code> for the database (redmine-sqlite is installed as a dependency by apt-get and it&#8217;s simpler to setup than mysql).</p>
<p>Now to configure the Apache bits.</p>

<div class="wp_syntax"><div class="code"><pre class="bash geshicode" id="geshiid" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;color: #729FCF;">sudo</span> <span style="color: #c20cb9; font-weight: bold;color: #729FCF;">ln</span> <span style="color: #660033;color: #35CECF;">-s</span> <span style=" color: #053163;">/</span>usr<span style=" color: #053163;">/</span>share<span style=" color: #053163;">/</span>redmine<span style=" color: #053163;">/</span>public <span style=" color: #053163;">/</span>var<span style=" color: #053163;">/</span>www<span style=" color: #053163;">/</span>redmine
<span style="color: #c20cb9; font-weight: bold;color: #729FCF;">sudo</span> <span style="color: #c20cb9; font-weight: bold;color: #729FCF;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;color: #729FCF;">install</span> libapache2-mod-passenger
<span style="color: #c20cb9; font-weight: bold;color: #729FCF;">sudo</span> <span style="color: #c20cb9; font-weight: bold;color: #729FCF;">vim</span> <span style=" color: #053163;">/</span>etc<span style=" color: #053163;">/</span>apache2<span style=" color: #053163;">/</span>mods-available<span style=" color: #053163;">/</span>passenger.conf</pre></div></div>

<p>Add the <code>PassengerDefaultUser www-data</code> line to <code>/etc/apache2/mods-available/passenger.conf</code>.  It should look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="conf geshicode" id="geshiid" style="font-family:monospace;">&lt;IfModule mod_passenger.c&gt;
  PassengerDefaultUser www-data
  PassengerRoot /usr
  PassengerRuby /usr/bin/ruby
&lt;/IfModule&gt;</pre></div></div>

<p>Configure apache by adding these lines to <code>/etc/apache2/sites-available/default</code></p>

<div class="wp_syntax"><div class="code"><pre class="apache geshicode" id="geshiid" style="font-family:monospace;">&lt;<span style="color: #000000; font-weight:bold;color: #729FCF;">Directory</span> /var/www/redmine&gt;
    RailsBaseURI /redmine
    PassengerResolveSymlinksInDocumentRoot <span style="color: #0000ff;color: #729FCF;">on</span>
&lt;/<span style="color: #000000; font-weight:bold;color: #729FCF;">Directory</span>&gt;</pre></div></div>

<p>Configure email</p>

<div class="wp_syntax"><div class="code"><pre class="bash geshicode" id="geshiid" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;color: #729FCF;">cd</span> <span style=" color: #053163;">/</span>etc<span style=" color: #053163;">/</span>redmine<span style=" color: #053163;">/</span>default
<span style="color: #c20cb9; font-weight: bold;color: #729FCF;">sudo</span> <span style="color: #c20cb9; font-weight: bold;color: #729FCF;">cp</span> <span style=" color: #053163;">/</span>usr<span style=" color: #053163;">/</span>share<span style=" color: #053163;">/</span>redmine<span style=" color: #053163;">/</span>config<span style=" color: #053163;">/</span>email.yml.example email.yml
<span style="color: #c20cb9; font-weight: bold;color: #729FCF;">sudo</span> <span style="color: #c20cb9; font-weight: bold;color: #729FCF;">vim</span> email.yml</pre></div></div>

<p>If you want to use gmail, delete the default settings and uncomment the gmail section settings.  Add the line</p>

<div class="wp_syntax"><div class="code"><pre class="bash geshicode" id="geshiid" style="font-family:monospace;">    enable_starttls_auto: <span style="color: #c20cb9; font-weight: bold;color: #729FCF;">true</span></pre></div></div>

<p>after the <code>tls: true</code> line.  (see <a href="http://www.redmine.org/projects/redmine/wiki/EmailConfiguration">Redmine Email Config</a> for more info.)</p>
<p>Restart Apache (you will have to restart Apache after you make any redmine config file changes)</p>

<div class="wp_syntax"><div class="code"><pre class="bash geshicode" id="geshiid" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;color: #729FCF;">sudo</span> service apache2 restart</pre></div></div>

<p>Now see if your install worked.  Try <strong>http://localhost/redmine</strong> or <strong>http://server.com/redmine</strong>.  Login with username <code>admin</code> and password <code>admin</code>.</p>
<p>Update: Until Ubuntu updates to Redmine 1.0.4 (currently it installs 1.0.0), there is a <a href="http://www.redmine.org/issues/7013">bug</a> where dates get displayed as {{count}} if you have the Ruby gem i18 v0.5.0 installed instead of v0.4.2.  Quick fix:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby geshicode" id="geshiid" style="font-family:monospace;">sudo gem install i18n <span style=" color: #053163;">-</span>v=0.4.2
sudo gem uninstall i18n <span style=" color: #053163;">-</span>v=0.5.0</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.moosechips.com/2011/02/redmine-on-ubuntu-maverick/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Python Getters and Setters</title>
		<link>http://www.moosechips.com/2011/02/python-getters-and-setters/</link>
		<comments>http://www.moosechips.com/2011/02/python-getters-and-setters/#comments</comments>
		<pubDate>Wed, 02 Feb 2011 00:12:47 +0000</pubDate>
		<dc:creator>moosechips</dc:creator>
				<category><![CDATA[<code>]]></category>
		<category><![CDATA[getter]]></category>
		<category><![CDATA[property]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[setter]]></category>

		<guid isPermaLink="false">http://www.moosechips.com/?p=679</guid>
		<description><![CDATA[A quick note on defining getters and setters using decorators for Python 2.6+ #Must inherit from object #class C: won't work. class C&#40;object&#41;: # Define getter for x #@x.getter doesn't work because self.x is not defined yet :( @property def x&#40;self&#41;: return self._x &#160; # Define setter for x @x.setter def x&#40;self, value&#41;: self._x = [...]]]></description>
			<content:encoded><![CDATA[<p>A quick note on defining getters and setters using decorators for Python 2.6+</p>

<div class="wp_syntax"><div class="code"><pre class="python geshicode" id="geshiid" style="font-family:monospace;"><span style="color: #808080; font-style: italic; color: #81D962;">#Must inherit from object</span>
<span style="color: #808080; font-style: italic; color: #81D962;">#class C: won't work.</span>
<span style="color: #ff7700;font-weight:bold;color: #729FCF;">class</span> C<span style=" color: #053163;">&#40;</span><span style="color: #008000;color: #729FCF;">object</span><span style=" color: #053163;">&#41;</span>:
    <span style="color: #808080; font-style: italic; color: #81D962;"># Define getter for x</span>
    <span style="color: #808080; font-style: italic; color: #81D962;">#@x.getter doesn't work because self.x is not defined yet  :(</span>
    @<span style="color: #008000;color: #729FCF;">property</span>
    <span style="color: #ff7700;font-weight:bold;color: #729FCF;">def</span> x<span style=" color: #053163;">&#40;</span><span style="color: #008000;color: #729FCF;">self</span><span style=" color: #053163;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;color: #729FCF;">return</span> <span style="color: #008000;color: #729FCF;">self</span>._x
&nbsp;
    <span style="color: #808080; font-style: italic; color: #81D962;"># Define setter for x</span>
    @x.<span style="color: #35CECE;">setter</span>
    <span style="color: #ff7700;font-weight:bold;color: #729FCF;">def</span> x<span style=" color: #053163;">&#40;</span><span style="color: #008000;color: #729FCF;">self</span>, value<span style=" color: #053163;">&#41;</span>:
        <span style="color: #008000;color: #729FCF;">self</span>._x = value
&nbsp;
    <span style="color: #808080; font-style: italic; color: #81D962;"># Define deleter for x</span>
    @x.<span style="color: #35CECE;">deleter</span>
    <span style="color: #ff7700;font-weight:bold;color: #729FCF;">def</span> x<span style=" color: #053163;">&#40;</span><span style="color: #008000;color: #729FCF;">self</span><span style=" color: #053163;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;color: #729FCF;">del</span> <span style="color: #008000;color: #729FCF;">self</span>._x
&nbsp;
<span style="color: #ff7700;font-weight:bold;color: #729FCF;">class</span> D<span style=" color: #053163;">&#40;</span>C<span style=" color: #053163;">&#41;</span>:
    @C.<span style="color: #35CECE;">x</span>.<span style="color: #35CECE;">getter</span>
    <span style="color: #ff7700;font-weight:bold;color: #729FCF;">def</span> x<span style=" color: #053163;">&#40;</span><span style="color: #008000;color: #729FCF;">self</span><span style=" color: #053163;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;color: #729FCF;">return</span> <span style="color: #008000;color: #729FCF;">self</span>._x <span style=" color: #053163;">*</span> <span style="color: #ff4500;color: red;">2</span>
&nbsp;
    @x.<span style="color: #35CECE;">setter</span>
    <span style="color: #ff7700;font-weight:bold;color: #729FCF;">def</span> x<span style=" color: #053163;">&#40;</span><span style="color: #008000;color: #729FCF;">self</span>, value<span style=" color: #053163;">&#41;</span>:
        <span style="color: #008000;color: #729FCF;">self</span>._x = value / <span style="color: #ff4500;color: red;">2</span></pre></div></div>

<p>code stolen from the <a href="http://docs.python.org/dev/whatsnew/2.6.html">What&#8217;s new in 2.6 doc</a></p>
<p>Editorializing: I don&#8217;t like the asymmetry of defining the getter and the setter.  It would be better if <code>@x.getter</code> would work for the setter instead of using <code>@property</code> for the getter.  But I guess it&#8217;s better than using <code>x=property(x_getter, x_setter)</code>.  Work on it, Guido.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.moosechips.com/2011/02/python-getters-and-setters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to setup a SparkleShare Private Server on Ubuntu</title>
		<link>http://www.moosechips.com/2011/02/sparkleshare-testing-ubuntu/</link>
		<comments>http://www.moosechips.com/2011/02/sparkleshare-testing-ubuntu/#comments</comments>
		<pubDate>Tue, 01 Feb 2011 09:10:22 +0000</pubDate>
		<dc:creator>moosechips</dc:creator>
				<category><![CDATA[<code>]]></category>
		<category><![CDATA[<linux>]]></category>
		<category><![CDATA[dropbox]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[private]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[setup]]></category>
		<category><![CDATA[sparkleshare]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.moosechips.com/?p=651</guid>
		<description><![CDATA[*Feb 3, 2011: This is a work in progress... *Todo: nautilus integration not working - missing dependencies? (no ubuntu python-nautilus-dev package?) *Todo: compile a release build instead of a debug build? *Todo: build a ubuntu/debian package? SparkleShare is dropbox-like software that can sync to your own private server. The SparkleShare documentation recommends syncing to GitHub [...]]]></description>
			<content:encoded><![CDATA[<p><code>*Feb 3, 2011: This is a work in progress...</code><br />
<code>*Todo: nautilus integration not working - missing dependencies? (no ubuntu python-nautilus-dev package?)</code><br />
<code>*Todo: compile a release build instead of a debug build?</code><br />
<code>*Todo: build a ubuntu/debian package?</code></p>
<p><a href="http://www.sparkleshare.org/">SparkleShare</a> is dropbox-like software that can sync to your own private server.  The <a href="http://www.sparkleshare.org/documentation.php">SparkleShare documentation</a> recommends syncing to GitHub or Gitorius, but all you need is a server with ssh and git.  By using your own private server, your files won&#8217;t be publicly viewable and you can use as much storage space as you have on your server.  Here&#8217;s how to setup SparkleShare with a private server on Ubuntu.</p>
<p>First setup the server.  You will need to have ssh access to the server because<br />
SparkleShare will sync to an existing git repository using ssh public key login.  To setup ssh public key login (passwordless login) run this on your local box</p>

<div class="wp_syntax"><div class="code"><pre class="bash geshicode" id="geshiid" style="font-family:monospace;">ssh-copy-id user<span style=" color: #053163;">@</span>server.com</pre></div></div>

<p>If you get an error, you may need to create a ssh key first.  Run <code>ssh-keygen</code> and create a key without a password.  Then run <code>ssh-copy-id</code> again.</p>
<p>If you don&#8217;t have a server, you can test on the same machine.  Just use <code>localhost</code> for the server address.</p>

<div class="wp_syntax"><div class="code"><pre class="bash geshicode" id="geshiid" style="font-family:monospace;">ssh-copy-id user<span style=" color: #053163;">@</span>localhost</pre></div></div>

<p>Now create a git repository on your server.</p>

<div class="wp_syntax"><div class="code"><pre class="bash geshicode" id="geshiid" style="font-family:monospace;"><span style="color: #666666; font-style: italic; color: #81D962;">#If your public key setup worked, you should</span>
<span style="color: #666666; font-style: italic; color: #81D962;">#be able to login to ssh without entering a password</span>
<span style="color: #c20cb9; font-weight: bold;color: #729FCF;">ssh</span> user<span style=" color: #053163;">@</span>server.com
<span style="color: #c20cb9; font-weight: bold;color: #729FCF;">git</span> init <span style="color: #660033;color: #35CECF;">--bare</span> sparkle.git
<span style="color: #7a0874; font-weight: bold;color: #729FCF;">exit</span></pre></div></div>

<p>Then set up SparkleShare.  You will need sudo privileges for this.
</p>

<div class="wp_syntax"><div class="code"><pre class="bash geshicode" id="geshiid" style="font-family:monospace;"><span style="color: #666666; font-style: italic; color: #81D962;"># There may be more missing dependencies here</span>
<span style="color: #c20cb9; font-weight: bold;color: #729FCF;">sudo</span> <span style="color: #c20cb9; font-weight: bold;color: #729FCF;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;color: #729FCF;">install</span> <span style="color: #c20cb9; font-weight: bold;color: #729FCF;">git</span> build-essential intltool mono-devel gtk-sharp2 nant python-nautilus
<span style="color: #c20cb9; font-weight: bold;color: #729FCF;">mkdir</span> ~<span style=" color: #053163;">/</span><span style="color: #c20cb9; font-weight: bold;color: #729FCF;">install</span>
<span style="color: #7a0874; font-weight: bold;color: #729FCF;">cd</span> ~<span style=" color: #053163;">/</span><span style="color: #c20cb9; font-weight: bold;color: #729FCF;">install</span>
<span style="color: #c20cb9; font-weight: bold;color: #729FCF;">git</span> clone https:<span style=" color: #053163;">//</span>github.com<span style=" color: #053163;">/</span>hbons<span style=" color: #053163;">/</span>SparkleShare.git
<span style="color: #7a0874; font-weight: bold;color: #729FCF;">cd</span> SparkleShare
.<span style=" color: #053163;">/</span>autogen.sh <span style="color: #660033;color: #35CECF;">--prefix</span>=<span style=" color: #053163;">/</span>usr
<span style="color: #c20cb9; font-weight: bold;color: #729FCF;">make</span>
<span style="color: #c20cb9; font-weight: bold;color: #729FCF;">sudo</span> <span style="color: #c20cb9; font-weight: bold;color: #729FCF;">make</span> <span style="color: #c20cb9; font-weight: bold;color: #729FCF;">install</span>
sparkleshare start</pre></div></div>

<p>SparkleShare pops up a welcome dialog with some setup.  Fill in <code>user@server.com</code> for the server and use <code>/home/user/sparkle.git</code> for the folder location.  Then click <code>Sync</code>.  When SparkleShare finishes syncing you should have a SparkleShare folder at <code>~/SparkleShare/sparkle</code> where you can put files.</p>
<p>To redo the setup, stop sparkleshare <code>sparkleshare stop</code> then remove the sparkleshare config directory <code>rm -rf ~/.config/sparkleshare</code> and remove sparkleshare&#8217;s synced directory <code>rm -rf ~/SparkleShare</code> and restart sparkleshare <code>sparkleshare start</code></p>
<p>To uninstall</p>

<div class="wp_syntax"><div class="code"><pre class="bash geshicode" id="geshiid" style="font-family:monospace;">sparkleshare stop
<span style="color: #7a0874; font-weight: bold;color: #729FCF;">cd</span> ~<span style=" color: #053163;">/</span>install<span style=" color: #053163;">/</span>SparkleShare
<span style="color: #c20cb9; font-weight: bold;color: #729FCF;">sudo</span> <span style="color: #c20cb9; font-weight: bold;color: #729FCF;">make</span> uninstall
<span style="color: #c20cb9; font-weight: bold;color: #729FCF;">sudo</span> <span style="color: #c20cb9; font-weight: bold;color: #729FCF;">rm</span> <span style="color: #660033;color: #35CECF;">-rf</span> <span style=" color: #053163;">/</span>usr<span style=" color: #053163;">/</span><span style=" color: #053163;">&#123;</span>lib,share<span style=" color: #053163;">/</span>gnome<span style=" color: #053163;">/</span><span style="color: #7a0874; font-weight: bold;color: #729FCF;">help</span>,share<span style=" color: #053163;">&#125;</span><span style=" color: #053163;">/</span>sparkleshare
<span style="color: #c20cb9; font-weight: bold;color: #729FCF;">rm</span> <span style="color: #660033;color: #35CECF;">-rf</span> ~<span style=" color: #053163;">/</span>SparkleShare
<span style="color: #c20cb9; font-weight: bold;color: #729FCF;">rm</span> <span style="color: #660033;color: #35CECF;">-rf</span> ~<span style=" color: #053163;">/</span>.config<span style=" color: #053163;">/</span>sparkleshare</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.moosechips.com/2011/02/sparkleshare-testing-ubuntu/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Python woes</title>
		<link>http://www.moosechips.com/2011/01/python-woes/</link>
		<comments>http://www.moosechips.com/2011/01/python-woes/#comments</comments>
		<pubDate>Thu, 27 Jan 2011 08:48:07 +0000</pubDate>
		<dc:creator>moosechips</dc:creator>
				<category><![CDATA[<code>]]></category>

		<guid isPermaLink="false">http://www.moosechips.com/2011/01/python-woes/</guid>
		<description><![CDATA[It&#8217;s cool that there are so many Python modules available, but it&#8217;s kinda a pain to install them all. It&#8217;s too bad easy_install doesn&#8217;t do better dependency checking. It just errors out when there&#8217;s something missing. I couldn&#8217;t get numpy to work with the 64 bit version of Python 2.7 for Windows, so I uninstalled [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s cool that there are so many Python modules available, but it&#8217;s kinda a pain to install them all.  It&#8217;s too bad easy_install doesn&#8217;t do better dependency checking.  It just errors out when there&#8217;s something missing.</p>
<p>I couldn&#8217;t get numpy to work with the 64 bit version of Python 2.7 for Windows, so I uninstalled the 64 bit version and installed the 32 bit Python.  Now I need Cython, but Cython gives me some vcvarsall.bat error.  The <a href="http://wiki.cython.org/FAQ#HowdoIworkaroundthe.22unabletofindvcvarsall.bat.22errorwhenusingMinGWasthecompiler.28onWindows.29.3F">Cython FAQ</a> mentions some this vcvarsall error, but none of the workarounds there work.  (Interestingly, the patch they have seems to have been applied twice to pyxbuild.py.)  Getting desperate, I tried installing ActivePython, but it gets stuck on &#8220;determining disk space requirements&#8221; forever.  =P</p>
<p>The trick to installing ActivePython is invoking the installer from a command prompt using <code>msiexec</code>.  Set the <code>INSTALLDIR </code> property if you want to change the directory that ActivePython is installed to (default is <code>C:\python27</code>)</p>

<div class="wp_syntax"><div class="code"><pre class="dos geshicode" id="geshiid" style="font-family:monospace;">msiexec /package ActivePython-2.7.1.3-win64-x64.msi INSTALLDIR=&quot;C:\activepython27&quot; /qr</pre></div></div>

<p><small>I used the ORCA MSI Editor to find the INSTALLDIR property.  Thanks to <a href="http://bloggingabout.net/blogs/harold/archive/2009/01/14/windows-installer-doesn-t-finish-determining-disk-space-requirements.aspx">Harold van de Kamp&#8217;s blog</a> for the info on using msiexec.</small></p>
]]></content:encoded>
			<wfw:commentRss>http://www.moosechips.com/2011/01/python-woes/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Vim: Save and Run Shortcut</title>
		<link>http://www.moosechips.com/2011/01/vim-save-and-run-shortcut/</link>
		<comments>http://www.moosechips.com/2011/01/vim-save-and-run-shortcut/#comments</comments>
		<pubDate>Sat, 22 Jan 2011 05:52:26 +0000</pubDate>
		<dc:creator>moosechips</dc:creator>
				<category><![CDATA[<customization>]]></category>
		<category><![CDATA[<linux>]]></category>
		<category><![CDATA[ide]]></category>
		<category><![CDATA[run]]></category>
		<category><![CDATA[save]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[shortcut]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://www.moosechips.com/?p=638</guid>
		<description><![CDATA[Make Vim more IDE-like by assigning F5 to save and run your current script. Just add this to your ~/.vimrc map &#60;F5&#62; &#60;Esc&#62;:w&#60;CR&#62;:!%:p&#60;CR&#62; This maps the F5 key to run two things: :w, which saves your file, and :!%:p, which will run your current script (! runs a shell command and %:p expands to the [...]]]></description>
			<content:encoded><![CDATA[<p>Make Vim more IDE-like by assigning <code>F5</code> to save and run your current script.  Just add this to your <code>~/.vimrc</code></p>

<div class="wp_syntax"><div class="code"><pre class="bash geshicode" id="geshiid" style="font-family:monospace;">map <span style=" color: #053163;">&lt;</span>F5<span style=" color: #053163;">&gt;</span> <span style=" color: #053163;">&lt;</span>Esc<span style=" color: #053163;">&gt;</span>:<span style="color: #c20cb9; font-weight: bold;color: #729FCF;">w</span><span style=" color: #053163;">&lt;</span>CR<span style=" color: #053163;">&gt;</span>:<span style=" color: #053163;">!%</span>:p<span style=" color: #053163;">&lt;</span>CR<span style=" color: #053163;">&gt;</span></pre></div></div>

<p>This maps the F5 key to run two things: <code>:w</code>, which saves your file, and <code>:!%:p</code>, which will run your current script (<code>!</code> runs a shell command and <code>%:p</code> expands to the path of your current file).</p>
<p>A test example</p>

<div class="wp_syntax"><div class="code"><pre class="bash geshicode" id="geshiid" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;color: #729FCF;">echo</span> <span style="color: #ff0000;color: #AD7FA8;">&quot;#!/bin/bash&quot;</span> <span style=" color: #053163;">&gt;</span> test.sh
<span style="color: #7a0874; font-weight: bold;color: #729FCF;">echo</span> <span style="color: #ff0000;color: #AD7FA8;">&quot;echo hello world&quot;</span> <span style=" color: #053163;">&gt;&gt;</span> test.sh
<span style="color: #c20cb9; font-weight: bold;color: #729FCF;">chmod</span> +x test.sh
<span style="color: #c20cb9; font-weight: bold;color: #729FCF;">vim</span> test.sh</pre></div></div>

<p>Now pressing <code>F5</code> while in Vim will save test.sh and run the file in Vim&#8217;s internal shell.  Just press enter when the script is done to return to Vim.</p>
<p><small>code based on discussion at <a href="http://stackoverflow.com/questions/601039/vim-save-and-run-at-the-same-time">stackoverflow</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://www.moosechips.com/2011/01/vim-save-and-run-shortcut/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Python: Create directory</title>
		<link>http://www.moosechips.com/2011/01/python-create-directory/</link>
		<comments>http://www.moosechips.com/2011/01/python-create-directory/#comments</comments>
		<pubDate>Sat, 22 Jan 2011 03:59:24 +0000</pubDate>
		<dc:creator>moosechips</dc:creator>
				<category><![CDATA[<code>]]></category>
		<category><![CDATA[directory]]></category>
		<category><![CDATA[exists]]></category>
		<category><![CDATA[mkdir]]></category>
		<category><![CDATA[os]]></category>
		<category><![CDATA[path]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.moosechips.com/?p=635</guid>
		<description><![CDATA[Simple Python snippet which creates a directory if it doesn&#8217;t exist. #! /usr/bin/env python import os &#160; # create directory &#34;mydir&#34; if it doesn't exist already os.path.exists&#40;&#34;mydir&#34;&#41; or os.mkdir&#40;&#34;mydir&#34;&#41;]]></description>
			<content:encoded><![CDATA[<p>Simple Python snippet which creates a directory if it doesn&#8217;t exist.</p>

<div class="wp_syntax"><div class="code"><pre class="python geshicode" id="geshiid" style="font-family:monospace;"><span style="color: #808080; font-style: italic; color: #81D962;">#! /usr/bin/env python</span>
<span style="color: #ff7700;font-weight:bold;color: #729FCF;">import</span> <span style="color: #dc143c;color: #729FCF;">os</span>
&nbsp;
<span style="color: #808080; font-style: italic; color: #81D962;"># create directory &quot;mydir&quot; if it doesn't exist already</span>
<span style="color: #dc143c;color: #729FCF;">os</span>.<span style="color: #35CECE;">path</span>.<span style="color: #35CECE;">exists</span><span style=" color: #053163;">&#40;</span><span style="color: #483d8b;color: #AD7FA8;">&quot;mydir&quot;</span><span style=" color: #053163;">&#41;</span> <span style="color: #ff7700;font-weight:bold;color: #729FCF;">or</span> <span style="color: #dc143c;color: #729FCF;">os</span>.<span style="color: #35CECE;">mkdir</span><span style=" color: #053163;">&#40;</span><span style="color: #483d8b;color: #AD7FA8;">&quot;mydir&quot;</span><span style=" color: #053163;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.moosechips.com/2011/01/python-create-directory/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
