3 """Usage: l10n-report.py [OPTION...]
5 Send the l10n translation status report to an email address. If the
6 email address is not specified, print in stdout.
10 -h, --help Show this help message.
12 -m, --to-email-id Send the l10n translation status report to this
22 def usage_and_exit(errmsg
=None):
23 """Print a usage message, plus an ERRMSG (if provided), then exit.
24 If ERRMSG is provided, the usage message is printed to stderr and
25 the script exits with a non-zero error code. Otherwise, the usage
26 message goes to stdout, and the script exits with a zero
32 print >> stream
, __doc__
34 print >> stream
, "\nError: %s" % (errmsg
)
40 def __init__(self
, to_email_id
="bhuvan@collab.net"):
41 self
.to_email_id
= to_email_id
42 self
.from_email_id
= "<dev@subversion.tigris.org>"
44 def safe_command(self
, cmd_and_args
, cmd_in
=""):
45 [stdout
, stderr
] = subprocess
.Popen(cmd_and_args
, \
46 stdin
=subprocess
.PIPE
, \
47 stdout
=subprocess
.PIPE
, \
48 stderr
=subprocess
.PIPE
).communicate(input=cmd_in
)
51 def match(self
, pattern
, string
):
52 match
= re
.compile(pattern
).search(string
)
53 if match
and match
.groups():
58 def get_msgattribs(self
, file):
59 msgout
= self
.safe_command(['msgattrib', '--translated', file])[0]
60 grepout
= self
.safe_command(['grep', '-E', '^msgid *"'], msgout
)[0]
61 sedout
= self
.safe_command(['sed', '1d'], grepout
)[0]
62 trans
= self
.safe_command(['wc', '-l'], sedout
)[0]
64 msgout
= self
.safe_command(['msgattrib', '--untranslated', file])[0]
65 grepout
= self
.safe_command(['grep', '-E', '^msgid *"'], msgout
)[0]
66 sedout
= self
.safe_command(['sed', '1d'], grepout
)[0]
67 untrans
= self
.safe_command(['wc', '-l'], sedout
)[0]
69 msgout
= self
.safe_command(['msgattrib', '--only-fuzzy', file])[0]
70 grepout
= self
.safe_command(['grep', '-E', '^msgid *"'], msgout
)[0]
71 sedout
= self
.safe_command(['sed', '1d'], grepout
)[0]
72 fuzzy
= self
.safe_command(['wc', '-l'], sedout
)[0]
74 msgout
= self
.safe_command(['msgattrib', '--only-obsolete', file])[0]
75 grepout
= self
.safe_command(['grep', '-E', '^#~ msgid *"'], msgout
)[0]
76 obsolete
= self
.safe_command(['wc', '-l'], grepout
)[0]
78 return int(trans
), int(untrans
), int(fuzzy
), int(obsolete
)
80 def pre_l10n_report(self
):
81 # svn revert --recursive subversion/po
82 cmd
= ['svn', 'revert', '--recursive', 'subversion/po']
83 stderr
= self
.safe_command(cmd
)[1]
85 print >> sys
.stderr
, "\nError: %s" % (stderr
)
89 cmd
= ['svn', 'update']
90 stderr
= self
.safe_command(cmd
)[1]
92 print >> sys
.stderr
, "\nError: %s" % (stderr
)
95 # tools/po/po-update.sh
96 cmd
= ['sh', 'tools/po/po-update.sh']
97 self
.safe_command(cmd
)
101 # Parse the command-line options and arguments.
103 opts
, args
= getopt
.gnu_getopt(sys
.argv
[1:], "hm:",
107 except getopt
.GetoptError
, msg
:
111 for opt
, arg
in opts
:
112 if opt
in ("-h", "--help"):
114 elif opt
in ("-m", "--to-email-id"):
118 os
.chdir("%s/../.." % os
.path
.dirname(os
.path
.abspath(sys
.argv
[0])))
119 l10n
.pre_l10n_report()
120 [info_out
, info_err
] = l10n
.safe_command(['svn', 'info'])
122 print >> sys
.stderr
, "\nError: %s" % (info_err
)
125 po_dir
= 'subversion/po'
126 branch_name
= l10n
.match('URL:.*/svn/(\S+)', info_out
)
127 [info_out
, info_err
] = l10n
.safe_command(['svnversion', po_dir
])
129 print >> sys
.stderr
, "\nError: %s" % (info_err
)
132 wc_version
= re
.sub('[MS]', '', info_out
)
133 title
= "Translation status report for %s r%s" % \
134 (branch_name
, wc_version
)
137 files
= os
.listdir('.')
139 format_head
= "%6s %7s %7s %7s %7s" % ("lang", "trans", "untrans",
141 format_line
= "--------------------------------------"
142 print "\n%s\n%s\n%s" % (title
, format_head
, format_line
)
146 lang
= l10n
.match('(.*).po$', file)
149 [trans
, untrans
, fuzzy
, obsolete
] = l10n
.get_msgattribs(file)
150 po_format
= "%6s %7d %7d %7d %7d" %\
151 (lang
, trans
, untrans
, fuzzy
, obsolete
)
152 body
+= "%s\n" % po_format
156 email_from
= "From: SVN DEV <noreply@subversion.tigris.org>"
157 email_to
= "To: %s" % to_email_id
158 email_sub
= "Subject: [l10n] Translation status report for %s r%s" \
159 % (branch_name
, wc_version
)
161 msg
= "%s\n%s\n%s\n%s\n%s\n%s\n%s" % (email_from
, email_to
,\
162 email_sub
, title
, format_head
, format_line
, body
)
164 cmd
= ['sendmail', '-t']
165 l10n
.safe_command(cmd
, msg
)
166 print "The report is sent to '%s' email id." % to_email_id
168 print "\nYou have not passed '-m' option, so email is not sent."
170 if __name__
== "__main__":