From 26f28e57aabf0f7191b1227beb0dd85f4497a9c6 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sun, 17 Aug 2003 20:54:29 +0000 Subject: [PATCH] * python/gettext.py: Remove. We already require python 2.1, which includes gettext.py. * configure.in: Require python 2.1, as INSTALL.texi says. it. * Documentation/topdocs/INSTALL.texi: Add note to avoid bison versions 1.50 and 1.75. Remove note about lexer patch. --- ChangeLog | 25 +++ Documentation/topdocs/INSTALL.texi | 67 +++--- GNUmakefile.in | 7 + configure.in | 3 +- cygwin/changelog | 8 + cygwin/mknetrel | 281 ++++-------------------- debian/control | 2 +- python/gettext.py | 329 ----------------------------- 8 files changed, 115 insertions(+), 607 deletions(-) delete mode 100644 python/gettext.py diff --git a/ChangeLog b/ChangeLog index 65083d6427..4bbddb6753 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,28 @@ +2003-08-17 Jan Nieuwenhuizen + + * python/gettext.py: Remove. We already require python 2.1, which + includes gettext.py. + + * configure.in: Require python 2.1, as INSTALL.texi says. + it. + + * Documentation/topdocs/INSTALL.texi: Add note to avoid bison + versions 1.50 and 1.75. Remove note about lexer patch. + +2003-08-16 Jan Nieuwenhuizen + + * Documentation/topdocs/INSTALL.texi: Update type1 font + description to actual situation. Add comment about new font ball + layout. + + * GNUmakefile.in (pfa-fonts): Create font-ball so that untar + in $LILYPONDPREFIX suffices for installation. + +2003-08-11 Jan Nieuwenhuizen + + * debian/control (Build-Depends): Add flex-old as alternative to + flex. Deprecate bison 1.75. + 2003-08-17 Juergen Reuter * lilypond.words, ly/engraver-init.ly, ly/params-init.ly: added diff --git a/Documentation/topdocs/INSTALL.texi b/Documentation/topdocs/INSTALL.texi index 0c8778b36a..3bae599001 100644 --- a/Documentation/topdocs/INSTALL.texi +++ b/Documentation/topdocs/INSTALL.texi @@ -92,9 +92,10 @@ EGCS 1.1 may work, but is no longer supported. WARNING: plain Flex 2.5.4(a) generates invalid C++ code. GCC 3.x chokes on this. If you wish to use GCC 3.x, make sure that your distribution supports g++ 3.x and flex. For workarounds, see -lexer-gcc-3.0.patch and lexer-gcc-3.1.sh in the source directory. +lexer-gcc-3.1.sh in the source directory. -@item @uref{http://www.gnu.org/software/bison/,Bison} (version 1.25 or newer). +@item @uref{http://www.gnu.org/software/bison/,Bison} (version 1.25 or +newer, but not 1.50 or 1.75). @item @TeX{}. @@ -181,32 +182,47 @@ work. To install GNU LilyPond, type @example - gunzip -c lilypond-x.y.z | tar xf - - cd lilypond-x.y.z - ./configure # run with --help to see appropriate options - make - make install - sh buildscripts/clean-fonts.sh +gunzip -c lilypond-x.y.z | tar xf - +cd lilypond-x.y.z +./configure # run with --help to see appropriate options +make +make install +sh buildscripts/clean-fonts.sh @end example If, in addition, you want to generate PDF files of your scores and have installed mftrace, type @example - make pfa-fonts - make MAKE_PFA_FILES=1 install - texhash +make pfa-fonts +make MAKE_PFA_FILES=1 install +texhash @end example PFA versions of the fonts for the latest LilyPond version can also be obtained from the web site using -@example - mkdir /tmp/newfonts - cd /tmp/newfonts/ - wget -l 1 -nd -r -A pfa,map http://lilypond.org/stable/mf/out/ - mv *.pfa $LILYPONDSHARE/fonts/type1/ - mv *.map $LILYPONDSHARE/dvips/ - texhash +@example +@ignore +# old stuff +mkdir /tmp/newfonts +cd /tmp/newfonts/ +wget -l 1 -nd -r -A pfa,map http://lilypond.org/stable/mf/out/ +mv *.pfa $LILYPONDSHARE/fonts/type1/ +mv *.map $LILYPONDSHARE/dvips/ +texhash +@end ignore +@c this matches the current type1-1.8.0.tar.gz tarball at lilypond.org +@c better not change this before 1.8.1? +wget -P/tmp ftp://ftp.lilypond.org/pub/LilyPond/v1.8/type1-1.8.0.tar.gz +tar -C /usr/share/lilypond/1.8.0/fonts -xf /tmp/type1-1.8.0.tar.gz +mv /usr/share/lilypond/1.8.0/ && mv fonts/type1/*.map /usr/share/lilypond/1.8.0/dvips +texhash @end example -where @code{$LILYPONDSHARE} denotes @code{/usr/share/lilypond/1.7.*/} or +@ignore +@c this matches new font tarbal layout and should work for 1.8.1. +wget -P/tmp ftp://ftp.lilypond.org/pub/LilyPond/v1.8/type1-1.8.1.tar.gz +tar -C /usr/share/lilypond/1.8.1 -xf /tmp/type1-1.8.1.tar.gz +texhash +@end ignore +where @code{$LILYPONDSHARE} denotes @code{/usr/share/lilypond/1.8.0/} or wherever LilyPond is installed on your system. If you are doing an upgrade, you should remove all @file{feta} @@ -326,18 +342,6 @@ Gcc 3.0.4 is flaky; upgrade GCC. @unnumberedsubsec Flex-2.5.4a and gcc-3.x -Flex 2.5.4a does not produce g++-3.0 compliant C++ code. To compile -LilyPond with gcc-3.0 you may do - -@example - CC=gcc-3.0 CXX=g++-3.0 ./configure --enable-config=gcc-3.0 - make conf=gcc-3.0 -C lily out-gcc-3.0/lexer.cc - patch -p1 < lexer-gcc-3.0.patch - make conf=gcc-3.0 -C lily -@end example - -@unnumberedsubsec Flex-2.5.4a and gcc-3.1.x - Flex 2.5.4a does not produce g++-3.1.1 compliant C++ code. To compile LilyPond with gcc-3.1.1 you may do @@ -350,7 +354,6 @@ LilyPond with gcc-3.1.1 you may do @end example - @unnumberedsubsec OpenBSD @itemize @bullet diff --git a/GNUmakefile.in b/GNUmakefile.in index 1c42d31020..de2170d2b8 100644 --- a/GNUmakefile.in +++ b/GNUmakefile.in @@ -35,8 +35,15 @@ doc: pfa-fonts: $(MAKE) MAKE_PFA_FILES=1 -C mf +ifeq (0,1) + # the font ball; used for 1.8.0 (cd $(builddir)/share/lilypond/fonts && \ tar czvf ../../../$(outbase)/type1.tar.gz type1/*.pfa type1/fonts.* type1/lilypond.* ) +else + # the new font ball; to be used for for 1.8.1 + (cd $(builddir)/share/lilypond && \ + tar czvf ../../$(outbase)/type1-$(TOPLEVEL_VERSION).tar.gz fonts/type1/*.pfa fonts/type1/fonts.* dvips/*.map ) +endif web-install: -$(INSTALL) -m 755 -d $(webdir) diff --git a/configure.in b/configure.in index d830d1268d..da18169b13 100644 --- a/configure.in +++ b/configure.in @@ -25,12 +25,13 @@ AC_CONFIG_SUBDIRS(stepmake) # must come before any header checks STEPMAKE_COMPILE -STEPMAKE_PYTHON(REQUIRED,2.0) +STEPMAKE_PYTHON(REQUIRED,2.1) STEPMAKE_GCC(REQUIRED, 2.8) STEPMAKE_CXX(REQUIRED) STEPMAKE_GXX(REQUIRED, 2.95) STEPMAKE_CXXTEMPLATE STEPMAKE_LIB(REQUIRED) +# Do not use bison 1.50 and 1.75. STEPMAKE_BISON(REQUIRED, 1.25) STEPMAKE_FLEX(REQUIRED) STEPMAKE_FLEXLEXER(REQUIRED) diff --git a/cygwin/changelog b/cygwin/changelog index fb085ca2a0..6da5d9a53c 100644 --- a/cygwin/changelog +++ b/cygwin/changelog @@ -1,3 +1,11 @@ +lilypond (1.8.0-11) unstable; urgency=low + + * New upstream release. + * Build on 1.5.1. + * Omit moving of /usr/share/doc -> /usr/doc. + + -- Jan Nieuwenhuizen Thu, 7 Aug 2003 17:47:52 +0200 + lilypond (1.7.29-11) unstable; urgency=low * New upstream release; pre1.8 build. diff --git a/cygwin/mknetrel b/cygwin/mknetrel index bddd54ca62..293e8a8ff9 100644 --- a/cygwin/mknetrel +++ b/cygwin/mknetrel @@ -1,16 +1,16 @@ # -*- shell-script -*- -# stable LilyPond releases: lilypond-1.6 +# ancient LilyPond releases: lilypond-1.6 # archive=ftp://lilypond.org/pub/LilyPond/v1.6 -# LilyPond development: lilypond-1.7 -# archive=ftp://lilypond.org/pub/LilyPond/v1.7 +# stable LilyPond releases: lilypond-1.8 +# archive=ftp://lilypond.org/pub/LilyPond/v1.8 # LilyPond mknetrel overrides # To use this, do something like: cat >/dev/null < config.cache - -ac_cv_c_bigendian=${ac_cv_c_bigendian=no} -ac_cv_sizeof_char=${ac_cv_sizeof_char=1} -ac_cv_sizeof_char_p=${ac_cv_sizeof_char_p=4} -ac_cv_sizeof_double=${ac_cv_sizeof_double=8} -ac_cv_sizeof_float=${ac_cv_sizeof_float=4} -ac_cv_sizeof_int=${ac_cv_sizeof_int=4} -ac_cv_sizeof_long=${ac_cv_sizeof_long=4} -ac_cv_sizeof_long_double=${ac_cv_sizeof_long_double=12} -ac_cv_sizeof_long_long=${ac_cv_sizeof_long_long=8} -ac_cv_sizeof_short=${ac_cv_sizeof_short=2} -ac_cv_sizeof_void_p=${ac_cv_sizeof_void_p=4} -ac_cv_c_long_size_t=${ac_cv_c_long_size_t=no} -ac_cv_c_long_time_t=${ac_cv_c_long_time_t=yes} -ac_16bit_type=${ac_16bit_type=short} -ac_32bit_type=${ac_32bit_type=int} -ac_64bit_type=${ac_64bit_type=none} -ac_cv_sys_restartable_syscalls=${ac_cv_sys_restartable_syscalls=no} -ac_cv_sprintf_count=${ac_cv_sprintf_count=yes} -ac_cv_spinlocks=${ac_cv_spinlocks=no} -ac_cv_func_getpgrp_void=${ac_cv_func_getpgrp_void=yes} -ac_cv_func_setvbuf_reversed=${ac_cv_func_setvbuf_reversed=no} -ac_cv_func_mkfifo=yes - -# Try at preventing to break make rules while crosscompiling. This -# used work, but nowadays ./configure thinks it knows better than me. - -# But what ./configure doesn't know, is that automake and libtool are -# broken wrt cross-building, and wrt cc_for_build. See new -# workarounds above. - -ac_exeext=${ac_exeext=} -ac_cv_exeext=${ac_cv_exeext=} -EOF -} - - - -# -# Subpackage stuff -- Maybe move to mknetrel -# - -# Possibly, using file-lists globs is smarter than separate install -# prefixes. We'll see what happens when packaging tetex-*. - - -lib_name () { - echo lib$base$sover -} - -devel_name () { - echo $base-devel -} - -doc_name () { - echo $base-doc -} - -lib_split () { - mkdir -p ./$prefix/bin || exit 1 - mv $inst/$prefix/bin/*.dll ./$prefix/bin - mkdir -p ./$prefix/share || exit 1 - mv $inst/$prefix/share/$base ./$prefix/share - true -} - -devel_split () { - mkdir -p ./$prefix/bin || exit 1 - mv $inst/$prefix/include ./$prefix/include - mkdir -p ./$prefix/lib || exit 1 - mv $inst/$prefix/lib/*.a ./$prefix/lib - mkdir -p ./$prefix/lib || exit 1 - mv $inst/$prefix/lib/*.la ./$prefix/lib - mkdir -p ./$prefix/share || exit 1 - mv $inst/$prefix/share/aclocal ./$prefix/share - true -} - -doc_split () { - mkdir -p ./$prefix || exit 1 - mv $inst/$prefix/info ./$prefix - true -} - -prebuild () { - for i in $sub_packages; do - rm -rf $inst-$i - mkdir -p $inst-$i || exit 1 - done -} - -domkdist() { - # - # Fix up installation slightly - # - cd $inst || exit 1 - chmod -R a+w . - cd usr 2>/dev/null && dousrstuff - - - # Split off any sub-packages. The actual splitting is handled by - # a package's specific code in extra/. - - # To package `foo' in foo, foo-doc and foo-devel, set - # sub_packages='doc devel'. - - # Then provide functions doc_name and devel_name, that return the - # full name of the sub-package. Also provide functions doc_split - # and devel_split, that mv part of foo's installation in $inst to - # the sub-packages' installation roots $inst-doc and $inst-devel. - - cd $inst || exit 1 - presplit - - for i in $sub_packages; do - subname=$(${i}_name) - cd $inst-$i || exit 1 - ${i}_split || exit 1 - done - - # - # Make tar balls - # - - cd $inst || exit 1 - prepackage - - # The base package - echo creating $tarstem.tar.bz2 - cd $inst || exit 1 - - f=$src/cygwin/setup.hint && test -r $f && cp $f $uploads - f=$src/cygwin/$base.hint && test -r $f && cp $f $uploads/setup.hint - find * -print | sort | tar -T - --no-recursion -cjf $tarstem.tar.bz2 - - # Any sub-packages - for i in $sub_packages; do - subname=$(${i}_name) - subload=$uploads/$subname - subtarstem=$subload/$subname-$ver - mkdir -p $subload || exit 1 - echo creating $subtarstem.tar.bz2 - f=$src/cygwin/$subname.hint && test -r $f && cp $f $subload/setup.hint - cd $inst-$i - find * -print | sort | tar -T - --no-recursion -cjf $subtarstem.tar.bz2 - done - - # The source package - cd $src/.. || exit 1 - echo creating "$tarstem"-src.tar.bz2 - find $package_src/* -print -follow | egrep -v '\.cvsignore|\.bak$|\.orig$|\.o$|~$|^.#|CVS|%redact|/tags$' | egrep -v "$src_exclude" | sort | tar -T - --no-recursion -cjf "$tarstem"-src.tar.bz2 - postpackage -} - - -# end jcn - - +# copy and include extra mknetrel stuff +extras="doc patch auto cross split" +for i in $extras; do + f=mknetrel.$i + [ -r $extra/$f ] && cp -pv $extra/$f $src/cygwin/$f + . $src/cygwin/$f +done needdevoflags () { @@ -267,6 +69,10 @@ EOF chmod 755 guile-config PATH=$(pwd):$PATH + + if [ "$ABI" != "1.5" ];then + export LDFLAGS="$cygwin_prefix/bin/cygkpathsea-3abi13.dll" + fi ##opt='-O2 -g' LDFLAGS='"$cygwin_prefix/bin/libpython2.2.dll" rm -f config.cache } @@ -307,7 +113,11 @@ prebuild () { mkdir -p mf/out cp -pv mf/out-for-build/* mf/out - addmakeflags MAKE_PFA_FILES=1 ' ' LDFLAGS="$cygwin_prefix/bin/libpython2.2.dll" ' ' 'target=i686-pc-cygwin' + if false; then #[ "$ABI" != "1.5" ]; then + addmakeflags MAKE_PFA_FILES=1 ' ' LDFLAGS="$cygwin_prefix/bin/libpython2.2.dll" ' ' 'target=i686-pc-cygwin' + else + addmakeflags MAKE_PFA_FILES=1 ' ' LDFLAGS="$cygwin_prefix/bin/libpython2.3.dll" ' ' 'target=i686-pc-cygwin' + fi } preinstall () { @@ -315,62 +125,45 @@ preinstall () { cp -v scripts/out-for-build/midi2ly.1 scripts/out cp -v lily/out-for-build/lilypond.1 lily/out - addmakeflags MAKE_PFA_FILES=1 ' ' LDFLAGS="$cygwin_prefix/bin/libpython2.2.dll" ' ' 'target=i686-pc-cygwin' + if false; then # [ "$ABI" != "1.5" ]; then + addmakeflags MAKE_PFA_FILES=1 ' ' LDFLAGS="$cygwin_prefix/bin/libpython2.2.dll" ' ' 'target=i686-pc-cygwin' + else + addmakeflags MAKE_PFA_FILES=1 ' ' LDFLAGS="$cygwin_prefix/bin/libpython2.3.dll" ' ' 'target=i686-pc-cygwin' + fi } postinstall () { - mkdir -p $inst-doc/$prefix + fixdoc + + mkdir -p $inst-doc/$docprefix cd $build || exit 1 - docdir=$prefix/share/doc/$base-$ver - #make conf=for-build docdir=$inst-doc/$docdir install-html-doc - make conf=for-build webdir=$inst-doc/$docdir web-install - + make conf=for-build webdir=$inst-doc/$packagedocdir web-install ## copy READMEs etc cd $src || exit 1 - install -d -m755 $inst/$docdir + install -d -m755 $inst/$packagedocdir ## Generic READMEs - find . -maxdepth 1 -type f -exec cp -pv \{\} $inst/$docdir \; + find . -maxdepth 1 -type f -exec cp -pv \{\} $inst/$packagedocdir \; ## Cygwin readmes cygwin=cygwin cd $src || exit 1 - #install -m644 $cygwin/README $inst/$docdir/README.Cygwin - install -m644 $cygwin/changelog $inst/$docdir/changelog.Cygwin + install -m644 $cygwin/changelog $inst/$cygdocdir/changelog.Cygwin install -d -m755 $inst/$prefix/doc/Cygwin - #install -m644 $cygwin/README $inst/$prefix/doc/Cygwin/$package.README + #install -m644 $cygwin/README $inst/$cygdocdir/Cygwin/$package.README cd $build || exit 1 - install -m644 $cygwin/out/README $inst/$docdir/README.Cygwin - install -m644 $cygwin/out/README $inst/$prefix/doc/Cygwin/$package.README + install -m644 $cygwin/out/README $inst/$packagedocdir/README.Cygwin + install -m644 $cygwin/out/README $inst/$cygdocdir/$package.README ## copy examples cd $src || exit 1 - cp -prv input $inst/$docdir + cp -prv input $inst/$packagedocdir - cd $inst-doc/$prefix/share/doc/$base-$ver && + cd $inst-doc/$packagedocdir && ln -s $(find html/Documentation -name '*.ps.gz') . - - ## Cygwin doesn't adhere to FHS (and why should they?) - cd $inst/$prefix/share && tar cf - doc | (cd ..; tar xf -) && rm -rf doc - cd $inst-doc/$prefix/share && tar cf - doc | (cd ..; tar xf -) && rm -rf doc } -#presplit () { -# docdir=$prefix/share/doc/$base-$ver -# mkdir -p $inst-doc/$docdir || exit 1 -#} - -doc_split () { - mkdir -p ./$prefix || exit 1 - mv $inst/$prefix/info ./$prefix - true -} - - -#prepackage () { -# mv $inst/$prefix/bin/guile-* $inst-devel/$prefix/bin -#} diff --git a/debian/control b/debian/control index 5362371512..d6ea2f009d 100644 --- a/debian/control +++ b/debian/control @@ -1,5 +1,5 @@ Source: lilypond -Build-Depends: debhelper (>= 4.0.0), binutils (>= 2.11.92.0.10-2), libc6-dev (>= 2.2.4-6) | libc6.1-dev (>= 2.2.4-6) | libc0.2-dev (>= 2.2.4-6), python-dev, guile-1.6-dev | libguile-dev, tetex-bin, libkpathsea-dev, tetex-extra, flex (>= 2.5.4a-14), bison (<< 1:1.50) | bison (>= 1:1.75-1), texinfo (>= 4.6-1), groff, m4, gettext (>= 0.10.36-1), mftrace (>= 1.0.17-1), pfaedit (>= 0.0.20020312-1), autotrace (>= 0.29-1.4), t1utils +Build-Depends: debhelper (>= 4.0.0), binutils (>= 2.11.92.0.10-2), libc6-dev (>= 2.2.4-6) | libc6.1-dev (>= 2.2.4-6) | libc0.2-dev (>= 2.2.4-6), python-dev, guile-1.6-dev | libguile-dev, tetex-bin, libkpathsea-dev, tetex-extra, flex (>= 2.5.4a-14) | flex-old, bison (<< 1:1.50) | bison (>> 1:1.75-1), texinfo (>= 4.6-1), groff, m4, gettext (>= 0.10.36-1), mftrace (>= 1.0.17-1), pfaedit (>= 0.0.20020312-1), autotrace (>= 0.29-1.4), t1utils Build-Depends-Indep: gs | gs-aladdin, netpbm (>= 2:9.10-1) Section: tex Priority: optional diff --git a/python/gettext.py b/python/gettext.py deleted file mode 100644 index e34cc77a2e..0000000000 --- a/python/gettext.py +++ /dev/null @@ -1,329 +0,0 @@ -"""This module allows python programs to use GNU gettext message catalogs. - -Author: James Henstridge -(This is loosely based on gettext.pl in the GNU gettext distribution) - -The best way to use it is like so: - import gettext - gettext.bindtextdomain(PACKAGE, LOCALEDIR) - gettext.textdomain(PACKAGE) - _ = gettext.gettext - print _('Hello World') - -where PACKAGE is the domain for this package, and LOCALEDIR is usually -'$prefix/share/locale' where $prefix is the install prefix. - -If you have more than one catalog to use, you can directly create catalog -objects. These objects are created as so: - import gettext - cat = gettext.Catalog(PACKAGE, localedir=LOCALEDIR) - _ = cat.gettext - print _('Hello World') - -The catalog object can also be accessed as a dictionary (ie cat['hello']). - -There are also some experimental features. You can add to the catalog, just -as you would with a normal dictionary. When you are finished, you can call -its save method, which will create a new .mo file containing all the -translations: - import gettext - cat = Catalog() - cat['Hello'] = 'konichiwa' - cat.save('./tmp.mo') - -Once you have written an internationalized program, you can create a .po file -for it with "xgettext --keyword=_ fillename ...". Then do the translation and -compile it into a .mo file, ready for use with this module. Note that you -will have to use C style strings (ie. use double quotes) for proper string -extraction. -""" -import os, string - -prefix = '/usr/local' -localedir = prefix + '/share/locale' - -def _expandLang(str): - langs = [str] - # remove charset ... - if '.' in str: - langs.append(string.split(str, '.')[0]) - # also add 2 character language code ... - if len(str) > 2: - langs.append(str[:2]) - return langs - -lang = [] -for env in 'LANGUAGE', 'LC_ALL', 'LC_MESSAGES', 'LANG': - if os.environ.has_key(env): - lang = string.split(os.environ[env], ':') - lang = map(_expandLang, lang) - lang = reduce(lambda a, b: a + b, lang) - break -if 'C' not in lang: - lang.append('C') - -# remove duplicates -i = 0 -while i < len(lang): - j = i + 1 - while j < len(lang): - if lang[i] == lang[j]: - del lang[j] - else: - j = j + 1 - i = i + 1 -del i, j - -if os.environ.has_key('PY_XGETTEXT'): - xgettext = os.environ['PY_XGETTEXT'] -else: - xgettext = None - -del os, string - -error = 'gettext.error' - -def _lsbStrToInt(str): - return ord(str[0]) + \ - (ord(str[1]) << 8) + \ - (ord(str[2]) << 16) + \ - (ord(str[3]) << 24) -def _msbStrToInt(str): - return (ord(str[0]) << 24) + \ - (ord(str[1]) << 16) + \ - (ord(str[2]) << 8) + \ - ord(str[3]) -def _intToLsbStr(int): - return chr(int & 0xff) + \ - chr((int >> 8) & 0xff) + \ - chr((int >> 16) & 0xff) + \ - chr((int >> 24) & 0xff) - -def _getpos(levels = 0): - """Returns the position in the code where the function was called. - The function uses some knowledge about python stack frames.""" - import sys - # get access to the stack frame by generating an exception. - try: - raise RuntimeError - except RuntimeError: - frame = sys.exc_traceback.tb_frame - frame = frame.f_back # caller's frame - while levels > 0: - frame = frame.f_back - levels = levels - 1 - return (frame.f_globals['__name__'], - frame.f_code.co_name, - frame.f_lineno) - -class Catalog: - def __init__(self, domain=None, localedir=localedir): - self.domain = domain - self.localedir = localedir - self.cat = {} - if not domain: return - for self.lang in lang: - if self.lang == 'C': - return - catalog = "%s//%s/LC_MESSAGES/%s.mo" % ( - localedir, self.lang, domain) - try: - f = open(catalog, "rb") - buffer = f.read() - del f - break - except IOError: - pass - else: - return # assume C locale - - strToInt = _lsbStrToInt - if strToInt(buffer[:4]) != 0x950412de: - # catalog is encoded with MSB offsets. - strToInt = _msbStrToInt - if strToInt(buffer[:4]) != 0x950412de: - # magic number doesn't match - raise error, 'Bad magic number in %s' % (catalog,) - - self.revision = strToInt(buffer[4:8]) - nstrings = strToInt(buffer[8:12]) - origTabOffset = strToInt(buffer[12:16]) - transTabOffset = strToInt(buffer[16:20]) - for i in range(nstrings): - origLength = strToInt(buffer[origTabOffset: - origTabOffset+4]) - origOffset = strToInt(buffer[origTabOffset+4: - origTabOffset+8]) - origTabOffset = origTabOffset + 8 - origStr = buffer[origOffset:origOffset+origLength] - - transLength = strToInt(buffer[transTabOffset: - transTabOffset+4]) - transOffset = strToInt(buffer[transTabOffset+4: - transTabOffset+8]) - transTabOffset = transTabOffset + 8 - transStr = buffer[transOffset:transOffset+transLength] - - self.cat[origStr] = transStr - - def gettext(self, string): - """Get the translation of a given string""" - if self.cat.has_key(string): - return self.cat[string] - else: - return string - # allow catalog access as cat(str) and cat[str] and cat.gettext(str) - __getitem__ = gettext - __call__ = gettext - - # this is experimental code for producing mo files from Catalog objects - def __setitem__(self, string, trans): - """Set the translation of a given string""" - self.cat[string] = trans - def save(self, file): - """Create a .mo file from a Catalog object""" - try: - f = open(file, "wb") - except IOError: - raise error, "can't open " + file + " for writing" - f.write(_intToLsbStr(0x950412de)) # magic number - f.write(_intToLsbStr(0)) # revision - f.write(_intToLsbStr(len(self.cat))) # nstrings - - oIndex = []; oData = '' - tIndex = []; tData = '' - for orig, trans in self.cat.items(): - oIndex.append((len(orig), len(oData))) - oData = oData + orig + '\0' - tIndex.append((len(trans), len(tData))) - tData = tData + trans + '\0' - oIndexOfs = 20 - tIndexOfs = oIndexOfs + 8 * len(oIndex) - oDataOfs = tIndexOfs + 8 * len(tIndex) - tDataOfs = oDataOfs + len(oData) - f.write(_intToLsbStr(oIndexOfs)) - f.write(_intToLsbStr(tIndexOfs)) - for length, offset in oIndex: - f.write(_intToLsbStr(length)) - f.write(_intToLsbStr(offset + oDataOfs)) - for length, offset in tIndex: - f.write(_intToLsbStr(length)) - f.write(_intToLsbStr(offset + tDataOfs)) - f.write(oData) - f.write(tData) - -_cat = None -_cats = {} - -if xgettext: - class Catalog: - def __init__(self, domain, localedir): - self.domain = domain - self.localedir = localedir - self._strings = {} - def gettext(self, string): - # there is always one level of redirection for calls - # to this function - pos = _getpos(2) # get this function's caller - if self._strings.has_key(string): - if pos not in self._strings[string]: - self._strings[string].append(pos) - else: - self._strings[string] = [pos] - return string - __getitem__ = gettext - __call__ = gettext - def __setitem__(self, item, data): - pass - def save(self, file): - pass - def output(self, fp): - import string - fp.write('# POT file for domain %s\n' % (self.domain,)) - for str in self._strings.keys(): - pos = map(lambda x: "%s(%s):%d" % x, - self._strings[str]) - pos.sort() - length = 80 - for p in pos: - if length + len(p) > 74: - fp.write('\n#:') - length = 2 - fp.write(' ') - fp.write(p) - length = length + 1 + len(p) - fp.write('\n') - if '\n' in str: - fp.write('msgid ""\n') - lines = string.split(str, '\n') - lines = map(lambda x: - '"%s\\n"\n' % (x,), - lines[:-1]) + \ - ['"%s"\n' % (lines[-1],)] - fp.writelines(lines) - else: - fp.write('msgid "%s"\n' % (str,)) - fp.write('msgstr ""\n') - - import sys - if hasattr(sys, 'exitfunc'): - _exitchain = sys.exitfunc - else: - _exitchain = None - def exitfunc(dir=xgettext, _exitchain=_exitchain): - # actually output all the .pot files. - import os - for file in _cats.keys(): - fp = open(os.path.join(dir, file + '.pot'), 'w') - cat = _cats[file] - cat.output(fp) - fp.close() - if _exitchain: _exitchain() - sys.exitfunc = exitfunc - del sys, exitfunc, _exitchain, xgettext - -def bindtextdomain(domain, localedir=localedir): - global _cat - if not _cats.has_key(domain): - _cats[domain] = Catalog(domain, localedir) - if not _cat: _cat = _cats[domain] - -def textdomain(domain): - global _cat - if not _cats.has_key(domain): - _cats[domain] = Catalog(domain) - _cat = _cats[domain] - -def gettext(string): - if _cat == None: raise error, "No catalog loaded" - return _cat.gettext(string) - -_ = gettext - -def dgettext(domain, string): - if domain is None: - return gettext(string) - if not _cats.has_key(domain): - raise error, "Domain '" + domain + "' not loaded" - return _cats[domain].gettext(string) - -def test(): - import sys - global localedir - if len(sys.argv) not in (2, 3): - print "Usage: %s DOMAIN [LOCALEDIR]" % (sys.argv[0],) - sys.exit(1) - domain = sys.argv[1] - if len(sys.argv) == 3: - bindtextdomain(domain, sys.argv[2]) - textdomain(domain) - info = gettext('') # this is where special info is often stored - if info: - print "Info for domain %s, lang %s." % (domain, _cat.lang) - print info - else: - print "No info given in mo file." - -if __name__ == '__main__': - test() - -- 2.39.2