view roundup/dist/command/build.py @ 7800:2d4684e4702d

fix: enhancement to history command output and % template fix. Rather than using the key field, use the label field for descriptions. Call cls.labelprop(default_to_id=True) so it returns id rather than the first sorted property name. If labelprop() returns 'id' or 'title', we return nothing. 'id' means there is no label set and no properties named 'name' or 'title'. So have the caller do whatever it wants (prepend classname for example) when there is no human readable name. This prevents %(name)s%(key)s from producing: 23(23). Also don't accept the 'title' property. Titles can be too long. Arguably we could: '%(name)20s' to limit the title length. However without ellipses or something truncating the title might be confusing. So again pretend there is no human readable name.
author John Rouillard <rouilj@ieee.org>
date Tue, 12 Mar 2024 11:52:17 -0400
parents 1acdc651133b
children fed0f839c260
line wrap: on
line source

#
# Copyright (C) 2009 Stefan Seefeld
# All rights reserved.
# For license terms see the file COPYING.txt.
#
from __future__ import print_function
from roundup import msgfmt
try:
    from setuptool.command.install import install as base
except ImportError:
    from distutils.command.build import build as base
import os
from glob import glob

def list_message_files(suffix=".po"):
    """Return list of all found message files and their intallation paths"""
    _files = glob("locale/*" + suffix)
    _list = []
    for _file in _files:
        # basename (without extension) is a locale name
        _locale = os.path.splitext(os.path.basename(_file))[0]
        _list.append((_file, os.path.join(
            "share", "locale", _locale, "LC_MESSAGES", "roundup.mo")))
    return _list

def check_manifest():
    """Check that the files listed in the MANIFEST are present when the
    source is unpacked.
    """
    manifest_file = 'roundup.egg-info/SOURCES.txt'
    try:
        f=open(manifest_file)
    except:
        print('\n*** SOURCE WARNING: The MANIFEST file "%s" is missing!' % manifest_file)
        return
    try:
        manifest = [l.strip() for l in f.readlines()]
    finally:
        f.close()
    err = set([line for line in manifest if not os.path.exists(line)])
    # ignore auto-generated files
    err = err - set(['roundup-admin', 'roundup-demo', 'roundup-gettext',
        'roundup-mailgw', 'roundup-server', 'roundup-xmlrpc-server'])
    if err:
        n = len(manifest)
        print('\n*** SOURCE WARNING: There are files missing (%d/%d found)!'%(
            n-len(err), n))
        print('Missing:', '\nMissing: '.join(err))

def build_message_files(command):
    """For each locale/*.po, build .mo file in target locale directory"""
    for (_src, _dst) in list_message_files():
        _build_dst = os.path.join("build", _dst)
        command.mkpath(os.path.dirname(_build_dst))
        command.announce("Compiling %s -> %s" % (_src, _build_dst))
        mo = msgfmt.Msgfmt(_src).get()
        open(_build_dst, 'wb').write(mo)


class build(base):

    def run(self):
        check_manifest()
        build_message_files(self)
        base.run(self)


Roundup Issue Tracker: http://roundup-tracker.org/