/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/export_pot.py

  • Committer: Jelmer Vernooij
  • Date: 2018-11-06 01:18:08 UTC
  • mfrom: (7143 work)
  • mto: This revision was merged to the branch mainline in revision 7151.
  • Revision ID: jelmer@jelmer.uk-20181106011808-y870f4vq0ork3ahu
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
    plugin as _mod_plugin,
41
41
    help,
42
42
    )
 
43
from .sixish import PY3
43
44
from .trace import (
44
45
    mutter,
45
46
    note,
71
72
    return s
72
73
 
73
74
 
74
 
def _parse_source(source_text):
 
75
def _parse_source(source_text, filename='<unknown>'):
75
76
    """Get object to lineno mappings from given source_text"""
76
77
    import ast
77
78
    cls_to_lineno = {}
78
79
    str_to_lineno = {}
79
 
    for node in ast.walk(ast.parse(source_text)):
 
80
    for node in ast.walk(ast.parse(source_text, filename)):
80
81
        # TODO: worry about duplicates?
81
82
        if isinstance(node, ast.ClassDef):
82
83
            # TODO: worry about nesting?
106
107
        # TODO: fix this to do the right thing rather than rely on cwd
107
108
        relpath = os.path.relpath(sourcepath)
108
109
        return cls(relpath,
109
 
            _source_info=_parse_source("".join(inspect.findsource(module)[0])))
 
110
            _source_info=_parse_source("".join(inspect.findsource(module)[0]), module.__file__))
110
111
 
111
112
    def from_class(self, cls):
112
113
        """Get new context with same details but lineno of class in source"""
150
151
        else:
151
152
            comment = "# %s\n" % comment
152
153
        mutter("Exporting msg %r at line %d in %r", s[:20], lineno, path)
153
 
        self.outf.write(
 
154
        line = (
154
155
            "#: {path}:{lineno}\n"
155
156
            "{comment}"
156
157
            "msgid {msg}\n"
157
158
            "msgstr \"\"\n"
158
159
            "\n".format(
159
160
                path=path, lineno=lineno, comment=comment, msg=_normalize(s)))
 
161
        if not PY3:
 
162
            line = line.decode('utf-8')
 
163
        self.outf.write(line)
160
164
 
161
165
    def poentry_in_context(self, context, string, comment=None):
162
166
        context = context.from_string(string)