comparison roundup/dist/command/build_scripts.py @ 5435:12baa5b9b597

Python 3 preparation: avoid string.translate() and string.maketrans().
author Joseph Myers <jsm@polyomino.org.uk>
date Wed, 25 Jul 2018 10:44:30 +0000
parents 0942fe89e82e
children
comparison
equal deleted inserted replaced
5434:1ab2c81a64df 5435:12baa5b9b597
94 94
95 def copy_scripts(self): 95 def copy_scripts(self):
96 """ Create each script listed in 'self.scripts' 96 """ Create each script listed in 'self.scripts'
97 """ 97 """
98 98
99 to_module = string.maketrans('-/', '_.') 99 try:
100 # Python 3.
101 maketrans = str.maketrans
102 except AttributeError:
103 # Python 2.
104 maketrans = string.maketrans
105 to_module = maketrans('-/', '_.')
100 106
101 self.mkpath(self.build_dir) 107 self.mkpath(self.build_dir)
102 for script in self.scripts: 108 for script in self.scripts:
103 outfile = os.path.join(self.build_dir, os.path.basename(script)) 109 outfile = os.path.join(self.build_dir, os.path.basename(script))
104 110
109 if self.dry_run: 115 if self.dry_run:
110 log.info("would create %s" % outfile) 116 log.info("would create %s" % outfile)
111 continue 117 continue
112 118
113 module = os.path.splitext(os.path.basename(script))[0] 119 module = os.path.splitext(os.path.basename(script))[0]
114 module = string.translate(module, to_module) 120 module = module.translate(to_module)
115 script_vars = { 121 script_vars = {
116 'python': self.python_executable, 122 'python': self.python_executable,
117 'package': self.package_name, 123 'package': self.package_name,
118 'module': module, 124 'module': module,
119 'prefix': self.script_preamble, 125 'prefix': self.script_preamble,

Roundup Issue Tracker: http://roundup-tracker.org/