| 1 |
# -*- coding: utf-8 -*- |
|---|
| 2 |
""" |
|---|
| 3 |
Copyright 2005 Spike^ekipS <spikeekips@gmail.com> |
|---|
| 4 |
|
|---|
| 5 |
This program is free software; you can redistribute it and/or modify |
|---|
| 6 |
it under the terms of the GNU General Public License as published by |
|---|
| 7 |
the Free Software Foundation; either version 2 of the License, or |
|---|
| 8 |
(at your option) any later version. |
|---|
| 9 |
|
|---|
| 10 |
This program is distributed in the hope that it will be useful, |
|---|
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 13 |
GNU General Public License for more details. |
|---|
| 14 |
|
|---|
| 15 |
You should have received a copy of the GNU General Public License |
|---|
| 16 |
along with this program; if not, write to the Free Software |
|---|
| 17 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 18 |
""" |
|---|
| 19 |
|
|---|
| 20 |
import os, re, sys |
|---|
| 21 |
|
|---|
| 22 |
def print_usage () : |
|---|
| 23 |
print """ |
|---|
| 24 |
%s <document filepath> <target, orig|trans> |
|---|
| 25 |
""" % sys.argv[0] |
|---|
| 26 |
|
|---|
| 27 |
if len(sys.argv) < 2 : |
|---|
| 28 |
print_usage() |
|---|
| 29 |
sys.exit() |
|---|
| 30 |
|
|---|
| 31 |
RE_TRANS_START_ORIG = re.compile("^>>\!$") |
|---|
| 32 |
RE_TRANS_END_ORIG = re.compile("^<<!$") |
|---|
| 33 |
RE_TRANS_START_TRANS = re.compile("^>>!!$") |
|---|
| 34 |
RE_TRANS_END_TRANS = re.compile("^<<!!$") |
|---|
| 35 |
|
|---|
| 36 |
started_orig = False |
|---|
| 37 |
ended_orig = False |
|---|
| 38 |
started_trans = False |
|---|
| 39 |
ended_trans = False |
|---|
| 40 |
|
|---|
| 41 |
lines_trans = list() |
|---|
| 42 |
lines_orig = list() |
|---|
| 43 |
|
|---|
| 44 |
filename = sys.argv[1] |
|---|
| 45 |
path_filename = os.path.dirname(filename) |
|---|
| 46 |
document_name = os.path.splitext(os.path.basename(filename))[0] |
|---|
| 47 |
|
|---|
| 48 |
for i in file(filename) : |
|---|
| 49 |
i = i.rstrip() |
|---|
| 50 |
|
|---|
| 51 |
if RE_TRANS_START_ORIG.findall(i) : |
|---|
| 52 |
started_orig = True |
|---|
| 53 |
started_trans = False |
|---|
| 54 |
continue |
|---|
| 55 |
elif started_orig and RE_TRANS_END_ORIG.findall(i) : |
|---|
| 56 |
started_orig = False |
|---|
| 57 |
started_trans = False |
|---|
| 58 |
continue |
|---|
| 59 |
|
|---|
| 60 |
if RE_TRANS_START_TRANS.findall(i) : |
|---|
| 61 |
started_orig = False |
|---|
| 62 |
started_trans = True |
|---|
| 63 |
continue |
|---|
| 64 |
elif started_trans and RE_TRANS_END_TRANS.findall(i) : |
|---|
| 65 |
started_orig = False |
|---|
| 66 |
started_trans = False |
|---|
| 67 |
continue |
|---|
| 68 |
|
|---|
| 69 |
if started_orig : |
|---|
| 70 |
lines_orig.append(i) |
|---|
| 71 |
elif started_trans : |
|---|
| 72 |
lines_trans.append(i) |
|---|
| 73 |
elif not started_orig and not started_trans : |
|---|
| 74 |
lines_orig.append(i) |
|---|
| 75 |
lines_trans.append(i) |
|---|
| 76 |
|
|---|
| 77 |
fd = file(os.path.join(path_filename, "%s-en.txt" % document_name), "w") |
|---|
| 78 |
fd.write("\n".join(lines_orig)) |
|---|
| 79 |
fd.close() |
|---|
| 80 |
|
|---|
| 81 |
fd = file(os.path.join(path_filename, "%s-ko.txt" % document_name), "w") |
|---|
| 82 |
fd.write("\n".join(lines_trans)) |
|---|
| 83 |
fd.close() |
|---|
| 84 |
|
|---|
| 85 |
""" |
|---|
| 86 |
Description |
|---|
| 87 |
----------- |
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
ChangeLog |
|---|
| 91 |
--------- |
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 |
Usage |
|---|
| 95 |
----- |
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
""" |
|---|
| 99 |
|
|---|
| 100 |
__author__ = "Spike^ekipS <spikeekips@gmail.com>" |
|---|
| 101 |
__version__= "0.1" |
|---|
| 102 |
__nonsense__ = "" |
|---|