Exemplo n.º 1
0
def _verifydest(dest):
    """ Uses the checkdir library to verify that the dest is valid
        and create any additional directories needed. 
    dest: A string containing a path and filename for our file.
    returns: dest variable which may have changes.
    """

    # Verify the path and filename is valid.
    if 'linux' in sys.platform: 
        dest = checkdir.validate_string_unix(dest)
    else:
        raise 'OS not supported'

    # Splits the path into a path and filename. Tests if there is a filename
    splitPath = os.path.split(dest)
    if splitPath[1] == '': 
        raise 'No file name provided'

    # Check if there is a path and it exists. Create if it does not.
    if splitPath[0] and (not os.path.exists(splitPath[0])):
        os.makedirs(splitPath[0])

    return dest
Exemplo n.º 2
0
# a unix system BUT you want to insure that the file structure is also
# valid for an ntfs file system like windows.  Since you are given the
# function a Unix directory path you MUST set the pathType value to
# UNIX_PATH_TYPE.
print 'Windows Error Control - Given a Linux path name\n'
print 'Unix path is invalid for Windows: ', unixTest
print 'Corrected Unix path for Windows:  ', checkdir.validate_string_ntfs(unixTest, pathType=checkdir.UNIX_PATH_TYPE)
print '\nEND\n\n\n'


# validate_string_unix when a unix directory path would be used when
# you only intend on the directory/file being used only on a unix file
# system.  No pathType needs to be declared since a unix path is given.
print 'Unix Error Control - Given a Linux path name\n'
print 'Invalid Unix Path:   ', unixTest
print 'Corrected Unix Path: ', checkdir.validate_string_unix(unixTest)
print '\nEND\n\n\n'


# This use of validate_string_unix is when you are writing a file to 
# Windows BUT you want to insure that the file structure is also valid 
# for a unix file system. The pathType flag must be set to 
# NTFS_PATH_TYPE
print 'Unix Error Control - Given a Windows path name\n'
print 'Windows path is invalid for Unix: ', ntfsTest
print 'Corrected Windows path for Unix:  ', checkdir.validate_string_unix(ntfsTest, pathType=checkdir.NTFS_PATH_TYPE)
print '\nEND\n\n\n'


# To truely make sure you want your directory path works for all file
# systems you want to use multiple checks.  In this example we are going