Fixed Blog; On Nginx now

Finally fixed my website and switched to Nginx (from Lighttpd, sorry Jan!). Was a pain setting up Nginx, but afterwards, the configuration looks clean. Actually, the major headache was setting up WordPress with SSL admin on different server.

Using printf format %P with find in RPM spec file

While creating a spec file for an RPM, I needed to generate the list of files installed by the RPM. Solution is simple, use the UNIX command find. Right..

My first attempt was the following:

# copy the files
( cd %{buildroot} ; find -type f -print "/%P\n" ) > INSTALLED_FILES

If you do the above, you’ll find that all entries in INSTALLED_FILES are wrong: file name have ‘ATCH’ at the end. Why is this? Because %p is a special macro in RPM spec files.

You can try to escape %P in an RPM spec file. If you manage that, let me know, I couldn’t.

Here is the solution I came up with after lots of hacking: it defines the pattern used in the find command as a macro.

%define findpat %( echo "/%""P" )

# copy the files
( cd %{buildroot} ; find -type f -print "%{findpat}\n" ) > INSTALLED_FILES

I hope you never have to do this though.

By |February 4th, 2013|Work|0 Comments|

Find out if every element of a list is part of another, with Python

Update 2010-08-27: Comments indicated that what I did here is not the best solution. Like noted in my original post, a set would be better in this case. I eventually used set(r).issubset(set(l)). Marius also pointed out to set(r) <= set(l), but I like the issubset one more.

I wanted to check if every element of one list or tuple is part of another one using Python. A set has the issubset()-method, but I couldn't find anything build-in for a tuple. It was, however, rather quickly done:

>>> r = (1,2)
>>> l = (3,4,1,5,2)
>>> False not in [ e in l for e in r ]
>>> r = (1,9)
>>> False not in [ e in l for e in r ]

Why I'm posting this? I just found it cute code, somehow.

Using Globals in Pylons.. everywhere

In Pylons v1.0 you can define global variables by adding them to the Globals-class. If you want a variable called spam and you want it to be globally available, your lib.app_globals.Globals-class would look like this:

class Globals(object):
  def __init__(self, config):
    self.cache = CacheManager(**parse_cache_config_options(config))
    self.spam = False

To use it in a model-module for example, you have to import app_globals from the pylons module, like this:

from pylons import app_globals as g

print g.spam

It took me a while to figure this out.. And I’m starting to like Pylons somehow.

AppleScript exporting photos from Aperture

The following AppleScript will:

  1. Prompt for a destination folder

  2. Ask for an album name, which will be a folder in destination folder
  3. Get currently selected photo(s) from Aperture
  4. Store the image files using the Image ID of Aperture
  5. Store some META information in a text file, with similar name as image file

The export format is PNG 1024x1024. I needed only that, so I hardcoded it.

Note dependencies: You need the renameFile, joinList and splitString functions found in earlier blog entries.

property defExportSetting : "PNG - Fit within 1024 x 1024"

on apertureExport(fldAlbum)
 tell application "Aperture"
  set imageSel to (get selection)
 end tell
 set out to {}
 repeat with img in imageSel
  tell application "Aperture"
   set kwList to (get id of every keyword of img)
   set imgDate to value of EXIF tag "ImageDate" of img
  end tell
  set imgId to id of img
  set imgName to name of img
  set imgTags to my joinList(kwList, ",")
  copy "Name: " & imgName to end of out
  copy "Tags: " & imgTags to end of out
  copy "ApertureId: " & imgId to end of out
  set dstFileMeta to (fldAlbum & imgId & ".meta") as string
 end repeat
 tell application "Aperture"
  set dstFile to (export imageSel using export setting defExportSetting to fldAlbum)
 end tell
 set dstFile to my renameFile(dstFile, imgId)
 copy "File: " & (POSIX path of dstFile) to end of out
 tell application "Finder"
 end tell
 set fp to open for access file dstFileMeta with write permission
 write (joinList of out given delimiter:return) to fp
 close access fp
end apertureExport

on run
 set dstFolder to (choose folder with prompt "Choose an destination") as text
 set dlgAlbum to display dialog "Album name" buttons {"OK", "Cancel"} default answer "Picture pool"
 set dstAlbum to (text returned of dlgAlbum) as text
 tell application "Finder"
  if not (exists alias (dstFolder & dstAlbum)) then
   make new folder at alias (dstFolder) with properties {name:dstAlbum}
  end if
 end tell
 set fldAlbum to (dstFolder & dstAlbum) as alias
end run

This script is safe, but I don’t take any responsibility when it screws up you Aperture library. It shouldn’t really, I coded it on my main library: hardcore!