import os
import re
import zipfile

current_path = os.path.dirname(os.path.abspath(__file__))

out_zip_name = os.path.join(current_path, 
                            os.path.basename(current_path) + ".esriaddin")

BACKUP_FILE_PATTERN = re.compile(".*_addin_[0-9]+[.]py$", re.IGNORECASE)

def looks_like_a_backup(filename):
    return bool(BACKUP_FILE_PATTERN.match(filename))

zip_file = zipfile.ZipFile(out_zip_name, 'w')
for filename in ('config.xml', 'README.md', 'makeaddin.py'):
    zip_file.write(os.path.join(current_path, filename), filename)
dirs_to_add = ['Images', 'Install']
for directory in dirs_to_add:
    for (path, dirs, files) in os.walk(os.path.join(current_path, directory)):
        archive_path = os.path.relpath(path, current_path)
        found_file = False
        for file in (f for f in files if not looks_like_a_backup(f)):
            archive_file = os.path.join(archive_path, file)
            print archive_file
            zip_file.write(os.path.join(path, file), archive_file)
            found_file = True
        if not found_file:
            zip_file.writestr(os.path.join(archive_path, 'placeholder.txt'), 
                              "(Empty directory)")
zip_file.close()

@@ -220,29 +220,57 @@
 %0D%0A%0D%0A
+backup_patterns = %7B%0D%0A    'PLUGIN_
 BACKUP_
-FILE_
 PATTERN
- =
+':
  re.
@@ -320,100 +320,354 @@
 ASE)
-%0D%0A%0D%0Adef looks_like_a_backup(filename):%0D%0A    return bool(BACKUP_FILE_PATTERN.match(filename))
+,%0D%0A    'VIM_SWAP_PATTERN': re.compile(%22.*.sw%5Bop%5D$%22, re.IGNORECASE),%0D%0A    'COMPLIED_PYTHON_PATTERN': re.compile(%22.*.pyc$%22, re.IGNORECASE)%0D%0A%7D%0D%0A%0D%0Adef looks_like_a_backup(filename):%0D%0A    is_backup = False%0D%0A    for name, pattern in backup_patterns.items():%0D%0A        if bool(pattern.match(filename)):%0D%0A            is_backup = True%0D%0A    return is_backup
 %0D%0A%0D%0A

add more robust ignores to build process; fixes #26.