#!/usr/bin/env python2.7

import sys
import os.path
dev_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
sys.path.insert(0, dev_path)

import logging
import argparse

import gdrivefs.config
import gdrivefs.config.log
import gdrivefs.gdfs.gdfuse

_logger = logging.getLogger(__name__)

def main():
    parser = argparse.ArgumentParser()

    parser.add_argument('auth_storage_file', 
                        help='Authorization storage file')

    parser.add_argument('mountpoint', 
                        help='Mount point')

    parser.add_argument('-o', '--opt', 
                        help='Mount options',
                        action='store', 
                        required=False,
                        nargs=1)

    args = parser.parse_args()

    option_string = args.opt[0] if args.opt else None

    _logger.debug("Mounting GD with creds at [%s]: %s", 
                  args.auth_storage_file, args.mountpoint)

    gdrivefs.gdfs.gdfuse.mount(
        auth_storage_filepath=args.auth_storage_file, 
        mountpoint=args.mountpoint, 
        debug=gdrivefs.config.IS_DEBUG, 
        nothreads=gdrivefs.config.IS_DEBUG, 
        option_string=option_string)

if __name__ == '__main__':
    main()
