1 import os
2 import re
3 from uuid import uuid4
4
5
6 MAX_CHARS_IN_ONE_LINE = 20000
7
8 __CSL = None
10 '''symlink(source, link_name)
11 Creates a symbolic link pointing to source named link_name'''
12 global __CSL
13 if __CSL is None:
14 import ctypes
15 csl = ctypes.windll.LoadLibrary("kernel32.dll").CreateSymbolicLinkW
16 csl.argtypes = (ctypes.c_wchar_p, ctypes.c_wchar_p, ctypes.c_uint32)
17 csl.restype = ctypes.c_ubyte
18 __CSL = csl
19 flags = 0
20 if source is not None and os.path.isdir(source):
21 flags = 1
22 if __CSL(link_name, source, flags) == 0:
23 raise ctypes.WinError()
24
26 """
27 Returns original string minus any characters that are invalid in file names
28 @param value: String to convert to a valid file name
29 @type value: str
30 @rtype: str
31 """
32 return re.sub(r'[\\/:?]', '_', value)[:100]+"_"+uuid4().hex
33