A few Gentoo tips

Mostly archived here for my benefit for when I break something with a reckless emerge -uDNAv world update again. *vbg*

  1. To install a binary version when something major's borked (like when you can't get anything to compile, including gcc, because you broke gcc…)
    • Go to tinderbox.dev.gentoo.org and find the correct directory for your machine. (For example, my AMD64 server uses binaries in the tinderbox.dev.gentoo.org/default/linux/amd64/ directory.)
    • Add this to your /etc/make.conf (or /etc/portage/make.conf), all on one line: PORTAGE_BINHOST="http://tinderbox.dev.gentoo.org/default-linux/amd64/"

      (Use the directory you chose in the previous step, obviously.)

    • To install the binary from tinderbox, use emerge -G $package. So, to install a gcc binary, you would type: emerge -G gcc
    • More info available here.
  2. To find out what a USE flag does:
    • euse -i $flag
    • So to find out what the multilib flag does, you would type euse -i multilib
    • Euse is part of the gentoolkit package, so you'll need to emerge that if you haven't already (emerge -uDNav gentoolkit).
  3. One way to fix the dreaded C++ preprocessor "/lib/cpp" fails sanity check error:
    • Update your active gcc version with a binary from tinderbox, as explained above. To see which gcc version that's installed on your machine the system is using as the default, type gcc-config -l. (That's an L for list.)
    • Make sure that gcc has the cxx USE flag enabled (in your /etc/portage/package.use or make.conf), so that it will build with support for C++ and won't break when rebuilt. (Ask me how I learned that flag was needed. Yeah. *vbg*)
    • Rebuild gcc (emerge -uDNav gcc).
  4. Typing emerge --info --verbose $package will tell you the system info and all the USE flags a package was built with, so you can see if the flags you needed enabled/disabled are.
  5. Older snapshots of portage are available if you are trying to update an older system that hasn't been updated in a while.
  6. List of USE flags
  7. Gentoo cheat sheet

What's your favorite tip or trick when dealing with an "oh crap, what the hell did I do?" moment?

Default (initial) value in Django's admin for a choice field

I was trying to set the initial value for a choice field in the admin like this:

from django import forms
from django.contrib import admin
from mptt.admin import MPTTModelAdmin
from author.models import Author
from serials.constants import STATUS_CHOICES

class AuthorAdminForm(forms.ModelForm):
    class Meta:
        model = Author

class AuthorAdmin(MPTTModelAdmin):
    form = AuthorAdminForm(initial={'status': STATUS_CHOICES[0][0]})
admin.site.register(Author, AuthorAdmin)

Logically, I should have been able to do it this way, I thought, at least according to the docs. But instead it was giving me this error: TypeError: issubclass() arg 1 must be a class. (Uh, ok.) After a bit of searching, I eventually found this comment, and realized I must be trying to instantiate a form that the admin would instantiate automatically, had already been instantiated, or something like that.

After some more searching, I found the answer on the way to do what I needed here:

from django import forms
from django.contrib import admin
from mptt.admin import MPTTModelAdmin
from author.models import Author
from serials.constants import STATUS_CHOICES

class AuthorAdminForm(forms.ModelForm):
    class Meta:
        model = Author

    def __init__(self, *args, **kwargs):
        super(AuthorAdminForm, self).__init__(*args, **kwargs)
        self.initial['status'] = STATUS_CHOICES[0][0]
class AuthorAdmin(MPTTModelAdmin):
    form = AuthorAdminForm
admin.site.register(Author, AuthorAdmin)

Yay! Hope this helps someone else who has the same issue. :)

Django trick: using named admin urls in templates

To add a link to an admin page on the user-side of your django site, you can use the named url patterns. (Seems like a simple and fairly straightforward thing to want to do, but I frequently find that things are not so simply found in most open source docs, nor are the examples always useful. But my usual open source docs rant is for another day. *g*)

It took a bit of digging, but I finally found that the admin url pattern options are listed here. From that, I was able to figure out that if I wanted to link to the edit (change action) page (parameter) for an article (model) in the app article, the pattern was:

{{ app_label }}_{{ model_name }}_action [parameters]

The namespace for the admin is, of course, admin, so putting that together using the {% url %} template tag, you get:

<a href="{% url 'admin:article_article_change' article.pk %}">{% trans 'Edit' %}</a>

That correctly creates the relative url to /admin/article/article/2. Yay!

Be sure to load the admin template tags in your template, too, or it won't work:

{% load admin_urls %}

Et voilà! *vbg* Hope this saves someone else a bit of time.

(This works for Django 1.4, btw.)


Stephen Colbert interviewing Maurice Sendak:

ETA: The next part of the interview is here viagra pharmacie sans ordonnance.

Holy Hannah, what are these authors thinking?

(Yes, I'm rewatching SG-1 lately. Hush.)

I'm checking out the websites of the authors attending COSine this weekend, so I have some idea of who they are, what they write, and how much they need my help, and wow, seriously. 1995-era GeoCities just called and wants its websites back. Yikes!

I mock because I love, but seriously, folks: the whole point of an author's site is to get readers to read what you've written, so give them that information. Most readers don't care about your cat, your past lives, or your obsession with Cheez-Its; we're visiting your site because we read something by you that we enjoyed and now we just want to read more of your stories.

More on this topic later. (I'm working on a presentation about it right now, as a matter of fact.)


I'm not just saying that: I really do love helping authors reach out to readers, and I hate seeing it done badly. It causes me physical pain every time I visit an author's site that looks like it was thrown together by the neighbor's kid or That Guy you know from work who knows web design. *rolls eyes* You get what you pay for, folks!