Created
December 14, 2018 07:39
-
-
Save DuckOfDoom/40675ba363a4de5c9f0d96924827b1eb to your computer and use it in GitHub Desktop.
Zip dSYM files from Downloads folder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!python | |
import os | |
import shutil | |
from zipfile import ZipFile | |
import zipfile | |
os.chdir(os.environ["HOME"] + "/Downloads") | |
def findfile(f): | |
for item in os.listdir("."): | |
if f(item): | |
return item | |
packagename = | |
dsym_file_name = | |
plist_file_name = | |
zipname = packagename + ".zip" | |
dirs = packagename + "/Contents/Resources/DWARF/" | |
dsympath = dirs + "/" + dsym_file_name | |
plistpath = packagename + "/Contents/" + plist_file_name | |
if (os.path.exists(zipname)): | |
os.remove(zipname) | |
if (os.path.exists(packagename)): | |
shutil.rmtree(packagename) | |
os.makedirs(dirs) | |
dsym = findfile(lambda x: x == dsym_file_name) | |
plist = findfile(lambda x: x == plist_file_name) | |
if (dsym): | |
shutil.copy(dsym, dsympath) | |
os.remove(dsym) | |
print("Copied: " + dsym) | |
else: | |
print "no dsym file" | |
if (plist): | |
shutil.copy(plist, plistpath) | |
os.remove(plist) | |
print("Copied: " + plist) | |
else: | |
print "no plist file" | |
def zipdir(path, ziph): | |
# ziph is zipfile handle | |
for root, dirs, files in os.walk(path): | |
for file in files: | |
ziph.write(os.path.join(root, file)) | |
with ZipFile(zipname, 'w', zipfile.ZIP_DEFLATED) as z: | |
zipdir(packagename, z) | |
print "zipped: " + zipname | |
if (os.path.exists(packagename)): | |
shutil.rmtree(packagename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment