| 1 | #!/usr/bin/env python |
|---|
| 2 | |
|---|
| 3 | import os |
|---|
| 4 | import subprocess |
|---|
| 5 | from setuptools import setup, find_packages, Command |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | def run(*args, **kwargs): |
|---|
| 9 | """Run a command""" |
|---|
| 10 | defaults = {"stdout": subprocess.PIPE} |
|---|
| 11 | defaults.update(kwargs) |
|---|
| 12 | print " ".join(args) |
|---|
| 13 | process = subprocess.Popen(args, **defaults) |
|---|
| 14 | return process.wait() |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | def walk(iterator, path="."): |
|---|
| 18 | """Iterator version of os.walk()""" |
|---|
| 19 | # Cache os.walk result to allow modification of the current path in |
|---|
| 20 | # commands |
|---|
| 21 | cache = list(os.walk(os.path.abspath(path))) |
|---|
| 22 | for directory in cache: |
|---|
| 23 | if ".svn" not in directory[0]: |
|---|
| 24 | for item in iterator(directory): |
|---|
| 25 | yield item |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | def localized_directories(directory): |
|---|
| 29 | dirpath, dirnames, filenames = directory |
|---|
| 30 | if "locale" in dirnames: |
|---|
| 31 | yield os.path.join(dirpath) |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | class NoOptionsCommand(Command): |
|---|
| 35 | user_options = [] |
|---|
| 36 | |
|---|
| 37 | def initialize_options(self): |
|---|
| 38 | pass |
|---|
| 39 | def finalize_options(self): |
|---|
| 40 | pass |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | class MakeMessages(NoOptionsCommand): |
|---|
| 44 | description = "create django's language files from source" |
|---|
| 45 | |
|---|
| 46 | def run(self): |
|---|
| 47 | for dir in walk(localized_directories): |
|---|
| 48 | run("django-admin.py", "makemessages", "-a", cwd=dir) |
|---|
| 49 | run("django-admin.py", "makemessages", "-d", "djangojs", "-a", |
|---|
| 50 | cwd=dir) |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | class CompileMessages(NoOptionsCommand): |
|---|
| 54 | description = "compile django's language files" |
|---|
| 55 | |
|---|
| 56 | def run(self): |
|---|
| 57 | for dir in walk(localized_directories): |
|---|
| 58 | run("django-admin.py", "compilemessages", cwd=dir) |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | setup( |
|---|
| 63 | name = "derez", |
|---|
| 64 | version = 0.1, |
|---|
| 65 | author = "Luper Rouch", |
|---|
| 66 | author_email = "luper.rouch@gmail.com", |
|---|
| 67 | |
|---|
| 68 | packages = find_packages(), |
|---|
| 69 | |
|---|
| 70 | cmdclass = { |
|---|
| 71 | # Update language files from the source files |
|---|
| 72 | "makemessages": MakeMessages, |
|---|
| 73 | # Compile language files |
|---|
| 74 | "compilemessages": CompileMessages, |
|---|
| 75 | }, |
|---|
| 76 | ) |
|---|