~ubuntu-branches/ubuntu/natty/moin/natty-updates

« back to all changes in this revision

Viewing changes to MoinMoin/i18n/recode.py

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-22 21:17:13 UTC
  • mfrom: (0.9.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080622211713-fpo2zrq3s5dfecxg
Tags: 1.7.0-3
Simplify /etc/moin/wikilist format: "USER URL" (drop unneeded middle
CONFIG_DIR that was wrongly advertised as DATA_DIR).  Make
moin-mass-migrate handle both formats and warn about deprecation of
the old one.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
# -*- coding: iso-8859-1 -*-
3
 
"""
4
 
    MoinMoin - file encoding conversion
5
 
 
6
 
    @copyright: 2005 by Thomas Waldmann (MoinMoin:ThomasWaldmann)
7
 
    @license: GNU GPL, see COPYING for details.
8
 
 
9
 
    Convert data in encoding src_enc to encoding dst_enc, both specified
10
 
    on command line. Data is read from standard input and written to
11
 
    standard output.
12
 
 
13
 
    Usage:
14
 
 
15
 
    ./recode.py src_enc dst_enc < src  > dst
16
 
 
17
 
    Example:
18
 
 
19
 
    # Using non utf-8 editor to edit utf-8 file:
20
 
 
21
 
    # Make a working copy using iso-8859-1 encoding
22
 
    ./recode.py utf-8 iso-8859-1 < de.po > de-iso1.po
23
 
 
24
 
    # Use non-utf8 editor
25
 
    $EDITOR de-iso1.po
26
 
 
27
 
    # Recode back to utf-8
28
 
    ./recode.py iso-8859-1 utf-8 < de-iso1.po > de-utf8.po
29
 
 
30
 
    # Review changes and replace original if everything is ok
31
 
    diff de.po de-utf8.po | less
32
 
    mv de-utf8.po de.po
33
 
 
34
 
"""
35
 
 
36
 
import sys
37
 
 
38
 
def error(msg):
39
 
    sys.stderr.write(msg + '\n')
40
 
    
41
 
def run():
42
 
    try:
43
 
        cmd, src_enc, dst_enc = sys.argv
44
 
 
45
 
        for line in sys.stdin:
46
 
            line = unicode(line, src_enc).encode(dst_enc)
47
 
            sys.stdout.write(line)
48
 
 
49
 
    except UnicodeError, err:
50
 
        error("Can't recode: %s" % str(err))
51
 
    except LookupError, err:
52
 
        error(str(err))
53
 
    except ValueError:
54
 
        error("Wrong number of arguments")
55
 
        error(__doc__)
56
 
 
57
 
 
58
 
if __name__ == "__main__":
59
 
    run()
60