#!/usr/bin/env python
"""
    S3 File Upload

    @author: Jean-Lou Dupont
"""
__version__="0.1"
import os, sys, argparse
op=os.path

try:
    if os.environ.get("DEVMODE", False):
        raise        
    import jldaws #@UnusedImport
except:
    ### must be in dev mode then    
    this_dir=op.dirname(__file__)
    lib_path=op.abspath(op.join(this_dir, ".."))
    sys.path.insert(0, lib_path)
    import jldaws #@UnusedImport

########################################################################

DESC="Simple upload file to S3 - %s" % __version__
DEFAULTS={
          }

def main():
    try:
        import jldaws.do_setup  #@UnusedImport
        import logging
        import jldaws.do_checks #@UnusedImport
        
        parser=argparse.ArgumentParser(description=DESC, fromfile_prefix_chars='@', formatter_class=argparse.RawTextHelpFormatter)
        parser.add_argument('-t',  dest='enable_simulate', action="store_true", help="Simulate processing", default=False)
        
        parser.add_argument('-bn', dest='bucket_name',   type=str, help="Bucket name",   required=True)
        parser.add_argument('-pr', dest='bucket_prefix', type=str, help="Bucket prefix", default=None)
        
        parser.add_argument('-sp', dest='path_source', type=str, help="Path to source file",   required=True)
        parser.add_argument('-dp', dest='path_dest',   type=str, help="Path for destination file")        

        parser.add_argument('-do', dest='delete_old',  action="store_true", help="Delete old files")
        
        from jldaws.script_s3up import run
        from jldaws.tools_sys import process_command_line
        args=process_command_line(parser)
        run(**args)


    except KeyboardInterrupt:
        logging.info("..Exiting")
        sys.exit(0)##no probs
        
    except Exception,e:
        logging.error(str(e))
        sys.exit(1)
        
sys.exit(main())
