File: phase

package info (click to toggle)
translate-toolkit 3.17.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,780 kB
  • sloc: python: 69,719; sh: 1,412; makefile: 186; xml: 48
file content (669 lines) | stat: -rwxr-xr-x 18,999 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
#!/bin/bash
#
# Copyright 2005 Zuza Software Foundation
#
# This file is part of The Translate Toolkit.
#
# The Translate Toolkit is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# translate is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with translate; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


# phase - is a set of commands that allows you to break up a translation package 
# and create phases to send to translators.  It will manage the return, checking and
# integration of changes.  Ultimately this should convert to Python so that
# other people on less well known platforms like Windows can use them.


# Commands error handling

function error_notacommand {
	echo "$1 is not a valid command"
	usage
}

function usagecommands {
	cat <<EOF
Commands:
	makephaselist <template-dir> <new-phase-list-name> -- creates a phase list
	listphases <phase-list> -- lists the different phases that appear in the phase-list file
	listfiles <phase-list> <phase-name> -- list all files for the given phase in the phase-list file
	checkphaselist <language-dir> <phase-list> -- checks to see which files are not included in the phaselist
	countpo <language-dir> <phase-list> <phase-name> -- counts PO file in the given phase
	countpot <template-dir> <phase-list> <phase-name> -- counts POT file in the given phase
	missingpo <language-dir> <phase-list> <phase-name> -- lists files that have not been returned for a phase
	packpot <template-dir> <phase-list> <phase-name> -- packs all POT files for a given phase into a ZIP file
	packpo <language-dir> <phase-list> <phase-name> -- packs all PO files for a given phase into a ZIP file
	packall <template-dir> <phase-list> -- packs all phases found in the phase list
	packallpo <language-dir> <phase-list> -- packs all phases found in the phase list for the given language
	countmismatch <language-dir> <template-dir> <phase-list> <phase-name> -- compares the source word count between PO and POT to determine if there are any file errors.
	editpo <language-dir> <phase-list> <phase-name> -- edit the PO files in a phase
	editpochecks <language> <phase-list> <phase-name> -- edit the PO checks output by checkpo
	editconflicts <language-dir> <phase-list> <phase-name> -- edit the extracted conconflict items
	checkpo <language-dir> <phase-list> <phase-name> [pofilter options] -- run pofilter checks against the given phase
	greppo <language-dir> <phase-list> <phase-name> [pogrep options] -- run pogrep against the given phase
	mergepo <language> <phase-list> <phase-name> -- merge the checks back into the main language directory
	conflictpo <language-dir> <phase-list> <phase-name> [poconflict options] -- run poconflict checks against the given phase
	diffpo <language-dir> <phase-list> <phase-name> -- perform a cvs diff for the phase
	cvslog <language-dir> <phase-list> <phase-name> -- perform a cvs log against files in the phase
	lastlog <language-dir> <phase-list> <phase-name> -- retrieves the last cvs log entry for each file in a phase
	cvsadd <languages-dir> <phase-list> <phase-name> -- CVS adds files and directories that are not already in CVS
	reviewpo <language-dir> <phase-list> <phase-name> [pofilter options] -- extract items marked for review for the given phase
	editreviews <language-dir> <phase-list> <phase-name> -- edit the extracted review items
	countreviews <language-dir> <phase-list> <phase-name> -- count the number of strings and words under review
	checkinpo <language-dir> <phase-list> <phase-name> -- cvs checkin the files in the given phase
	creategsi <language-dir> <en-US.gsi> <target-language> [scp target destination] -- creates a BZ2 GSI/SDF file for the language against the en-US GSI file
	reviewsinout <language> <phase-name> -- counts the number of review files returned vs sent and shows which are missing 
	reviewsdiff <language> <phase-name> -- create a diff between what was sent for review and what was returned

Note:
	A phase-name of ALL will perform the operation against all phases.
	phase-name can be a regex that usable by egrep eg. "(firefox|thunderbird)"
EOF
	#emailpot <template-dir> <phase-list> <phase-name> <emails> -- emails the POT files with wordcount to the addresses
	#emailpo <language-dir> <phase-list> <phase-name> <emails> -- emails the PO files with wordcount to the addresses
	#emailreview <language> <phase-name> <emails> -- emails the prepared review files to the addresses
}

function usage() {
	programname=`basename $0`
    	echo "Usage: $programname <command> options"
	usagecommands
	exit 1
}

# Operation

function report {
	if [ "$*" == "DONE" ]; then
		echo " done."
	else
		echo -n "$* "
	fi
}

function getphasefiles {
	# Returns a list of files that are valid for this phase
	filelist=$1
	phase=$2
	if [ "$phase" != "ALL" ]; then
                for i in `echo $phase | sed "s/,/ /g"`
		do
			egrep --count "^$i\b" $filelist > /dev/null
			if [ $? -ne 0 ]; then
				echo "No such phase exists" > /dev/stderr
				exit 1
			fi
			egrep "^$i\b" $filelist
		done
	else
		cat $filelist
	fi | cut -f 2 | sort
}

function getphases {
	# Returns a list of all the defines phases
	filelist=$1
	cut -f1 $filelist | sort | uniq
}

function countpo {
	# Counts PO files
	directory=$1
	filelist=$2
	phase=$3
	files=$(getphasefiles $filelist $phase)
	cd $directory
	pocount $files
}

function countreviews {
	# Counts PO files for review
	language=$1
	filelist=$2
	phase=$3
	pocount $(find $language-$phase-review -name "*.po")
}

function countpot {
	# Counts POT files
	directory=$1
	filelist=$2
	phase=$3
	files=$(getphasefiles $filelist $phase | sed "s/\.po$/\.pot/")
	cd $directory
	pocount $files
}

function missingpo {
	# Reports PO files that are missing from the filelist
	directory=$1
	filelist=$2
	phase=$3
	files=$(getphasefiles $filelist $phase)
	cd $directory
	for file in $files
	do
		if [ ! -f $file ]; then
			echo $file
			missingfiles=$( echo $missingfiles $file)
		fi
	done
}

function copy_po_to_temp_dir {
	basedir=$1
	tempdir=$2
	shift 2
	files=$*
	for file in $files
	do
		fromdir=$(dirname $file)	
		mkdir -p $tempdir/$fromdir
		cp -p $basedir/$file $tempdir/$fromdir
	done
}

function packpot {
	# Packs POT files that match the file list
	directory=$1
	filelist=$2
	phase=$3
    	outdir=phase$phase-templates
	rm -rf $outdir
	files=$(getphasefiles $filelist $phase | sed "s/\.po$/\.pot/")
		report "Packpot: creating"
	copy_po_to_temp_dir $directory $outdir $files
		report ": wordcount"
	pocount $(find $outdir -name "*.pot") > $outdir/wordcount.txt
		report ', PO'
	for potfile in $(find $outdir -name "*.pot")
	do
		pofile=$(echo $potfile | sed "s/\.pot$/\.po/")
		msginit --no-translator --locale=af_ZA -i $potfile -o $pofile > /dev/null 2>&1
	done
		report ", CSV"
	po2csv --progress=none $outdir $outdir
		report ", tarball"
	tar czf $outdir.tar.gz $outdir
		report ", zip"
	zip -qr9 $outdir.zip $outdir
		report DONE
}	

function packpo {
	# Packs PO files that match the file list
	language=$1
	filelist=$2
	phase=$3
	outdir=$language-$phase-translations
	rm -rf $outdir
	files=$(getphasefiles $filelist $phase)
		report "Packpo: creating"
	copy_po_to_temp_dir $language $outdir $files
		report ": wordcount"
	pocount $(find $outdir -name "*.po") > $outdir/wordcount.txt
		report ", CSV"
	po2csv --progress=none $outdir $outdir
		report ", tarball"
	tar czf $outdir.tar.gz $outdir
		report ", zip"
	zip -qr9 $outdir.zip $outdir
		report DONE
}	

function packall {
	# Pack all phases in a project
		report "Packing all phases:"
	for phase in $(getphases $2)
	do
			report $phase
		packpot $1 $2 $phase
	done
		report DONE
}

function packallpo {
	# Pack all phases in a project for a language
	language=$1
	filelist=$2
		report "Packing all phases:"
	for phase in $(getphases $2)
	do
			report $phase
		packpo $1 $2 $phase
	done
		report DONE
}

function count_source_words {
	file=$1
	pocount --csv $file | tail -1 | cut -d"," -f10
}

