eric6/Project/Project.py

changeset 7785
9978016560ec
parent 7780
41420f82c0ac
child 7830
72499e626226
equal deleted inserted replaced
7784:3257703e10c5 7785:9978016560ec
2349 # (only for Python and Python3) 2349 # (only for Python and Python3)
2350 if self.pdata["PROGLANGUAGE"] in [ 2350 if self.pdata["PROGLANGUAGE"] in [
2351 "Python3", "MicroPython" 2351 "Python3", "MicroPython"
2352 ]: 2352 ]:
2353 fn = os.path.join(self.ppath, "__init__.py") 2353 fn = os.path.join(self.ppath, "__init__.py")
2354 f = open(fn, "w", encoding="utf-8") 2354 with open(fn, "w", encoding="utf-8"):
2355 f.close() 2355 pass
2356 self.appendFile(fn, True) 2356 self.appendFile(fn, True)
2357 2357
2358 # create an empty main script file, if a name was given 2358 # create an empty main script file, if a name was given
2359 if self.pdata["MAINSCRIPT"]: 2359 if self.pdata["MAINSCRIPT"]:
2360 if not os.path.isabs(self.pdata["MAINSCRIPT"]): 2360 if not os.path.isabs(self.pdata["MAINSCRIPT"]):
2361 ms = os.path.join( 2361 ms = os.path.join(
2362 self.ppath, self.pdata["MAINSCRIPT"]) 2362 self.ppath, self.pdata["MAINSCRIPT"])
2363 else: 2363 else:
2364 ms = self.pdata["MAINSCRIPT"] 2364 ms = self.pdata["MAINSCRIPT"]
2365 f = open(ms, "w") 2365 with open(ms, "w"):
2366 f.close() 2366 pass
2367 self.appendFile(ms, True) 2367 self.appendFile(ms, True)
2368 2368
2369 if self.pdata["MAKEPARAMS"]["MakeEnabled"]: 2369 if self.pdata["MAKEPARAMS"]["MakeEnabled"]:
2370 mf = self.pdata["MAKEPARAMS"]["MakeFile"] 2370 mf = self.pdata["MAKEPARAMS"]["MakeFile"]
2371 if mf: 2371 if mf:
2372 if not os.path.isabs(mf): 2372 if not os.path.isabs(mf):
2373 mf = os.path.join(self.ppath, mf) 2373 mf = os.path.join(self.ppath, mf)
2374 else: 2374 else:
2375 mf = os.path.join(self.ppath, Project.DefaultMakefile) 2375 mf = os.path.join(self.ppath, Project.DefaultMakefile)
2376 f = open(mf, "w") 2376 with open(mf, "w"):
2377 f.close() 2377 pass
2378 self.appendFile(mf) 2378 self.appendFile(mf)
2379 2379
2380 tpd = os.path.join(self.ppath, self.translationsRoot) 2380 tpd = os.path.join(self.ppath, self.translationsRoot)
2381 if not self.translationsRoot.endswith(os.sep): 2381 if not self.translationsRoot.endswith(os.sep):
2382 tpd = os.path.dirname(tpd) 2382 tpd = os.path.dirname(tpd)
2413 self.ppath, self.pdata["MAINSCRIPT"]) 2413 self.ppath, self.pdata["MAINSCRIPT"])
2414 else: 2414 else:
2415 ms = self.pdata["MAINSCRIPT"] 2415 ms = self.pdata["MAINSCRIPT"]
2416 if not os.path.exists(ms): 2416 if not os.path.exists(ms):
2417 try: 2417 try:
2418 f = open(ms, "w") 2418 with open(ms, "w"):
2419 f.close() 2419 pass
2420 except EnvironmentError as err: 2420 except EnvironmentError as err:
2421 E5MessageBox.critical( 2421 E5MessageBox.critical(
2422 self.ui, 2422 self.ui,
2423 self.tr("Create main script"), 2423 self.tr("Create main script"),
2424 self.tr( 2424 self.tr(
2436 mf = os.path.join(self.ppath, mf) 2436 mf = os.path.join(self.ppath, mf)
2437 else: 2437 else:
2438 mf = os.path.join(self.ppath, Project.DefaultMakefile) 2438 mf = os.path.join(self.ppath, Project.DefaultMakefile)
2439 if not os.path.exists(mf): 2439 if not os.path.exists(mf):
2440 try: 2440 try:
2441 f = open(mf, "w") 2441 with open(mf, "w"):
2442 f.close() 2442 pass
2443 except EnvironmentError as err: 2443 except EnvironmentError as err:
2444 E5MessageBox.critical( 2444 E5MessageBox.critical(
2445 self.ui, 2445 self.ui,
2446 self.tr("Create Makefile"), 2446 self.tr("Create Makefile"),
2447 self.tr( 2447 self.tr(
2464 if self.pdata["PROGLANGUAGE"] in [ 2464 if self.pdata["PROGLANGUAGE"] in [
2465 "Python3", "MicroPython" 2465 "Python3", "MicroPython"
2466 ]: 2466 ]:
2467 fn = os.path.join(self.ppath, "__init__.py") 2467 fn = os.path.join(self.ppath, "__init__.py")
2468 if not os.path.exists(fn): 2468 if not os.path.exists(fn):
2469 f = open(fn, "w", encoding="utf-8") 2469 with open(fn, "w", encoding="utf-8"):
2470 f.close() 2470 pass
2471 self.appendFile(fn, True) 2471 self.appendFile(fn, True)
2472 self.saveProject() 2472 self.saveProject()
2473 2473
2474 # check, if the existing project directory is already under 2474 # check, if the existing project directory is already under
2475 # VCS control 2475 # VCS control
2727 mf = os.path.join(self.ppath, mf) 2727 mf = os.path.join(self.ppath, mf)
2728 else: 2728 else:
2729 mf = os.path.join(self.ppath, Project.DefaultMakefile) 2729 mf = os.path.join(self.ppath, Project.DefaultMakefile)
2730 if not os.path.exists(mf): 2730 if not os.path.exists(mf):
2731 try: 2731 try:
2732 f = open(mf, "w") 2732 with open(mf, "w"):
2733 f.close() 2733 pass
2734 except EnvironmentError as err: 2734 except EnvironmentError as err:
2735 E5MessageBox.critical( 2735 E5MessageBox.critical(
2736 self.ui, 2736 self.ui,
2737 self.tr("Create Makefile"), 2737 self.tr("Create Makefile"),
2738 self.tr( 2738 self.tr(
5267 try: 5267 try:
5268 if self.pdata["EOL"] == 0: 5268 if self.pdata["EOL"] == 0:
5269 newline = None 5269 newline = None
5270 else: 5270 else:
5271 newline = self.getEolString() 5271 newline = self.getEolString()
5272 pkglistFile = open(pkglist, "w", encoding="utf-8", newline=newline) 5272 with open(pkglist, "w", encoding="utf-8",
5273 pkglistFile.write("\n".join(header) + "\n") 5273 newline=newline) as pkglistFile:
5274 pkglistFile.write( 5274 pkglistFile.write("\n".join(header) + "\n")
5275 "\n".join([Utilities.fromNativeSeparators(f) for f in lst])) 5275 pkglistFile.write(
5276 pkglistFile.write("\n") # ensure the file ends with an empty line 5276 "\n".join([Utilities.fromNativeSeparators(f)
5277 pkglistFile.close() 5277 for f in lst]))
5278 pkglistFile.write("\n")
5279 # ensure the file ends with an empty line
5278 except IOError as why: 5280 except IOError as why:
5279 E5MessageBox.critical( 5281 E5MessageBox.critical(
5280 self.ui, 5282 self.ui,
5281 self.tr("Create Package List"), 5283 self.tr("Create Package List"),
5282 self.tr( 5284 self.tr(
5338 progress.setValue(count) 5340 progress.setValue(count)
5339 if progress.wasCanceled(): 5341 if progress.wasCanceled():
5340 break 5342 break
5341 5343
5342 try: 5344 try:
5343 pkglistFile = open(pkglist, "r", encoding="utf-8") 5345 with open(pkglist, "r", encoding="utf-8") as pkglistFile:
5344 names = pkglistFile.read() 5346 names = pkglistFile.read()
5345 pkglistFile.close()
5346 except IOError as why: 5347 except IOError as why:
5347 E5MessageBox.critical( 5348 E5MessageBox.critical(
5348 self.ui, 5349 self.ui,
5349 self.tr("Create Plugin Archive"), 5350 self.tr("Create Plugin Archive"),
5350 self.tr( 5351 self.tr(

eric ide

mercurial