#!/usr/bin/python
import glob
import os
import sys
import zipfile
from StringIO import StringIO

import boto3

import settings
from noopy.utils import to_pascal_case


def main():
    target_dir = 'src'
    names, zip_bytes = make_zip(target_dir)
    for name in names:
        create_function(zip_bytes, name.rstrip('.py'))


def make_zip(target_dir):
    f = StringIO()
    zip_file = zipfile.ZipFile(f, 'w')

    file_names = glob.glob('{}/*.py'.format(target_dir))
    if not file_names:
        sys.stderr.write('There is no python file in src directory')
        sys.exit(1)

    for file_name in file_names:
        zip_file.write(file_name, os.path.split(file_name)[1])

    zip_file.close()
    f.seek(0)
    bytes_ = f.read()
    f.close()
    return zip_file.namelist(), bytes_


def create_function(zip_bytes, file_name):
    lambda_settings = settings.LAMBDA
    client = boto3.client('lambda')
    function_prefix = 'arn:aws:lambda:{}:{}:{}'.format(
            client._client_config.region_name,
            settings.ACCOUNT_ID,
            lambda_settings['Prefix']
    )

    print client.create_function(
            FunctionName='{}{}'.format(function_prefix, to_pascal_case(file_name)),
            Runtime='python2.7',
            Role=lambda_settings['Role'],
            Handler='{}.lambda_handler'.format(file_name),
            Code={
                'ZipFile': zip_bytes
            }
    )


if __name__ == '__main__':
    main()

@@ -107,24 +107,20 @@
 to3%0A
-%0A
 import 
-settings
+noopy
 %0Afro
@@ -156,16 +156,33 @@
 l_case%0A%0A
+import settings%0A%0A
 %0Adef mai
@@ -685,16 +685,327 @@
 e)%5B1%5D)%0A%0A
+    noopy_parent = os.path.split(noopy.__path__%5B0%5D)%5B0%5D%0A    for root, _, file_names in os.walk(noopy.__path__%5B0%5D):%0A        for file_name in file_names:%0A            full_path = os.path.join(root, file_name)%0A            local_path = full_path%5Blen(noopy_parent):%5D%0A            zip_file.write(full_path, local_path)%0A%0A
     zip_
@@ -1071,38 +1071,93 @@
 e()%0A
+%0A
     
-return zip_file.namelist()
+srcs = %5Bname for name in zip_file.namelist() if '/' not in name%5D%0A    return srcs
 , by

Add noopy package in zip to be uploaded