Posts for May 2012

  • Last modified May 24, 2012, 12:57 a.m.
    Posted May 22, 2012, 3:07 p.m. by admin

    I first discovered this issue when trying to set up a ZEO server with multiple filestorages under Plone 4.

    At time of writing the latest version of collective.recipe.filestorage is 0.6 with no sign of getting updated.

    For those not in the know, collective.recipe.filestorage is a very handy utility that allows you to easily configure multiple storages (filestorage, blobstorage) behind a single Zeoserver from your buildout configuration. This is essential to the way I'm currently handling my client's infrastructure in the Amazon cloud.

    Basically the problem is if you configure zeo-address in your plone.recipe.zope2instance section to be zeohostname:8100 but the zeoserver itself is set to bind to 0.0.0.0:8100 (also essential in my client's infrastructure), collective.recipe.filestorage will not detect that as a match and will not complete the required configuration that allow the zope clients to be correctly configured with the extra storage information.

    I have submitted a patch to the code maintainers here but I haven't had any response so I'm not sure how active the project is anymore.

    The patch needs to be applied to __init__.py under collective/recipe/filestorage in the egg.

    You can get the patch that needs to be applied to that file from the above link or here for convenience.

    The contents of the patch for posterity:

    41,42c41,50
    <                     if zeo_address is None or zeo_address == part.get('zeo-address', 8100):
    <                         self.zope_parts.append(part_name)
    ---
    >                     try:
    >                         zeo_host, zeo_port = zeo_address.split(':')
    >                     except ValueError, AttributeError:
    >                         if zeo_address is None or zeo_address == part.get('zeo-address', 8100):
    >                             self.zope_parts.append(part_name)
    >                     else:
    >                         zope_address = part.get('zeo-address', '8100')
    >                         zope_tokens = zope_address.split(':')
    >                         if zeo_port == zope_tokens[-1]:
    >                             self.zope_parts.append(part_name)
    

    It just makes the process a little bit smarter. It still makes the same assumption as the original code, that the port number of the zeo server uniquely identifies it. What it does differently is allows for the format where the IP address is specified, thus allowing the correct configuration of the Zope clients with regards to the multiple storages.

  • Last modified May 24, 2012, 1:14 a.m.
    Posted May 15, 2012, 11:45 p.m. by admin

    Getting emacs right when it comes to making it Django dev friendly can be fiddly. Here's how I did it.

    I did this on Debian 7 "wheezy", so your mileage may vary. I would imagine you will have similar results on a recent version of Ubuntu.

    Step 1 - Install and configure django html syntax highlighting

    First, get the files in place

    cd ~/.emacs.d
    wget http://ourcomments.org/Emacs/DL/elisp/nxhtml/zip/nxhtml-2.08-100425.zip
    unzip nxhtml-2.08-100425.zip
    

    Next, edit your .emacs file. I've used vim as the editor here but feel free to use what you're most comfortable with. Even emacs will do!

    cd ~/
    vim .emacs
    

    Add the following lines of code to the end of the file.

    ;; ---------------------------------------------------------------------------
    ;; For django html
    (autoload 'django-html-mumamo-mode "~/.emacs.d/nxhtml/autostart.el")
    (setq auto-mode-alist
    (append '(("\\.html?$" . django-html-mumamo-mode)) auto-mode-alist))
    (setq mumamo-background-colors nil)
    (add-to-list 'auto-mode-alist '("\\.html$" . django-html-mumamo-mode))
    

    Try running emacs. If you get the following error:

    Warning: 'font-lock-beginning-of-syntax-function' is an obsolete variable (as
    of Emacs 23.3); use 'syntax-begin-function' instead.
    

    Run this from the command line:

    replace font-lock-beginning-of-syntax-function syntax-begin-function -- .emacs.d/nxhtml/util/mumamo.el
    

    Step 2 - Configure a colour scheme

    I generally work in a terminal with white text on a black background so my theme choice was color-theme-hober. After the colour scheme is installed there is a ton to chose from. From within emacs META-x, then type "color-theme-". Tap the tab key a couple of times to see all the options.

    If you're using Ubuntu/Debian the colour theme should be an installable package via apt. I took most of these steps from this resource here.

    If you can't use apt, you can download the colour themes from here. Otherwise run:

    sudo apt-get install emacs-goodies-el
    

    From a terminal (once again you can use your editor of choice here).

    vim ~/.emacs
    

    Add the lines:

    ;; ---------------------------------------------------------------------------
    ;; Color-theme
    (add-to-list 'load-path "/usr/share/emacs/site-lisp/emacs-goodies-el/color-theme.el")
    (require 'color-theme)
    (eval-after-load "color-theme"
    '(progn
    (color-theme-initialize)
    (color-theme-hober)))
    

    Replace "color-theme-hober" with another option if you prefer a different colour scheme.

    Step 3 - Add an 80 character column marker

    This step is optional but it's a nice way to get emacs to tell you that you're going over the standard 80 character terminal width.

    Taken from instructions here.

    Install the colomn-marker feature by running the following from a terminal:

    cd ~/.emacs.d
    wget http://www.emacswiki.org/emacs/download/column-marker.el
    

    Once again, edit your .emacs file and add the following lines to the bottom:

    ;; ---------------------------------------------------------------------------
    ;; Column Marker
    (require 'column-marker)
    (add-hook 'python-mode-hook (lambda () (interactive) (column-marker-1 79)))
    

    Note that the column-marker-1 value is 79 not 80. This is because emacs will wrap one character early if a line reaches 80 characters.

    Run emacs again. If you get loading issues add the following to the top of your .emacs file:

    (add-to-list 'load-path "~/.emacs.d/") 
    

    Step 4 - Additional configurations

    Below are some more configurations you can add to emacs that I find rather handy.

    Add any of these code snippets to the end of your .emacs file

    For adding the shortcut key combination META-g to bring up the goto-line feature:

    ;; Set goto line
    (global-set-key "\M-g" 'goto-line)
    

    Ensure files when saved end with a newline character:

    ;; Always end a file with a newline
    (setq require-final-newline t)
    

    Switch off the menu bar I find pretty useless and free up another line for text!

    ;; Turn off menu bar
    (menu-bar-mode -1)
    

    For posterity - here's my whole .emacs file with all configs in one:

    (add-to-list 'load-path "~/.emacs.d/")
    
    ;; ---------------------------------------------------------------------------
    ;; Column Marker
    (require 'column-marker)
    (add-hook 'python-mode-hook (lambda () (interactive) (column-marker-1 79)))
    
    ;; ---------------------------------------------------------------------------
    ;; For django html
    (autoload 'django-html-mumamo-mode "~/.emacs.d/nxhtml/autostart.el")
    (setq auto-mode-alist
    (append '(("\\.html?$" . django-html-mumamo-mode)) auto-mode-alist))
    (setq mumamo-background-colors nil)
    (add-to-list 'auto-mode-alist '("\\.html$" . django-html-mumamo-mode))
    
    ;; ---------------------------------------------------------------------------
    ;; Color-theme
    (add-to-list 'load-path "/usr/share/emacs/site-lisp/emacs-goodies-el/color-theme.el")
    (require 'color-theme)
    (eval-after-load "color-theme"
    '(progn
    (color-theme-initialize)
    (color-theme-hober)))
    
    ;; Set goto line
    (global-set-key "\M-g" 'goto-line)
    
    ;; Always end a file with a newline
    (setq require-final-newline t)
    
    ;; Turn off menu bar
    (menu-bar-mode -1)
    
  • Last modified May 15, 2012, 11:14 p.m.
    Posted May 15, 2012, 11:12 p.m. by admin

    But it just might help someone out...

    I've relied on the kindness of strangers in order to solve the daily problems I face as a developer for too long. I figure it's time to give back a little.

    If it's something I couldn't find a fix for and then subsequently solved the problem myself, you'll find it here. I also plan to document anything I release as open source here, including the code that implemented this blog once I get to packaging it up!