# Buggy code
def translate_desktop(self, args):
    messages_file = os.path.join(args.translations_dir, "desktop.pot")

    if args.extract_update:
        sources = args.sources.split(",")
        k = {"_cwd": args.translations_dir}
        xgettext(
            "--output=desktop.pot",
            "--language=Desktop",
            "--keyword",
            "--keyword=Name",
            "--package-version",
            args.version,
            "--msgid-bugs-address=securedrop@freedom.press",
            "--copyright-holder=Freedom of the Press Foundation",
            *sources,
            **k,
        )
        sed("-i", "-e", '/^"POT-Creation-Date/d', messages_file, **k)

        if self.file_is_modified(messages_file):
            for f in os.listdir(args.translations_dir):
                if not f.endswith(".po"):
                    continue
                po_file = os.path.join(args.translations_dir, f)
                msgmerge("--update", po_file, messages_file)
            log.warning("messages translations updated in " + messages_file)
        else:
            log.warning("desktop translations are already up to date")

    if args.compile:
        pos = filter(lambda f: f.endswith(".po"), os.listdir(args.translations_dir))
        linguas = map(lambda l: l.rstrip(".po"), pos)
        content = "\n".join(linguas) + "\n"
        open(join(args.translations_dir, "LINGUAS"), "w").write(content)

        for source in args.sources.split(","):
            target = source.rstrip(".in")
            msgfmt(
                "--desktop",
                "--template",
                source,
                "-o",
                target,
                "-d",
                ".",
                _cwd=args.translations_dir,
            )


# Traceback (sh.ErrorReturnCode_1)
$ securedrop/bin/dev-shell ./i18n_tool.py --verbose translate-desktop --compile
Run with DOCKER_BUILD_VERBOSE=true for more information
Docker image build in progress  done !
2019-02-25 17:28:43,373 INFO <Command u'/usr/bin/msgfmt --desktop --template desktop-journalist-icon.j2.in -o desktop-journalist-icon.j2 -d .'>: starting process
2019-02-25 17:28:43,380 INFO <Command u'/usr/bin/msgfmt --desktop --template desktop-journalist-icon.j2.in -o desktop-journalist-icon.j2 -d .', pid 9>: process started
Traceback (most recent call last):
File "./i18n_tool.py", line 372, in <module>
sys.exit(I18NTool().main(sys.argv[1:]))
File "./i18n_tool.py", line 366, in main
return args.func(args)
File "./i18n_tool.py", line 139, in translate_desktop
_cwd=args.translations_dir)
File "/usr/local/lib/python2.7/dist-packages/sh.py", line 1427, in __call__
return RunningCommand(cmd, call_args, stdin, stdout, stderr)
File "/usr/local/lib/python2.7/dist-packages/sh.py", line 774, in __init__
self.wait()
File "/usr/local/lib/python2.7/dist-packages/sh.py", line 792, in wait
self.handle_command_exit_code(exit_code)
File "/usr/local/lib/python2.7/dist-packages/sh.py", line 815, in handle_command_exit_code
raise exc
sh.ErrorReturnCode_1:

RAN: /usr/bin/msgfmt --desktop --template desktop-journalist-icon.j2.in -o desktop-journalist-icon.j2 -d .

STDOUT:


STDERR:
/usr/bin/msgfmt: error while opening "r.po" for reading: No such file or directory

# Fixed code
def translate_desktop(self, args):
    messages_file = os.path.join(args.translations_dir, "desktop.pot")

    if args.extract_update:
        sources = args.sources.split(",")
        k = {"_cwd": args.translations_dir}
        xgettext(
            "--output=desktop.pot",
            "--language=Desktop",
            "--keyword",
            "--keyword=Name",
            "--package-version",
            args.version,
            "--msgid-bugs-address=securedrop@freedom.press",
            "--copyright-holder=Freedom of the Press Foundation",
            *sources,
            **k,
        )
        sed("-i", "-e", '/^"POT-Creation-Date/d', messages_file, **k)

        if self.file_is_modified(messages_file):
            for f in os.listdir(args.translations_dir):
                if not f.endswith(".po"):
                    continue
                po_file = os.path.join(args.translations_dir, f)
                msgmerge("--update", po_file, messages_file)
            log.warning("messages translations updated in " + messages_file)
        else:
            log.warning("desktop translations are already up to date")

    if args.compile:
        pos = filter(lambda f: f.endswith(".po"), os.listdir(args.translations_dir))
        linguas = map(lambda l: l[:-3], pos)
        content = "\n".join(linguas) + "\n"
        open(join(args.translations_dir, "LINGUAS"), "w").write(content)

        for source in args.sources.split(","):
            target = source.rstrip(".in")
            msgfmt(
                "--desktop",
                "--template",
                source,
                "-o",
                target,
                "-d",
                ".",
                _cwd=args.translations_dir,
            )