calibre-customize: When building plugins from a directory, exclude known version control subdirectories

This commit is contained in:
Kovid Goyal 2014-07-25 09:24:26 +05:30
parent d1674cc8a4
commit cdd267637b
2 changed files with 5 additions and 3 deletions

View File

@ -619,7 +619,7 @@ def build_plugin(path):
raise SystemExit(1)
t = PersistentTemporaryFile(u'.zip')
with ZipFile(t, u'w', ZIP_STORED) as zf:
zf.add_dir(path)
zf.add_dir(path, simple_filter=lambda x:x in {'.git', '.bzr', '.svn', '.hg'})
t.close()
plugin = add_plugin(t.name)
os.remove(t.name)

View File

@ -1303,7 +1303,7 @@ class ZipFile:
self.filelist.append(zinfo)
self.NameToInfo[zinfo.filename] = zinfo
def add_dir(self, path, prefix=''):
def add_dir(self, path, prefix='', simple_filter=lambda x:False):
'''
Add a directory recursively to the zip file with an optional prefix.
'''
@ -1314,9 +1314,11 @@ class ZipFile:
os.chdir(path)
fp = (prefix + ('/' if prefix else '')).replace('//', '/')
for f in os.listdir('.'):
if simple_filter(f): # Added by Kovid
continue
arcname = fp + f
if os.path.isdir(f):
self.add_dir(f, prefix=arcname)
self.add_dir(f, prefix=arcname, simple_filter=simple_filter)
else:
self.write(f, arcname)
finally: