1. Guido Draheim
  2. trac-dvbcronrecording-plugin


trac-dvbcronrecording-plugin / src / mysetup.py

Guido Draheim 1106a2a 

## not quite like the GNUmakefile but better to have the
## "compile_catalog" in the normal setup.py build phase
## such that py-installer users can install as normal.

from distutils.cmd import Command
from distutils import log
import re, glob

import os.path
import shutil

EXTRA_DIST = { "." : [ "*.txt", "*.spec", "*/*.po" ]}

class copy_catalog(Command):
    description = "copies a message catalog named <domain>.<lang>.po into <directory>/<lang>/LC_MESSAGES/<domain>.po"
    user_options = [
        ('output-dir=', 'd',
         'path to base directory containing the output catalogs - defaults to "./locale"'),
        ('source-dir=', 'd',
         'path to base directory containing the input catalogs - defaults to parent of "directory"'),
    def initialize_options(self):
        self.domain = 'messages'
        self.output_dir = 'locale'
        self.source_dir = None
    def finalize_options(self):
    def run(self):
        check = re.compile(r"(.*)[.](\w+)([.]po)$")
        directory = self.output_dir or "locale"
        sourcedir = self.source_dir or os.path.dirname(directory)
        sourcepattern = os.path.join(sourcedir, "*.po")
        log.debug("looking for %s", sourcepattern)
        for filename in glob.glob(sourcepattern):
            m = check.match(os.path.basename(filename))
            if m:
                domain, locale, ext = m.groups()
                po_file = os.path.join(directory, locale,
                    "LC_MESSAGES", domain + ext)
                log.error("copying %s into %s", filename, po_file)
                po_dirpath = os.path.dirname(po_file)
                if not os.path.isdir(po_dirpath):
                shutil.copy(filename, po_file)
from distutils.command.sdist import sdist

class dist(sdist):
    description = "create a source distribution (tarball, zip file, etc.)"
    extra_dist = EXTRA_DIST
    def get_file_list(self):
        for data in [ "package_data", "data_files", "extra_dist" ]:
            package_data = getattr(self.distribution, data, getattr(self, data, {}))           
            if not package_data: continue
            for package, patterns in package_data.items():
                for pattern in patterns:
                    import glob, os.path
                    for name in glob.glob(os.path.join(package, pattern)):

def spec(filename, variable):
    section = None
    for line in open(filename):
        if section is not None:
            if line.startswith("%"):
                return section
            section += line
        m = re.match(r"%define\s+(\w+)\s+(\S+)", line)
        if m and m.group(1) == "_"+variable:
            return m.group(2)
        m = re.match(r"(\w+):\s+(\S+)", line)
        if m and m.group(1) == variable:
            return m.group(2)
        m = re.match(r"%(\w+)\s*$", line)
        if m and m.group(1) == variable:
            section = ""