def py_strings(dir, domain="none", exclude=()): """Retrieve all Python messages from `dir` that are in the `domain`. """ eater = TokenEater() make_escapes(0) for filename in find_files( # We want to include cpy and vpy scripts as well # dir, '*.py', exclude=('extract.py', 'pygettext.py')+tuple(exclude)): dir, '*.*py', exclude=('extract.py', 'pygettext.py') + tuple(exclude)): fp = codecs.open(filename, 'r', DEFAULT_CHARSET) try: eater.set_filename(filename) try: tokenize.tokenize(fp.readline, eater) except tokenize.TokenError, e: print >> sys.stderr, '%s: %s, line %d, column %d' % ( e[0], filename, e[1][0], e[1][1]) finally: fp.close() # One limitation of the Python message extractor is that it cannot # determine the domain of the string, since it is not contained anywhere # directly. The only way this could be done is by loading the module and # inspect the '_' function. For now we simply assume that all the found # strings have the domain the user specified. return eater.getCatalog()
def py_strings(dir, domain="none", exclude=()): """Retrieve all Python messages from `dir` that are in the `domain`. """ eater = TokenEater() make_escapes(0) for filename in find_files( # We want to include cpy and vpy scripts as well # dir, '*.py', exclude=('extract.py', 'pygettext.py')+tuple(exclude)): dir, '*.*py', exclude=('extract.py', 'pygettext.py')+tuple(exclude)): fp = codecs.open(filename, 'r', DEFAULT_CHARSET) try: eater.set_filename(filename) try: tokenize.tokenize(fp.readline, eater) except tokenize.TokenError, e: print >> sys.stderr, '%s: %s, line %d, column %d' % ( e[0], filename, e[1][0], e[1][1]) finally: fp.close() # One limitation of the Python message extractor is that it cannot # determine the domain of the string, since it is not contained anywhere # directly. The only way this could be done is by loading the module and # inspect the '_' function. For now we simply assume that all the found # strings have the domain the user specified. return eater.getCatalog()
def finalize_options(self): options = self.options self.name = self.distribution.get_name() # Build default options for the TokenEater if self.default_domain: self.output = self.default_domain + '.pot' if self.keyword: options.keywords.extend(self.keyword.split(',')) if self.no_default_keywords: options.keywords = [ ] if self.no_location: options.writelocations = 0 if self.style: if self.style == 'gnu': options.locationstyle = self.GNU elif self.style == 'solaris': options.locationstyle = self.SOLARIS else: raise SystemExit, 'Invalid value for --style: %s' % self.style if not self.output: self.output = self.distribution.get_name() + '.pot' if not self.output_dir: self.output_dir = self.podir if self.docstrings: options.docstrings = 1 options.width = int(self.width) if self.exclude_file: try: fp = open(self.exclude_file) options.toexclude = fp.readlines() fp.close() except IOError: raise SystemExit, "Can't read --exclude-file: %s" % self.exclude_file # skip: self.no_docstrings if self.all_linguas: self.all_linguas = self.all_linguas.split(',') # calculate escapes pygettext.make_escapes(self.escape) # calculate all keywords options.keywords.append('_') if self.output_dir: self.output = os.path.join(self.output_dir, self.output) self.packages = self.distribution.packages
def py_strings(dir, domain="zope", exclude=(), verify_domain=False): """Retrieve all Python messages from `dir` that are in the `domain`. Retrieves all the messages in all the domains if verify_domain is False. """ eater = TokenEater() make_escapes(0) for filename in find_files(dir, '*.py', exclude=('extract.py', 'pygettext.py') + tuple(exclude)): if verify_domain: module_name = module_from_filename(filename) try: module = __import__(module_name, *_import_chickens) except ImportError, e: # XXX if we can't import it - we assume that the domain is # the right one print >> sys.stderr, ("Could not import %s, " "assuming i18n domain OK" % module_name) else: mf = getattr(module, '_', None) # XXX if _ is has no _domain set we assume that the domain # is the right one, so if you are using something non # MessageFactory you should set it's _domain attribute. if hasattr(mf, '_domain'): if mf._domain != domain: # domain mismatch - skip this file continue elif mf: print >> sys.stderr, ( "Could not figure out the i18n domain" "for module %s, assuming it is OK" % module_name) fp = open(filename) try: eater.set_filename(filename) try: tokenize.tokenize(fp.readline, eater) except tokenize.TokenError, e: print >> sys.stderr, '%s: %s, line %d, column %d' % ( e[0], filename, e[1][0], e[1][1]) finally: fp.close()
def py_strings(dir, domain="zope", exclude=(), verify_domain=False): """Retrieve all Python messages from `dir` that are in the `domain`. Retrieves all the messages in all the domains if verify_domain is False. """ eater = TokenEater() make_escapes(0) for filename in find_files( dir, '*.py', exclude=('extract.py', 'pygettext.py')+tuple(exclude)): if verify_domain: module_name = module_from_filename(filename) try: module = __import__(module_name, *_import_chickens) except ImportError, e: # XXX if we can't import it - we assume that the domain is # the right one print >> sys.stderr, ("Could not import %s, " "assuming i18n domain OK" % module_name) else: mf = getattr(module, '_', None) # XXX if _ is has no _domain set we assume that the domain # is the right one, so if you are using something non # MessageFactory you should set it's _domain attribute. if hasattr(mf, '_domain'): if mf._domain != domain: # domain mismatch - skip this file continue elif mf: print >> sys.stderr, ("Could not figure out the i18n domain" "for module %s, assuming it is OK" % module_name) fp = open(filename) try: eater.set_filename(filename) try: tokenize.tokenize(fp.readline, eater) except tokenize.TokenError, e: print >> sys.stderr, '%s: %s, line %d, column %d' % ( e[0], filename, e[1][0], e[1][1]) finally: fp.close()