Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Command line tool that runs nib2cib for changed nibs
#!/usr/bin/env python
# encoding: utf-8
import sys
import os
import commands
import hashlib
import getopt
from pyfsevents import registerpath, listen
def usage():
return 'usage: %s [PATH]' % __file__
def main(argv=None):
if argv is None:
argv = sys.argv
if len(argv) != 2:
print usage()
return 1
path = os.path.abspath(argv[1])
if not os.path.isdir(path):
print 'Not a directory: %s' % path
print usage()
return 1
checksums = {}
files = os.listdir(path)
for filename in files:
if os.path.splitext(filename)[1] != '.xib':
xibfile = file(os.path.join(path, filename), 'rb')
checksums[filename] = hashlib.md5(
def rebuild(path, recursive):
for filename in os.listdir(path):
if os.path.splitext(filename)[1] != '.xib':
xibfile = file(os.path.join(path, filename), 'rb')
checksum = hashlib.md5(;
cachedChecksum = checksums.get(filename, None)
if cachedChecksum == None or cachedChecksum == checksum:
checksums[filename] = checksum
command = 'nib2cib %s -R %s' % (os.path.join(path, filename), path)
print command
output = commands.getstatusoutput(command)
assert output[0] == 0, output
registerpath(path, rebuild)
print 'Listening for changes at %s' % path
if __name__ == "__main__":

klaaspieter commented Jan 27, 2011

Requires pyfsevents. Run easy_install pyfsevents to install.

Very nice :)


klaaspieter commented Mar 11, 2011

Now a proper repository

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment