100-python3-compat.patch 83 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046
  1. --- a/engine/SCons/dblite.py
  2. +++ b/engine/SCons/dblite.py
  3. @@ -10,11 +10,11 @@ import pickle
  4. import shutil
  5. import time
  6. -keep_all_files = 00000
  7. +keep_all_files = 0o0
  8. ignore_corrupt_dbfiles = 0
  9. def corruption_warning(filename):
  10. - print "Warning: Discarding corrupt database:", filename
  11. + print("Warning: Discarding corrupt database:", filename)
  12. try: unicode
  13. except NameError:
  14. @@ -70,14 +70,14 @@ class dblite(object):
  15. self._flag = flag
  16. self._mode = mode
  17. self._dict = {}
  18. - self._needs_sync = 00000
  19. + self._needs_sync = 0o0
  20. if self._os_chown is not None and (os.geteuid()==0 or os.getuid()==0):
  21. # running as root; chown back to current owner/group when done
  22. try:
  23. statinfo = os.stat(self._file_name)
  24. self._chown_to = statinfo.st_uid
  25. self._chgrp_to = statinfo.st_gid
  26. - except OSError, e:
  27. + except OSError as e:
  28. # db file doesn't exist yet.
  29. # Check os.environ for SUDO_UID, use if set
  30. self._chown_to = int(os.environ.get('SUDO_UID', -1))
  31. @@ -90,7 +90,7 @@ class dblite(object):
  32. else:
  33. try:
  34. f = self._open(self._file_name, "rb")
  35. - except IOError, e:
  36. + except IOError as e:
  37. if (self._flag != "c"):
  38. raise e
  39. self._open(self._file_name, "wb", self._mode)
  40. @@ -122,7 +122,7 @@ class dblite(object):
  41. # (e.g. from a previous run as root). We should still be able to
  42. # unlink() the file if the directory's writable, though, so ignore
  43. # any OSError exception thrown by the chmod() call.
  44. - try: self._os_chmod(self._file_name, 0777)
  45. + try: self._os_chmod(self._file_name, 0o777)
  46. except OSError: pass
  47. self._os_unlink(self._file_name)
  48. self._os_rename(self._tmp_name, self._file_name)
  49. @@ -131,7 +131,7 @@ class dblite(object):
  50. self._os_chown(self._file_name, self._chown_to, self._chgrp_to)
  51. except OSError:
  52. pass
  53. - self._needs_sync = 00000
  54. + self._needs_sync = 0o0
  55. if (keep_all_files):
  56. self._shutil_copyfile(
  57. self._file_name,
  58. @@ -151,7 +151,7 @@ class dblite(object):
  59. if (not is_string(value)):
  60. raise TypeError("value `%s' must be a string but is %s" % (value, type(value)))
  61. self._dict[key] = value
  62. - self._needs_sync = 0001
  63. + self._needs_sync = 0o1
  64. def keys(self):
  65. return list(self._dict.keys())
  66. @@ -171,7 +171,7 @@ class dblite(object):
  67. def __len__(self):
  68. return len(self._dict)
  69. -def open(file, flag=None, mode=0666):
  70. +def open(file, flag=None, mode=0o666):
  71. return dblite(file, flag, mode)
  72. def _exercise():
  73. @@ -198,7 +198,7 @@ def _exercise():
  74. assert db[unicode("ubar")] == unicode("ufoo")
  75. try:
  76. db.sync()
  77. - except IOError, e:
  78. + except IOError as e:
  79. assert str(e) == "Read-only database: tmp.dblite"
  80. else:
  81. raise RuntimeError("IOError expected.")
  82. @@ -208,13 +208,13 @@ def _exercise():
  83. db.sync()
  84. try:
  85. db[(1,2)] = "tuple"
  86. - except TypeError, e:
  87. + except TypeError as e:
  88. assert str(e) == "key `(1, 2)' must be a string but is <type 'tuple'>", str(e)
  89. else:
  90. raise RuntimeError("TypeError exception expected")
  91. try:
  92. db["list"] = [1,2]
  93. - except TypeError, e:
  94. + except TypeError as e:
  95. assert str(e) == "value `[1, 2]' must be a string but is <type 'list'>", str(e)
  96. else:
  97. raise RuntimeError("TypeError exception expected")
  98. @@ -238,11 +238,11 @@ def _exercise():
  99. os.unlink("tmp.dblite")
  100. try:
  101. db = open("tmp", "w")
  102. - except IOError, e:
  103. + except IOError as e:
  104. assert str(e) == "[Errno 2] No such file or directory: 'tmp.dblite'", str(e)
  105. else:
  106. raise RuntimeError("IOError expected.")
  107. - print "OK"
  108. + print("OK")
  109. if (__name__ == "__main__"):
  110. _exercise()
  111. --- a/engine/SCons/SConsign.py
  112. +++ b/engine/SCons/SConsign.py
  113. @@ -84,7 +84,7 @@ def Get_DataBase(dir):
  114. DB_sync_list.append(db)
  115. return db, "c"
  116. except TypeError:
  117. - print "DataBase =", DataBase
  118. + print("DataBase =", DataBase)
  119. raise
  120. def Reset():
  121. @@ -215,7 +215,7 @@ class DB(Base):
  122. raise TypeError
  123. except KeyboardInterrupt:
  124. raise
  125. - except Exception, e:
  126. + except Exception as e:
  127. SCons.Warnings.warn(SCons.Warnings.CorruptSConsignWarning,
  128. "Ignoring corrupt sconsign entry : %s (%s)\n"%(self.dir.tpath, e))
  129. for key, entry in self.entries.items():
  130. @@ -340,7 +340,7 @@ class DirFile(Dir):
  131. if fname != self.sconsign:
  132. try:
  133. mode = os.stat(self.sconsign)[0]
  134. - os.chmod(self.sconsign, 0666)
  135. + os.chmod(self.sconsign, 0o666)
  136. os.unlink(self.sconsign)
  137. except (IOError, OSError):
  138. # Try to carry on in the face of either OSError
  139. --- a/engine/SCons/Util.py
  140. +++ b/engine/SCons/Util.py
  141. @@ -264,10 +264,10 @@ def print_tree(root, child_func, prune=0
  142. children = child_func(root)
  143. if prune and rname in visited and children:
  144. - sys.stdout.write(''.join(tags + margins + ['+-[', rname, ']']) + u'\n')
  145. + sys.stdout.write(''.join(tags + margins + ['+-[', rname, ']']) + '\n')
  146. return
  147. - sys.stdout.write(''.join(tags + margins + ['+-', rname]) + u'\n')
  148. + sys.stdout.write(''.join(tags + margins + ['+-', rname]) + '\n')
  149. visited[rname] = 1
  150. @@ -718,7 +718,7 @@ else:
  151. # raised so as to not mask possibly serious disk or
  152. # network issues.
  153. continue
  154. - if stat.S_IMODE(st[stat.ST_MODE]) & 0111:
  155. + if stat.S_IMODE(st[stat.ST_MODE]) & 0o111:
  156. try:
  157. reject.index(f)
  158. except ValueError:
  159. @@ -1355,9 +1355,9 @@ def AddMethod(obj, function, name=None):
  160. self.z = x + y
  161. AddMethod(f, A, "add")
  162. a.add(2, 4)
  163. - print a.z
  164. + print(a.z)
  165. AddMethod(lambda self, i: self.l[i], a, "listIndex")
  166. - print a.listIndex(5)
  167. + print(a.listIndex(5))
  168. """
  169. if name is None:
  170. name = function.func_name
  171. --- a/setup.py
  172. +++ b/setup.py
  173. @@ -333,7 +333,7 @@ class install_scripts(_install_scripts):
  174. # log.info("changing mode of %s", file)
  175. pass
  176. else:
  177. - mode = ((os.stat(file)[stat.ST_MODE]) | 0555) & 07777
  178. + mode = ((os.stat(file)[stat.ST_MODE]) | 0o555) & 0o7777
  179. # log.info("changing mode of %s to %o", file, mode)
  180. os.chmod(file, mode)
  181. # --- /distutils copy/paste ---
  182. @@ -414,7 +414,7 @@ arguments = {
  183. distutils.core.setup(**arguments)
  184. if Installed:
  185. - print '\n'.join(Installed)
  186. + print('\n'.join(Installed))
  187. # Local Variables:
  188. # tab-width:4
  189. --- a/engine/SCons/compat/_scons_subprocess.py
  190. +++ b/engine/SCons/compat/_scons_subprocess.py
  191. @@ -248,11 +248,11 @@ A more real-world example would look lik
  192. try:
  193. retcode = call("mycmd" + " myarg", shell=True)
  194. if retcode < 0:
  195. - print >>sys.stderr, "Child was terminated by signal", -retcode
  196. + print(>>sys.stderr, "Child was terminated by signal", -retcode)
  197. else:
  198. - print >>sys.stderr, "Child returned", retcode
  199. -except OSError, e:
  200. - print >>sys.stderr, "Execution failed:", e
  201. + print(>>sys.stderr, "Child returned", retcode)
  202. +except OSError as e:
  203. + print(>>sys.stderr, "Execution failed:", e)
  204. Replacing os.spawn*
  205. @@ -439,7 +439,7 @@ except TypeError:
  206. def is_int(obj):
  207. return isinstance(obj, type(1))
  208. def is_int_or_long(obj):
  209. - return type(obj) in (type(1), type(1L))
  210. + return type(obj) in (type(1), type(1))
  211. else:
  212. def is_int(obj):
  213. return isinstance(obj, int)
  214. @@ -802,7 +802,7 @@ class Popen(object):
  215. startupinfo.wShowWindow = SW_HIDE
  216. comspec = os.environ.get("COMSPEC", "cmd.exe")
  217. args = comspec + " /c " + args
  218. - if (GetVersion() >= 0x80000000L or
  219. + if (GetVersion() >= 0x80000000 or
  220. os.path.basename(comspec).lower() == "command.com"):
  221. # Win9x, or using command.com on NT. We need to
  222. # use the w9xpopen intermediate program. For more
  223. @@ -830,7 +830,7 @@ class Popen(object):
  224. env,
  225. cwd,
  226. startupinfo)
  227. - except pywintypes.error, e:
  228. + except pywintypes.error as e:
  229. # Translate pywintypes.error to WindowsError, which is
  230. # a subclass of OSError. FIXME: We should really
  231. # translate errno using _sys_errlist (or simliar), but
  232. @@ -1215,8 +1215,8 @@ def _demo_posix():
  233. # Example 1: Simple redirection: Get process list
  234. #
  235. plist = Popen(["ps"], stdout=PIPE).communicate()[0]
  236. - print "Process list:"
  237. - print plist
  238. + print("Process list:")
  239. + print(plist)
  240. #
  241. # Example 2: Change uid before executing child
  242. @@ -1228,25 +1228,25 @@ def _demo_posix():
  243. #
  244. # Example 3: Connecting several subprocesses
  245. #
  246. - print "Looking for 'hda'..."
  247. + print("Looking for 'hda'...")
  248. p1 = Popen(["dmesg"], stdout=PIPE)
  249. p2 = Popen(["grep", "hda"], stdin=p1.stdout, stdout=PIPE)
  250. - print repr(p2.communicate()[0])
  251. + print(repr(p2.communicate()[0]))
  252. #
  253. # Example 4: Catch execution error
  254. #
  255. print
  256. - print "Trying a weird file..."
  257. + print("Trying a weird file...")
  258. try:
  259. - print Popen(["/this/path/does/not/exist"]).communicate()
  260. - except OSError, e:
  261. + print(Popen(["/this/path/does/not/exist"]).communicate())
  262. + except OSError as e:
  263. if e.errno == errno.ENOENT:
  264. - print "The file didn't exist. I thought so..."
  265. - print "Child traceback:"
  266. - print e.child_traceback
  267. + print("The file didn't exist. I thought so...")
  268. + print("Child traceback:")
  269. + print(e.child_traceback)
  270. else:
  271. - print "Error", e.errno
  272. + print("Error", e.errno)
  273. else:
  274. sys.stderr.write( "Gosh. No error.\n" )
  275. @@ -1255,15 +1255,15 @@ def _demo_windows():
  276. #
  277. # Example 1: Connecting several subprocesses
  278. #
  279. - print "Looking for 'PROMPT' in set output..."
  280. + print("Looking for 'PROMPT' in set output...")
  281. p1 = Popen("set", stdout=PIPE, shell=True)
  282. p2 = Popen('find "PROMPT"', stdin=p1.stdout, stdout=PIPE)
  283. - print repr(p2.communicate()[0])
  284. + print(repr(p2.communicate()[0]))
  285. #
  286. # Example 2: Simple execution of program
  287. #
  288. - print "Executing calc..."
  289. + print("Executing calc...")
  290. p = Popen("calc")
  291. p.wait()
  292. --- a/engine/SCons/Memoize.py
  293. +++ b/engine/SCons/Memoize.py
  294. @@ -143,7 +143,7 @@ class Counter(object):
  295. CounterList.append(self)
  296. def display(self):
  297. fmt = " %7d hits %7d misses %s()"
  298. - print fmt % (self.hit, self.miss, self.name)
  299. + print(fmt % (self.hit, self.miss, self.name))
  300. def __cmp__(self, other):
  301. try:
  302. return cmp(self.name, other.name)
  303. @@ -215,7 +215,7 @@ class Memoizer(object):
  304. def Dump(title=None):
  305. if title:
  306. - print title
  307. + print(title)
  308. CounterList.sort()
  309. for counter in CounterList:
  310. counter.display()
  311. --- a/engine/SCons/Node/FS.py
  312. +++ b/engine/SCons/Node/FS.py
  313. @@ -550,7 +550,7 @@ class EntryProxy(SCons.Util.Proxy):
  314. except KeyError:
  315. try:
  316. attr = SCons.Util.Proxy.__getattr__(self, name)
  317. - except AttributeError, e:
  318. + except AttributeError as e:
  319. # Raise our own AttributeError subclass with an
  320. # overridden __str__() method that identifies the
  321. # name of the entry that caused the exception.
  322. @@ -2420,7 +2420,7 @@ class File(Base):
  323. fname = self.rfile().abspath
  324. try:
  325. contents = open(fname, "rb").read()
  326. - except EnvironmentError, e:
  327. + except EnvironmentError as e:
  328. if not e.filename:
  329. e.filename = fname
  330. raise
  331. @@ -2455,7 +2455,7 @@ class File(Base):
  332. try:
  333. cs = SCons.Util.MD5filesignature(fname,
  334. chunksize=SCons.Node.FS.File.md5_chunksize*1024)
  335. - except EnvironmentError, e:
  336. + except EnvironmentError as e:
  337. if not e.filename:
  338. e.filename = fname
  339. raise
  340. @@ -2793,7 +2793,7 @@ class File(Base):
  341. def _rmv_existing(self):
  342. self.clear_memoized_values()
  343. if print_duplicate:
  344. - print "dup: removing existing target %s"%self
  345. + print("dup: removing existing target %s"%self)
  346. e = Unlink(self, [], None)
  347. if isinstance(e, SCons.Errors.BuildError):
  348. raise e
  349. @@ -2817,7 +2817,7 @@ class File(Base):
  350. else:
  351. try:
  352. self._createDir()
  353. - except SCons.Errors.StopError, drive:
  354. + except SCons.Errors.StopError as drive:
  355. desc = "No drive `%s' for target `%s'." % (drive, self)
  356. raise SCons.Errors.StopError(desc)
  357. @@ -2835,7 +2835,7 @@ class File(Base):
  358. def do_duplicate(self, src):
  359. self._createDir()
  360. if print_duplicate:
  361. - print "dup: relinking variant '%s' from '%s'"%(self, src)
  362. + print("dup: relinking variant '%s' from '%s'"%(self, src))
  363. Unlink(self, None, None)
  364. e = Link(self, src, None)
  365. if isinstance(e, SCons.Errors.BuildError):
  366. @@ -2870,7 +2870,7 @@ class File(Base):
  367. # The source file does not exist. Make sure no old
  368. # copy remains in the variant directory.
  369. if print_duplicate:
  370. - print "dup: no src for %s, unlinking old variant copy"%self
  371. + print("dup: no src for %s, unlinking old variant copy"%self)
  372. if Base.exists(self) or self.islink():
  373. self.fs.unlink(self.path)
  374. # Return None explicitly because the Base.exists() call
  375. @@ -3199,7 +3199,7 @@ class FileFinder(object):
  376. if verbose and not callable(verbose):
  377. if not SCons.Util.is_String(verbose):
  378. verbose = "find_file"
  379. - _verbose = u' %s: ' % verbose
  380. + _verbose = ' %s: ' % verbose
  381. verbose = lambda s: sys.stdout.write(_verbose + s)
  382. filedir, filename = os.path.split(filename)
  383. --- a/engine/SCons/SConf.py
  384. +++ b/engine/SCons/SConf.py
  385. @@ -239,7 +239,7 @@ class SConfBuildTask(SCons.Taskmaster.Al
  386. # Earlier versions of Python don't have sys.excepthook...
  387. def excepthook(type, value, tb):
  388. traceback.print_tb(tb)
  389. - print type, value
  390. + print(type, value)
  391. excepthook(*self.exc_info())
  392. return SCons.Taskmaster.Task.failed(self)
  393. @@ -332,7 +332,7 @@ class SConfBuildTask(SCons.Taskmaster.Al
  394. except SystemExit:
  395. exc_value = sys.exc_info()[1]
  396. raise SCons.Errors.ExplicitExit(self.targets[0],exc_value.code)
  397. - except Exception, e:
  398. + except Exception as e:
  399. for t in self.targets:
  400. binfo = t.get_binfo()
  401. binfo.__class__ = SConfBuildInfo
  402. --- a/engine/SCons/Script/Interactive.py
  403. +++ b/engine/SCons/Script/Interactive.py
  404. @@ -129,12 +129,12 @@ class SConsInteractiveCmd(cmd.Cmd):
  405. self.shell_variable = 'SHELL'
  406. def default(self, argv):
  407. - print "*** Unknown command: %s" % argv[0]
  408. + print("*** Unknown command: %s" % argv[0])
  409. def onecmd(self, line):
  410. line = line.strip()
  411. if not line:
  412. - print self.lastcmd
  413. + print(self.lastcmd)
  414. return self.emptyline()
  415. self.lastcmd = line
  416. if line[0] == '!':
  417. @@ -274,7 +274,7 @@ class SConsInteractiveCmd(cmd.Cmd):
  418. return self.do_build(['build', '--clean'] + argv[1:])
  419. def do_EOF(self, argv):
  420. - print
  421. + print()
  422. self.do_exit(argv)
  423. def _do_one_help(self, arg):
  424. @@ -357,7 +357,7 @@ class SConsInteractiveCmd(cmd.Cmd):
  425. # Doing the right thing with an argument list currently
  426. # requires different shell= values on Windows and Linux.
  427. p = subprocess.Popen(argv, shell=(sys.platform=='win32'))
  428. - except EnvironmentError, e:
  429. + except EnvironmentError as e:
  430. sys.stderr.write('scons: %s: %s\n' % (argv[0], e.strerror))
  431. else:
  432. p.wait()
  433. --- a/engine/SCons/Script/Main.py
  434. +++ b/engine/SCons/Script/Main.py
  435. @@ -224,7 +224,7 @@ class BuildTask(SCons.Taskmaster.OutOfDa
  436. self.exception_set()
  437. self.do_failed()
  438. else:
  439. - print "scons: Nothing to be done for `%s'." % t
  440. + print("scons: Nothing to be done for `%s'." % t)
  441. SCons.Taskmaster.OutOfDateTask.executed(self)
  442. else:
  443. SCons.Taskmaster.OutOfDateTask.executed(self)
  444. @@ -290,8 +290,8 @@ class BuildTask(SCons.Taskmaster.OutOfDa
  445. if self.options.debug_includes:
  446. tree = t.render_include_tree()
  447. if tree:
  448. - print
  449. - print tree
  450. + print()
  451. + print(tree)
  452. SCons.Taskmaster.OutOfDateTask.postprocess(self)
  453. def make_ready(self):
  454. @@ -326,10 +326,10 @@ class CleanTask(SCons.Taskmaster.AlwaysT
  455. else:
  456. errstr = "Path '%s' exists but isn't a file or directory."
  457. raise SCons.Errors.UserError(errstr % (pathstr))
  458. - except SCons.Errors.UserError, e:
  459. - print e
  460. - except (IOError, OSError), e:
  461. - print "scons: Could not remove '%s':" % pathstr, e.strerror
  462. + except SCons.Errors.UserError as e:
  463. + print(e)
  464. + except (IOError, OSError) as e:
  465. + print("scons: Could not remove '%s':" % pathstr, e.strerror)
  466. def show(self):
  467. target = self.targets[0]
  468. @@ -348,13 +348,13 @@ class CleanTask(SCons.Taskmaster.AlwaysT
  469. for t in self.targets:
  470. try:
  471. removed = t.remove()
  472. - except OSError, e:
  473. + except OSError as e:
  474. # An OSError may indicate something like a permissions
  475. # issue, an IOError would indicate something like
  476. # the file not existing. In either case, print a
  477. # message and keep going to try to remove as many
  478. # targets aa possible.
  479. - print "scons: Could not remove '%s':" % str(t), e.strerror
  480. + print("scons: Could not remove '%s':" % str(t), e.strerror)
  481. else:
  482. if removed:
  483. display("Removed " + str(t))
  484. @@ -595,7 +595,7 @@ def _scons_internal_error():
  485. """Handle all errors but user errors. Print out a message telling
  486. the user what to do in this case and print a normal trace.
  487. """
  488. - print 'internal error'
  489. + print('internal error')
  490. traceback.print_exc()
  491. sys.exit(2)
  492. @@ -707,7 +707,7 @@ def _load_site_scons_dir(topdir, site_di
  493. # the error checking makes it longer.
  494. try:
  495. m = sys.modules['SCons.Script']
  496. - except Exception, e:
  497. + except Exception as e:
  498. fmt = 'cannot import site_init.py: missing SCons.Script module %s'
  499. raise SCons.Errors.InternalError(fmt % repr(e))
  500. try:
  501. @@ -720,10 +720,10 @@ def _load_site_scons_dir(topdir, site_di
  502. site_m[k] = m.__dict__[k]
  503. # This is the magic.
  504. - exec fp in site_m
  505. + exec(fp.read()) in site_m
  506. except KeyboardInterrupt:
  507. raise
  508. - except Exception, e:
  509. + except Exception as e:
  510. fmt = '*** Error loading site_init file %s:\n'
  511. sys.stderr.write(fmt % repr(site_init_file))
  512. raise
  513. @@ -733,7 +733,7 @@ def _load_site_scons_dir(topdir, site_di
  514. m.__dict__[k] = site_m[k]
  515. except KeyboardInterrupt:
  516. raise
  517. - except ImportError, e:
  518. + except ImportError as e:
  519. fmt = '*** cannot import site init file %s:\n'
  520. sys.stderr.write(fmt % repr(site_init_file))
  521. raise
  522. @@ -785,7 +785,7 @@ def _load_all_site_scons_dirs(topdir, ve
  523. dirs=sysdirs + [topdir]
  524. for d in dirs:
  525. if verbose: # this is used by unit tests.
  526. - print "Loading site dir ", d
  527. + print("Loading site dir ", d)
  528. _load_site_scons_dir(d)
  529. def test_load_all_site_scons_dirs(d):
  530. @@ -976,7 +976,7 @@ def _main(parser):
  531. try:
  532. for script in scripts:
  533. SCons.Script._SConscript._SConscript(fs, script)
  534. - except SCons.Errors.StopError, e:
  535. + except SCons.Errors.StopError as e:
  536. # We had problems reading an SConscript file, such as it
  537. # couldn't be copied in to the VariantDir. Since we're just
  538. # reading SConscript files and haven't started building
  539. @@ -1032,8 +1032,8 @@ def _main(parser):
  540. # SConscript files. Give them the options usage.
  541. raise SConsPrintHelpException
  542. else:
  543. - print help_text
  544. - print "Use scons -H for help about command-line options."
  545. + print(help_text)
  546. + print("Use scons -H for help about command-line options.")
  547. exit_status = 0
  548. return
  549. @@ -1296,7 +1296,7 @@ def _exec_main(parser, values):
  550. prof = Profile()
  551. try:
  552. prof.runcall(_main, parser)
  553. - except SConsPrintHelpException, e:
  554. + except SConsPrintHelpException as e:
  555. prof.dump_stats(options.profile_file)
  556. raise e
  557. except SystemExit:
  558. @@ -1340,22 +1340,22 @@ def main():
  559. try:
  560. _exec_main(parser, values)
  561. - except SystemExit, s:
  562. + except SystemExit as s:
  563. if s:
  564. exit_status = s
  565. except KeyboardInterrupt:
  566. print("scons: Build interrupted.")
  567. sys.exit(2)
  568. - except SyntaxError, e:
  569. + except SyntaxError as e:
  570. _scons_syntax_error(e)
  571. except SCons.Errors.InternalError:
  572. _scons_internal_error()
  573. - except SCons.Errors.UserError, e:
  574. + except SCons.Errors.UserError as e:
  575. _scons_user_error(e)
  576. except SConsPrintHelpException:
  577. parser.print_help()
  578. exit_status = 0
  579. - except SCons.Errors.BuildError, e:
  580. + except SCons.Errors.BuildError as e:
  581. exit_status = e.exitstatus
  582. except:
  583. # An exception here is likely a builtin Python exception Python
  584. @@ -1391,10 +1391,10 @@ def main():
  585. else:
  586. ct = last_command_end - first_command_start
  587. scons_time = total_time - sconscript_time - ct
  588. - print "Total build time: %f seconds"%total_time
  589. - print "Total SConscript file execution time: %f seconds"%sconscript_time
  590. - print "Total SCons execution time: %f seconds"%scons_time
  591. - print "Total command execution time: %f seconds"%ct
  592. + print("Total build time: %f seconds"%total_time)
  593. + print("Total SConscript file execution time: %f seconds"%sconscript_time)
  594. + print("Total SCons execution time: %f seconds"%scons_time)
  595. + print("Total command execution time: %f seconds"%ct)
  596. sys.exit(exit_status)
  597. --- a/engine/SCons/Script/SConscript.py
  598. +++ b/engine/SCons/Script/SConscript.py
  599. @@ -113,7 +113,7 @@ def compute_exports(exports):
  600. retval[export] = loc[export]
  601. except KeyError:
  602. retval[export] = glob[export]
  603. - except KeyError, x:
  604. + except KeyError as x:
  605. raise SCons.Errors.UserError("Export of non-existent variable '%s'"%x)
  606. return retval
  607. @@ -145,7 +145,7 @@ def Return(*vars, **kw):
  608. for var in fvars:
  609. for v in var.split():
  610. retval.append(call_stack[-1].globals[v])
  611. - except KeyError, x:
  612. + except KeyError as x:
  613. raise SCons.Errors.UserError("Return of non-existent variable '%s'"%x)
  614. if len(retval) == 1:
  615. @@ -174,7 +174,7 @@ def _SConscript(fs, *files, **kw):
  616. try:
  617. SCons.Script.sconscript_reading = SCons.Script.sconscript_reading + 1
  618. if fn == "-":
  619. - exec sys.stdin in call_stack[-1].globals
  620. + exec(sys.stdin.read()) in call_stack[-1].globals
  621. else:
  622. if isinstance(fn, SCons.Node.Node):
  623. f = fn
  624. @@ -257,7 +257,7 @@ def _SConscript(fs, *files, **kw):
  625. pass
  626. try:
  627. try:
  628. - exec _file_ in call_stack[-1].globals
  629. + exec(_file_.read()) in call_stack[-1].globals
  630. except SConscriptReturn:
  631. pass
  632. finally:
  633. @@ -282,7 +282,7 @@ def _SConscript(fs, *files, **kw):
  634. rdir._create() # Make sure there's a directory there.
  635. try:
  636. os.chdir(rdir.get_abspath())
  637. - except OSError, e:
  638. + except OSError as e:
  639. # We still couldn't chdir there, so raise the error,
  640. # but only if actions are being executed.
  641. #
  642. @@ -467,8 +467,8 @@ class SConsEnvironment(SCons.Environment
  643. scons_ver_string = '%d.%d.%d' % (major, minor, revision)
  644. else:
  645. scons_ver_string = '%d.%d' % (major, minor)
  646. - print "SCons %s or greater required, but you have SCons %s" % \
  647. - (scons_ver_string, SCons.__version__)
  648. + print("SCons %s or greater required, but you have SCons %s" % \
  649. + (scons_ver_string, SCons.__version__))
  650. sys.exit(2)
  651. def EnsurePythonVersion(self, major, minor):
  652. @@ -480,7 +480,7 @@ class SConsEnvironment(SCons.Environment
  653. python_ver = self._get_major_minor_revision(sys.version)[:2]
  654. if python_ver < (major, minor):
  655. v = sys.version.split(" ", 1)[0]
  656. - print "Python %d.%d or greater required, but you have Python %s" %(major,minor,v)
  657. + print("Python %d.%d or greater required, but you have Python %s" %(major,minor,v))
  658. sys.exit(2)
  659. def Exit(self, value=0):
  660. @@ -519,7 +519,7 @@ class SConsEnvironment(SCons.Environment
  661. globals[v] = exports[v]
  662. else:
  663. globals[v] = global_exports[v]
  664. - except KeyError,x:
  665. + except KeyError as x:
  666. raise SCons.Errors.UserError("Import of non-existent variable '%s'"%x)
  667. def SConscript(self, *ls, **kw):
  668. --- a/engine/SCons/Taskmaster.py
  669. +++ b/engine/SCons/Taskmaster.py
  670. @@ -107,7 +107,7 @@ fmt = "%(considered)3d "\
  671. def dump_stats():
  672. for n in sorted(StatsNodes, key=lambda a: str(a)):
  673. - print (fmt % n.stats.__dict__) + str(n)
  674. + print((fmt % n.stats.__dict__) + str(n))
  675. @@ -164,7 +164,7 @@ class Task(object):
  676. """
  677. global print_prepare
  678. T = self.tm.trace
  679. - if T: T.write(self.trace_message(u'Task.prepare()', self.node))
  680. + if T: T.write(self.trace_message('Task.prepare()', self.node))
  681. # Now that it's the appropriate time, give the TaskMaster a
  682. # chance to raise any exceptions it encountered while preparing
  683. @@ -189,13 +189,13 @@ class Task(object):
  684. executor.prepare()
  685. for t in executor.get_action_targets():
  686. if print_prepare:
  687. - print "Preparing target %s..."%t
  688. + print("Preparing target %s..."%t)
  689. for s in t.side_effects:
  690. - print "...with side-effect %s..."%s
  691. + print("...with side-effect %s..."%s)
  692. t.prepare()
  693. for s in t.side_effects:
  694. if print_prepare:
  695. - print "...Preparing side-effect %s..."%s
  696. + print("...Preparing side-effect %s..."%s)
  697. s.prepare()
  698. def get_target(self):
  699. @@ -224,7 +224,7 @@ class Task(object):
  700. prepare(), executed() or failed().
  701. """
  702. T = self.tm.trace
  703. - if T: T.write(self.trace_message(u'Task.execute()', self.node))
  704. + if T: T.write(self.trace_message('Task.execute()', self.node))
  705. try:
  706. everything_was_cached = 1
  707. @@ -248,7 +248,7 @@ class Task(object):
  708. raise
  709. except SCons.Errors.BuildError:
  710. raise
  711. - except Exception, e:
  712. + except Exception as e:
  713. buildError = SCons.Errors.convert_to_BuildError(e)
  714. buildError.node = self.targets[0]
  715. buildError.exc_info = sys.exc_info()
  716. @@ -376,7 +376,7 @@ class Task(object):
  717. This is the default behavior for building only what's necessary.
  718. """
  719. T = self.tm.trace
  720. - if T: T.write(self.trace_message(u'Task.make_ready_current()',
  721. + if T: T.write(self.trace_message('Task.make_ready_current()',
  722. self.node))
  723. self.out_of_date = []
  724. @@ -386,7 +386,7 @@ class Task(object):
  725. t.disambiguate().make_ready()
  726. is_up_to_date = not t.has_builder() or \
  727. (not t.always_build and t.is_up_to_date())
  728. - except EnvironmentError, e:
  729. + except EnvironmentError as e:
  730. raise SCons.Errors.BuildError(node=t, errstr=e.strerror, filename=e.filename)
  731. if not is_up_to_date:
  732. @@ -421,7 +421,7 @@ class Task(object):
  733. that can be put back on the candidates list.
  734. """
  735. T = self.tm.trace
  736. - if T: T.write(self.trace_message(u'Task.postprocess()', self.node))
  737. + if T: T.write(self.trace_message('Task.postprocess()', self.node))
  738. # We may have built multiple targets, some of which may have
  739. # common parents waiting for this build. Count up how many
  740. @@ -438,7 +438,7 @@ class Task(object):
  741. # A node can only be in the pending_children set if it has
  742. # some waiting_parents.
  743. if t.waiting_parents:
  744. - if T: T.write(self.trace_message(u'Task.postprocess()',
  745. + if T: T.write(self.trace_message('Task.postprocess()',
  746. t,
  747. 'removing'))
  748. pending_children.discard(t)
  749. @@ -457,7 +457,7 @@ class Task(object):
  750. for p, subtract in parents.items():
  751. p.ref_count = p.ref_count - subtract
  752. - if T: T.write(self.trace_message(u'Task.postprocess()',
  753. + if T: T.write(self.trace_message('Task.postprocess()',
  754. p,
  755. 'adjusted parent ref count'))
  756. if p.ref_count == 0:
  757. @@ -517,7 +517,9 @@ class Task(object):
  758. except ValueError:
  759. exc_type, exc_value = exc
  760. exc_traceback = None
  761. - raise exc_type, exc_value, exc_traceback
  762. + e = exc_type(exc_value)
  763. + e.__traceback__ = exc_traceback
  764. + raise e
  765. class AlwaysTask(Task):
  766. def needs_execute(self):
  767. @@ -741,12 +743,12 @@ class Taskmaster(object):
  768. self.ready_exc = None
  769. T = self.trace
  770. - if T: T.write(u'\n' + self.trace_message('Looking for a node to evaluate'))
  771. + if T: T.write('\n' + self.trace_message('Looking for a node to evaluate'))
  772. while True:
  773. node = self.next_candidate()
  774. if node is None:
  775. - if T: T.write(self.trace_message('No candidate anymore.') + u'\n')
  776. + if T: T.write(self.trace_message('No candidate anymore.') + '\n')
  777. return None
  778. node = node.disambiguate()
  779. @@ -769,7 +771,7 @@ class Taskmaster(object):
  780. else:
  781. S = None
  782. - if T: T.write(self.trace_message(u' Considering node %s and its children:' % self.trace_node(node)))
  783. + if T: T.write(self.trace_message(' Considering node %s and its children:' % self.trace_node(node)))
  784. if state == NODE_NO_STATE:
  785. # Mark this node as being on the execution stack:
  786. @@ -777,7 +779,7 @@ class Taskmaster(object):
  787. elif state > NODE_PENDING:
  788. # Skip this node if it has already been evaluated:
  789. if S: S.already_handled = S.already_handled + 1
  790. - if T: T.write(self.trace_message(u' already handled (executed)'))
  791. + if T: T.write(self.trace_message(' already handled (executed)'))
  792. continue
  793. executor = node.get_executor()
  794. @@ -790,7 +792,7 @@ class Taskmaster(object):
  795. self.ready_exc = (SCons.Errors.ExplicitExit, e)
  796. if T: T.write(self.trace_message(' SystemExit'))
  797. return node
  798. - except Exception, e:
  799. + except Exception as e:
  800. # We had a problem just trying to figure out the
  801. # children (like a child couldn't be linked in to a
  802. # VariantDir, or a Scanner threw something). Arrange to
  803. @@ -808,7 +810,7 @@ class Taskmaster(object):
  804. for child in chain(executor.get_all_prerequisites(), children):
  805. childstate = child.get_state()
  806. - if T: T.write(self.trace_message(u' ' + self.trace_node(child)))
  807. + if T: T.write(self.trace_message(' ' + self.trace_node(child)))
  808. if childstate == NODE_NO_STATE:
  809. children_not_visited.append(child)
  810. @@ -867,7 +869,7 @@ class Taskmaster(object):
  811. # count so we can be put back on the list for
  812. # re-evaluation when they've all finished.
  813. node.ref_count = node.ref_count + child.add_to_waiting_parents(node)
  814. - if T: T.write(self.trace_message(u' adjusted ref count: %s, child %s' %
  815. + if T: T.write(self.trace_message(' adjusted ref count: %s, child %s' %
  816. (self.trace_node(node), repr(str(child)))))
  817. if T:
  818. @@ -893,7 +895,7 @@ class Taskmaster(object):
  819. # The default when we've gotten through all of the checks above:
  820. # this node is ready to be built.
  821. if S: S.build = S.build + 1
  822. - if T: T.write(self.trace_message(u'Evaluating %s\n' %
  823. + if T: T.write(self.trace_message('Evaluating %s\n' %
  824. self.trace_node(node)))
  825. # For debugging only:
  826. --- a/engine/SCons/Tool/FortranCommon.py
  827. +++ b/engine/SCons/Tool/FortranCommon.py
  828. @@ -61,7 +61,7 @@ def isfortran(env, source):
  829. def _fortranEmitter(target, source, env):
  830. node = source[0].rfile()
  831. if not node.exists() and not node.is_derived():
  832. - print "Could not locate " + str(node.name)
  833. + print("Could not locate " + str(node.name))
  834. return ([], [])
  835. mod_regex = """(?i)^\s*MODULE\s+(?!PROCEDURE)(\w+)"""
  836. cre = re.compile(mod_regex,re.M)
  837. @@ -167,7 +167,7 @@ def add_fortran_to_env(env):
  838. except KeyError:
  839. FortranSuffixes = ['.f', '.for', '.ftn']
  840. - #print "Adding %s to fortran suffixes" % FortranSuffixes
  841. + #print("Adding %s to fortran suffixes" % FortranSuffixes)
  842. try:
  843. FortranPPSuffixes = env['FORTRANPPFILESUFFIXES']
  844. except KeyError:
  845. @@ -191,7 +191,7 @@ def add_f77_to_env(env):
  846. except KeyError:
  847. F77Suffixes = ['.f77']
  848. - #print "Adding %s to f77 suffixes" % F77Suffixes
  849. + #print("Adding %s to f77 suffixes" % F77Suffixes)
  850. try:
  851. F77PPSuffixes = env['F77PPFILESUFFIXES']
  852. except KeyError:
  853. @@ -206,7 +206,7 @@ def add_f90_to_env(env):
  854. except KeyError:
  855. F90Suffixes = ['.f90']
  856. - #print "Adding %s to f90 suffixes" % F90Suffixes
  857. + #print("Adding %s to f90 suffixes" % F90Suffixes)
  858. try:
  859. F90PPSuffixes = env['F90PPFILESUFFIXES']
  860. except KeyError:
  861. @@ -222,7 +222,7 @@ def add_f95_to_env(env):
  862. except KeyError:
  863. F95Suffixes = ['.f95']
  864. - #print "Adding %s to f95 suffixes" % F95Suffixes
  865. + #print("Adding %s to f95 suffixes" % F95Suffixes)
  866. try:
  867. F95PPSuffixes = env['F95PPFILESUFFIXES']
  868. except KeyError:
  869. @@ -238,7 +238,7 @@ def add_f03_to_env(env):
  870. except KeyError:
  871. F03Suffixes = ['.f03']
  872. - #print "Adding %s to f95 suffixes" % F95Suffixes
  873. + #print("Adding %s to f95 suffixes" % F95Suffixes)
  874. try:
  875. F03PPSuffixes = env['F03PPFILESUFFIXES']
  876. except KeyError:
  877. --- a/engine/SCons/Tool/intelc.py
  878. +++ b/engine/SCons/Tool/intelc.py
  879. @@ -205,17 +205,17 @@ def get_all_compiler_versions():
  880. # Registry points to nonexistent dir. Ignore this
  881. # version.
  882. value = get_intel_registry_value('ProductDir', subkey, 'IA32')
  883. - except MissingRegistryError, e:
  884. + except MissingRegistryError as e:
  885. # Registry key is left dangling (potentially
  886. # after uninstalling).
  887. - print \
  888. + print(\
  889. "scons: *** Ignoring the registry key for the Intel compiler version %s.\n" \
  890. "scons: *** It seems that the compiler was uninstalled and that the registry\n" \
  891. - "scons: *** was not cleaned up properly.\n" % subkey
  892. + "scons: *** was not cleaned up properly.\n" % subkey)
  893. else:
  894. - print "scons: *** Ignoring "+str(value)
  895. + print("scons: *** Ignoring "+str(value))
  896. i = i + 1
  897. except EnvironmentError:
  898. @@ -294,7 +294,7 @@ def get_intel_compiler_top(version, abi)
  899. break
  900. return top
  901. top = find_in_2010style_dir(version) or find_in_2008style_dir(version)
  902. - print "INTELC: top=",top
  903. + print("INTELC: top=",top)
  904. if not top:
  905. raise MissingDirError("Can't find version %s Intel compiler in %s (abi='%s')"%(version,top, abi))
  906. return top
  907. @@ -394,8 +394,8 @@ def generate(env, version=None, abi=None
  908. bindir="bin"
  909. libdir="lib"
  910. if verbose:
  911. - print "Intel C compiler: using version %s (%g), abi %s, in '%s/%s'"%\
  912. - (repr(version), linux_ver_normalize(version),abi,topdir,bindir)
  913. + print("Intel C compiler: using version %s (%g), abi %s, in '%s/%s'"%\
  914. + (repr(version), linux_ver_normalize(version),abi,topdir,bindir))
  915. if is_linux:
  916. # Show the actual compiler version by running the compiler.
  917. os.system('%s/%s/icc --version'%(topdir,bindir))
  918. @@ -439,7 +439,7 @@ def generate(env, version=None, abi=None
  919. env.PrependENVPath(p[0], os.path.join(topdir, p[2]))
  920. else:
  921. env.PrependENVPath(p[0], path.split(os.pathsep))
  922. - # print "ICL %s: %s, final=%s"%(p[0], path, str(env['ENV'][p[0]]))
  923. + # print("ICL %s: %s, final=%s"%(p[0], path, str(env['ENV'][p[0]])))
  924. if is_windows:
  925. env['CC'] = 'icl'
  926. --- a/engine/SCons/Tool/MSCommon/common.py
  927. +++ b/engine/SCons/Tool/MSCommon/common.py
  928. @@ -38,7 +38,7 @@ import SCons.Util
  929. logfile = os.environ.get('SCONS_MSCOMMON_DEBUG')
  930. if logfile == '-':
  931. def debug(x):
  932. - print x
  933. + print(x)
  934. elif logfile:
  935. try:
  936. import logging
  937. --- a/engine/SCons/Tool/mslink.py
  938. +++ b/engine/SCons/Tool/mslink.py
  939. @@ -186,7 +186,7 @@ def RegServerFunc(target, source, env):
  940. if ret:
  941. raise SCons.Errors.UserError("Unable to register %s" % target[0])
  942. else:
  943. - print "Registered %s sucessfully" % target[0]
  944. + print("Registered %s sucessfully" % target[0])
  945. return ret
  946. return 0
  947. @@ -203,10 +203,10 @@ def embedManifestDllCheck(target, source
  948. if os.path.exists(manifestSrc):
  949. ret = (embedManifestDllAction) ([target[0]],None,env)
  950. if ret:
  951. - raise SCons.Errors.UserError, "Unable to embed manifest into %s" % (target[0])
  952. + raise SCons.Errors.UserError("Unable to embed manifest into %s" % (target[0]))
  953. return ret
  954. else:
  955. - print '(embed: no %s.manifest found; not embedding.)'%str(target[0])
  956. + print('(embed: no %s.manifest found; not embedding.)'%str(target[0]))
  957. return 0
  958. def embedManifestExeCheck(target, source, env):
  959. @@ -217,10 +217,10 @@ def embedManifestExeCheck(target, source
  960. if os.path.exists(manifestSrc):
  961. ret = (embedManifestExeAction) ([target[0]],None,env)
  962. if ret:
  963. - raise SCons.Errors.UserError, "Unable to embed manifest into %s" % (target[0])
  964. + raise SCons.Errors.UserError("Unable to embed manifest into %s" % (target[0]))
  965. return ret
  966. else:
  967. - print '(embed: no %s.manifest found; not embedding.)'%str(target[0])
  968. + print('(embed: no %s.manifest found; not embedding.)'%str(target[0]))
  969. return 0
  970. embedManifestDllCheckAction = SCons.Action.Action(embedManifestDllCheck, None)
  971. --- a/engine/SCons/Tool/msvs.py
  972. +++ b/engine/SCons/Tool/msvs.py
  973. @@ -195,7 +195,7 @@ def makeHierarchy(sources):
  974. dict = dict[part]
  975. dict[path[-1]] = file
  976. #else:
  977. - # print 'Warning: failed to decompose path for '+str(file)
  978. + # print('Warning: failed to decompose path for '+str(file))
  979. return hierarchy
  980. class _DSPGenerator(object):
  981. @@ -351,7 +351,7 @@ class _DSPGenerator(object):
  982. config.platform = 'Win32'
  983. self.configs[variant] = config
  984. - print "Adding '" + self.name + ' - ' + config.variant + '|' + config.platform + "' to '" + str(dspfile) + "'"
  985. + print("Adding '" + self.name + ' - ' + config.variant + '|' + config.platform + "' to '" + str(dspfile) + "'")
  986. for i in range(len(variants)):
  987. AddConfig(self, variants[i], buildtarget[i], outdir[i], runfile[i], cmdargs)
  988. @@ -551,7 +551,7 @@ class _GenerateV6DSP(_DSPGenerator):
  989. def Build(self):
  990. try:
  991. self.file = open(self.dspabs,'w')
  992. - except IOError, detail:
  993. + except IOError as detail:
  994. raise SCons.Errors.InternalError('Unable to open "' + self.dspabs + '" for writing:' + str(detail))
  995. else:
  996. self.PrintHeader()
  997. @@ -865,7 +865,7 @@ class _GenerateV7DSP(_DSPGenerator):
  998. def Build(self):
  999. try:
  1000. self.file = open(self.dspabs,'w')
  1001. - except IOError, detail:
  1002. + except IOError as detail:
  1003. raise SCons.Errors.InternalError('Unable to open "' + self.dspabs + '" for writing:' + str(detail))
  1004. else:
  1005. self.PrintHeader()
  1006. @@ -1033,7 +1033,7 @@ class _GenerateV10DSP(_DSPGenerator):
  1007. self.filtersabs = self.dspabs + '.filters'
  1008. try:
  1009. self.filters_file = open(self.filtersabs, 'w')
  1010. - except IOError, detail:
  1011. + except IOError as detail:
  1012. raise SCons.Errors.InternalError('Unable to open "' + self.filtersabs + '" for writing:' + str(detail))
  1013. self.filters_file.write('<?xml version="1.0" encoding="utf-8"?>\n'
  1014. @@ -1105,7 +1105,7 @@ class _GenerateV10DSP(_DSPGenerator):
  1015. cats = sorted([k for k in categories.keys() if self.sources[k]],
  1016. key = lambda a: a.lower())
  1017. - # print vcxproj.filters file first
  1018. + # print(vcxproj.filters file first)
  1019. self.filters_file.write('\t<ItemGroup>\n')
  1020. for kind in cats:
  1021. self.filters_file.write('\t\t<Filter Include="%s">\n'
  1022. @@ -1135,7 +1135,7 @@ class _GenerateV10DSP(_DSPGenerator):
  1023. self.filters_file.write('\t</ItemGroup>\n')
  1024. - # then print files and filters
  1025. + # then print(files and filters)
  1026. for kind in cats:
  1027. self.file.write('\t<ItemGroup>\n')
  1028. self.filters_file.write('\t<ItemGroup>\n')
  1029. @@ -1170,12 +1170,12 @@ class _GenerateV10DSP(_DSPGenerator):
  1030. '\t</ItemGroup>\n' % str(self.sconscript))
  1031. def Parse(self):
  1032. - print "_GenerateV10DSP.Parse()"
  1033. + print("_GenerateV10DSP.Parse()")
  1034. def Build(self):
  1035. try:
  1036. self.file = open(self.dspabs, 'w')
  1037. - except IOError, detail:
  1038. + except IOError as detail:
  1039. raise SCons.Errors.InternalError('Unable to open "' + self.dspabs + '" for writing:' + str(detail))
  1040. else:
  1041. self.PrintHeader()
  1042. @@ -1252,7 +1252,7 @@ class _GenerateV7DSW(_DSWGenerator):
  1043. config.platform = 'Win32'
  1044. self.configs[variant] = config
  1045. - print "Adding '" + self.name + ' - ' + config.variant + '|' + config.platform + "' to '" + str(dswfile) + "'"
  1046. + print("Adding '" + self.name + ' - ' + config.variant + '|' + config.platform + "' to '" + str(dswfile) + "'")
  1047. if 'variant' not in env:
  1048. raise SCons.Errors.InternalError("You must specify a 'variant' argument (i.e. 'Debug' or " +\
  1049. @@ -1431,7 +1431,7 @@ class _GenerateV7DSW(_DSWGenerator):
  1050. def Build(self):
  1051. try:
  1052. self.file = open(self.dswfile,'w')
  1053. - except IOError, detail:
  1054. + except IOError as detail:
  1055. raise SCons.Errors.InternalError('Unable to open "' + self.dswfile + '" for writing:' + str(detail))
  1056. else:
  1057. self.PrintSolution()
  1058. @@ -1480,7 +1480,7 @@ class _GenerateV6DSW(_DSWGenerator):
  1059. def Build(self):
  1060. try:
  1061. self.file = open(self.dswfile,'w')
  1062. - except IOError, detail:
  1063. + except IOError as detail:
  1064. raise SCons.Errors.InternalError('Unable to open "' + self.dswfile + '" for writing:' + str(detail))
  1065. else:
  1066. self.PrintWorkspace()
  1067. @@ -1537,8 +1537,8 @@ def GenerateProject(target, source, env)
  1068. if not dspfile is builddspfile:
  1069. try:
  1070. bdsp = open(str(builddspfile), "w+")
  1071. - except IOError, detail:
  1072. - print 'Unable to open "' + str(dspfile) + '" for writing:',detail,'\n'
  1073. + except IOError as detail:
  1074. + print('Unable to open "' + str(dspfile) + '" for writing:',detail,'\n')
  1075. raise
  1076. bdsp.write("This is just a placeholder file.\nThe real project file is here:\n%s\n" % dspfile.get_abspath())
  1077. @@ -1553,8 +1553,8 @@ def GenerateProject(target, source, env)
  1078. try:
  1079. bdsw = open(str(builddswfile), "w+")
  1080. - except IOError, detail:
  1081. - print 'Unable to open "' + str(dspfile) + '" for writing:',detail,'\n'
  1082. + except IOError as detail:
  1083. + print('Unable to open "' + str(dspfile) + '" for writing:',detail,'\n')
  1084. raise
  1085. bdsw.write("This is just a placeholder file.\nThe real workspace file is here:\n%s\n" % dswfile.get_abspath())
  1086. --- a/engine/SCons/Tool/qt.py
  1087. +++ b/engine/SCons/Tool/qt.py
  1088. @@ -130,12 +130,12 @@ class _Automoc(object):
  1089. if not obj.has_builder():
  1090. # binary obj file provided
  1091. if debug:
  1092. - print "scons: qt: '%s' seems to be a binary. Discarded." % str(obj)
  1093. + print("scons: qt: '%s' seems to be a binary. Discarded." % str(obj))
  1094. continue
  1095. cpp = obj.sources[0]
  1096. if not splitext(str(cpp))[1] in cxx_suffixes:
  1097. if debug:
  1098. - print "scons: qt: '%s' is no cxx file. Discarded." % str(cpp)
  1099. + print("scons: qt: '%s' is no cxx file. Discarded." % str(cpp) )
  1100. # c or fortran source
  1101. continue
  1102. #cpp_contents = comment.sub('', cpp.get_text_contents())
  1103. @@ -148,12 +148,12 @@ class _Automoc(object):
  1104. h = find_file(hname, (cpp.get_dir(),), env.File)
  1105. if h:
  1106. if debug:
  1107. - print "scons: qt: Scanning '%s' (header of '%s')" % (str(h), str(cpp))
  1108. + print("scons: qt: Scanning '%s' (header of '%s')" % (str(h), str(cpp)))
  1109. #h_contents = comment.sub('', h.get_text_contents())
  1110. h_contents = h.get_text_contents()
  1111. break
  1112. if not h and debug:
  1113. - print "scons: qt: no header for '%s'." % (str(cpp))
  1114. + print("scons: qt: no header for '%s'." % (str(cpp)))
  1115. if h and q_object_search.search(h_contents):
  1116. # h file with the Q_OBJECT macro found -> add moc_cpp
  1117. moc_cpp = env.Moc(h)
  1118. @@ -161,14 +161,14 @@ class _Automoc(object):
  1119. out_sources.append(moc_o)
  1120. #moc_cpp.target_scanner = SCons.Defaults.CScan
  1121. if debug:
  1122. - print "scons: qt: found Q_OBJECT macro in '%s', moc'ing to '%s'" % (str(h), str(moc_cpp))
  1123. + print("scons: qt: found Q_OBJECT macro in '%s', moc'ing to '%s'" % (str(h), str(moc_cpp)))
  1124. if cpp and q_object_search.search(cpp_contents):
  1125. # cpp file with Q_OBJECT macro found -> add moc
  1126. # (to be included in cpp)
  1127. moc = env.Moc(cpp)
  1128. env.Ignore(moc, moc)
  1129. if debug:
  1130. - print "scons: qt: found Q_OBJECT macro in '%s', moc'ing to '%s'" % (str(cpp), str(moc))
  1131. + print("scons: qt: found Q_OBJECT macro in '%s', moc'ing to '%s'" % (str(cpp), str(moc)))
  1132. #moc.source_scanner = SCons.Defaults.CScan
  1133. # restore the original env attributes (FIXME)
  1134. objBuilder.env = objBuilderEnv
  1135. --- a/engine/SCons/Tool/tex.py
  1136. +++ b/engine/SCons/Tool/tex.py
  1137. @@ -147,15 +147,15 @@ def FindFile(name,suffixes,paths,env,req
  1138. if ext:
  1139. name = name + ext
  1140. if Verbose:
  1141. - print " searching for '%s' with extensions: " % name,suffixes
  1142. + print(" searching for '%s' with extensions: " % name,suffixes)
  1143. for path in paths:
  1144. testName = os.path.join(path,name)
  1145. if Verbose:
  1146. - print " look for '%s'" % testName
  1147. + print(" look for '%s'" % testName)
  1148. if os.path.isfile(testName):
  1149. if Verbose:
  1150. - print " found '%s'" % testName
  1151. + print(" found '%s'" % testName)
  1152. return env.fs.File(testName)
  1153. else:
  1154. name_ext = SCons.Util.splitext(testName)[1]
  1155. @@ -166,14 +166,14 @@ def FindFile(name,suffixes,paths,env,req
  1156. for suffix in suffixes:
  1157. testNameExt = testName + suffix
  1158. if Verbose:
  1159. - print " look for '%s'" % testNameExt
  1160. + print(" look for '%s'" % testNameExt)
  1161. if os.path.isfile(testNameExt):
  1162. if Verbose:
  1163. - print " found '%s'" % testNameExt
  1164. + print(" found '%s'" % testNameExt)
  1165. return env.fs.File(testNameExt)
  1166. if Verbose:
  1167. - print " did not find '%s'" % name
  1168. + print(" did not find '%s'" % name)
  1169. return None
  1170. def InternalLaTeXAuxAction(XXXLaTeXAction, target = None, source= None, env=None):
  1171. @@ -232,7 +232,7 @@ def InternalLaTeXAuxAction(XXXLaTeXActio
  1172. saved_hashes[suffix] = theNode.get_csig()
  1173. if Verbose:
  1174. - print "hashes: ",saved_hashes
  1175. + print("hashes: ",saved_hashes)
  1176. must_rerun_latex = True
  1177. @@ -248,12 +248,12 @@ def InternalLaTeXAuxAction(XXXLaTeXActio
  1178. if saved_hashes[suffix] == new_md5:
  1179. if Verbose:
  1180. - print "file %s not changed" % (targetbase+suffix)
  1181. + print("file %s not changed" % (targetbase+suffix))
  1182. return False # unchanged
  1183. saved_hashes[suffix] = new_md5
  1184. must_rerun_latex = True
  1185. if Verbose:
  1186. - print "file %s changed, rerunning Latex, new hash = " % (targetbase+suffix), new_md5
  1187. + print("file %s changed, rerunning Latex, new hash = " % (targetbase+suffix), new_md5)
  1188. return True # changed
  1189. # generate the file name that latex will generate
  1190. @@ -292,7 +292,7 @@ def InternalLaTeXAuxAction(XXXLaTeXActio
  1191. auxfiles = list(dups.keys())
  1192. if Verbose:
  1193. - print "auxfiles ",auxfiles
  1194. + print("auxfiles ",auxfiles)
  1195. # Now decide if bibtex will need to be run.
  1196. # The information that bibtex reads from the .aux file is
  1197. @@ -306,7 +306,7 @@ def InternalLaTeXAuxAction(XXXLaTeXActio
  1198. content = open(target_aux, "rb").read()
  1199. if content.find("bibdata") != -1:
  1200. if Verbose:
  1201. - print "Need to run bibtex"
  1202. + print("Need to run bibtex")
  1203. bibfile = env.fs.File(SCons.Util.splitext(target_aux)[0])
  1204. result = BibTeXAction(bibfile, bibfile, env)
  1205. if result != 0:
  1206. @@ -317,7 +317,7 @@ def InternalLaTeXAuxAction(XXXLaTeXActio
  1207. if check_MD5(suffix_nodes['.idx'],'.idx') or (count == 1 and run_makeindex):
  1208. # We must run makeindex
  1209. if Verbose:
  1210. - print "Need to run makeindex"
  1211. + print("Need to run makeindex")
  1212. idxfile = suffix_nodes['.idx']
  1213. result = MakeIndexAction(idxfile, idxfile, env)
  1214. if result != 0:
  1215. @@ -335,7 +335,7 @@ def InternalLaTeXAuxAction(XXXLaTeXActio
  1216. if check_MD5(suffix_nodes['.nlo'],'.nlo') or (count == 1 and run_nomenclature):
  1217. # We must run makeindex
  1218. if Verbose:
  1219. - print "Need to run makeindex for nomenclature"
  1220. + print("Need to run makeindex for nomenclature")
  1221. nclfile = suffix_nodes['.nlo']
  1222. result = MakeNclAction(nclfile, nclfile, env)
  1223. if result != 0:
  1224. @@ -347,7 +347,7 @@ def InternalLaTeXAuxAction(XXXLaTeXActio
  1225. if check_MD5(suffix_nodes['.glo'],'.glo') or (count == 1 and run_glossaries) or (count == 1 and run_glossary):
  1226. # We must run makeindex
  1227. if Verbose:
  1228. - print "Need to run makeindex for glossary"
  1229. + print("Need to run makeindex for glossary")
  1230. glofile = suffix_nodes['.glo']
  1231. result = MakeGlossaryAction(glofile, glofile, env)
  1232. if result != 0:
  1233. @@ -359,7 +359,7 @@ def InternalLaTeXAuxAction(XXXLaTeXActio
  1234. if check_MD5(suffix_nodes['.acn'],'.acn') or (count == 1 and run_acronyms):
  1235. # We must run makeindex
  1236. if Verbose:
  1237. - print "Need to run makeindex for acronyms"
  1238. + print("Need to run makeindex for acronyms")
  1239. acrfile = suffix_nodes['.acn']
  1240. result = MakeAcronymsAction(acrfile, acrfile, env)
  1241. if result != 0:
  1242. @@ -371,26 +371,26 @@ def InternalLaTeXAuxAction(XXXLaTeXActio
  1243. if warning_rerun_re.search(logContent):
  1244. must_rerun_latex = True
  1245. if Verbose:
  1246. - print "rerun Latex due to latex or package rerun warning"
  1247. + print("rerun Latex due to latex or package rerun warning")
  1248. if rerun_citations_re.search(logContent):
  1249. must_rerun_latex = True
  1250. if Verbose:
  1251. - print "rerun Latex due to 'Rerun to get citations correct' warning"
  1252. + print("rerun Latex due to 'Rerun to get citations correct' warning")
  1253. if undefined_references_re.search(logContent):
  1254. must_rerun_latex = True
  1255. if Verbose:
  1256. - print "rerun Latex due to undefined references or citations"
  1257. + print("rerun Latex due to undefined references or citations")
  1258. if (count >= int(env.subst('$LATEXRETRIES')) and must_rerun_latex):
  1259. - print "reached max number of retries on Latex ,",int(env.subst('$LATEXRETRIES'))
  1260. + print("reached max number of retries on Latex ,",int(env.subst('$LATEXRETRIES')))
  1261. # end of while loop
  1262. # rename Latex's output to what the target name is
  1263. if not (str(target[0]) == resultfilename and os.path.isfile(resultfilename)):
  1264. if os.path.isfile(resultfilename):
  1265. - print "move %s to %s" % (resultfilename, str(target[0]), )
  1266. + print("move %s to %s" % (resultfilename, str(target[0]), ))
  1267. shutil.move(resultfilename,str(target[0]))
  1268. # Original comment (when TEXPICTS was not restored):
  1269. @@ -444,27 +444,27 @@ def is_LaTeX(flist,env,abspath):
  1270. else:
  1271. env['ENV']['TEXINPUTS'] = savedpath
  1272. if Verbose:
  1273. - print "is_LaTeX search path ",paths
  1274. - print "files to search :",flist
  1275. + print("is_LaTeX search path ",paths)
  1276. + print("files to search :",flist)
  1277. # Now that we have the search path and file list, check each one
  1278. for f in flist:
  1279. if Verbose:
  1280. - print " checking for Latex source ",str(f)
  1281. + print(" checking for Latex source ",str(f))
  1282. content = f.get_text_contents()
  1283. if LaTeX_re.search(content):
  1284. if Verbose:
  1285. - print "file %s is a LaTeX file" % str(f)
  1286. + print("file %s is a LaTeX file" % str(f))
  1287. return 1
  1288. if Verbose:
  1289. - print "file %s is not a LaTeX file" % str(f)
  1290. + print("file %s is not a LaTeX file" % str(f))
  1291. # now find included files
  1292. inc_files = [ ]
  1293. inc_files.extend( include_re.findall(content) )
  1294. if Verbose:
  1295. - print "files included by '%s': "%str(f),inc_files
  1296. + print("files included by '%s': "%str(f),inc_files)
  1297. # inc_files is list of file names as given. need to find them
  1298. # using TEXINPUTS paths.
  1299. @@ -474,7 +474,7 @@ def is_LaTeX(flist,env,abspath):
  1300. # make this a list since is_LaTeX takes a list.
  1301. fileList = [srcNode,]
  1302. if Verbose:
  1303. - print "FindFile found ",srcNode
  1304. + print("FindFile found ",srcNode)
  1305. if srcNode is not None:
  1306. file_test = is_LaTeX(fileList, env, abspath)
  1307. @@ -483,7 +483,7 @@ def is_LaTeX(flist,env,abspath):
  1308. return file_test
  1309. if Verbose:
  1310. - print " done scanning ",str(f)
  1311. + print(" done scanning ",str(f))
  1312. return 0
  1313. @@ -548,7 +548,7 @@ def ScanFiles(theFile, target, paths, fi
  1314. content = theFile.get_text_contents()
  1315. if Verbose:
  1316. - print " scanning ",str(theFile)
  1317. + print(" scanning ",str(theFile))
  1318. for i in range(len(file_tests_search)):
  1319. if file_tests[i][0] is None:
  1320. @@ -558,12 +558,12 @@ def ScanFiles(theFile, target, paths, fi
  1321. if incResult:
  1322. aux_files.append(os.path.join(targetdir, incResult.group(1)))
  1323. if Verbose:
  1324. - print "\include file names : ", aux_files
  1325. + print("\include file names : ", aux_files)
  1326. # recursively call this on each of the included files
  1327. inc_files = [ ]
  1328. inc_files.extend( include_re.findall(content) )
  1329. if Verbose:
  1330. - print "files included by '%s': "%str(theFile),inc_files
  1331. + print("files included by '%s': "%str(theFile),inc_files)
  1332. # inc_files is list of file names as given. need to find them
  1333. # using TEXINPUTS paths.
  1334. @@ -572,7 +572,7 @@ def ScanFiles(theFile, target, paths, fi
  1335. if srcNode is not None:
  1336. file_tests = ScanFiles(srcNode, target, paths, file_tests, file_tests_search, env, graphics_extensions, targetdir, aux_files)
  1337. if Verbose:
  1338. - print " done scanning ",str(theFile)
  1339. + print(" done scanning ",str(theFile))
  1340. return file_tests
  1341. def tex_emitter_core(target, source, env, graphics_extensions):
  1342. @@ -602,7 +602,7 @@ def tex_emitter_core(target, source, env
  1343. env.SideEffect(logfilename,target[0])
  1344. env.SideEffect(flsfilename,target[0])
  1345. if Verbose:
  1346. - print "side effect :",auxfilename,logfilename,flsfilename
  1347. + print("side effect :",auxfilename,logfilename,flsfilename)
  1348. env.Clean(target[0],auxfilename)
  1349. env.Clean(target[0],logfilename)
  1350. env.Clean(target[0],flsfilename)
  1351. @@ -671,7 +671,7 @@ def tex_emitter_core(target, source, env
  1352. else:
  1353. env['ENV']['TEXINPUTS'] = savedpath
  1354. if Verbose:
  1355. - print "search path ",paths
  1356. + print("search path ",paths)
  1357. aux_files = []
  1358. file_tests = ScanFiles(source[0], target, paths, file_tests, file_tests_search, env, graphics_extensions, targetdir, aux_files)
  1359. @@ -692,14 +692,14 @@ def tex_emitter_core(target, source, env
  1360. for suffix in suffix_list[:-1]:
  1361. env.SideEffect(file_name + suffix,target[0])
  1362. if Verbose:
  1363. - print "side effect :",file_name + suffix
  1364. + print("side effect :",file_name + suffix)
  1365. env.Clean(target[0],file_name + suffix)
  1366. for aFile in aux_files:
  1367. aFile_base = SCons.Util.splitext(aFile)[0]
  1368. env.SideEffect(aFile_base + '.aux',target[0])
  1369. if Verbose:
  1370. - print "side effect :",aFile_base + '.aux'
  1371. + print("side effect :",aFile_base + '.aux')
  1372. env.Clean(target[0],aFile_base + '.aux')
  1373. # read fls file to get all other files that latex creates and will read on the next pass
  1374. # remove files from list that we explicitly dealt with above
  1375. @@ -712,7 +712,7 @@ def tex_emitter_core(target, source, env
  1376. out_files.remove(filename)
  1377. env.SideEffect(out_files,target[0])
  1378. if Verbose:
  1379. - print "side effect :",out_files
  1380. + print("side effect :",out_files)
  1381. env.Clean(target[0],out_files)
  1382. return (target, source)
  1383. --- a/engine/SCons/Action.py
  1384. +++ b/engine/SCons/Action.py
  1385. @@ -553,7 +553,7 @@ class _ActionAction(ActionBase):
  1386. source = executor.get_all_sources()
  1387. t = ' and '.join(map(str, target))
  1388. l = '\n '.join(self.presub_lines(env))
  1389. - out = u"Building %s with action:\n %s\n" % (t, l)
  1390. + out = "Building %s with action:\n %s\n" % (t, l)
  1391. sys.stdout.write(out)
  1392. cmd = None
  1393. if show and self.strfunction:
  1394. @@ -672,7 +672,7 @@ def _subproc(scons_env, cmd, error = 'ig
  1395. try:
  1396. return subprocess.Popen(cmd, **kw)
  1397. - except EnvironmentError, e:
  1398. + except EnvironmentError as e:
  1399. if error == 'raise': raise
  1400. # return a dummy Popen instance that only returns error
  1401. class dummyPopen(object):
  1402. @@ -1060,11 +1060,11 @@ class FunctionAction(_ActionAction):
  1403. rsources = list(map(rfile, source))
  1404. try:
  1405. result = self.execfunction(target=target, source=rsources, env=env)
  1406. - except KeyboardInterrupt, e:
  1407. + except KeyboardInterrupt as e:
  1408. raise
  1409. - except SystemExit, e:
  1410. + except SystemExit as e:
  1411. raise
  1412. - except Exception, e:
  1413. + except Exception as e:
  1414. result = e
  1415. exc_info = sys.exc_info()
  1416. --- a/engine/SCons/Builder.py
  1417. +++ b/engine/SCons/Builder.py
  1418. @@ -167,7 +167,7 @@ class DictCmdGenerator(SCons.Util.Select
  1419. try:
  1420. ret = SCons.Util.Selector.__call__(self, env, source, ext)
  1421. - except KeyError, e:
  1422. + except KeyError as e:
  1423. raise UserError("Ambiguous suffixes after environment substitution: %s == %s == %s" % (e.args[0], e.args[1], e.args[2]))
  1424. if ret is None:
  1425. raise UserError("While building `%s' from `%s': Don't know how to build from a source file with suffix `%s'. Expected a suffix in this list: %s." % \
  1426. --- a/engine/SCons/Defaults.py
  1427. +++ b/engine/SCons/Defaults.py
  1428. @@ -221,7 +221,7 @@ def mkdir_func(dest):
  1429. for entry in dest:
  1430. try:
  1431. os.makedirs(str(entry))
  1432. - except os.error, e:
  1433. + except os.error as e:
  1434. p = str(entry)
  1435. if (e.args[0] == errno.EEXIST or
  1436. (sys.platform=='win32' and e.args[0]==183)) \
  1437. --- a/engine/SCons/Job.py
  1438. +++ b/engine/SCons/Job.py
  1439. @@ -278,14 +278,14 @@ else:
  1440. try:
  1441. prev_size = threading.stack_size(stack_size*1024)
  1442. - except AttributeError, e:
  1443. + except AttributeError as e:
  1444. # Only print a warning if the stack size has been
  1445. # explicitly set.
  1446. if not explicit_stack_size is None:
  1447. msg = "Setting stack size is unsupported by this version of Python:\n " + \
  1448. e.args[0]
  1449. SCons.Warnings.warn(SCons.Warnings.StackSizeWarning, msg)
  1450. - except ValueError, e:
  1451. + except ValueError as e:
  1452. msg = "Setting stack size failed:\n " + str(e)
  1453. SCons.Warnings.warn(SCons.Warnings.StackSizeWarning, msg)
  1454. --- a/engine/SCons/Node/__init__.py
  1455. +++ b/engine/SCons/Node/__init__.py
  1456. @@ -370,7 +370,7 @@ class Node(object):
  1457. """
  1458. try:
  1459. self.get_executor()(self, **kw)
  1460. - except SCons.Errors.BuildError, e:
  1461. + except SCons.Errors.BuildError as e:
  1462. e.node = self
  1463. raise
  1464. @@ -826,7 +826,7 @@ class Node(object):
  1465. """Adds dependencies."""
  1466. try:
  1467. self._add_child(self.depends, self.depends_set, depend)
  1468. - except TypeError, e:
  1469. + except TypeError as e:
  1470. e = e.args[0]
  1471. if SCons.Util.is_List(e):
  1472. s = list(map(str, e))
  1473. @@ -843,7 +843,7 @@ class Node(object):
  1474. """Adds dependencies to ignore."""
  1475. try:
  1476. self._add_child(self.ignore, self.ignore_set, depend)
  1477. - except TypeError, e:
  1478. + except TypeError as e:
  1479. e = e.args[0]
  1480. if SCons.Util.is_List(e):
  1481. s = list(map(str, e))
  1482. @@ -857,7 +857,7 @@ class Node(object):
  1483. return
  1484. try:
  1485. self._add_child(self.sources, self.sources_set, source)
  1486. - except TypeError, e:
  1487. + except TypeError as e:
  1488. e = e.args[0]
  1489. if SCons.Util.is_List(e):
  1490. s = list(map(str, e))
  1491. --- a/engine/SCons/Platform/posix.py
  1492. +++ b/engine/SCons/Platform/posix.py
  1493. @@ -77,7 +77,7 @@ def exec_fork(l, env):
  1494. exitval = 127
  1495. try:
  1496. os.execvpe(l[0], l, env)
  1497. - except OSError, e:
  1498. + except OSError as e:
  1499. exitval = exitvalmap.get(e[0], e[0])
  1500. sys.stderr.write("scons: %s: %s\n" % (l[0], e[1]))
  1501. os._exit(exitval)
  1502. @@ -125,8 +125,8 @@ def process_cmd_output(cmd_stdout, cmd_s
  1503. else:
  1504. #sys.__stderr__.write( "str(stderr) = %s\n" % str )
  1505. stderr.write(str)
  1506. - except select.error, (_errno, _strerror):
  1507. - if _errno != errno.EINTR:
  1508. + except OSError as e:
  1509. + if e.errno != errno.EINTR:
  1510. raise
  1511. def exec_popen3(l, env, stdout, stderr):
  1512. @@ -164,7 +164,7 @@ def exec_piped_fork(l, env, stdout, stde
  1513. exitval = 127
  1514. try:
  1515. os.execvpe(l[0], l, env)
  1516. - except OSError, e:
  1517. + except OSError as e:
  1518. exitval = exitvalmap.get(e[0], e[0])
  1519. stderr.write("scons: %s: %s\n" % (l[0], e[1]))
  1520. os._exit(exitval)
  1521. --- a/engine/SCons/Platform/win32.py
  1522. +++ b/engine/SCons/Platform/win32.py
  1523. @@ -125,7 +125,7 @@ def piped_spawn(sh, escape, cmd, args, e
  1524. try:
  1525. args = [sh, '/C', escape(' '.join(args)) ]
  1526. ret = os.spawnve(os.P_WAIT, sh, args, env)
  1527. - except OSError, e:
  1528. + except OSError as e:
  1529. # catch any error
  1530. try:
  1531. ret = exitvalmap[e[0]]
  1532. @@ -153,7 +153,7 @@ def piped_spawn(sh, escape, cmd, args, e
  1533. def exec_spawn(l, env):
  1534. try:
  1535. result = os.spawnve(os.P_WAIT, l[0], l, env)
  1536. - except OSError, e:
  1537. + except OSError as e:
  1538. try:
  1539. result = exitvalmap[e[0]]
  1540. sys.stderr.write("scons: %s: %s\n" % (l[0], e[1]))
  1541. --- a/engine/SCons/Scanner/C.py
  1542. +++ b/engine/SCons/Scanner/C.py
  1543. @@ -59,7 +59,7 @@ class SConsCPPScanner(SCons.cpp.PreProce
  1544. def read_file(self, file):
  1545. try:
  1546. fp = open(str(file.rfile()))
  1547. - except EnvironmentError, e:
  1548. + except EnvironmentError as e:
  1549. self.missing.append((file, self.current_file))
  1550. return ''
  1551. else:
  1552. --- a/engine/SCons/Script/SConsOptions.py
  1553. +++ b/engine/SCons/Script/SConsOptions.py
  1554. @@ -161,7 +161,7 @@ class SConsValues(optparse.Values):
  1555. elif name == 'diskcheck':
  1556. try:
  1557. value = diskcheck_convert(value)
  1558. - except ValueError, v:
  1559. + except ValueError as v:
  1560. raise SCons.Errors.UserError("Not a valid diskcheck value: %s"%v)
  1561. if 'diskcheck' not in self.__dict__:
  1562. # No --diskcheck= option was specified on the command line.
  1563. @@ -629,7 +629,7 @@ def Parser(version):
  1564. def opt_diskcheck(option, opt, value, parser):
  1565. try:
  1566. diskcheck_value = diskcheck_convert(value)
  1567. - except ValueError, e:
  1568. + except ValueError as e:
  1569. raise OptionValueError("Warning: `%s' is not a valid diskcheck type" % e)
  1570. setattr(parser.values, option.dest, diskcheck_value)
  1571. --- a/engine/SCons/Subst.py
  1572. +++ b/engine/SCons/Subst.py
  1573. @@ -438,7 +438,7 @@ def scons_subst(strSubst, env, mode=SUBS
  1574. s = eval(key, self.gvars, lvars)
  1575. except KeyboardInterrupt:
  1576. raise
  1577. - except Exception, e:
  1578. + except Exception as e:
  1579. if e.__class__ in AllowableExceptions:
  1580. return ''
  1581. raise_exception(e, lvars['TARGETS'], s)
  1582. @@ -653,7 +653,7 @@ def scons_subst_list(strSubst, env, mode
  1583. s = eval(key, self.gvars, lvars)
  1584. except KeyboardInterrupt:
  1585. raise
  1586. - except Exception, e:
  1587. + except Exception as e:
  1588. if e.__class__ in AllowableExceptions:
  1589. return
  1590. raise_exception(e, lvars['TARGETS'], s)
  1591. --- a/engine/SCons/Tool/filesystem.py
  1592. +++ b/engine/SCons/Tool/filesystem.py
  1593. @@ -66,7 +66,7 @@ def generate(env):
  1594. try:
  1595. env['BUILDERS']['CopyTo']
  1596. env['BUILDERS']['CopyAs']
  1597. - except KeyError, e:
  1598. + except KeyError as e:
  1599. global copyToBuilder
  1600. if copyToBuilder is None:
  1601. copyToBuilder = SCons.Builder.Builder(
  1602. --- a/engine/SCons/Tool/__init__.py
  1603. +++ b/engine/SCons/Tool/__init__.py
  1604. @@ -110,7 +110,7 @@ class Tool(object):
  1605. finally:
  1606. if file:
  1607. file.close()
  1608. - except ImportError, e:
  1609. + except ImportError as e:
  1610. if str(e)!="No module named %s"%self.name:
  1611. raise SCons.Errors.EnvironmentError(e)
  1612. try:
  1613. @@ -122,7 +122,7 @@ class Tool(object):
  1614. try:
  1615. importer = zipimport.zipimporter(aPath)
  1616. return importer.load_module(self.name)
  1617. - except ImportError, e:
  1618. + except ImportError as e:
  1619. pass
  1620. finally:
  1621. sys.path = oldpythonpath
  1622. @@ -140,7 +140,7 @@ class Tool(object):
  1623. if file:
  1624. file.close()
  1625. return module
  1626. - except ImportError, e:
  1627. + except ImportError as e:
  1628. if str(e)!="No module named %s"%self.name:
  1629. raise SCons.Errors.EnvironmentError(e)
  1630. try:
  1631. @@ -149,10 +149,10 @@ class Tool(object):
  1632. module = importer.load_module(full_name)
  1633. setattr(SCons.Tool, self.name, module)
  1634. return module
  1635. - except ImportError, e:
  1636. + except ImportError as e:
  1637. m = "No tool named '%s': %s" % (self.name, e)
  1638. raise SCons.Errors.EnvironmentError(m)
  1639. - except ImportError, e:
  1640. + except ImportError as e:
  1641. m = "No tool named '%s': %s" % (self.name, e)
  1642. raise SCons.Errors.EnvironmentError(m)
  1643. --- a/engine/SCons/Tool/install.py
  1644. +++ b/engine/SCons/Tool/install.py
  1645. @@ -81,21 +81,21 @@ def scons_copytree(src, dst, symlinks=Fa
  1646. else:
  1647. shutil.copy2(srcname, dstname)
  1648. # XXX What about devices, sockets etc.?
  1649. - except (IOError, os.error), why:
  1650. + except (IOError, os.error) as why:
  1651. errors.append((srcname, dstname, str(why)))
  1652. # catch the CopytreeError from the recursive copytree so that we can
  1653. # continue with other files
  1654. - except CopytreeError, err:
  1655. + except CopytreeError as err:
  1656. errors.extend(err.args[0])
  1657. try:
  1658. shutil.copystat(src, dst)
  1659. except WindowsError:
  1660. # can't copy file access times on Windows
  1661. pass
  1662. - except OSError, why:
  1663. + except OSError as why:
  1664. errors.extend((src, dst, str(why)))
  1665. if errors:
  1666. - raise CopytreeError, errors
  1667. + raise CopytreeError(errors)
  1668. #
  1669. --- a/engine/SCons/Tool/MSCommon/netframework.py
  1670. +++ b/engine/SCons/Tool/MSCommon/netframework.py
  1671. @@ -40,7 +40,7 @@ def find_framework_root():
  1672. try:
  1673. froot = read_reg(_FRAMEWORKDIR_HKEY_ROOT)
  1674. debug("Found framework install root in registry: %s" % froot)
  1675. - except WindowsError, e:
  1676. + except WindowsError as e:
  1677. debug("Could not read reg key %s" % _FRAMEWORKDIR_HKEY_ROOT)
  1678. return None
  1679. --- a/engine/SCons/Tool/MSCommon/sdk.py
  1680. +++ b/engine/SCons/Tool/MSCommon/sdk.py
  1681. @@ -80,7 +80,7 @@ class SDKDefinition(object):
  1682. try:
  1683. sdk_dir = common.read_reg(hkey)
  1684. - except WindowsError, e:
  1685. + except WindowsError as e:
  1686. debug('find_sdk_dir(): no SDK registry key %s' % repr(hkey))
  1687. return None
  1688. @@ -299,7 +299,7 @@ def get_cur_sdk_dir_from_reg():
  1689. try:
  1690. val = common.read_reg(_CURINSTALLED_SDK_HKEY_ROOT)
  1691. debug("Found current sdk dir in registry: %s" % val)
  1692. - except WindowsError, e:
  1693. + except WindowsError as e:
  1694. debug("Did not find current sdk in registry")
  1695. return None
  1696. --- a/engine/SCons/Tool/MSCommon/vc.py
  1697. +++ b/engine/SCons/Tool/MSCommon/vc.py
  1698. @@ -117,13 +117,13 @@ def get_host_target(env):
  1699. try:
  1700. host = _ARCH_TO_CANONICAL[host_platform.lower()]
  1701. - except KeyError, e:
  1702. + except KeyError as e:
  1703. msg = "Unrecognized host architecture %s"
  1704. raise ValueError(msg % repr(host_platform))
  1705. try:
  1706. target = _ARCH_TO_CANONICAL[target_platform.lower()]
  1707. - except KeyError, e:
  1708. + except KeyError as e:
  1709. raise ValueError("Unrecognized target architecture %s" % target_platform)
  1710. return (host, target,req_target_platform)
  1711. @@ -161,7 +161,7 @@ def msvc_version_to_maj_min(msvc_version
  1712. maj = int(t[0])
  1713. min = int(t[1])
  1714. return maj, min
  1715. - except ValueError, e:
  1716. + except ValueError as e:
  1717. raise ValueError("Unrecognized version %s (%s)" % (msvc_version,msvc_version_numeric))
  1718. def is_host_target_supported(host_target, msvc_version):
  1719. @@ -210,7 +210,7 @@ def find_vc_pdir(msvc_version):
  1720. key = root + key
  1721. try:
  1722. comps = common.read_reg(key)
  1723. - except WindowsError, e:
  1724. + except WindowsError as e:
  1725. debug('find_vc_dir(): no VC registry key %s' % repr(key))
  1726. else:
  1727. debug('find_vc_dir(): found VC in registry: %s' % comps)
  1728. @@ -282,7 +282,7 @@ def get_installed_vcs():
  1729. installed_versions.append(ver)
  1730. else:
  1731. debug('find_vc_pdir return None for ver %s' % ver)
  1732. - except VisualCException, e:
  1733. + except VisualCException as e:
  1734. debug('did not find VC %s: caught exception %s' % (ver, str(e)))
  1735. return installed_versions
  1736. @@ -376,7 +376,7 @@ def msvc_find_valid_batch_script(env,ver
  1737. try:
  1738. (vc_script,sdk_script) = find_batch_file(env,version,host_platform,tp)
  1739. debug('vc.py:msvc_find_valid_batch_script() vc_script:%s sdk_script:%s'%(vc_script,sdk_script))
  1740. - except VisualCException, e:
  1741. + except VisualCException as e:
  1742. msg = str(e)
  1743. debug('Caught exception while looking for batch file (%s)' % msg)
  1744. warn_msg = "VC version %s not installed. " + \
  1745. @@ -391,14 +391,14 @@ def msvc_find_valid_batch_script(env,ver
  1746. if vc_script:
  1747. try:
  1748. d = script_env(vc_script, args=arg)
  1749. - except BatchFileExecutionError, e:
  1750. + except BatchFileExecutionError as e:
  1751. debug('vc.py:msvc_find_valid_batch_script() use_script 3: failed running VC script %s: %s: Error:%s'%(repr(vc_script),arg,e))
  1752. vc_script=None
  1753. if not vc_script and sdk_script:
  1754. debug('vc.py:msvc_find_valid_batch_script() use_script 4: trying sdk script: %s'%(sdk_script))
  1755. try:
  1756. d = script_env(sdk_script,args=[])
  1757. - except BatchFileExecutionError,e:
  1758. + except BatchFileExecutionError as e:
  1759. debug('vc.py:msvc_find_valid_batch_script() use_script 5: failed running SDK script %s: Error:%s'%(repr(sdk_script),e))
  1760. continue
  1761. elif not vc_script and not sdk_script:
  1762. --- a/engine/SCons/Tool/MSCommon/vs.py
  1763. +++ b/engine/SCons/Tool/MSCommon/vs.py
  1764. @@ -85,7 +85,7 @@ class VisualStudio(object):
  1765. key = root + key
  1766. try:
  1767. comps = read_reg(key)
  1768. - except WindowsError, e:
  1769. + except WindowsError as e:
  1770. debug('find_vs_dir_by_reg(): no VS registry key %s' % repr(key))
  1771. else:
  1772. debug('find_vs_dir_by_reg(): found VS in registry: %s' % comps)
  1773. --- a/engine/SCons/Tool/packaging/__init__.py
  1774. +++ b/engine/SCons/Tool/packaging/__init__.py
  1775. @@ -120,7 +120,7 @@ def Package(env, target=None, source=Non
  1776. try:
  1777. file,path,desc=imp.find_module(type, __path__)
  1778. return imp.load_module(type, file, path, desc)
  1779. - except ImportError, e:
  1780. + except ImportError as e:
  1781. raise EnvironmentError("packager %s not available: %s"%(type,str(e)))
  1782. packagers=list(map(load_packager, PACKAGETYPE))
  1783. @@ -141,7 +141,7 @@ def Package(env, target=None, source=Non
  1784. if 'PACKAGEROOT' not in kw:
  1785. kw['PACKAGEROOT'] = default_name%kw
  1786. - except KeyError, e:
  1787. + except KeyError as e:
  1788. raise SCons.Errors.UserError( "Missing Packagetag '%s'"%e.args[0] )
  1789. # setup the source files
  1790. @@ -157,10 +157,10 @@ def Package(env, target=None, source=Non
  1791. assert( len(target) == 0 )
  1792. - except KeyError, e:
  1793. + except KeyError as e:
  1794. raise SCons.Errors.UserError( "Missing Packagetag '%s' for %s packager"\
  1795. % (e.args[0],packager.__name__) )
  1796. - except TypeError, e:
  1797. + except TypeError as e:
  1798. # this exception means that a needed argument for the packager is
  1799. # missing. As our packagers get their "tags" as named function
  1800. # arguments we need to find out which one is missing.
  1801. --- a/engine/SCons/Tool/packaging/msi.py
  1802. +++ b/engine/SCons/Tool/packaging/msi.py
  1803. @@ -216,7 +216,7 @@ def build_wxsfile(target, source, env):
  1804. if 'CHANGE_SPECFILE' in env:
  1805. env['CHANGE_SPECFILE'](target, source)
  1806. - except KeyError, e:
  1807. + except KeyError as e:
  1808. raise SCons.Errors.UserError( '"%s" package field for MSI is missing.' % e.args[0] )
  1809. #
  1810. --- a/engine/SCons/Tool/packaging/rpm.py
  1811. +++ b/engine/SCons/Tool/packaging/rpm.py
  1812. @@ -115,7 +115,7 @@ def collectintargz(target, source, env):
  1813. try:
  1814. #tarball = env['SOURCE_URL'].split('/')[-1]
  1815. tarball = env['SOURCE_URL'].split('/')[-1]
  1816. - except KeyError, e:
  1817. + except KeyError as e:
  1818. raise SCons.Errors.UserError( "Missing PackageTag '%s' for RPM packager" % e.args[0] )
  1819. tarball = src_targz.package(env, source=sources, target=tarball,
  1820. @@ -151,7 +151,7 @@ def build_specfile(target, source, env):
  1821. if 'CHANGE_SPECFILE' in env:
  1822. env['CHANGE_SPECFILE'](target, source)
  1823. - except KeyError, e:
  1824. + except KeyError as e:
  1825. raise SCons.Errors.UserError( '"%s" package field for RPM is missing.' % e.args[0] )
  1826. @@ -339,7 +339,7 @@ class SimpleTagCompiler(object):
  1827. for key, replacement in domestic:
  1828. try:
  1829. str = str + replacement % values[key]
  1830. - except KeyError, e:
  1831. + except KeyError as e:
  1832. if self.mandatory:
  1833. raise e
  1834. @@ -352,7 +352,7 @@ class SimpleTagCompiler(object):
  1835. int_values_for_key = [(get_country_code(t[0]),t[1]) for t in x]
  1836. for v in int_values_for_key:
  1837. str = str + replacement % v
  1838. - except KeyError, e:
  1839. + except KeyError as e:
  1840. if self.mandatory:
  1841. raise e
  1842. --- a/engine/SCons/Tool/textfile.py
  1843. +++ b/engine/SCons/Tool/textfile.py
  1844. @@ -107,7 +107,7 @@ def _action(target, source, env):
  1845. # write the file
  1846. try:
  1847. fd = open(target[0].get_path(), "wb")
  1848. - except (OSError,IOError), e:
  1849. + except (OSError,IOError) as e:
  1850. raise SCons.Errors.UserError("Can't write target file %s" % target[0])
  1851. # separate lines by 'linesep' only if linesep is not empty
  1852. lsep = None
  1853. --- a/engine/SCons/Variables/__init__.py
  1854. +++ b/engine/SCons/Variables/__init__.py
  1855. @@ -170,7 +170,7 @@ class Variables(object):
  1856. sys.path.insert(0, dir)
  1857. try:
  1858. values['__name__'] = filename
  1859. - exec open(filename, 'rU').read() in {}, values
  1860. + exec(open(filename, 'rU').read() in {}, values)
  1861. finally:
  1862. if dir:
  1863. del sys.path[0]
  1864. @@ -206,7 +206,7 @@ class Variables(object):
  1865. env[option.key] = option.converter(value)
  1866. except TypeError:
  1867. env[option.key] = option.converter(value, env)
  1868. - except ValueError, x:
  1869. + except ValueError as x:
  1870. raise SCons.Errors.UserError('Error converting option: %s\n%s'%(option.key, x))
  1871. @@ -268,7 +268,7 @@ class Variables(object):
  1872. finally:
  1873. fh.close()
  1874. - except IOError, x:
  1875. + except IOError as x:
  1876. raise SCons.Errors.UserError('Error writing options to file: %s\n%s' % (filename, x))
  1877. def GenerateHelpText(self, env, sort=None):
  1878. --- a/engine/SCons/Script/__init__.py
  1879. +++ b/engine/SCons/Script/__init__.py
  1880. @@ -364,7 +364,7 @@ GlobalDefaultBuilders = [
  1881. ]
  1882. for name in GlobalDefaultEnvironmentFunctions + GlobalDefaultBuilders:
  1883. - exec "%s = _SConscript.DefaultEnvironmentCall(%s)" % (name, repr(name))
  1884. + exec("%s = _SConscript.DefaultEnvironmentCall(%s)" % (name, repr(name)))
  1885. del name
  1886. # There are a handful of variables that used to live in the