Skip to content

Instantly share code, notes, and snippets.

@thbaumann
Last active March 12, 2019 14:41
Show Gist options
  • Save thbaumann/7f617d4d3b3417fdb50ae9048e2056cc to your computer and use it in GitHub Desktop.
Save thbaumann/7f617d4d3b3417fdb50ae9048e2056cc to your computer and use it in GitHub Desktop.
Find macosx folder in qgis plugin zipfiles
# encoding: utf-8
from __future__ import unicode_literals
#-----------------------------------------------------------
# Copyright (C) 2019 Thomas Baumann
#-----------------------------------------------------------
# Licensed under the terms of GNU GPL 2
#
# This program 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 2 of the License, or
# (at your option) any later version.
#---------------------------------------------------------------------
from xml.dom.minidom import parseString
import zipfile
from StringIO import StringIO
import os
class MacFinder():
def __init__(self,path):
self.total_zipfile=0
self.count_bad_zipfile=0
self.count_good_zipfile=0
self.count_no_zipfile=0
self.scan_files(path)
def scan_files(self,folderpath):
print (' - '*8)+('Plugins with macosx-folder: ')+(' - '*8)
for root, subdirs, files in os.walk(folderpath):
for filename in files:
if filename.endswith('.zip'):
self.total_zipfile+=1
if self.findmacfolder(os.path.join(root, filename))==True:
print filename
else:
continue
print (' - '*25)
print('-- Score --\n'\
+'Total number of Zipfiles: {}\n'\
+'Bad Zipfiles: {}\n'\
+'Good Zipfiles: {}\n'\
+'No Zipfiles: {}\n').format(self.total_zipfile, self.count_bad_zipfile,self.count_good_zipfile,self.count_no_zipfile)
def findmacfolder(self,zipfile_name):
if zipfile.is_zipfile(zipfile_name) != True:
self.count_no_zipfile+=1
return False
current_zipfile = zipfile.ZipFile(zipfile_name, allowZip64 = True)
for name in current_zipfile.namelist():
if '__MACOSX' in name:
self.count_bad_zipfile+=1
return True
self.count_good_zipfile+=1
return False
MacFinder('/path/to/my/plugin-folder')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment