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):
        pass
    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):
                    os.makedirs(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):
        sdist.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)):
                        self.filelist.append(name)

def spec(filename, variable):
    section = None
    for line in open(filename):
        if section is not None:
            if line.startswith("%"):
                return section
            section += line
            continue
        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 = ""
        
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.