diff -r d4bb7a333937 scripts/nml_langcheck/languages.py --- a/scripts/nml_langcheck/languages.py Fri Jan 30 13:10:17 2015 +0000 +++ b/scripts/nml_langcheck/languages.py Sat Jan 31 16:10:24 2015 +0000 @@ -29,10 +29,10 @@ def make_revline(rev, line): if rev is None: if line is None: return None - return u"Line %d" % line + return "Line %d" % line else: if line is None: - return u"r%d" % rev + return "r%d" % rev return "at line %d, r%d" % (line, rev) @@ -90,34 +90,34 @@ self.old_rev = None def write(self, fp): - text = [u'%s:\n' % (self.str_name,)] + text = ['%s:\n' % (self.str_name,)] printed = False if self.trans_text is not None: - if printed: text.append(u'\n') + if printed: text.append('\n') rv = make_revline(self.trans_rev, self.trans_line) if rv is None: - text.append(u'\tTranslation: "%s"\n' % self.trans_text) + text.append('\tTranslation: "%s"\n' % self.trans_text) else: - text.append(u'\tTranslation %s: "%s"\n' % (rv, self.trans_text)) + text.append('\tTranslation %s: "%s"\n' % (rv, self.trans_text)) printed = True if self.master_text is not None: - if printed: text.append(u'\n') + if printed: text.append('\n') rv = make_revline(self.master_rev, self.master_line) if rv is None: - text.append(u'\tCurrent source: "%s"\n' % self.master_text) + text.append('\tCurrent source: "%s"\n' % self.master_text) else: - text.append(u'\tCurrent source %s: "%s"\n' % (rv, self.master_text)) + text.append('\tCurrent source %s: "%s"\n' % (rv, self.master_text)) printed = True if self.old_text is not None: - if printed: text.append(u'\n') + if printed: text.append('\n') rv = make_revline(self.old_rev, None) if rv is None: - text.append(u'\tOld source: "%s"\n' % self.old_text) + text.append('\tOld source: "%s"\n' % self.old_text) else: - text.append(u'\tOld source %s: "%s"\n' % (rv, self.old_text)) + text.append('\tOld source %s: "%s"\n' % (rv, self.old_text)) printed = True @@ -159,11 +159,11 @@ @rtype: C{unicode} """ if self.gender is None: return self.name - return self.name + u"." + self.gender + return self.name + "." + self.gender # Pattern to match annotation revision. -re_annot = re.compile(u' *(\\d+):') +re_annot = re.compile(' *(\\d+):') utf8_bom = codecs.BOM_UTF8.decode('utf-8') def get_annotated(fname, revision): @@ -186,12 +186,12 @@ p = subprocess.Popen(cmd, stdout = subprocess.PIPE, stderr = subprocess.PIPE) out_data, err_data = p.communicate() if err_data != "": - msg= u'Warning: Mercurial command \"%s\" failed (message: "%s")' \ - % (u" ".join(cmd), err_data) + msg= 'Warning: Mercurial command \"%s\" failed (message: "%s")' \ + % (" ".join(cmd), err_data) raise LanguageReadError(msg) out_data = out_data.decode('utf-8') - for idx, line in enumerate(out_data.split(u'\n')): + for idx, line in enumerate(out_data.split('\n')): if idx == 0 and line[0] == utf8_bom: line = line[1:] line = line.rstrip() m = re_annot.match(line) @@ -201,7 +201,7 @@ if idx == 0 and len(line) > i and line[i] == utf8_bom: i = i + 1 if len(line) == i: - yield int(m.group(1)), idx + 1, u'' + yield int(m.group(1)), idx + 1, '' else: yield int(m.group(1)), idx + 1, line[i:] @@ -227,9 +227,9 @@ texts = [] for rev, num, text in get_annotated(fname, revision): # cases!! - if len(text) == 0 or text[0] == u'#': continue + if len(text) == 0 or text[0] == '#': continue - i, j = text.find(u' '), text.find(u'\t') + i, j = text.find(' '), text.find('\t') if i < 0: es = j elif j < 0: @@ -238,24 +238,24 @@ es = min([i, j]) if es < 0: - raise LanguageReadError(u"Invalid string-name at line %d in %r (text %r)" + raise LanguageReadError("Invalid string-name at line %d in %r (text %r)" % (num, fname, text)) - j = text.find(u'.') + j = text.find('.') if j > 0 and j < es: name, gender = text[:j], text[j + 1:es] else: name, gender = text[:es], None - i = text.find(u':') + i = text.find(':') if i < 0: - raise LanguageReadError(u"Missing colon at line %d in %r (text %r)" + raise LanguageReadError("Missing colon at line %d in %r (text %r)" % (num, fname, text)) text = text[i + 1:] tid = (name, gender) if tid in line_numbers: - raise LanguageReadError(u"String %r is defined twice in %r (at lines %d and %d)" + raise LanguageReadError("String %r is defined twice in %r (at lines %d and %d)" % (name, fname, line_numbers[name], num)) line_numbers[tid] = num @@ -304,8 +304,8 @@ try: data = make_mapping(read_lang(master_name, revision)) - except LanguageReadError, exc: - print "Warning: Retrieving version information failed: %r" % str(exc.err) + except LanguageReadError as exc: + print("Warning: Retrieving version information failed: %r" % str(exc.err)) return None cached_master_files[revision] = data @@ -357,7 +357,7 @@ This may reduce access to old master language revisions. """ translation = make_mapping(translation) # Convert translation to a dict - t_names = set(translation.iterkeys()) # names in the translation that have not been processed. + t_names = set(translation.keys()) # names in the translation that have not been processed. missing = [] # Strings missing in the translation. outdated = [] # Strings that need to be updated. diff -r d4bb7a333937 scripts/nml_langcheck/main.py --- a/scripts/nml_langcheck/main.py Fri Jan 30 13:10:17 2015 +0000 +++ b/scripts/nml_langcheck/main.py Sat Jan 31 16:10:24 2015 +0000 @@ -30,7 +30,7 @@ - Release of first version, cl 2.0 """ -import os, sys, getopt, ConfigParser +import os, sys, getopt, configparser from nml_langcheck import output, languages _version = '2.3' @@ -120,7 +120,7 @@ usage(sys.stdout) sys.exit(0) else: - print "Warning: Skipped the --help option." + print("Warning: Skipped the --help option.") return True if opt in ('-e', '--ext'): @@ -147,7 +147,7 @@ if allow_cfg: self.load_cfg(arg) else: - print "Warning: Skipped the --cfg option." + print("Warning: Skipped the --cfg option.") return True return False @@ -159,7 +159,7 @@ @param fname: Name of the INI file. @type fname: C{str} """ - cfg_parser = ConfigParser.SafeConfigParser() + cfg_parser = configparser.SafeConfigParser() cfg_parser.read([fname]) if not cfg_parser.has_section('options'): return @@ -169,7 +169,7 @@ msg = "Unknown option '--%s' encountered in option file '%s'" \ % (opt, fname) - print "Warning: " + msg + print("Warning: " + msg) def set_args(self, args): @@ -254,8 +254,8 @@ try: opts, args = getopt.getopt(sys.argv[1:], CmdLine.short_opts, CmdLine.long_opts) - except getopt.GetoptError, err: - print "nml_langcheck: " + str(err) + except getopt.GetoptError as err: + print("nml_langcheck: " + str(err)) usage(sys.stdout) sys.exit(2) @@ -272,8 +272,8 @@ err = cmd_line.get_error() if err is not None: - print "nml_langcheck: " + err - print + print("nml_langcheck: " + err) + print() usage(sys.stdout) sys.exit(1) @@ -305,8 +305,8 @@ """ try: return languages.read_lang(fname, None) - except languages.LanguageReadError, exc: - print "Language file \"%s\" cannot be found: %r" % (fname, str(exc.err)) + except languages.LanguageReadError as exc: + print("Language file \"%s\" cannot be found: %r" % (fname, str(exc.err))) return None @@ -316,7 +316,7 @@ master_data = get_language(cmd_line.master) if master_data is None: - print "Quitting!" + print("Quitting!") sys.exit(1) index_data = output.IndexData(cmd_line.transl_url, cmd_line.index_name, len(master_data)) @@ -324,11 +324,11 @@ for src, lang_name, dest in cmd_line.get_jobs(): if cmd_line.verbose > 0: - print "%r -> %r" % (src, dest) + print("%r -> %r" % (src, dest)) translation = get_language(src) if translation is None: - print "Quitting!" + print("Quitting!") sys.exit(1) missing, outdated, obsolete = languages.compare_langs(master_data, translation) diff -r d4bb7a333937 src/render_docs.py --- a/src/render_docs.py Fri Jan 30 13:10:17 2015 +0000 +++ b/src/render_docs.py Sat Jan 31 16:10:24 2015 +0000 @@ -6,7 +6,7 @@ FIRS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with FIRS. If not, see . """ -print "[PYTHON] render docs" +print("[PYTHON] render docs") import codecs # used for writing files - more unicode friendly than standard open() module @@ -148,7 +148,7 @@ # convenient to have items sorted result[industry_key]['economies'] = sorted(result[industry_key]['economies'], key=lambda economy: self.get_economy_name(economy)) # return a list, sorted by economies (only need first economy entry in each list of economies) - return sorted(result.values(), key = lambda combo: self.get_economy_name(combo['economies'][0])) + return sorted(list(result.values()), key = lambda combo: self.get_economy_name(combo['economies'][0])) def industry_find_cargos_active_in_economy_for_industry(self, industry, economy, accept_or_produce): @@ -177,7 +177,7 @@ # convenient to have items sorted result[cargo_key]['economies'] = sorted(result[cargo_key]['economies'], key=lambda economy: self.get_economy_name(economy)) # return a list, sorted by economies (only need first economy entry in each list of economies) - return sorted(result.values(), key = lambda combo: self.get_economy_name(combo['economies'][0])) + return sorted(list(result.values()), key = lambda combo: self.get_economy_name(combo['economies'][0])) def get_active_nav(self, doc_name, nav_link): diff -r d4bb7a333937 src/render_pnml.py --- a/src/render_pnml.py Fri Jan 30 13:10:17 2015 +0000 +++ b/src/render_pnml.py Sat Jan 31 16:10:24 2015 +0000 @@ -5,7 +5,7 @@ See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with FIRS. If not, see . """ -print "[PYTHON] render pnml" +print("[PYTHON] render pnml") import codecs # used for writing files - more unicode friendly than standard open() module @@ -82,7 +82,7 @@ pool.join() # linker - print "Linking" + print("Linking") template = header_item_templates['firs.pypnml'] firs_pnml = codecs.open(os.path.join(firs.generated_files_path, 'firs.pnml'), 'w','utf8') firs_pnml.write(utils.unescape_chameleon_output(template(registered_industries=registered_industries, global_constants=global_constants, diff -r d4bb7a333937 src/utils.py --- a/src/utils.py Fri Jan 30 13:10:17 2015 +0000 +++ b/src/utils.py Sat Jan 31 16:10:24 2015 +0000 @@ -18,7 +18,7 @@ def parse_base_lang(): - print "[PARSE BASE LANG & EXTRA STRINGS] utils.py" + print("[PARSE BASE LANG & EXTRA STRINGS] utils.py") import os.path currentdir = os.curdir @@ -54,4 +54,4 @@ def echo_message(message): # use to raise messages from templates to standard out (can't print directly from template render) # magically wraps these messages in ANSI colour to make them visible - they are only intended for noticeable messages, not general output - print '\033[33m' + message + '\033[0m' + print('\033[33m' + message + '\033[0m')