Update Chinese Translations (Babyfai Cheung)
[rox-archive.git] / support.py
blobc39ef9687ba22dee279c00397e9740808a82179c
1 from rox import g, saving
2 import rox
3 import fcntl
4 from rox import processes
5 import sys, os
7 def shell_escape(text):
8 """Return text with \ and ' escaped"""
9 return text.replace("\\", "\\\\").replace("'", "\\'")
11 def Tmp(mode = 'w+b'):
12 "Create a seekable, randomly named temp file (deleted automatically after use)."
13 import tempfile
14 try:
15 return tempfile.NamedTemporaryFile(mode, suffix = '-archive')
16 except:
17 # python2.2 doesn't have NamedTemporaryFile...
18 pass
20 import random
21 name = tempfile.mktemp(`random.randint(1, 1000000)` + '-archive')
23 fd = os.open(name, os.O_RDWR|os.O_CREAT|os.O_EXCL, 0700)
24 tmp = tempfile.TemporaryFileWrapper(os.fdopen(fd, mode), name)
25 tmp.name = name
26 return tmp
28 def keep_on_exec(fd):
29 fcntl.fcntl(fd, fcntl.F_SETFD, 0)