#!/usr/bin/python3 -sP
#-*- coding: utf-8 -*-

#***********************************************
# oct2spec 
#
# oct2spec helps to create a specfile for an octave package
# It works from a package name (from Octave Forge), source file (*.tar.gz) or
# a url (http://...*.tar.gz)
#
# This software has been based on the guidelines for octave packaging
# http://fedoraproject.org/wiki/Packaging/Octave
#
# Based on R2spec, Made the 13th February 2008
# by Pierre-Yves chibon
#
# Copyright (C) 2011 Orion Poplawski <orion@cora.nwra.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#***********************************************

from Oct2spec import Oct2spec
from optparse import OptionParser

#################################################
### argument
# retrieve the arguments given and show the help when needed
def getArgument():
    ''' Handle the parameters'''
    parser = OptionParser(version="%prog 1.0.1")
    parser.add_option("-p", "--package", dest="package",
                  help="The name of the octave package")
    parser.add_option("-u", "--url", dest="url",
                  help="Url of the octave package")
    parser.add_option("-s", "--source", dest="source",
                  help="The source file (tarball) of the octave package")
                  
    parser.add_option("--forge", dest="forge", default=True, action="store_true",
                  help="For Octave Forge package, will add the correct Source0 in the spec file")
                  
    parser.add_option("-c", "--copyFile", dest="copyFile", default=False, action="store_true",
                  help="Copy directly the file to the SOURCES folder without asking")
    parser.add_option("-n", "--name", dest="name",
                  help="Name of the packager that will be used in the spec file")
    parser.add_option("-e", "--email", dest="email",
                  help="Email of the packager that will be used in the spec file")
    parser.add_option("-f", "--force", dest="force", default=False, action="store_true",
                  help="Create the spec file even if a file of the same name exists already in the working directory")
    (options, args) = parser.parse_args()

    return (options.source, options.url, options.package, \
    options.forge, \
    options.copyFile, options.name, \
    options.email, options.force)
################################################


if __name__ == "__main__":
    # Retrieve the given arguments
    (source, url, package, forge, copyFile, name, email, force) = getArgument()
    Oct2spec.Oct2spec().main(source, url, package, forge, copyFile, name, email, force)