function countmismatch {
	# Checks that the source wordcount matches in each returned file in a phase
	language=$1
	templates=$2
	filelist=$3
	phase=$4
	files=$(getphasefiles $filelist $phase)
	for file in $files
	do
		if [ -f $language/$file ]; then
			powords=$(count_source_words $language/$file)
		else
			powords=0
		fi
		potfile=$templates/$(echo $file | sed "s/\.po$/.pot/")
		if [ -f $potfile ]; then
			potwords=$(count_source_words $potfile)
		else
			potwords=0
		fi
		if [ $powords -ne $potwords ]; then
			echo "Mismatch: $file - expected $potwords got $powords"
		fi
	done
}

function editpo {
	# Edit the PO files for this phase
	language=$1
	filelist=$2
	phase=$3
	editor="vim"
	files=$(getphasefiles $filelist $phase)
	(cd $language; exec $editor $files)
}

function editreviews {
	# Edit the PO files for this phase
	language=$1
	phaselist=$2
	phase=$3
	editor="vim"
	files=$(getphasefiles $phaselist $phase)
	if [ -d $language-$phase-review ]; then
		for file in $files
		do
			[ -f $language-$phase-review/$file ] && present_files=$(echo $present_files $file)
		done
		(cd $language-$phase-review; exec $editor $present_files)
	else
		echo "No reviews present for language $language phase $phase."
		echo "Run reviewpo to create them"
		exit 1
	fi
}

function editconflicts {
	# Edit the PO files for this phase
	language=$1
	phaselist=$2
	phase=$3
	editor="vim"
	if [ -d $language-$phase-conflicts ]; then
		(cd $language-$phase-conflicts; exec $editor $(ls *.po))
	else
		echo "No conflicts present for language $language phase $phase."
		echo "Run conflictpo to create them"
		exit 1
	fi
}

function editpochecks {
	language=$1
	phaselist=$2
	phase=$3
	editor="vim"
	files=$(getphasefiles $phaselist $phase)
	if [ -d $language-$phase-check ]; then
		for file in $files
		do
			[ -f $language-$phase-check/$file ] && present_files=$(echo $present_files $file)
		done
		(cd $language-$phase-check; exec $editor $(echo $present_files| sort))
	else
		echo "No checks present for language $language phase $phase."
		echo "Run checkpo to create them"
		exit 1
	fi
}

function checkpo {
	# Uses pofilter to check a language
	language=$1
	filelist=$2
	phase=$3
	shift 3
	otheroptions=$*
	files=$(getphasefiles $filelist $phase)
	tempdir=`mktemp -d tmp.XXXXXXXXXX`
	copy_po_to_temp_dir $language $tempdir $files
	pofilter --excludefilter=untranslated $otheroptions $tempdir $language-$phase-check
        rm -rf $tempdir
}

function greppo {
	# Uses pogrep to grep a language
	language=$1
	filelist=$2
	phase=$3
	shift 3
	otheroptions=$*
	files=$(getphasefiles $filelist $phase)
	tempdir=`mktemp -d tmp.XXXXXXXXXX`
	copy_po_to_temp_dir $language $tempdir $files
	pogrep $otheroptions $tempdir $language-$phase-grep
        rm -rf $tempdir
}

function conflictpo {
	# Uses pofilter to check a language
	language=$1
	filelist=$2
	phase=$3
	shift 3
	otheroptions=$*
	files=$(getphasefiles $filelist $phase)
	tempdir=`mktemp -d tmp.XXXXXXXXXX`
	copy_po_to_temp_dir $language $tempdir $files
        rm -rf $language-$phase-conflicts
	(curdir=$(pwd); cd $tempdir ; poconflicts $otheroptions . $curdir/$language-$phase-conflicts)
        rm -rf $tempdir
        zip -qr9 $language-$phase-conflicts.zip $language-$phase-conflicts
}

function mergepo {
	language=$1
	filelist=$2
	phase=$3
	pomerge -t $language -o $language -i $language-$phase-check
}

function diffpo {
	language=$1
	filelist=$2
	phase=$3
	files=$(getphasefiles $filelist $phase)
	for file in $files
	do
		if [ -f $language/$file ]; then
			present_files=$(echo $present_files $file)
		else
			echo "Skipping - $file - file not found"
		fi	
	done
	(cd $language; cvs diff -u $present_files)
}

function reviewpo {
	# Uses pofilter to extract the review items for a language
	language=$1
	filelist=$2
	phase=$3
	shift 3
	otheroptions=$*
	files=$(getphasefiles $filelist $phase)
	tempdir=`mktemp -d tmp.XXXXXXXXXX`
	copy_po_to_temp_dir $language $tempdir $files
	review_dir=$language-$phase-review
        rm -rf $review_dir
	pofilter -t isreview -t untranslated -t blank -t isfuzzy $otheroptions $tempdir $review_dir
	po2csv $review_dir $review_dir
	# Transform "#, review" to # REVIEW
	sed -i "/#, review/s/#, review/# REVIEW/" $(find $review_dir -name "*.po")
	(cat <<-EOF
	These are the review comments for $language phase $phase.

	The format of this file is as follows:
	Each file with errors is introduced with a line starting with the word 'File:'.  Thereafter
	the errors appear.  Each error is separated from the next by a blank line.  They should correspond
	to the lines in the CSV file or the messages in the PO file.  Please edit the corrections taking
	into consideration the comments in this file.

	The error is presented first with a comment starting with #. This describes the error.  After
	the comments you will see a line starting with 'msgid' - this is for information only and is
	there to assist you in locating the error if you lose your place.  Make all corrections in the
	CSV or PO file NOT in this file.  This file is simply for your information, not for editing.

	Now for the review comments:

	EOF
	cd $review_dir; for review_file in $(find . -name "*.po")
	do
		echo "File: $review_file (the following comments relate to this file)"
		echo
		egrep "^$|^# REVIEW|^#_ |^# \(pofilter\)|^# \(review\)|^msgid \"" $review_file | egrep -v "^#_ isreview"
	done ) > $review_dir/review-notes.txt
	unix2dos $review_dir/review-notes.txt
	pocount $(find $review_dir -name "*.po") > $review_dir/wordcount.txt
	unix2dos $review_dir/wordcount.txt
	zip -qr9 $review_dir.zip $review_dir
        rm -rf tempdir
}

function checkinpo {
	# Check the files into CVS but only those in the phase
	language=$1
	filelist=$2
	phase=$3
	files=$(getphasefiles $filelist $phase)
	# remove files that are missing
	for file in $files
	do
		if [ -f $language/$file ]; then
			exists="$exists $file"
		else
			echo "$file - missing ignoring"
		fi
	done
	files=$exists
	(cd $language; cvs ci $files)
}

function creategsi {
	# Creates a GSI file for the given language
	language=$1
	enusgsi=$2
	if [ "$3" == "" -o "$3" == "-" ]; then
		targetgsilanguage=$language
	else
		targetgsilanguage=$3
	fi
        publish=$4
	po2oo --filteraction=warn -l $targetgsilanguage -t $enusgsi $language GSI_$targetgsilanguage.sdf && rm -f GSI_$targetgsilanguage.sdf.bz2 && bzip2 GSI_$targetgsilanguage.sdf
        if [ "$publish" != "" ]; then
		echo "Publishing GSI"
		scp -p GSI_$targetgsilanguage.sdf.bz2 $publish
	fi
}

function reviewsinout {
	# Checks which files have not been returned from a review
	language=$1
	phase=$2
	reviewdir=$language-$phase-review
	returndir=$language-$phase-review-returned
	reviewlist=`mktemp tmp.XXXXXXXXXX`
	returnlist=`mktemp tmp.XXXXXXXXXX`
	(cd $reviewdir; find . -type f -name "*.po" | sort ) > $reviewlist
	(cd $returndir; find . -type f -name "*.po" | sort ) > $returnlist
	echo "Reviews out: `cat $reviewlist | wc -l`"
	echo "Reviews returned: `cat $returnlist | wc -l`"
	diff -u $reviewlist $returnlist
	rm $reviewlist $returnlist
}

function reviewsdiff {
	# Creates a diff between what was sent for review and what was returned
	language=$1
	phase=$2
	diff -ur $language-$phase-review $language-$phase-review-returned
}

