#!/usr/bin/env python3
###########################################################################################
#  package:   pNbody
#  file:      infogmov
#  copyright: GPLv3
#             Copyright (C) 2019 EPFL (Ecole Polytechnique Federale de Lausanne)
#             LASTRO - Laboratory of Astrophysics of EPFL
#  author:    Yves Revaz <yves.revaz@epfl.ch>
#
# This file is part of pNbody.
###########################################################################################

import sys
import os
import string
import getopt
import math

from pNbody import Movie

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


def version():
    ##########################################################################
    print('version 1.0')
    sys.exit(0)


##########################################################################
def help_message():
    ##########################################################################
    print("""Usage : infogmov -f film [options]

  This function gives info on a film

  Options: -h        -- this help message
           -f 	     -- name of the input
           --help    -- this help message
           --version -- displays version
""")
    sys.exit(0)


##########################################################################
def check_arguments(options, xarguments):
    ##########################################################################

    n1 = 0
    n2 = 0
    output = "out.mov"
    input = None
    info = None

    for a in options[:]:
        if a[0] == '-h':
            help_message()

        if a[0] == '--help':
            help_message()

        if a[0] == '--version':
            version()

        if a[0] == '-f':
            if a[1] == '':
                help_message()
            else:
                input = a[1]
                continue

    if input is None:
        help_message()

    return input


##########################################################################
#
#  MAIN
#
##########################################################################


try:
    options, xarguments = getopt.getopt(
        sys.argv[1:], 'f:h', ['help', 'version'])
except getopt.error:
    help_message()
    sys.exit(0)


# check arguments
film = check_arguments(options, xarguments)


# check that the film exists
if (os.path.exists(film) == 0):
    print("Error : the file ", film, " do no not exist.")
    sys.exit(0)

# open the file
fi = Movie.Movie(film)
fi.open()

# write info
fi.info()
