/snap/core20/2922/usr/bin
NameSizeModeActions
aa-enabled312480755editdlrm
aa-exec353440755editdlrm
addpart309520755editdlrm
arch392880755editdlrm
awk1625520755editdlrm
b2sum597680755editdlrm
base32433520755editdlrm
base64433520755editdlrm
basename392560755editdlrm
bash11834480755editdlrm
bashbug67940755editdlrm
bootctl638400755editdlrm
bunzip2391440755editdlrm
busctl884160755editdlrm
bzcat391440755editdlrm
bzcmp22270755editdlrm
bzdiff22270755editdlrm
bzegrep37750755editdlrm
bzexe48770755editdlrm
bzfgrep37750755editdlrm
bzgrep37750755editdlrm
bzip2391440755editdlrm
bzip2recover185840755editdlrm
bzless12970755editdlrm
bzmore12970755editdlrm
captoinfo925840755editdlrm
cat434160755editdlrm
catchsegv33360755editdlrm
cautious-launcher8530755editdlrm
chage845122755editdlrm
chardet33890755editdlrm
chardetect33890755editdlrm
chattr146560755editdlrm
chcon720240755editdlrm
chfn850644755editdlrm
chgrp720240755editdlrm
chmod638640755editdlrm
choom514320755editdlrm
chown720240755editdlrm
chrt391440755editdlrm
chsh530404755editdlrm
cksum392560755editdlrm
clear146560755editdlrm
clear_console145680755editdlrm
cloud-id3960755editdlrm
cloud-init4000755editdlrm
cloud-init-per21080755editdlrm
cmp514480755editdlrm
comm433840755editdlrm
compose184870755editdlrm
console-conf4060755editdlrm
core-sshd-host-keygen15210755editdlrm
cp1539760755editdlrm
csplit556720755editdlrm
ctstat312400755editdlrm
cut474800755editdlrm
cvtsudoers2730960755editdlrm
c_rehash68060755editdlrm
dash1298160755editdlrm
date1089200755editdlrm
dbus-cleanup-sockets144800755editdlrm
dbus-daemon2490320755editdlrm
dbus-monitor308640755editdlrm
dbus-run-session144800755editdlrm
dbus-send308640755editdlrm
dbus-update-activation-environment144800755editdlrm
dbus-uuidgen144800755editdlrm
dd802560755editdlrm
deb-systemd-helper213280755editdlrm
deb-systemd-invoke44300755editdlrm
delpart309520755editdlrm
df931280755editdlrm
dh_bash-completion24460755editdlrm
diff2196400755editdlrm
diff3679600755editdlrm
dir1421440755editdlrm
dircolors474560755editdlrm
dirname392560755editdlrm
dmesg844400755editdlrm
dnsdomainname268560755editdlrm
domainname268560755editdlrm
dpkg-deb1787280755editdlrm
du1089200755editdlrm
ec2metadata72950755editdlrm
echo392560755editdlrm
edit184870755editdlrm
editor13539760755editdlrm
egrep280755editdlrm
env433520755editdlrm
ex13539760755editdlrm
expand433840755editdlrm
expiry313122755editdlrm
expr556400755editdlrm
factor802480755editdlrm
faillog231360755editdlrm
fallocate350480755editdlrm
false392560755editdlrm
fgrep280755editdlrm
file271040755editdlrm
finalrd21520755editdlrm
fincore350960755editdlrm
find3201600755editdlrm
findmnt731280755editdlrm
flock351280755editdlrm
fmt474480755editdlrm
fold433520755editdlrm
free268640755editdlrm
gdbserver5217760755editdlrm
getconf351120755editdlrm
getent395760755editdlrm
getopt227600755editdlrm
gpasswd884644755editdlrm
gpgv4578800755editdlrm
grep1991360755editdlrm
groups392560755editdlrm
growpart245220755editdlrm
gunzip23460755editdlrm
gzexe64470755editdlrm
gzip974960755editdlrm
head474800755editdlrm
helpztags25140755editdlrm
hostid392560755editdlrm
hostname268560755editdlrm
hostnamectl268480755editdlrm
i386271360755editdlrm
iconv680000755editdlrm
id474800755editdlrm
infocmp638800755editdlrm
infotocap925840755editdlrm
install1581120755editdlrm
ionice309520755editdlrm
ip6119600755editdlrm
ipcmk351200755editdlrm
ipcrm350480755editdlrm
ipcs678160755editdlrm
iptables-xml992960755editdlrm
ischroot145360755editdlrm
join556720755editdlrm
journalctl801200755editdlrm
jsondiff10040755editdlrm
jsonpatch36620755editdlrm
jsonpatch-jsondiff10040755editdlrm
jsonpointer18380755editdlrm
jsonschema3970755editdlrm
kernel-install51910755editdlrm
kill309520755editdlrm
kmod1744240755editdlrm
kmodsign228240755editdlrm
last514320755editdlrm
lastb514320755editdlrm
lastlog324160755editdlrm
lcf77860755editdlrm
ldd54330755editdlrm
less1800640755editdlrm
lessecho146560755editdlrm
lessfile85640755editdlrm
lesskey242880755editdlrm
lesspipe85640755editdlrm
link392560755editdlrm
linux32271360755editdlrm
linux64271360755editdlrm
ln761600755editdlrm
lnstat312400755editdlrm
locale589440755editdlrm
locale-check144960755editdlrm
localectl268480755editdlrm
localedef3348080755editdlrm
logger520400755editdlrm
login571040755editdlrm
loginctl597360755editdlrm
logname392560755editdlrm
ls1421440755editdlrm
lsattr146560755editdlrm
lsblk1333520755editdlrm
lscpu1005840755editdlrm
lsipc964880755editdlrm
lslocks394800755editdlrm
lslogins678160755editdlrm
lsmem678160755editdlrm
lsmod1744240755editdlrm
lsns514400755editdlrm
man1280755editdlrm
mawk1625520755editdlrm
mcookie351200755editdlrm
md5sum474800755editdlrm
md5sum.textutils474800755editdlrm
mesg145680755editdlrm
miniterm350980755editdlrm
mkdir884080755editdlrm
mkfifo679280755editdlrm
mknod720240755editdlrm
mksquashfs2109040755editdlrm
mkswapfile8650755editdlrm
mktemp474480755editdlrm
more431600755editdlrm
mount555284755editdlrm
mountpoint145680755editdlrm
mv1498880755editdlrm
namei350480755editdlrm
nawk1625520755editdlrm
nc436640755editdlrm
nc.openbsd436640755editdlrm
netcat436640755editdlrm
networkctl760080755editdlrm
newgrp447844755editdlrm
nice433520755editdlrm
nisdomainname268560755editdlrm
nl434480755editdlrm
nohup433520755editdlrm
nproc433520755editdlrm
nsenter352560755editdlrm
nstat801120755editdlrm
numfmt679920755editdlrm
od720560755editdlrm
openssl7533360755editdlrm
p11-kit352160755editdlrm
p11tool3680080755editdlrm
pager1800640755editdlrm
partx1210720755editdlrm
passwd682084755editdlrm
paste433840755editdlrm
pathchk392560755editdlrm
pdb3627380755editdlrm
pdb3.8627380755editdlrm
perl34743680755editdlrm
perl5.30.034743680755editdlrm
pgrep309680755editdlrm
pidof270160755editdlrm
ping727760755editdlrm
ping4727760755editdlrm
ping6727760755editdlrm
pinky433840755editdlrm
pkcs11-tool1564400755editdlrm
pkill309680755editdlrm
pldd229040755editdlrm
pmap350640755editdlrm
pr762160755editdlrm
print184870755editdlrm
printenv392560755editdlrm
printf597360755editdlrm
prlimit396720755editdlrm
ps1376880755editdlrm
ptx802800755editdlrm
pwd433520755editdlrm
pwdx145680755editdlrm
py3clean78130755editdlrm
py3compile121200755editdlrm
py3versions117170755editdlrm
pydoc3790755editdlrm
pydoc3.8790755editdlrm
pygettext3215350755editdlrm
pygettext3.8215350755editdlrm
pyjwt33720755editdlrm
python354863200755editdlrm
python3.854863200755editdlrm
rbash11834480755editdlrm
rcp1170400755editdlrm
rdma1333600755editdlrm
readlink515440755editdlrm
realpath515760755editdlrm
rename.ul227600755editdlrm
renice145680755editdlrm
reset310400755editdlrm
resizepart637200755editdlrm
resolvectl1294080755editdlrm
rev145680755editdlrm
rgrep300755editdlrm
rlogin7935440755editdlrm
rm720560755editdlrm
rmdir474480755editdlrm
routef2080755editdlrm
routel16560755editdlrm
rsh7935440755editdlrm
rtstat312400755editdlrm
run-mailcap184870755editdlrm
run-parts271440755editdlrm
runcon392560755editdlrm
rview13539760755editdlrm
savelog104810755editdlrm
sbattach598880755editdlrm
sbkeysync683040755editdlrm
sbsiglist599520755editdlrm
sbsign599520755editdlrm
sbvarsign682080755editdlrm
sbverify639840755editdlrm
scp1170400755editdlrm
script555280755editdlrm
scriptreplay309520755editdlrm
sdiff514480755editdlrm
sed1214400755editdlrm
see184870755editdlrm
select-editor24420755editdlrm
sensible-browser12300755editdlrm
sensible-editor11690755editdlrm
sensible-pager4520755editdlrm
seq515440755editdlrm
setarch271360755editdlrm
setpriv473440755editdlrm
setsid145680755editdlrm
setterm473360755editdlrm
sftp1705040755editdlrm
sg447844755editdlrm
sh1298160755editdlrm
sha1sum515760755editdlrm
sha224sum597680755editdlrm
sha256sum597680755editdlrm
sha384sum679600755editdlrm
sha512sum679600755editdlrm
shred638640755editdlrm
shuf597360755editdlrm
skill309520755editdlrm
slabtop227680755editdlrm
sleep392560755editdlrm
slogin7935440755editdlrm
snap236585690755editdlrm
snapctl-0editdlrm
snice309520755editdlrm
sort1173760755editdlrm
split601840755editdlrm
ss1688000755editdlrm
ssh7935440755editdlrm
ssh-add3709760755editdlrm
ssh-agent3505042755editdlrm
ssh-argv014550755editdlrm
ssh-copy-id106580755editdlrm
ssh-keygen4774880755editdlrm
ssh-keyscan4652080755editdlrm
stat884400755editdlrm
stdbuf515440755editdlrm
stty843440755editdlrm
su678164755editdlrm
sudo1660564755editdlrm
sudoedit1660564755editdlrm
sudoreplay645120755editdlrm
sum474560755editdlrm
sync392560755editdlrm
systemctl9965840755editdlrm
systemd16202240755editdlrm
systemd-analyze15875840755editdlrm
systemd-ask-password146800755editdlrm
systemd-cat186640755editdlrm
systemd-cgls228640755editdlrm
systemd-cgtop391600755editdlrm
systemd-delta268480755editdlrm
systemd-detect-virt186560755editdlrm
systemd-escape227520755editdlrm
systemd-hwdb1090720755editdlrm
systemd-id128227520755editdlrm
systemd-inhibit227760755editdlrm
systemd-machine-id-setup269520755editdlrm
systemd-mount516640755editdlrm
systemd-notify186640755editdlrm
systemd-path186560755editdlrm
systemd-resolve1294080755editdlrm
systemd-run598240755editdlrm
systemd-socket-activate268480755editdlrm
systemd-stdio-bridge227600755editdlrm
systemd-sysusers558240755editdlrm
systemd-tmpfiles884800755editdlrm
systemd-tty-ask-password-agent309440755editdlrm
systemd-umount516640755editdlrm
tabs187440755editdlrm
tac433520755editdlrm
tail720880755editdlrm
tar4481120755editdlrm
taskset350480755editdlrm
tee433840755editdlrm
tempfile143600755editdlrm
test556400755editdlrm
tic925840755editdlrm
timedatectl8150755editdlrm
timedatectl.real473280755editdlrm
timeout438000755editdlrm
tload227760755editdlrm
toe228400755editdlrm
top1290720755editdlrm
touch1007280755editdlrm
tput269680755editdlrm
tr515440755editdlrm
true392560755editdlrm
truncate433520755editdlrm
tset310400755editdlrm
tsort433520755editdlrm
tty392560755editdlrm
tzselect153840755editdlrm
ucf406850755editdlrm
ucfq193670755editdlrm
ucfr107220755editdlrm
udevadm9576480755editdlrm
umount391444755editdlrm
uname392880755editdlrm
uncompress23460755editdlrm
unexpand433840755editdlrm
uniq515760755editdlrm
unlink392560755editdlrm
unshare434480755editdlrm
unsquashfs1148080755editdlrm
update-alternatives557120755editdlrm
uptime145680755editdlrm
users392560755editdlrm
utmpdump309520755editdlrm
vcs-run69120755editdlrm
vdir1421440755editdlrm
vi13539760755editdlrm
view13539760755editdlrm
vim.tiny13539760755editdlrm
vmstat391680755editdlrm
w227600755editdlrm
w.procps227600755editdlrm
wall350480755editdlrm
watch272080755editdlrm
wc474560755editdlrm
wdctl350480755editdlrm
whereis354960755editdlrm
which9460755editdlrm
who597680755editdlrm
whoami392560755editdlrm
wpa_passphrase842960755editdlrm
x86_64271360755editdlrm
xargs761520755editdlrm
xdg-open380755editdlrm
xdg-settings17230755editdlrm
xxd187120755editdlrm
yes392560755editdlrm
ypdomainname268560755editdlrm
zcat19840755editdlrm
zcmp16780755editdlrm
zdiff58980755editdlrm
zdump268400755editdlrm
zegrep290755editdlrm
zfgrep290755editdlrm
zforce20810755editdlrm
zgrep81030755editdlrm
zless22060755editdlrm
zmore18420755editdlrm
znew45770755editdlrm
[597360755editdlrm
Edit: /snap/core20/2922/usr/bin/pygettext3.8 (21535B)
#! /usr/bin/python3.8 # -*- coding: iso-8859-1 -*- # Originally written by Barry Warsaw # # Minimally patched to make it even more xgettext compatible # by Peter Funk # # 2002-11-22 Jürgen Hermann # Added checks that _() only contains string literals, and # command line args are resolved to module lists, i.e. you # can now pass a filename, a module or package name, or a # directory (including globbing chars, important for Win32). # Made docstring fit in 80 chars wide displays using pydoc. # # for selftesting try: import fintl _ = fintl.gettext except ImportError: _ = lambda s: s __doc__ = _("""pygettext -- Python equivalent of xgettext(1) Many systems (Solaris, Linux, Gnu) provide extensive tools that ease the internationalization of C programs. Most of these tools are independent of the programming language and can be used from within Python programs. Martin von Loewis' work[1] helps considerably in this regard. There's one problem though; xgettext is the program that scans source code looking for message strings, but it groks only C (or C++). Python introduces a few wrinkles, such as dual quoting characters, triple quoted strings, and raw strings. xgettext understands none of this. Enter pygettext, which uses Python's standard tokenize module to scan Python source code, generating .pot files identical to what GNU xgettext[2] generates for C and C++ code. From there, the standard GNU tools can be used. A word about marking Python strings as candidates for translation. GNU xgettext recognizes the following keywords: gettext, dgettext, dcgettext, and gettext_noop. But those can be a lot of text to include all over your code. C and C++ have a trick: they use the C preprocessor. Most internationalized C source includes a #define for gettext() to _() so that what has to be written in the source is much less. Thus these are both translatable strings: gettext("Translatable String") _("Translatable String") Python of course has no preprocessor so this doesn't work so well. Thus, pygettext searches only for _() by default, but see the -k/--keyword flag below for how to augment this. [1] http://www.python.org/workshops/1997-10/proceedings/loewis.html [2] http://www.gnu.org/software/gettext/gettext.html NOTE: pygettext attempts to be option and feature compatible with GNU xgettext where ever possible. However some options are still missing or are not fully implemented. Also, xgettext's use of command line switches with option arguments is broken, and in these cases, pygettext just defines additional switches. Usage: pygettext [options] inputfile ... Options: -a --extract-all Extract all strings. -d name --default-domain=name Rename the default output file from messages.pot to name.pot. -E --escape Replace non-ASCII characters with octal escape sequences. -D --docstrings Extract module, class, method, and function docstrings. These do not need to be wrapped in _() markers, and in fact cannot be for Python to consider them docstrings. (See also the -X option). -h --help Print this help message and exit. -k word --keyword=word Keywords to look for in addition to the default set, which are: %(DEFAULTKEYWORDS)s You can have multiple -k flags on the command line. -K --no-default-keywords Disable the default set of keywords (see above). Any keywords explicitly added with the -k/--keyword option are still recognized. --no-location Do not write filename/lineno location comments. -n --add-location Write filename/lineno location comments indicating where each extracted string is found in the source. These lines appear before each msgid. The style of comments is controlled by the -S/--style option. This is the default. -o filename --output=filename Rename the default output file from messages.pot to filename. If filename is `-' then the output is sent to standard out. -p dir --output-dir=dir Output files will be placed in directory dir. -S stylename --style stylename Specify which style to use for location comments. Two styles are supported: Solaris # File: filename, line: line-number GNU #: filename:line The style name is case insensitive. GNU style is the default. -v --verbose Print the names of the files being processed. -V --version Print the version of pygettext and exit. -w columns --width=columns Set width of output to columns. -x filename --exclude-file=filename Specify a file that contains a list of strings that are not be extracted from the input files. Each string to be excluded must appear on a line by itself in the file. -X filename --no-docstrings=filename Specify a file that contains a list of files (one per line) that should not have their docstrings extracted. This is only useful in conjunction with the -D option above. If `inputfile' is -, standard input is read. """) import os import importlib.machinery import importlib.util import sys import glob import time import getopt import token import tokenize __version__ = '1.5' default_keywords = ['_'] DEFAULTKEYWORDS = ', '.join(default_keywords) EMPTYSTRING = '' # The normal pot-file header. msgmerge and Emacs's po-mode work better if it's # there. pot_header = _('''\ # SOME DESCRIPTIVE TITLE. # Copyright (C) YEAR ORGANIZATION # FIRST AUTHOR , YEAR. # msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\\n" "POT-Creation-Date: %(time)s\\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n" "Last-Translator: FULL NAME \\n" "Language-Team: LANGUAGE \\n" "MIME-Version: 1.0\\n" "Content-Type: text/plain; charset=%(charset)s\\n" "Content-Transfer-Encoding: %(encoding)s\\n" "Generated-By: pygettext.py %(version)s\\n" ''') def usage(code, msg=''): print(__doc__ % globals(), file=sys.stderr) if msg: print(msg, file=sys.stderr) sys.exit(code) def make_escapes(pass_nonascii): global escapes, escape if pass_nonascii: # Allow non-ascii characters to pass through so that e.g. 'msgid # "Höhe"' would result not result in 'msgid "H\366he"'. Otherwise we # escape any character outside the 32..126 range. mod = 128 escape = escape_ascii else: mod = 256 escape = escape_nonascii escapes = [r"\%03o" % i for i in range(mod)] for i in range(32, 127): escapes[i] = chr(i) escapes[ord('\\')] = r'\\' escapes[ord('\t')] = r'\t' escapes[ord('\r')] = r'\r' escapes[ord('\n')] = r'\n' escapes[ord('\"')] = r'\"' def escape_ascii(s, encoding): return ''.join(escapes[ord(c)] if ord(c) < 128 else c for c in s) def escape_nonascii(s, encoding): return ''.join(escapes[b] for b in s.encode(encoding)) def is_literal_string(s): return s[0] in '\'"' or (s[0] in 'rRuU' and s[1] in '\'"') def safe_eval(s): # unwrap quotes, safely return eval(s, {'__builtins__':{}}, {}) def normalize(s, encoding): # This converts the various Python string types into a format that is # appropriate for .po files, namely much closer to C style. lines = s.split('\n') if len(lines) == 1: s = '"' + escape(s, encoding) + '"' else: if not lines[-1]: del lines[-1] lines[-1] = lines[-1] + '\n' for i in range(len(lines)): lines[i] = escape(lines[i], encoding) lineterm = '\\n"\n"' s = '""\n"' + lineterm.join(lines) + '"' return s def containsAny(str, set): """Check whether 'str' contains ANY of the chars in 'set'""" return 1 in [c in str for c in set] def getFilesForName(name): """Get a list of module files for a filename, a module or package name, or a directory. """ if not os.path.exists(name): # check for glob chars if containsAny(name, "*?[]"): files = glob.glob(name) list = [] for file in files: list.extend(getFilesForName(file)) return list # try to find module or package try: spec = importlib.util.find_spec(name) name = spec.origin except ImportError: name = None if not name: return [] if os.path.isdir(name): # find all python files in directory list = [] # get extension for python source files _py_ext = importlib.machinery.SOURCE_SUFFIXES[0] for root, dirs, files in os.walk(name): # don't recurse into CVS directories if 'CVS' in dirs: dirs.remove('CVS') # add all *.py files to list list.extend( [os.path.join(root, file) for file in files if os.path.splitext(file)[1] == _py_ext] ) return list elif os.path.exists(name): # a single file return [name] return [] class TokenEater: def __init__(self, options): self.__options = options self.__messages = {} self.__state = self.__waiting self.__data = [] self.__lineno = -1 self.__freshmodule = 1 self.__curfile = None self.__enclosurecount = 0 def __call__(self, ttype, tstring, stup, etup, line): # dispatch ## import token ## print('ttype:', token.tok_name[ttype], 'tstring:', tstring, ## file=sys.stderr) self.__state(ttype, tstring, stup[0]) def __waiting(self, ttype, tstring, lineno): opts = self.__options # Do docstring extractions, if enabled if opts.docstrings and not opts.nodocstrings.get(self.__curfile): # module docstring? if self.__freshmodule: if ttype == tokenize.STRING and is_literal_string(tstring): self.__addentry(safe_eval(tstring), lineno, isdocstring=1) self.__freshmodule = 0 elif ttype not in (tokenize.COMMENT, tokenize.NL): self.__freshmodule = 0 return # class or func/method docstring? if ttype == tokenize.NAME and tstring in ('class', 'def'): self.__state = self.__suiteseen return if ttype == tokenize.NAME and tstring in opts.keywords: self.__state = self.__keywordseen def __suiteseen(self, ttype, tstring, lineno): # skip over any enclosure pairs until we see the colon if ttype == tokenize.OP: if tstring == ':' and self.__enclosurecount == 0: # we see a colon and we're not in an enclosure: end of def self.__state = self.__suitedocstring elif tstring in '([{': self.__enclosurecount += 1 elif tstring in ')]}': self.__enclosurecount -= 1 def __suitedocstring(self, ttype, tstring, lineno): # ignore any intervening noise if ttype == tokenize.STRING and is_literal_string(tstring): self.__addentry(safe_eval(tstring), lineno, isdocstring=1) self.__state = self.__waiting elif ttype not in (tokenize.NEWLINE, tokenize.INDENT, tokenize.COMMENT): # there was no class docstring self.__state = self.__waiting def __keywordseen(self, ttype, tstring, lineno): if ttype == tokenize.OP and tstring == '(': self.__data = [] self.__lineno = lineno self.__state = self.__openseen else: self.__state = self.__waiting def __openseen(self, ttype, tstring, lineno): if ttype == tokenize.OP and tstring == ')': # We've seen the last of the translatable strings. Record the # line number of the first line of the strings and update the list # of messages seen. Reset state for the next batch. If there # were no strings inside _(), then just ignore this entry. if self.__data: self.__addentry(EMPTYSTRING.join(self.__data)) self.__state = self.__waiting elif ttype == tokenize.STRING and is_literal_string(tstring): self.__data.append(safe_eval(tstring)) elif ttype not in [tokenize.COMMENT, token.INDENT, token.DEDENT, token.NEWLINE, tokenize.NL]: # warn if we see anything else than STRING or whitespace print(_( '*** %(file)s:%(lineno)s: Seen unexpected token "%(token)s"' ) % { 'token': tstring, 'file': self.__curfile, 'lineno': self.__lineno }, file=sys.stderr) self.__state = self.__waiting def __addentry(self, msg, lineno=None, isdocstring=0): if lineno is None: lineno = self.__lineno if not msg in self.__options.toexclude: entry = (self.__curfile, lineno) self.__messages.setdefault(msg, {})[entry] = isdocstring def set_filename(self, filename): self.__curfile = filename self.__freshmodule = 1 def write(self, fp): options = self.__options timestamp = time.strftime('%Y-%m-%d %H:%M%z') encoding = fp.encoding if fp.encoding else 'UTF-8' print(pot_header % {'time': timestamp, 'version': __version__, 'charset': encoding, 'encoding': '8bit'}, file=fp) # Sort the entries. First sort each particular entry's keys, then # sort all the entries by their first item. reverse = {} for k, v in self.__messages.items(): keys = sorted(v.keys()) reverse.setdefault(tuple(keys), []).append((k, v)) rkeys = sorted(reverse.keys()) for rkey in rkeys: rentries = reverse[rkey] rentries.sort() for k, v in rentries: # If the entry was gleaned out of a docstring, then add a # comment stating so. This is to aid translators who may wish # to skip translating some unimportant docstrings. isdocstring = any(v.values()) # k is the message string, v is a dictionary-set of (filename, # lineno) tuples. We want to sort the entries in v first by # file name and then by line number. v = sorted(v.keys()) if not options.writelocations: pass # location comments are different b/w Solaris and GNU: elif options.locationstyle == options.SOLARIS: for filename, lineno in v: d = {'filename': filename, 'lineno': lineno} print(_( '# File: %(filename)s, line: %(lineno)d') % d, file=fp) elif options.locationstyle == options.GNU: # fit as many locations on one line, as long as the # resulting line length doesn't exceed 'options.width' locline = '#:' for filename, lineno in v: d = {'filename': filename, 'lineno': lineno} s = _(' %(filename)s:%(lineno)d') % d if len(locline) + len(s) <= options.width: locline = locline + s else: print(locline, file=fp) locline = "#:" + s if len(locline) > 2: print(locline, file=fp) if isdocstring: print('#, docstring', file=fp) print('msgid', normalize(k, encoding), file=fp) print('msgstr ""\n', file=fp) def main(): global default_keywords try: opts, args = getopt.getopt( sys.argv[1:], 'ad:DEhk:Kno:p:S:Vvw:x:X:', ['extract-all', 'default-domain=', 'escape', 'help', 'keyword=', 'no-default-keywords', 'add-location', 'no-location', 'output=', 'output-dir=', 'style=', 'verbose', 'version', 'width=', 'exclude-file=', 'docstrings', 'no-docstrings', ]) except getopt.error as msg: usage(1, msg) # for holding option values class Options: # constants GNU = 1 SOLARIS = 2 # defaults extractall = 0 # FIXME: currently this option has no effect at all. escape = 0 keywords = [] outpath = '' outfile = 'messages.pot' writelocations = 1 locationstyle = GNU verbose = 0 width = 78 excludefilename = '' docstrings = 0 nodocstrings = {} options = Options() locations = {'gnu' : options.GNU, 'solaris' : options.SOLARIS, } # parse options for opt, arg in opts: if opt in ('-h', '--help'): usage(0) elif opt in ('-a', '--extract-all'): options.extractall = 1 elif opt in ('-d', '--default-domain'): options.outfile = arg + '.pot' elif opt in ('-E', '--escape'): options.escape = 1 elif opt in ('-D', '--docstrings'): options.docstrings = 1 elif opt in ('-k', '--keyword'): options.keywords.append(arg) elif opt in ('-K', '--no-default-keywords'): default_keywords = [] elif opt in ('-n', '--add-location'): options.writelocations = 1 elif opt in ('--no-location',): options.writelocations = 0 elif opt in ('-S', '--style'): options.locationstyle = locations.get(arg.lower()) if options.locationstyle is None: usage(1, _('Invalid value for --style: %s') % arg) elif opt in ('-o', '--output'): options.outfile = arg elif opt in ('-p', '--output-dir'): options.outpath = arg elif opt in ('-v', '--verbose'): options.verbose = 1 elif opt in ('-V', '--version'): print(_('pygettext.py (xgettext for Python) %s') % __version__) sys.exit(0) elif opt in ('-w', '--width'): try: options.width = int(arg) except ValueError: usage(1, _('--width argument must be an integer: %s') % arg) elif opt in ('-x', '--exclude-file'): options.excludefilename = arg elif opt in ('-X', '--no-docstrings'): fp = open(arg) try: while 1: line = fp.readline() if not line: break options.nodocstrings[line[:-1]] = 1 finally: fp.close() # calculate escapes make_escapes(not options.escape) # calculate all keywords options.keywords.extend(default_keywords) # initialize list of strings to exclude if options.excludefilename: try: with open(options.excludefilename) as fp: options.toexclude = fp.readlines() except IOError: print(_( "Can't read --exclude-file: %s") % options.excludefilename, file=sys.stderr) sys.exit(1) else: options.toexclude = [] # resolve args to module lists expanded = [] for arg in args: if arg == '-': expanded.append(arg) else: expanded.extend(getFilesForName(arg)) args = expanded # slurp through all the files eater = TokenEater(options) for filename in args: if filename == '-': if options.verbose: print(_('Reading standard input')) fp = sys.stdin.buffer closep = 0 else: if options.verbose: print(_('Working on %s') % filename) fp = open(filename, 'rb') closep = 1 try: eater.set_filename(filename) try: tokens = tokenize.tokenize(fp.readline) for _token in tokens: eater(*_token) except tokenize.TokenError as e: print('%s: %s, line %d, column %d' % ( e.args[0], filename, e.args[1][0], e.args[1][1]), file=sys.stderr) finally: if closep: fp.close() # write the output if options.outfile == '-': fp = sys.stdout closep = 0 else: if options.outpath: options.outfile = os.path.join(options.outpath, options.outfile) fp = open(options.outfile, 'w') closep = 1 try: eater.write(fp) finally: if closep: fp.close() if __name__ == '__main__': main() # some more test strings # this one creates a warning _('*** Seen unexpected token "%(token)s"') % {'token': 'test'} _('more' 'than' 'one' 'string')