How to use the ratarmount.TarFileType function in ratarmount

To help you get started, we’ve selected a few ratarmount examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mxmlnkn / ratarmount / ratarmount.py View on Github external
# all positional arguments, including the mountpath will be parsed into the tarfilepaths namespace and we have to
    # manually separate them depending on the type.
    if os.path.isdir( args.mount_source[-1] ) or not os.path.exists( args.mount_source[-1] ):
        args.mount_point = args.mount_source[-1]
        args.mount_source = args.mount_source[:-1]
    if not args.mount_source:
        print( "[Error] You must at least specify one path to a valid TAR file or union mount source directory!" )
        exit( 1 )

    # Manually check that all specified TARs and folders exist
    compressions = [ '' ]
    if 'IndexedBzip2File' in globals():
        compressions += [ 'bz2' ]
    if 'IndexedGzipFile' in globals():
        compressions += [ 'gz' ]
    args.mount_source = [ TarFileType( mode = 'r', compressions = compressions )( tarFile )[0].name
                           if not os.path.isdir( tarFile ) else os.path.realpath( tarFile )
                           for tarFile in args.mount_source ]

    # Automatically generate a default mount path
    if args.mount_point is None:
        tarPath = args.mount_source[0]
        for doubleExtension in [ '.tar.bz2', '.tar.gz' ]:
            if tarPath[-len( doubleExtension ):].lower() == doubleExtension.lower():
                args.mount_point = tarPath[:-len( doubleExtension )]
                break
        if not args.mount_point:
            args.mount_point = os.path.splitext( tarPath )[0]
    args.mount_point = os.path.abspath( args.mount_point )

    return args