We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
有的时候需要在mac或linux的server生成一写window用的zip资源,但是
https://msdn.microsoft.com/en-us/library/windows/desktop/gg258117(v=vs.85).aspx
··· python
#!/usr/bin/python
import sys import os import zipfile import shutil
inputZipPath = os.path.normpath(str(sys.argv[1]))
print 'inputZipPath', inputZipPath print '-----------------------------------'
inputZipDirPath = os.path.dirname(inputZipPath) inputZipBasename = os.path.basename(inputZipPath) inputTempZipPath = os.path.join(inputZipDirPath, '__' + inputZipBasename)
shutil.copyfile(inputZipPath, inputTempZipPath) print 'copy temp file to', inputTempZipPath
with zipfile.ZipFile(inputTempZipPath, 'r', zipfile.ZIP_DEFLATED) as inputTargetZip: with zipfile.ZipFile(inputZipPath, 'w', zipfile.ZIP_DEFLATED) as outputTargetZip: for inputfileinfo in inputTargetZip.infolist(): inputfilename = inputfileinfo.filename inputfileIsDir = inputfilename.endswith('/') inputfilenameDepth = len(inputfilename.split('/')) if inputfileIsDir: inputfilenameDepth -= 1 inputfilebasename = os.path.basename(inputfilename) inputfilepurename = os.path.splitext(inputfilebasename)[0] inputfileextname = os.path.splitext(inputfilebasename)[1]
# print inputfilename # print inputfilenameDepth #we make the fake create_system inputfileinfo.create_system = 0 if inputfilenameDepth == 2: if(inputfileIsDir or (inputfileextname != '.exe' and inputfileextname != '.pdf')): # http://stackoverflow.com/questions/434641/how-do-i-set-permissions-attributes-on-a-file-in-a-zip-file-using-pythons-zip/6297838#6297838 # http://unix.stackexchange.com/questions/14705/the-zip-formats-external-file-attribute # https://msdn.microsoft.com/en-us/library/windows/desktop/gg258117(v=vs.85).aspx print inputfilename print hex(inputfileinfo.external_attr) #inputfileinfo.external_attr = inputfileinfo.external_attr | 0x2 #print inputfileinfo.create_system if(inputfileIsDir): inputfileinfo.external_attr = 0x12 else: inputfileinfo.external_attr = 0x2 print 'change to' print hex(inputfileinfo.external_attr) outputTargetZip.writestr(inputfileinfo, inputTargetZip.read(inputfilename))
os.remove(inputTempZipPath)
···
The text was updated successfully, but these errors were encountered:
No branches or pull requests
有的时候需要在mac或linux的server生成一写window用的zip资源,但是
https://msdn.microsoft.com/en-us/library/windows/desktop/gg258117(v=vs.85).aspx
··· python
#!/usr/bin/python
-- coding: utf-8 --
import sys
import os
import zipfile
import shutil
inputZipPath = os.path.normpath(str(sys.argv[1]))
print 'inputZipPath', inputZipPath
print '-----------------------------------'
inputZipDirPath = os.path.dirname(inputZipPath)
inputZipBasename = os.path.basename(inputZipPath)
inputTempZipPath = os.path.join(inputZipDirPath, '__' + inputZipBasename)
shutil.copyfile(inputZipPath, inputTempZipPath)
print 'copy temp file to', inputTempZipPath
with zipfile.ZipFile(inputTempZipPath, 'r', zipfile.ZIP_DEFLATED) as inputTargetZip:
with zipfile.ZipFile(inputZipPath, 'w', zipfile.ZIP_DEFLATED) as outputTargetZip:
for inputfileinfo in inputTargetZip.infolist():
inputfilename = inputfileinfo.filename
inputfileIsDir = inputfilename.endswith('/')
inputfilenameDepth = len(inputfilename.split('/'))
if inputfileIsDir: inputfilenameDepth -= 1
inputfilebasename = os.path.basename(inputfilename)
inputfilepurename = os.path.splitext(inputfilebasename)[0]
inputfileextname = os.path.splitext(inputfilebasename)[1]
os.remove(inputTempZipPath)
···
The text was updated successfully, but these errors were encountered: