scripts/install.py

changeset 7785
9978016560ec
parent 7775
4a1db75550bd
child 7799
5aeb0122e063
equal deleted inserted replaced
7784:3257703e10c5 7785:9978016560ec
233 Copy a string to a file. 233 Copy a string to a file.
234 234
235 @param name the name of the file. 235 @param name the name of the file.
236 @param text the contents to copy to the file. 236 @param text the contents to copy to the file.
237 """ 237 """
238 f = open(name, "w") 238 with open(name, "w") as f:
239 f.write(text) 239 f.write(text)
240 f.close()
241 240
242 241
243 def copyDesktopFile(src, dst): 242 def copyDesktopFile(src, dst):
244 """ 243 """
245 Modify a desktop file and write it to its destination. 244 Modify a desktop file and write it to its destination.
247 @param src source file name (string) 246 @param src source file name (string)
248 @param dst destination file name (string) 247 @param dst destination file name (string)
249 """ 248 """
250 global cfg, platBinDir 249 global cfg, platBinDir
251 250
252 f = open(src, "r", encoding="utf-8") 251 with open(src, "r", encoding="utf-8") as f:
253 text = f.read() 252 text = f.read()
254 f.close()
255 253
256 text = text.replace("@BINDIR@", platBinDir) 254 text = text.replace("@BINDIR@", platBinDir)
257 text = text.replace("@MARKER@", "") 255 text = text.replace("@MARKER@", "")
258 text = text.replace("@PY_MARKER@", "") 256 text = text.replace("@PY_MARKER@", "")
259 257
260 f = open(dst, "w", encoding="utf-8") 258 with open(dst, "w", encoding="utf-8") as f:
261 f.write(text) 259 f.write(text)
262 f.close()
263 os.chmod(dst, 0o644) 260 os.chmod(dst, 0o644)
264 261
265 262
266 def copyAppStreamFile(src, dst): 263 def copyAppStreamFile(src, dst):
267 """ 264 """
277 # Installing from source tree 274 # Installing from source tree
278 from eric6.UI.Info import Version 275 from eric6.UI.Info import Version
279 else: 276 else:
280 Version = "Unknown" 277 Version = "Unknown"
281 278
282 f = open(src, "r", encoding="utf-8") 279 with open(src, "r", encoding="utf-8") as f:
283 text = f.read() 280 text = f.read()
284 f.close()
285 281
286 text = ( 282 text = (
287 text.replace("@MARKER@", "") 283 text.replace("@MARKER@", "")
288 .replace("@VERSION@", Version.split(None, 1)[0]) 284 .replace("@VERSION@", Version.split(None, 1)[0])
289 .replace("@DATE@", time.strftime("%Y-%m-%d")) 285 .replace("@DATE@", time.strftime("%Y-%m-%d"))
290 ) 286 )
291 287
292 f = open(dst, "w", encoding="utf-8") 288 with open(dst, "w", encoding="utf-8") as f:
293 f.write(text) 289 f.write(text)
294 f.close()
295 os.chmod(dst, 0o644) 290 os.chmod(dst, 0o644)
296 291
297 292
298 def wrapperNames(dname, wfile): 293 def wrapperNames(dname, wfile):
299 """ 294 """
422 pdir = os.path.join(cfg['mdir'], "eric6plugins") 417 pdir = os.path.join(cfg['mdir'], "eric6plugins")
423 fname = os.path.join(pdir, "__init__.py") 418 fname = os.path.join(pdir, "__init__.py")
424 if not os.path.exists(fname): 419 if not os.path.exists(fname):
425 if not os.path.exists(pdir): 420 if not os.path.exists(pdir):
426 os.mkdir(pdir, 0o755) 421 os.mkdir(pdir, 0o755)
427 f = open(fname, "w") 422 with open(fname, "w") as f:
428 f.write( 423 f.write(
429 '''# -*- coding: utf-8 -*- 424 '''# -*- coding: utf-8 -*-
430 425
431 """ 426 """
432 Package containing the global plugins. 427 Package containing the global plugins.
433 """ 428 """
434 ''' 429 '''
435 ) 430 )
436 f.close()
437 os.chmod(fname, 0o644) 431 os.chmod(fname, 0o644)
438 432
439 433
440 def cleanupSource(dirName): 434 def cleanupSource(dirName):
441 """ 435 """
1688 hgOut = "" 1682 hgOut = ""
1689 if hgOut: 1683 if hgOut:
1690 hgOut = hgOut.strip() 1684 hgOut = hgOut.strip()
1691 if hgOut.endswith("+"): 1685 if hgOut.endswith("+"):
1692 hgOut = hgOut[:-1] 1686 hgOut = hgOut[:-1]
1693 f = open(fileName + ".orig", "r", encoding="utf-8") 1687 with open(fileName + ".orig", "r", encoding="utf-8") as f:
1694 text = f.read() 1688 text = f.read()
1695 f.close()
1696 text = ( 1689 text = (
1697 text.replace("@@REVISION@@", hgOut) 1690 text.replace("@@REVISION@@", hgOut)
1698 .replace("@@VERSION@@", "rev_" + hgOut) 1691 .replace("@@VERSION@@", "rev_" + hgOut)
1699 ) 1692 )
1700 copyToFile(fileName, text) 1693 copyToFile(fileName, text)

eric ide

mercurial