from __future__ import absolute_import

from django.core.management.base import BaseCommand
from zappa.zappa import Zappa

from .zappa_command import ZappaCommand


class Command(ZappaCommand):

    can_import_settings = True
    requires_system_checks = False

    help = '''Update the the lambda package for a given Zappa deployment.'''

    def add_arguments(self, parser):
        parser.add_argument('environment', nargs='+', type=str)

    def handle(self, *args, **options):  # NoQA
        """
        Execute the command.

        """

        # Load the settings
        self.require_settings(args, options)

        # Load your AWS credentials from ~/.aws/credentials
        self.zappa.load_credentials()

        # Create the Lambda Zip
        self.create_package()

        # Upload it to S3
        self.zappa.upload_to_s3(self.zip_path, self.s3_bucket_name)

        # Register the Lambda function with that zip as the source
        # You'll also need to define the path to your lambda_handler code.
        lambda_arn = self.zappa.update_lambda_function(
            self.s3_bucket_name, self.zip_path, self.lambda_name)

        # Remove the uploaded zip from S3, because it is now registered..
        self.zappa.remove_from_s3(self.zip_path, self.s3_bucket_name)

        print("Your updated Zappa deployment is live!")

        return

@@ -433,16 +433,147 @@
 ype=str)
+%0A        parser.add_argument('--zip',%0A            dest='zip',%0A            default=None,%0A            help='Use a supplied zip file')
 %0A%0A    de
@@ -873,16 +873,17 @@
 mbda Zip
+,
 %0A       
@@ -887,29 +887,162 @@
     
-self.create_package()
+# or used the supplied zip file.%0A        if not options%5B'zip'%5D:%0A            self.create_package()%0A        else:%0A            self.zip_path = options%5B'zip'%5D
 %0A%0A  
@@ -1473,16 +1473,16 @@
 tered..%0A
-
         
@@ -1536,32 +1536,222 @@
 3_bucket_name)%0A%0A
+        # Finally, delete the local copy our zip package%0A        if self.zappa_settings%5Bself.api_stage%5D.get('delete_zip', True) and not options%5B'zip'%5D:%0A            os.remove(self.zip_path)%0A%0A
         print(%22Y

Add optional --zip argument to update command