function checkphaselist {
	# Checks the files against the phase-list to see which are in and which are out
	language=$1
	phaselist=$2
	currentlist=`mktemp tmp.XXXXXXXXXX`
	tempphaselist=`mktemp tmp.XXXXXXXXXX`
	(cd $language; find . -name "*.po" | sort ) > $currentlist
	cat $phaselist | cut -f2- | sort > $tempphaselist
	echo "+ new files that are not in your phaselist (you need to add these)"
	echo "- files no longer in the destination but in your phaselist (you need to remove these)"
	diff -u $tempphaselist $currentlist
	rm $currentlist $tempphaselist
}

function cvslog {
	# Run CVS log against a phase so you can see what has happened
	language=$1
	phaselist=$2
	phase=$3
	options=$4
	files=$(getphasefiles $phaselist $phase)
	for file in $files
	do
		if [ -f $language/$file ]; then
			present_files=$(echo $present_files $file)
		else
			echo "Skipping - $file - file not found"
		fi	
	done
	(cd $language; cvs log $options $present_files)
}

function cvsadd {
	# Run CVS add against a phase so you can add files not already in CVS
	language=$1
	phaselist=$2
	phase=$3
	files=$(getphasefiles $phaselist $phase)
	# First check for un-added directories
	for file in $files
	do
		dir=`dirname $file`
		while [ $dir != "" -a $dir != "." ]
		do
			potential_dirs=$(echo $potential_dirs $dir)
			dir=`dirname $dir`
		done
	done
	for dir in `cd $language; find $potential_dirs -type d | sed "s/\/CVS$//" | sort -u`
	do
		if [ ! -d $language/$dir/CVS ]; then
			dir_to_add=$(echo $dir_to_add $dir)
		fi	
	done
	if [ "$dir_to_add" != "" ]; then
		(cd $language; cvs add $dir_to_add)
	fi
	# Now check and add un-added files
	for file in $files
	do
		filename=`basename $file`
		cvs_entry=`dirname $file`/CVS/Entries
		if [ "$(cd $language; egrep $filename $cvs_entry)" == "" ]; then
			files_to_add=$(echo $files_to_add $file)
		fi
	done
	if [ "$files_to_add" != "" ]; then
		(cd $language; cvs add $files_to_add)
	fi
}

function makephaselist {
	templatedir=$1
	newphaselist=$2
	(cd $templatedir; find . -name "*.pot") | sed "s/\.pot$/.po/" | sed "s/\(^.*$\)/1	\\1/" | LC_ALL="C" sort > $newphaselist
}

function listphases {
	phaselist=$1
	cat $phaselist | cut -d"	" -f 1 | sort | uniq -c
}

command=$1
shift
case $command in
        -h|--help) usagecommands
	  	;;
	makephaselist) makephaselist $1 $2
		;;
	listphases) listphases $1
		;;
	listfiles) getphasefiles $1 $2
		;;
	checkphaselist) checkphaselist $1 $2
		;;
	countpo) countpo $1 $2 $3
		;;
	countpot) countpot $1 $2 $3
		;;
	missingpo) missingpo $1 $2 $3
		;;
	packpot) packpot $1 $2 $3
		;;
	packpo) packpo $1 $2 $3
		;;
	packall) packall $1 $2
		;;
	packallpo) packallpo $1 $2
		;;
	countmismatch) countmismatch $1 $2 $3 $4
		;;
	editpo) editpo $1 $2 $3
		;;
	editpochecks) editpochecks $1 $2 $3
		;;
	checkpo) checkpo $*
		;;
	greppo) greppo $*
		;;
	mergepo) mergepo $1 $2 $3
		;;
	conflictpo) conflictpo $*
		;;
	diffpo) diffpo $1 $2 $3
		;;
	cvslog) cvslog $1 $2 $3
		;;
	lastlog) cvslog $1 $2 $3 -r
		;;
	cvsadd) cvsadd $1 $2 $3
		;;
	reviewpo) reviewpo $*
		;;
	editreviews) editreviews $1 $2 $3
		;;
	editconflicts) editconflicts $1 $2 $3
		;;
	countreviews) countreviews $1 $2 $3
		;;
	checkinpo) checkinpo $1 $2 $3
		;;
	creategsi) creategsi $1 $2 $3 $4
		;;
        reviewsinout) reviewsinout $1 $2
		;;
	reviewsdiff) reviewsdiff $1 $2
		;;
	"") usage
		;;
	*) error_notacommand $command
		;;
esac