Package tlib :: Package base :: Module FileHelper |
[hide private]
[frames] | no frames]

# Source Code for Module tlib.base.FileHelper

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