#!python
"""LICENSE
Copyright 2017 Hermann Krumrey <hermann@krumreyh.com>

This file is part of ci-scripts.

ci-scripts 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.

ci-scripts 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 ci-scripts.  If not, see <http://www.gnu.org/licenses/>.
LICENSE"""

import argparse
from ci_scripts.common import process_call


def main():
    """
    Uploads a release to the Google play store
    Wrapper around the __play_upload script
    :return: None
    """
    parser = argparse.ArgumentParser()
    parser.add_argument("package",
                        help="The name of the package to upload to,"
                             "for example: com.android.example")
    parser.add_argument("track",
                        choices={"rollout", "production", "beta", "alpha"},
                        help="The track to which to upload the release to. May"
                             " be 'rollout', 'production', 'beta' or 'alpha'")
    args = parser.parse_args()

    package = args.package
    track = args.track

    process_call(["python3", "-m", "venv", "playupload-venv"])
    process_call([
        "playupload-venv/bin/pip", "install",
        "ci-scripts",
        "google-api-python-client",
        "pyOpenSSL",
        "httplib2",
        "oauth2client"
    ])

    process_call([
        "playupload-venv/bin/python",
        "playupload-venv/bin/__play-upload",
        package,
        track
    ])


if __name__ == "__main__":
    main()
