#!/usr/bin/python

# =========================================================================== #
#                                                                             #
#   temporary file for development                                            #
#   when finished, it will become the new oasis CLI                           #
#                                                                             #
# =========================================================================== #

__version__ = "2.0.0"
__versionname__ = "Dakhla"

import getopt
import logging
import os
import sys
import time

from oasispackage.oasisAPI import oasisCLI
from oasispackage.flagfiles import FlagFile


"""
This is the CLI interface to OASIS package. 
It can be used to run the user part of OASIS, 
either directly from command line
or from another client, e.g. HTCondor.
"""

#
# FIXME
# this script is very similar to bin/oasisd
# should they be merged?
#


class Action(object):
    # FIXME: search for a less ugly name
    
    # FIXME: make a single Action class in a separate file
    #        and make all these little clients oasis-user-* 
    #        to import it and use it. 

    def __init__(self):

        self.oasis = oasisCLI()
        self.projectname = self.oasis.project.projectname

    def preinstall(self):
        '''
        just runs the preinstall part in class Project
        '''
        self.oasis.project.preinstall() 


def usage():

    print 'oasis-user-preinstall:'
    print ''
    print ' Syntax:'
    print '     oasis-user-preinstall [--help|-h]'
    print ''
    print ' Description:'
    print '     Synchronizes the user scratch area'
    print '     and the destination area.'
    print '     Reason is to remove any orphan file that'
    print '     could remain in the scratch area from'
    print '     previous failed installation processes.'
    print ''
    print ' Options:'
    print '     --help | -h         Displays usage and exits'
    print ''
    sys.exit()



# =============================================================================

def main(options):
    
    # parse input options
    opts, args = getopt.getopt(options, 'h', ['help'])
    for o,a in opts:
        if o == '-h' or o == '--help':
            usage()

    # run the process
    action = Action()
    rc = action.preinstall()
    return rc


if __name__ == '__main__':
    rc = main(sys.argv[1:])
    sys.exit(rc)

